调取微信支付的方法

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

                    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);

                    });

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容