当面付条码支付和扫码支付实例(5)

// (必填) 商户网站订单系统中唯一订单号,64个字符以内,只能包含字母、数字、下划线, // 需保证商户系统端不能重复,建议通过数据库sequence生成, $outTradeNo = "barpay" . date('Ymdhis') . mt_rand(100, 1000); $subject = "方倍工作室-支付宝-当面付-扫码支付"; $totalAmount = 0.01; // (必填) 订单总金额,单位为元,不能超过1亿元 // (必填) 付款条码,用户支付宝钱包手机app点击“付款”产生的付款条码 $authCode = $_POST['auth_code']; //28开头18位数字 // 支付超时,线下扫码交易定义为5分钟 $timeExpress = "5m"; // 创建请求builder,设置请求参数 $barPayRequestBuilder = new AlipayTradePayContentBuilder(); $barPayRequestBuilder->setOutTradeNo($outTradeNo); $barPayRequestBuilder->setTotalAmount($totalAmount); $barPayRequestBuilder->setAuthCode($authCode); $barPayRequestBuilder->setTimeExpress($timeExpress); $barPayRequestBuilder->setSubject($subject); // 调用barPay方法获取当面付应答 $barPay = new AlipayTradeService($config); $barPayResult = $barPay->barPay($barPayRequestBuilder); switch ($barPayResult->getTradeStatus()) { case "SUCCESS": echo "支付宝支付成功:" . "<br>--------------------------<br>"; print_r($barPayResult->getResponse()); break; case "FAILED": echo "支付宝支付失败!!!" . "<br>--------------------------<br>"; if (!empty($barPayResult->getResponse())) { print_r($barPayResult->getResponse()); } break; case "UNKNOWN": echo "系统异常,订单状态未知!!!" . "<br>--------------------------<br>"; if (!empty($barPayResult->getResponse())) { print_r($barPayResult->getResponse()); } break; default: echo "不支持的交易状态,交易返回异常!!!"; break; } return; }

程序监测,最终提交的url如下


发送的json数据如下:

{ "scene":"bar_code", "out_trade_no":"barpay20160826051452680", "total_amount":0.01, "auth_code":"289743098358423535", "timeout_express":"5m", "subject":"方倍工作室-支付宝-当面付-扫码支付" }

接收到的数据如下

{ "alipay_trade_pay_response":{ "code":"10000", "msg":"Success", "buyer_logon_id":"118***@qq.com", "buyer_pay_amount":"0.01", "buyer_user_id":"2088002364008751", "fund_bill_list":[ { "amount":"0.01", "fund_channel":"ALIPAYACCOUNT" } ], "gmt_payment":"2016-08-26 17:14:59", "invoice_amount":"0.01", "open_id":"20880044751374809757987911112575", "out_trade_no":"barpay20160826051452680", "point_amount":"0.00", "receipt_amount":"0.01", "total_amount":"0.01", "trade_no":"2016082621001004750244100034" }, "sign":"pEDeMwh6x73t9LmWrZpGnVb1npnKtODw6+8MDUTurNPVWXR1JHT+x3cRt2G4SDNHzxkJTzSpUXjNylsWisRTnQJJzqRP5XMujxmaAHP/d5xXeyWasDag5Cj7yGD7t80buDAsdE4eoqQ6ox7KzJ6LwKcphOX13tI+Ukt1dGCQS5o=" }

2. 扫码支付
扫码支付的参数配置如下

// (必填) 商户网站订单系统中唯一订单号,64个字符以内,只能包含字母、数字、下划线, // 需保证商户系统端不能重复,建议通过数据库sequence生成, $outTradeNo = "qrpay".date('Ymdhis').mt_rand(100,1000); $subject = "方倍工作室-支付宝-当面付-扫码支付"; $totalAmount = "0.01"; // 支付超时,线下扫码交易定义为5分钟 $timeExpress = "5m"; // 创建请求builder,设置请求参数 $qrPayRequestBuilder = new AlipayTradePrecreateContentBuilder(); $qrPayRequestBuilder->setOutTradeNo($outTradeNo); $qrPayRequestBuilder->setTotalAmount($totalAmount); $qrPayRequestBuilder->setTimeExpress($timeExpress); $qrPayRequestBuilder->setSubject($subject); // 调用qrPay方法获取当面付应答 $qrPay = new AlipayTradeService($config); $qrPayResult = $qrPay->qrPay($qrPayRequestBuilder); // 根据状态值进行业务处理 switch ($qrPayResult->getTradeStatus()){ case "SUCCESS": echo "支付宝创建订单二维码成功:"."<br>---------------------------------------<br>"; $response = $qrPayResult->getResponse(); $qrcode = $qrPay->create_erweima($response->qr_code); echo $qrcode; print_r($response); break; case "FAILED": echo "支付宝创建订单二维码失败!!!"."<br>--------------------------<br>"; if(!empty($qrPayResult->getResponse())){ print_r($qrPayResult->getResponse()); } break; case "UNKNOWN": echo "系统异常,状态未知!!!"."<br>--------------------------<br>"; if(!empty($qrPayResult->getResponse())){ print_r($qrPayResult->getResponse()); } break; default: echo "不支持的返回状态,创建订单二维码返回异常!!!"; break; }

生成的提交请求URL如下


发送的json数据如下:

{ "out_trade_no":"qrpay20160826053813582", "total_amount":"0.01", "timeout_express":"5m", "subject":"方倍工作室-支付宝-当面付-扫码支付" }

返回的数据如下:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/424033d3d1c500fceaff14f944b4cc6f.html