小程序支付代码示例
onPayTest() {
var data = {
"nonceStr": "23",
"timeStamp": "1528098190",
"signType": "MD5",
"paySign": "ED55C8",
"package": "0492238"
}
wx.requestPayment({
'timeStamp': data.timeStamp,
'nonceStr': data.nonceStr,
'package': "prepay_id=" + data.package,
'signType': data.signType,
'paySign': data.paySign,
'success': function (res) {
console.log("发起支付 res=>", res);
if (res.errMsg.indexOf("ok") != -1) {
wx.showModal({
title: '',
content: "已完成支付",
showCancel: false,
success: function (res) {
}
});
} else {
wx.showModal({
title: '',
content: res.errMsg + "",
showCancel: false,
success: function (res) {
}
});
}
},
'fail': function (err) {
console.log("发起支付 err=>", err);
if (err && err.errMsg == "requestPayment:fail cancel") {
//取消支付
} else {
}
}
})
}
参考文档:
1、https://pay.weixin.qq.com/static/applyment_guide/applyment_detail_miniapp.shtml
2、https://developers.weixin.qq.com/miniprogram/dev/api/payment/wx.requestPayment.html