1、调起支付
/*
**凯翼云
**
**/
public function kaiyiyun($order_id, $price, $pay_style){
//商户ID
$customerid="xxxxxxxx";
//商户流水号
$sdcustomno=$order_id;
$ordermoney = $price*100;
//支付方式
$cardno="3";
//后台通知地址,商户系统后台接收订单结果的地址
$noticeurl= 'http://' . $_SERVER['HTTP_HOST'] . U('pay/kyalipay_notify');
$backurl = 'http://' . $_SERVER['HTTP_HOST'] . U('user/index');
//商户自定义
$mark=time()+"";
//商户密钥,请登陆商户后台查询
$key="xxxxxxxxxxxxxxxxxxx";
//组合字符串
$signstr="customerid=".$customerid."&sdcustomno=".$sdcustomno."&orderAmount=".$ordermoney."&cardno=".$cardno."¬iceurl=".$noticeurl."&backurl=".$backurl.$key;
//生成MD5签名 strtoupper
$sign=strtoupper(md5($signstr,false));
if($pay_style=="wechat"){
$api_url = 'http://apt.n12.net/intf/wapwpay.html'; //不同通道使用
}else{
$api_url = 'http://apt.n12.net/intf/wapali.html';
}
echo '<html>
<head><title>跳转中...</title></head>
<body>
<form id="post_data" action="'.$api_url.'" method="post">
<input type="hidden" name="customerid" value="'.$customerid.'"/>
<input type="hidden" name="sdcustomno" value="'.$sdcustomno.'"/>
<input type="hidden" name="orderAmount" value="'.$ordermoney.'"/>
<input type="hidden" name="cardno" value="'.$cardno.'"/>
<input type="hidden" name="noticeurl" value="'.$noticeurl.'"/>
<input type="hidden" name="backurl" value="'.$backurl.'"/>
<input type="hidden" name="mark" value="'.$mark.'"/>
<input type="hidden" name="sign" value="'.$sign.'"/>
</form>
<script>document.getElementById("post_data").submit();</script>
</body>
</html>';
}
2、处理回调
public function kyalipay_notify(){
file_put_contents("kyPay.txt", var_export($_GET, 1).PHP_EOL, FILE_APPEND);
$state=trim($_GET['state']);
//商户在网关上的ID
$customerid=trim($_GET['customerid']);
//订单流水号
$sd51no=trim($_GET['sd51no']);
//商户提交的订单流水号
$sdcustomno=trim($_GET['sdcustomno']);
//商户订单金额
$ordermoney=trim($_GET['ordermoney']);
//商户自定义原样返回
$mark=trim($_GET['mark']);
//提交过来的MD5签名
$sign=trim($_GET['sign']);
$resign=trim($_GET['resign']);
$des=trim($_GET['des']);
//商户在网关上的交易密钥,登录商户后台可自行查询修改
$key="xxxxxxxxxxxxxxxxx";
$signstr='customerid='.$customerid.'&sd51no='.$sd51no.'&sdcustomno='.$sdcustomno.'&mark='.$mark.'&key='.$key.'';
//验证MD5签名
$signtmp=strtoupper(md5($signstr,false));
$signstr2='sign='.$signtmp.'&customerid='.$customerid.'&ordermoney='.$ordermoney.'&sd51no='.$sd51no.'&state='.$state.'&key='.$key.'';
$signtmp2=strtoupper(md5($signstr2,false));
//MD5签名正确
if ($sign==$signtmp && $resign==$signtmp2){
if ($state==1){
$ordernums = $sdcustomno;
$order=M('order')->where("ordernums='".$ordernums."'")->find();
if ($order) {
if ($order['orderswitch']==0) {
M('order')->where(['id'=>$order['id']])->setField('orderswitch', 1);
//TPDO::处理订单
}
}
}else{
header("HTTP/1.0 405 Method Not Allowed");
exit();
}
echo "<result>1</result>";
}else{
echo "customerid=".$customerid."&sd51no=".$sd51no."&sdcustomno=".$sdcustomno."&mark=".$mark."&key=".$key;
}
}