本文實例為大家分享了小程序調用微信支付的具體代碼,供大家參考,具體內容如下
首先調用小程序wx.login登錄接口 獲取用戶code
將code作為參數(shù) 傳給后端 調用后端接口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) } })
另外有需要云服務器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。