query("SELECT * FROM `".$db_config["def"]."member` WHERE `uid`='".$_COOKIE['uid']."' limit 1");
$member=$db->fetch_array($member_sql);
if($member['usertype'] != $_COOKIE['usertype']||md5($member['username'].$member['password'].$member['salt'])!=$_COOKIE['shell']){
echo '登录信息验证错误,请重新登录!';die;
}
$sql=$db->query("select * from `".$db_config["def"]."company_order` where `order_id`='$_POST[dingdan]' AND `order_price`>=0");
$row=$db->fetch_array($sql);
if(!$row['uid'] || $row['uid']!=$_COOKIE['uid'])
{
die;
}
if($_POST['coupon'] && $row['coupon']==""){
$where="`uid`='".$_COOKIE['uid']."' and `id`='".$_POST['coupon']."' and `validity`>'".time()."' and `status`='1' and `coupon_scope`<='".$row['order_price']."'";
$cousql=$db->query("select * from `".$db_config["def"]."coupon_list` where ".$where);
$coupon=$db->fetch_array($cousql);
$row['order_price']=sprintf("%.2f", $row['order_price']-$coupon['coupon_amount']);
if($row['order_price']<0){$row['order_price']='0.01';}
if($coupon['id']&&$row['coupon']<'1'){
$db->query("update `".$db_config[def]."coupon_list` set `status`='2',`xf_time`='".time()."' where `id`='".$coupon['id']."'");
$db->query("update `".$db_config[def]."company_order` set `coupon`='".$_POST['coupon']."',`order_price`='".$row['order_price']."' where `id`='".$row['id']."'");
}
}
if($invoice_title){
$up_order=$db->query("update `".$db_config["def"]."company_order` set `is_invoice`='".$_POST['is_invoice']."',`order_bank`='bank' where `order_id`='".$row['order_id']."'");
$db->fetch_array($up_order);//更改订单发票信息
}
/* 商户号 */
$bargainor_id = $tenpaydata[sy_tenpayid];
/* 密钥 */
$key = $tenpaydata[sy_tenpaycode];
/* 返回处理地址 */
$return_url = $tenpaydata[sy_weburl]."/api/tenpay/return_url.php";
//date_default_timezone_set(PRC);
$strDate = date("Ymd");
$strTime = date("His");
//4位随机数
$randNum = rand(1000, 9999);
$attach=$_POST[pay_type];
//10位序列号,可以自行调整。
$strReq = $strTime . $randNum;
/* 商家订单号,长度若超过32位,取前32位。财付通只记录商家订单号,不保证唯一。 */
$sp_billno = $_POST[dingdan];
/* 财付通交易单号,规则为:10位商户号+8位时间(YYYYmmdd)+10位流水号 */
$transaction_id =trim($bargainor_id.$strDate.$strReq);
/* 商品价格(包含运费),以分为单位 */
$total_fee = $row[order_price]*100;
//$total_fee = 1;
/* 商品名称 */
$desc = "订单号:" . $transaction_id;
/* 创建支付请求对象 */
$reqHandler = new PayRequestHandler();
$reqHandler->init();
$reqHandler->setKey($key);
//----------------------------------------
//设置支付参数
//----------------------------------------
$reqHandler->setParameter("bargainor_id", $bargainor_id); //商户号
$reqHandler->setParameter("transaction_id", $transaction_id); //财付通交易单号
$reqHandler->setParameter("sp_billno", $sp_billno); //商户订单号
$reqHandler->setParameter("total_fee", $total_fee); //商品总金额,以分为单位
$reqHandler->setParameter("return_url", $return_url); //返回处理地址
$reqHandler->setParameter("desc", "订单号:" . $transaction_id); //商品名称
$reqHandler->setParameter("attach", $attach); //自定义参数
//用户ip,测试环境时不要加这个ip参数,正式环境再加此参数
//$reqHandler->setParameter("spbill_create_ip", $_SERVER['REMOTE_ADDR']);
//请求的URL
$reqUrl = $reqHandler->getRequestURL();
//debug信息
//$debugInfo = $reqHandler->getDebugInfo();
//echo "
" . $reqUrl . "
";
//echo "
" . $debugInfo . "
";
//重定向到财付通支付
//$reqHandler->doSend();
Header("Location:$reqUrl");
?>