uniapp端,前端代码
// 在需要的地方引入 //#ifdef APP-PLUS AliPayApp(this); //#endif // 支付宝app支付 function AliPayApp(that) { console.log('AliPayApp') // 1、获取支付宝订单信息 that.$http.httpGet('/app.php',{ courseid: that.courseId, type: 'AliPayApp', }).then((res) => { // console.log(res.data); uni.requestPayment({ provider: 'alipay', orderInfo: res.data, success: function(res) { // console.log('success:' + JSON.stringify(res)); that.$utils.msg('支付成功'); that.$utils.redirectTo('my/myorder'); }, fail: function(err) { // console.log('fail:' + JSON.stringify(err)); that.$utils.msg(err.errMsg) } }); }).catch((error) => { console.log(error); }); }
app.php端代码
// 1、引入支付宝sdk require '../alipay/AopClient.php'; require '../alipay/request/AlipayTradeAppPayRequest.php';
// 2、支付宝订单信息 $alipay_order_info = AliPayApp($oid,$price); exit(json_encode(array('code' => 0,"msg" => "获取成功!","data" => $alipay_order_info))); }
3、AliPayApp函数 function AliPayApp($oid,$price){ $aop = new AopClient; $aop->gatewayUrl = "https://openapi.alipay.com/gateway.do"; $aop->appId = ""; $aop->rsaPrivateKey = ''; $aop->format = "json"; $aop->charset = "UTF-8"; $aop->signType = "RSA2"; $aop->alipayrsaPublicKey = ''; $request = new AlipayTradeAppPayRequest(); $bizcontent = "{/"body/":/"ZZZ/"," . "/"subject/": /"ZZZ/"," . "/"out_trade_no/": /"".$oid."/"," . "/"timeout_express/": /"30m/"," . "/"total_amount/": /"".$price."/"," . "/"product_code/":/"QUICK_MSECURITY_PAY/"" . "}"; $request->setNotifyUrl("http://www.boruiweb.com/api/v1/app_alipay_notify.php"); $request->setBizContent($bizcontent); $res = $aop->sdkExecute($request); return $res; }
支付宝app下单接口
支付宝sdk下载
原创文章,作者:sunnyman218,如若转载,请注明出处:https://blog.ytso.com/273236.html