本篇文章為大家展示了微信小程序與webview交互實(shí)現(xiàn)支付功能,內(nèi)容簡(jiǎn)明扼要并且容易理解,絕對(duì)能使你眼前一亮,通過(guò)這篇文章的詳細(xì)介紹希望你能有所收獲。
成都創(chuàng)新互聯(lián)專注于網(wǎng)站建設(shè)|成都網(wǎng)站維護(hù)|優(yōu)化|托管以及網(wǎng)絡(luò)推廣,積累了大量的網(wǎng)站設(shè)計(jì)與制作經(jīng)驗(yàn),為許多企業(yè)提供了網(wǎng)站定制設(shè)計(jì)服務(wù),案例作品覆蓋發(fā)電機(jī)維修等行業(yè)。能根據(jù)企業(yè)所處的行業(yè)與銷售的產(chǎn)品,結(jié)合品牌形象的塑造,量身定制品質(zhì)網(wǎng)站。
實(shí)現(xiàn)原理:點(diǎn)擊h6網(wǎng)頁(yè)的支付按鈕——(跳轉(zhuǎn))——>嵌套改h6的小程序的支付頁(yè)面——(處理支付)——>跳轉(zhuǎn)至支付完成后的頁(yè)面
注意:(1)網(wǎng)頁(yè)h6中,引入微信的jssdk
<script type="text/javascript" src="//res.wx.qq.com/open/js/jweixin-1.3.2.js"></script>
(2)小程序嵌套h6頁(yè)面后,需要在微信公眾平臺(tái)配置h6網(wǎng)頁(yè)的業(yè)務(wù)邏輯名,否則無(wú)法訪問(wèn)(且配置業(yè)務(wù)邏輯名的小程序只能是企業(yè)小程序,個(gè)人小程序暫時(shí)無(wú)法實(shí)現(xiàn))。
操作:登錄微信公眾平臺(tái)————開(kāi)發(fā)——————開(kāi)發(fā)設(shè)置
小程序目錄
<!--webview中(小程序page)--> //pages/lnyc2019/index.wxml <web-view class='page_web' src="{{url}}"></web-view> //pages/lnyc2019/index.js Page({ data: { url:'https://xxxxxxxx/wxmini/index.html'//h6地址 } })
<!--wxPay中(小程序page)--> // pages/wxPay/index.js Page({ data: { payTempcode:'', ordercode:'', payParam:{} }, onLoad: function (options) { console.log('支付開(kāi)始'); console.log(options); this.setData({ ordercode: options.ordercode }); this.getTempcode(); }, // 換取支付臨時(shí)code getTempcode:function(){ wx.login({ success: res => { // 發(fā)送 res.code 到后臺(tái)換取 openId, sessionKey, unionId this.setData({ payTempcode:res.code }); console.log('支付code:', this.data.payTempcode); this.getPayinfo(); } }) }, // 換取支付參數(shù) getPayinfo:function(){ var self=this; wx.request({ url: 'https://xxxxxx/pay/xcxpay',//后臺(tái)接口地址 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); // 調(diào)起支付 wx.requestPayment({ 'timeStamp': self.data.payParam.time,//為字符串,否則報(bào)錯(cuò) '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個(gè)頁(yè)面 }) } }) } }) } })
上述內(nèi)容就是微信小程序與webview交互實(shí)現(xiàn)支付功能,你們學(xué)到知識(shí)或技能了嗎?如果還想學(xué)到更多技能或者豐富自己的知識(shí)儲(chǔ)備,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道。
分享題目:微信小程序與webview交互實(shí)現(xiàn)支付功能
本文來(lái)源:http://aaarwkj.com/article24/ijppje.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供電子商務(wù)、外貿(mào)建站、定制開(kāi)發(fā)、網(wǎng)站導(dǎo)航、服務(wù)器托管、品牌網(wǎng)站設(shè)計(jì)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)