微信小程序与webview交互实现支付功能
本篇文章为大家展示了微信小程序与webview交互实现支付功能,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。
成都创新互联专注于网站建设|成都网站维护|优化|托管以及网络推广,积累了大量的网站设计与制作经验,为许多企业提供了网站定制设计服务,案例作品覆盖发电机维修等行业。能根据企业所处的行业与销售的产品,结合品牌形象的塑造,量身定制品质网站。
实现原理:点击h6网页的支付按钮——(跳转)——>嵌套改h6的小程序的支付页面——(处理支付)——>跳转至支付完成后的页面
注意:(1)网页h6中,引入微信的jssdk
(2)小程序嵌套h6页面后,需要在微信公众平台配置h6网页的业务逻辑名,否则无法访问(且配置业务逻辑名的小程序只能是企业小程序,个人小程序暂时无法实现)。
操作:登录微信公众平台————开发——————开发设置

小程序目录

//pages/lnyc2019/index.wxml//pages/lnyc2019/index.js Page({ data: { url:'https://xxxxxxxx/wxmini/index.html'//h6地址 } })
// pages/wxPay/index.js
Page({
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个页面
})
}
})
}
})
}
})上述内容就是微信小程序与webview交互实现支付功能,你们学到知识或技能了吗?如果还想学到更多技能或者丰富自己的知识储备,欢迎关注创新互联行业资讯频道。
当前文章:微信小程序与webview交互实现支付功能
文章路径:http://www.jxjierui.cn/article/ijppje.html


咨询
建站咨询
