文档:https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=7_7&index=6
需要的参数:
export default {
name: "friendPays",
data() {
return {
// 是否支付成功
isPaySuccess: false
};
},
payClick() {
// 是否支付成功--文字提示
if (this.isPaySuccess) {
return;
}
if (typeof WeixinJSBridge == "undefined") {
if (document.addEventListener) {
document.addEventListener(
"WeixinJSBridgeReady",
this.onBridgeReady,
false
);
} else if (document.attachEvent) {
document.attachEvent("WeixinJSBridgeReady", this.onBridgeReady);
document.attachEvent("onWeixinJSBridgeReady", this.onBridgeReady);
}
} else {
this.onBridgeReady();
}
},
onBridgeReady() {
//调起支付接口
this.$http.getPay(window.location.search).then(Response => {
if (Response.code === this.$http_status.success) {
WeixinJSBridge.invoke(
"getBrandWCPayRequest",
{
appId: Response.data.appId, //公众号名称,由商户传入
timeStamp: String(Response.data.timeStamp), //时间戳
nonceStr: Response.data.nonceStr, //随机串
package: Response.data.package,
signType: Response.data.signType, //微信签名方式:
paySign: Response.data.paySign //微信签名
},
res => {
if (res.err_msg === "get_brand_wcpay_request:ok") {
//支付成功
this.isPaySuccess = true;
// that.$router.replace({ name: "paymentend" });
} else if (res.err_msg === "get_brand_wcpay_request:cancel") {
$.toast("支付取消!", "text");
// alert("支付取消!");
} else {
$.toast("支付失败!", "text");
// alert("支付失败!");
}
}
);
}
});
}