微信支付、公众号支付、JSAPI,vue 调取微信支付功能
程序员文章站
2022-06-07 13:14:10
...
JSAPI微信支付 (需要在公众号后台配置一下,paydatac变量需要后台返回 微信签名之类的)
if (typeof WeixinJSBridge == "undefined") {
if (document.addEventListener) {
document.addEventListener('WeixinJSBridgeReady', _self.onBridgeReady, false);
} else if (document.attachEvent) {
document.attachEvent('WeixinJSBridgeReady', _self.onBridgeReady);
document.attachEvent('onWeixinJSBridgeReady', _self.onBridgeReady);
}
} else {
this.onBridgeReady(mypay);
}
公用方法
onBridgeReady(paydata) {
let self = this;
WeixinJSBridge.invoke(
'getBrandWCPayRequest', {
"appId": paydata.appId, //公众号名称,由商户传入
"timeStamp": paydata.timeStamp, //时间戳,自1970年以来的秒数
"nonceStr": paydata.nonceStr, //随机串
"package": paydata.package,
"signType": paydata.signType, //微信签名方式:
"paySign": paydata.paySign //微信签名
},
function (res) {
if (res.err_msg == "get_brand_wcpay_request:ok") {
self.isClick = false;
self.$router.replace({path: '/success'})
} else if (res.err_msg === 'get_brand_wcpay_request:cancel') {
self.isClick = false;
Toast('支付取消!')
} else {
self.isClick = false;
Toast('支付失败!')
}
});
}