微信小程序支付:业务流程
SDK与DEMO: 下载页
PHPPayDemo: demo
小程序端:
goPay(e){
var that = this;
//发起预支付,获取所需参数 wx.request({ url: app.globalData.host + \'/api/wx_pay/createOrder\', //请求地址 data: { openid: wx.getStorageSync(\'openid\'), total_fee: that.data.totalPrice, goods: JSON.stringify(that.data.goods) }, method: \'POST\', success(res){console.log(res)
if(res.data.code == 1){ //发起微信支付 wx.requestPayment({ timeStamp: res.data.data.timeStamp, nonceStr: res.data.data.nonceStr, package: res.data.data.package, signType: res.data.data.signType, paySign: res.data.data.paySign, success(r) {
console.log(r) //do something //比如回调,修改状态等操作 }, fail() { wx.showToast({ title: \'支付失败\', icon: \'none\' }) } }) }else{ wx.showToast({ title: res.data.data, icon: \'none\' }) } } }) },