uniapp implements WeChat official account payment

uniapp WeChat payment jsapi lacks the parameter appid
uniapp development WeChat official account uses the following methods to pay and sometimes reports an error


Change to the following payment (the following is the built-in payment of WeChat, no need to import anything)

 



 

改为以下支付即可(以下为微信内置支付,无需导入任何东西)
        WeixinJSBridge.invoke(
            'getBrandWCPayRequest', {
                "appId": res.data.data.appId, //公众号名称,由商户传入
                "timeStamp":res.data.data.timeStamp, //时间戳     
                "nonceStr":res.data.data.nonceStr, //随机串     
                "package": res.data.data.package,
                "signType":res.data.data.signType, //微信签名方式:     
                "paySign":res.data.data.paySign //微信签名 
            },
            function(ress) {
                if (ress.err_msg == "get_brand_wcpay_request:ok") {
                    uni.showToast({
                        icon: 'success',
                        title: '支付成功'
                    })
                    setTimeout(() => {
                        uni.navigateBack({
                            delta:2
                        })
                    }, 500);
                } else if (ress.err_msg == "get_brand_wcpay_request:cancel") {
                    uni.showToast({
                        icon: "none",
                        title: "'已取消支付"
                    })
                } else {
                    uni.showToast({
                        icon: "none",
                        title: "支付失败"
                    })
                }
            }
        );

Guess you like

Origin blog.csdn.net/YZ_ZZZ24/article/details/123479359