本篇文章為大家展示了微信小程序與webview交互實(shí)現(xiàn)支付功能,內(nèi)容簡(jiǎn)明扼要并且容易理解,絕對(duì)能使你眼前一亮,通過這篇文章的詳細(xì)介紹希望你能有所收獲。
成都創(chuàng)新互聯(lián)公司主營(yíng)市北網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營(yíng)網(wǎng)站建設(shè)方案,成都app開發(fā),市北h5成都小程序開發(fā)搭建,市北網(wǎng)站營(yíng)銷推廣歡迎市北等地區(qū)企業(yè)咨詢實(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ù)邏輯名,否則無法訪問(且配置業(yè)務(wù)邏輯名的小程序只能是企業(yè)小程序,個(gè)人小程序暫時(shí)無法實(shí)現(xiàn))。
操作:登錄微信公眾平臺(tái)————開發(fā)——————開發(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('支付開始'); 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)成都網(wǎng)站設(shè)計(jì)公司行業(yè)資訊頻道。
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。
網(wǎng)站標(biāo)題:微信小程序與webview交互實(shí)現(xiàn)支付功能-創(chuàng)新互聯(lián)
地址分享:http://muchs.cn/article24/cdoice.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站改版、搜索引擎優(yōu)化、企業(yè)網(wǎng)站制作、營(yíng)銷型網(wǎng)站建設(shè)、標(biāo)簽優(yōu)化、做網(wǎng)站
聲明:本網(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í)需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容