调取微信支付

//获取微信支付接口信息

                http.post(`${api.api}/config`,

                {

                    url: location.href.split("#")[0]//截取地址栏地址传到后台

                })

                .then((res) => {

                    //获取后台返回的参数

                    this.appId = res.data.appId

                    this.nonce = res.data.nonce

                    this.signature = res.data.signature

                    this.timestamp = res.data.timestamp

                    //调取微信官方config接口

                    wx.config({

                    debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。

                    appId: this.appId, // 必填,公众号的唯一标识

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

                    nonceStr: this.nonce, // 必填,生成签名的随机串

                    signature: this.signature,// 必填,签名

                    jsApiList: ['chooseWXPay'] // 必填,需要使用的JS接口列表

                });

                })

                .catch((error) => {

                    console.log(error);

                });

                //调取后台接口,获取下单信息,并用wx.ready调取微信支付方法

                var id = JSON.parse(localStorage.getItem('token')).id

                http.get(`${api.api}/orders?id=${id}&money=${this.total*100}&type=${0}&count=${this.date}&acount=${this.count}`)

                .then((res) => {

                    console.log(res)

                    wx.ready(()=>{

                        wx.chooseWXPay({

                            timestamp: res.data.timeStamp, // 支付签名时间戳,注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符

                            nonceStr: res.data.nonceStr, // 支付签名随机串,不长于 32 位

                            package: res.data.package, // 统一支付接口返回的prepay_id参数值,提交格式如:prepay_id=\*\*\*)

                            signType: 'MD5', // 签名方式,默认为'SHA1',使用新版支付需传入'MD5'

                            paySign: res.data.paySign, // 支付签名

                            success:  (res) => {

                            // 支付成功后的回调函数

                            this.$router.push({path:'/creditcard'})

                            }

                        });

                    })

                })

                .catch((error) => {

                    console.log(error);

                });
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值