一、开通app支付
1、代码片段
前端代码:
<!doctype html> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" /> <meta name="format-detection" content="telephone=no,email=no,date=no,address=no"> <title>底部导航</title> <link rel="stylesheet" type="text/css" href="css/weui/weui.min.css" /> <style> </style> </head> <body> 支付 </body> </html> <script type="text/javascript" src="script/api.js"></script> <script type="text/javascript" src="js/jquery-1.11.0.js"></script> <script type="text/javascript"> apiready = function() { aliPay(); } function aliPay() { api.ajax({ url: 'http://192.168.1.102:59770/api/home/getDemo', //url+模块 method: 'GET', dataType: 'text' }, function(ret, err) { var wxPay = api.require('wxPay'); //开发者通过 payOrder 方法来进行支付,自己处理订单信息以及签名过程 console.log("自己处理订单信息以及签名过程请求:", ret); var data = JSON.parse(ret); data = data.result; console.log("data:", data.noncestr); /* result = "{"result":{"appid":"wx6f6f4d261ef33980","noncestr":"645209991","package":"Sign=WXPay","partnerid":"1596592261","prepayid":"wx161223511269338d0d11bf3f1703145300","timestamp":"1592281432","sign":"A836BDC48F62D27910417330184FF0A1","mchid":"1596592261","returncode":"SUCCESS","returnmsg":"OK"}}"; return result; */ wxPay.payOrder({ apiKey: data.appid, orderId: data.prepayid, mchId: data.mchid, nonceStr: data.noncestr, timeStamp: data.timestamp, package: data.package, sign: data.sign }, function(ret, err) { if (ret.status) { //支付成功 } else { alert(err.code); } }); }); } </script>
后台代码:略