微信小程序前端支付代码
生活随笔
收集整理的這篇文章主要介紹了
微信小程序前端支付代码
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
<view bindtap ="requestPayment"></view>
// pages/paysrue/paysrue.jsPage({/** * 頁面的初始數據 */ data: { openid: '', order_id: '', paperId: '' }, requestPayment: function(){ var self = this
self.setData({ loading: true }) // 此處需要先調用wx.login方法獲取code,然后在服務端調用微信接口使用code換取下單用戶的openId // 具體文檔參考https://mp.weixin.qq.com/debug/wxadoc/dev/api/api-login.html?t=20161230#wxloginobject
console.log(self.data.order_id) console.log(self.data.openid) console.log(self.data.paperId) wx.request({ url: "http://caca.qianlh.com/home/jiekou/Wx_Pay", data: { 'order_id': self.data.order_id,//訂單號 'openid': self.data.openid, paper_id: self.data.paperId }, header: {//請求頭 "Content-Type": "application/x-www-form-urlencoded" }, method: "POST",//get為默認方法/POST success: function (res) { console.log('是統一下單方法返回值了'); console.log(res.data); wx.requestPayment({ 'nonceStr': res.data.nonceStr, 'package': res.data.package, 'signType': res.data.signType, 'timeStamp': res.data.timeStamp, 'paySign': res.data.paySign, 'success': function (res2) { console.log(res2); wx.redirectTo({ url: '../payover/payover', }) }, 'fail': function (res3) {
console.log('調用失敗---'); console.log(res3); } }) } }) }, /** * 生命周期函數--監聽頁面加載 */ onLoad: function (options) { var that = this that.setData({ order_id: options.order_id }) wx.getStorage({ /*微信小程序存儲數據的方式*/ key: 'openid', success: function (res) { console.log(res.data) that.setData({ openid: res.data }) } }) wx.getStorage({ key: 'paperId', success: function (res) { console.log(res.data) that.setData({ paperId: res.data }) } }) }
總結
以上是生活随笔為你收集整理的微信小程序前端支付代码的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 营收1086亿!联想第三财季业绩报告:P
- 下一篇: 三星s9和s10的区别(三星智能手机)