十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
本文实例为大家分享了小程序调用微信支付的具体代码,供大家参考,具体内容如下

首先调用小程序wx.login登录接口 获取用户code
将code作为参数 传给后端 调用后端接口wechat/pay/prepay
获取后端 这五个返回值
nonceStr
package2
paySign
signType
timeStamp
wx.login({
success: function (res) {
var userId = wx.getStorageSync('userId');
var passw = userId + orderId;
console.log(passw)
var password = util.sha1(passw);
//console.log(res) //获取用户的code 微信返回的值
wx.request({
url: url + 'wechat/pay/prepay',
method: "POST",
header: {
'content-type': 'application/json',
},
data: {
code: res.code, //微信返的code
userId: userId, //登录注册时后端返给我的
orderId: orderId, //用户提交时后端返给我的工单号
sign: password, //后端要求的serId + orderId加密
},
success: function (res) {
// if (res.data.resultCode == "000000"){
nonceStr = res.data.data.nonceStr;
package2 = res.data.data.package;
paySign = res.data.data.paySign;
signType = res.data.data.signType;
timeStamp = res.data.data.timeStamp;
that.pay2()
// }
console.log(res.data.data.nonceStr)
console.log(res.data.data.package)
console.log(res.data.data.paySign)
console.log(res.data.data.signType)
console.log(res.data.data.timeStamp)
},
fail(err) {
console.log(err)
}
})
},
fail(errs) {
console.log(errs)
}
})另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。