js 调用微信支付方法
Posted 我以为你不在乎
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了js 调用微信支付方法相关的知识,希望对你有一定的参考价值。
pay(){
let data ={
order_id:this.order_id,
wechatpay_type:this.wechatpay_type,
merchant_id:localStorage.merchant_id,
authentication_token:this.token,
client_token:this.client_token
}
this.$fetch(this.Wxpay, data)
.then(res=>{
if(res.code==200){
if (res.data.wechatpay_type == "wxpay") {
// 公众号支付
this.callWxPay(res.data.pay_param);
} else if (res.data.wechatpay_type == "wxpay_h5_wap") {
this.callWxPayH5(res.data.pay_param.mweb_url);
} else if (res.data.wechatpay_type == "wxpay_app") {
this.callWxPayAPP(res.data.pay_param);
} else {
Toast(‘无效的支付类型‘);
}
}else{
Toast(res.error)
}
},err=>{
alert(JSON.stringify(err))
})
},
jsApiCall(params) {
let that = this
WeixinJSBridge.invoke(
‘getBrandWCPayRequest‘, {
‘appId‘: params.appId,
‘timeStamp‘:params.timeStamp,
‘nonceStr‘: params.nonceStr,
‘package‘: params.package,
‘signType‘: params.signType,
‘paySign‘: params.paySign
},
function (res) {
if (res.err_msg === ‘get_brand_wcpay_request:ok‘) {
Toast(‘微信支付成功‘)
that.$router.replace({name:‘fullOrder‘,query:{id:‘2‘}})
} else if (res.err_msg === ‘get_brand_wcpay_request:cancel‘) {
Toast(‘用户取消支付‘)
that.$router.replace({name:‘fullOrder‘,query:{id:‘1‘}})
} else if (res.err_msg === ‘get_brand_wcpay_request:fail‘) {
Toast(‘网络异常,请重试‘)
}
}
);
},
callWxPay(params) {
if (typeof WeixinJSBridge == "undefined"){
if( document.addEventListener ){
document.addEventListener(‘WeixinJSBridgeReady‘, this.jsApiCall(params), false);
}else if (document.attachEvent){
document.attachEvent(‘WeixinJSBridgeReady‘, this.jsApiCall(params));
document.attachEvent(‘onWeixinJSBridgeReady‘, this.jsApiCall(params));
}
}else{
this.jsApiCall(params);
}
},
callWxPayH5(mweb_url) {
location.href = mweb_url;
},
callWxPayAPP(params) {
let dsBridge = require("dsbridge");
dsBridge.call("requestWeChatPay", params, function (data) {
alert(data);
})
},
wechatpaytype(){
if(this.isWeiXin()){
this.wechatpay_type=‘wxpay‘
}else{
this.wechatpay_type=‘wxpay_h5_wap‘
}
},
isWeiXin(){ //判断是否微信平台
var ua = window.navigator.userAgent.toLowerCase();
if (ua.match(/MicroMessenger/i) == ‘micromessenger‘){
return true;
} else {
return false;
}
}
以上是关于js 调用微信支付方法的主要内容,如果未能解决你的问题,请参考以下文章