微信小程序与webview交互实现支付功能

  介绍

本篇文章为大家展示了微信小程序与webview交互实现支付功能,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。

实现原理:点击到h6网页的支付按钮——跳(转)——在嵌套改仅有的小程序的支付页面——(处理支付)——在跳转至支付完成后的页面

注意:(1)网页编辑中,引入微信的jssdk

& lt; script 类型=拔谋?javascript", src=https://www.yisu.com/zixun/"//res.wx.qq.com/open/js/jweixin-1.3.2.js ">

(2)小程序嵌套编辑页面后,需要在微信公众平台配置代替网页的业务逻辑名,否则无法访问(且配置业务逻辑名的小程序只能是企业小程序,个人小程序暂时无法实现)。

操作:登录微信公众平台- - - - -开发- - - - - -开发设置

微信小程序与webview交互实现支付功能

<强>小程序目录

微信小程序与webview交互实现支付功能

& lt; !——webview中(小程序页面)——比;//页面/lnyc2019/index.wxml      ,& lt; web-view 类=& # 39;page_web& # 39;, src=皗{url}}“祝辞& lt;/web-view>      ,//页面/lnyc2019/index.js      页面({,      数据:时间{大敌;;      url: & # 39; https://xxxxxxxx/wxmini/index.html& # 39;//编辑地址,      },      }) & lt; !——wxPay中(小程序页面)——比;//页面/wxPay/index.js      页面({      ,数据:{      payTempcode才能:& # 39;& # 39;      ordercode才能:& # 39;& # 39;      payParam才能:{}      },      ,onLoad: function (选项),{      console.log才能(& # 39;支付开始& # 39;);      console.log才能(选项);      this.setData({才能      ,,ordercode: options.ordercode      ,,});      this.getTempcode才能();      },      ,//换取支付临时代码      ,getTempcode:函数(){      wx.login({才能      ,,,成功:res =祝辞,{      ,,,//,发送,res.code 到后台换取,openId,, sessionKey, unionId      ,,,this.setData ({      ,,,,payTempcode: res.code      ,,,});      ,,,console.log(& # 39;支付代码:& # 39;,,this.data.payTempcode);      ,      ,,,this.getPayinfo ();      ,,}      })才能      },      ,//换取支付参数      ,getPayinfo:函数(){      var 才能;自我=;      wx.request({才能      ,,,url: & # 39; https://xxxxxx/pay/xcxpay& # 39;//后台接口地址      ,,,数据:{      ,,,& # 39;wxcode& # 39;:, self.data.payTempcode,      ,,,& # 39;ordercode& # 39;:, self.data.ordercode,      ,,,& # 39;gid # 39;:, x,      ,,},      ,,,方法:& # 39;文章# 39;      ,,,成功:function  (res), {      ,,,console.log (res.data.data.payinfo);      ,,,self.setData ({      ,,,,payParam: res.data.data.payinfo      ,,,});      ,,,console.log(& # 39;支付的订单====& # 39;,self.data.ordercode);      ,,,//,调起支付      ,,,wx.requestPayment ({      ,,,,& # 39;时间戳# 39;:,self.data.payParam.time,//为字符串,否则报的错      ,,,,& # 39;nonceStr& # 39;:, self.data.payParam.nonce_str,      ,,,,& # 39;包# 39;:,“prepay_id=$ {self.data.payParam.prepay_id}”,      ,,,,& # 39;signType& # 39;:, & # 39; md5 # 39;      ,,,,& # 39;paySign& # 39;:, self.data.payParam.paysign,      ,,,,& # 39;成功# 39;:,function  (res), {      ,,,,,console.log (res)      ,,,,,console.log(& # 39;=======支付成功==========& # 39;);      ,,,,,wx.navigateTo ({      ,,,,,,url:,“/页/lnyc2019/细节? ordercode=$ {self.data.ordercode}’      ,,,,,})      ,,,,},      ,,,,& # 39;失败# 39;:,function  (res), {      ,,,,,console.log (res)      ,,,,,console.log(& # 39;=======支付失败==========& # 39;)      ,,,,,wx.navigateBack ({      ,,,,,,三角洲:,1//返回1个页面      ,,,,,})      ,,,,}      ,,,})      ,,}      })才能      ,}   })

上述内容就是微信小程序与webview交互实现支付功能,你们学到知识或技能了吗?如果还想学到更多技能或者丰富自己的知识储备,欢迎关注行业资讯频道。

微信小程序与webview交互实现支付功能