当面付、H5、PC、查询订单、退款订单、异步通知校验
class indexController extends Mb{
public $appid = '';//应用ID
public $PrivateKey = '';//商户私钥
public $alipayPublicKey = '';//支付宝公钥
public function index(){//扫码支付
$pay = t('AliPay')->setAppid($this->appid)->setPrivateKey($this->PrivateKey);
$outTradeNo = date("YmdHis",time()).rand(1000,9999);//生成订单号
$orderName = '一瓶矿泉水';
$payAmount = 2;//支付金额
$notifyUrl = 'http://www.liot.cn/index/notify';
$res = $pay->qrcodePay($outTradeNo,$orderName,$payAmount,$notifyUrl);
p($res);
}
public function pcpay(){//PC支付
$pay = t('AliPay')->setAppid($this->appid)->setPrivateKey($this->PrivateKey);
$outTradeNo = date("YmdHis",time()).rand(1000,9999);//生成订单号
$orderName = '一瓶矿泉水';
$payAmount = 2;//支付金额
$notifyUrl = 'http://www.liot.cn/index/notify';//用户支付成功后异步通知地址
$returnUrl = 'http://www.liot.cn';//用户支付成功后跳转的地址
$res = $pay->pcPay($outTradeNo,$orderName,$payAmount,$notifyUrl,$returnUrl);
p($res);
}
public function h5Pay(){//H5支付
$pay = t('AliPay')->setAppid($this->appid)->setPrivateKey($this->PrivateKey);
$outTradeNo = date("YmdHis",time()).rand(1000,9999);//生成订单号
$orderName = '一瓶矿泉水';
$payAmount = 2;//支付金额
$notifyUrl = 'http://www.liot.cn/index/notify';//用户支付成功后异步通知地址
$returnUrl = 'http://www.liot.cn';//用户支付成功后跳转的地址
$res = $pay->h5Pay($outTradeNo,$orderName,$payAmount,$notifyUrl,$returnUrl);
p($res);
}
public function notify(){//异步通知
$pay = t('AliPay')->setPublicKey($alipayPublicKey);
$res = $pay->rsaCheck($_POST,$_POST['sign_type']);
if($res===true && $_POST['trade_status'] == 'TRADE_SUCCESS'){
//处理你的逻辑,例如获取订单号$_POST['out_trade_no'],订单金额$_POST['total_amount']等
//程序执行完后必须打印输出“success”(不包含引号)。如果商户反馈给支付宝的字符不是success这7个字符,支付宝服务器会不断重发通知,直到超过24小时22分钟。一般情况下,25小时以内完成8次通知(通知的间隔频率一般是:4m,10m,10m,1h,2h,6h,15h);
//这里写用户付款成功后需执行的业务代码
echo 'success';exit();
}
t('writelog')->x('error');
}
public function Query(){//查询支付结果
$pay = t('AliPay')->setAppid($this->appid)->setPrivateKey($this->PrivateKey);
$res = $pay->PayQuery('2022122322001458841438390852',true);
p($res);
}
public function Close(){//关闭交易
$pay = t('AliPay')->setAppid($this->appid)->setPrivateKey($this->PrivateKey);
$res = $pay->PayClose('202212232258376155');
p($res);
}
public function Refund(){//订单退款
$pay = t('AliPay')->setAppid($this->appid)->setPrivateKey($this->PrivateKey);
$res = $pay->PayRefund(2,'202212232242121239');
p($res);
}
}可以赞助并支持下作者哦,谢谢!