小程序支付及H5支付前端代码小结
生活随笔
收集整理的這篇文章主要介紹了
小程序支付及H5支付前端代码小结
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
小程序支付和H5支付前端都不需要引入其他的js , 只需要后臺將相關(guān)的參數(shù)
(
timeStamp: '', nonceStr: '', package: '', signType: 'MD5', paySign: '',)
返回來就可以發(fā)起微信支付。
?
小程序支付:
wx.requestPayment({timeStamp: '',nonceStr: '',package: '',signType: 'MD5',paySign: '',success (res) { },fail (res) { } })?
H5支付:
1 callpay(needData) { 2 let that = this; 3 if (typeof WeixinJSBridge == "undefined") { 4 if (document.addEventListener) { 5 document.addEventListener('WeixinJSBridgeReady', that.jsApiCall, false); 6 } else if (document.attachEvent) { 7 document.attachEvent('WeixinJSBridgeReady', that.jsApiCall); 8 document.attachEvent('onWeixinJSBridgeReady', that.jsApiCall); 9 } 10 } else { 11 that.jsApiCall(needData); 12 } 13 }, 14 jsApiCall(needData) { 15 let that = this; 16 WeixinJSBridge.invoke( 17 'getBrandWCPayRequest', { 18 "appId": needData.appId, 19 "timeStamp": needData.timeStamp, 20 "nonceStr": needData.nonceStr, 21 "package": needData.package, 22 "signType": needData.signType, 23 "paySign": needData.paySign, 24 }, 25 function (res) { 26 27 if (res.err_msg == "get_brand_wcpay_request:ok") { 28 // alert('微信支付成功!'); 29 if (that.alonePay == true) { //單獨(dú)購買 30 window.location.href = "courseList.html" + "?goods_id=" + that 31 .goods_id; 32 } else { //拼團(tuán)購買 33 window.location.href = "groupDetail.html" + "?group_id=" + that 34 .group_id + "&goods_id=" + that.goods_id; 35 } 36 // window.location.href = "index.html"; 37 // window.location.href="http://h5.taotiangou.cn"; 38 } else if (res.err_msg == "get_brand_wcpay_request:cancel") { 39 alert('已取消微信支付!'); 40 // window.location.href = "index.html"; 41 // window.location.href="http://h5.taotiangou.cn"; 42 } else if (res.err_msg == "get_brand_wcpay_request:fail") { 43 alert('微信支付失敗!'); 44 // window.location.href = "index.html"; 45 46 // window.location.href="http://h5.taotiangou.cn"; 47 } 48 } 49 ); 50 },?
轉(zhuǎn)載于:https://www.cnblogs.com/teamemory/p/10977953.html
總結(jié)
以上是生活随笔為你收集整理的小程序支付及H5支付前端代码小结的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: centos7.3 安装 mysql-5
- 下一篇: CSS基础学习-15-1.CSS 浏览器