国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

微信小程序與webview交互實現支付功能

2019-11-19 11:22:24
字體:
來源:轉載
供稿:網友

實現原理:點擊h5網頁的支付按鈕――(跳轉)――>嵌套改h5的小程序的支付頁面――(處理支付)――>跳轉至支付完成后的頁面

注意:(1)網頁h5中,引入微信的jssdk

<script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.3.2.js"></script>

(2)小程序嵌套h5頁面后,需要在微信公眾平臺配置h5網頁的業務邏輯名,否則無法訪問(且配置業務邏輯名的小程序只能是企業小程序,個人小程序暫時無法實現)。

操作:登錄微信公眾平臺――――開發――――――開發設置

小程序目錄 

<!--webview中(小程序page)-->//pages/lnyc2019/index.wxml <web-view class='page_web' src="{{url}}"></web-view> //pages/lnyc2019/index.jsPage({   data: {     url:'https://xxxxxxxx/wxmini/index.html'//h5地址   } })
<!--wxPay中(小程序page)-->// pages/wxPay/index.jsPage({ data: {  payTempcode:'',  ordercode:'',  payParam:{} }, onLoad: function (options) {  console.log('支付開始');  console.log(options);  this.setData({   ordercode: options.ordercode  });  this.getTempcode(); }, // 換取支付臨時code getTempcode:function(){  wx.login({   success: res => {    // 發送 res.code 到后臺換取 openId, sessionKey, unionId    this.setData({     payTempcode:res.code    });    console.log('支付code:', this.data.payTempcode);     this.getPayinfo();   }  }) }, // 換取支付參數 getPayinfo:function(){  var self=this;  wx.request({   url: 'https://xxxxxx/pay/xcxpay',//后臺接口地址   data: {    'wxcode': self.data.payTempcode,    'ordercode': self.data.ordercode,    'gid': x,   },   method: 'POST',   success: function (res) {    console.log(res.data.data.payinfo);    self.setData({     payParam: res.data.data.payinfo    });    console.log('支付的訂單====',self.data.ordercode);    // 調起支付    wx.requestPayment({     'timeStamp': self.data.payParam.time,//為字符串,否則報錯     'nonceStr': self.data.payParam.nonce_str,     'package': `prepay_id=${self.data.payParam.prepay_id}`,     'signType': 'MD5',     'paySign': self.data.payParam.paysign,     'success': function (res) {      console.log(res)      console.log('=======支付成功==========');      wx.navigateTo({       url: `/pages/lnyc2019/detail?ordercode=${self.data.ordercode}`      })     },     'fail': function (res) {      console.log(res)      console.log('=======支付失敗==========')      wx.navigateBack({       delta: 1//返回1個頁面      })     }    })   }  }) }})

以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作具有一定的參考學習價值,謝謝大家對武林網的支持。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 津南区| 南郑县| 扎赉特旗| 什邡市| 翁源县| 五指山市| 延津县| 佛学| 交城县| 十堰市| 稻城县| 彭阳县| 农安县| 安远县| 莱州市| 涟源市| 若尔盖县| 厦门市| 吉林省| 刚察县| 额尔古纳市| 旺苍县| 金塔县| 衡东县| 古丈县| 略阳县| 伊宁市| 台南市| 定远县| 建始县| 年辖:市辖区| 汉寿县| 沂南县| 慈利县| 娄底市| 涿州市| 巨野县| 金平| 涡阳县| 惠水县| 阳泉市|