vue项目引入微信js-SDK

96
spring_zou
2018.07.10 20:16 字数 302

1、npm install --save-dev weixin-js-sdk

2、import wx from 'weixin-js-sdk';

mounted(){

wx.config({

                beta: true, // 必须这么写,否则wx.invoke调用形式的jsapi会有问题

                debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来

                appId: 'ww76673d8a0d7cd9d7', // 必填,企业微信的corpID

                timestamp: 1414587466, // 必填,生成签名的时间戳

                nonceStr: 'Wm3WZYTPz0wzccnC', // 必填,生成签名的随机串 必填,生成签名的随机串

                signature: that.ticketString, // 必填,签名

                jsApiList: ['getBrandWCPayRequest']

});

//H5网页支付例子

wx.invoke(

                'getBrandWCPayRequest', {

                    "appId": res.appId, //公众号名称,由商户传入

                    "timeStamp": res.timeStamp, //时间戳,自1970年以来的秒数

                    "nonceStr": res.nonceStr, //随机串

                    "package": res.packAge,

                    "signType": "MD5", //微信签名方式:

                    "paySign": res.signType //微信签名

                },

                function(res) {

                    Indicator.close();

                    var a = JSON.stringify(res);

                    if(res.err_msg == "get_brand_wcpay_request:ok") {

                        that.noLogin = false;

                        that.mySatake();

                        axios.get('/updateStatus/byOrderId?orderId='+that.orderId)

                        .then(()=>{

                            that.mySatake();

                            window.location.reload();

                        })

                        .catch(()=>{

                            Toast({message:"网络错误"})

                        })

                    }else{

                        that.mySatake();

                    } // 使用以上方式判断前端返回,微信团队郑重提示:res.err_msg将在用户支付成功后返回    ok,但并不保证它绝对可靠。

                }

            );

}


日记本
Web note ad 1