From 8ec39f1c3b4eea744c689d8cb1936ef45bd301c6 Mon Sep 17 00:00:00 2001 From: JinxChen <2183691628@qq.com> Date: Sat, 8 Apr 2023 16:39:34 +0800 Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E6=95=B4=E8=8E=B7=E5=8F=96openId?= =?UTF-8?q?=E7=9A=84=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/package-home/index.vue | 11 +++-------- src/views/package-list/index.vue | 22 ++++++++++++++++------ 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/views/package-home/index.vue b/src/views/package-home/index.vue index dde33a5..a0608ae 100644 --- a/src/views/package-home/index.vue +++ b/src/views/package-home/index.vue @@ -1,7 +1,7 @@ @@ -23,7 +23,6 @@ export default { return { params: {}, //获取路由的参数 isRecharge: null, //是否已经支付 - wxAuthCode: '' }; }, created() { @@ -64,13 +63,9 @@ export default { ) { let timeStamp = new Date().getTime(); let code = url.split("&")[0]; + console.log("code", code); if (isNotNull(code)) { - this.$store.commit("wxAuthCode", code); - this.wxAuthCode = code; - this.getOpenId(code); - setTimeout(() => { - this.getWxCode(); - },1000) + this.getWxCode(); } } else { this.getWxCode(); diff --git a/src/views/package-list/index.vue b/src/views/package-list/index.vue index c2bc6e6..e8bae71 100644 --- a/src/views/package-list/index.vue +++ b/src/views/package-list/index.vue @@ -146,6 +146,7 @@ export default { created() { this.getAuth(); this.getParams(); + this.getCode(); //this.getWxAutograph(); // 套餐列表 this.getDevicePayPackage(); @@ -153,8 +154,7 @@ export default { }, methods: { // 根据code获取openId - getOpenId() { - let code = this.$store.getters.wxAuthCode; + getOpenId(code) { APIPay.getOpenId(code).then(res => { let data= res.data; if(data.code === 20000) { @@ -170,11 +170,21 @@ export default { this.$store.commit("gatewayToken", res.data.data); }); }, + getCode() { + let url = window.location.href.split("?code=")[1]; + console.log("url", url); + if (isNotNull(url) ||window.location.href.indexOf("code") > -1) { + let code = url.split("&")[0]; + if (isNotNull(code)) { + this.getOpenId(code); + } + } + }, // 获取url传过来的参数 getParams() { let params = this.$route.query; + console.log("params", params); if (params) { - //this.getOpenId(); this.params = {...params}; } }, @@ -286,7 +296,7 @@ export default { this.aliPay(data); } else { // 微信 - let openId = this.$store.getters.openId; + let openId = this.openId; this.payProductId = payTypeToPackAgeId.filter(item => { return item.payType === '1' || item.payType === 1 })[0].productId; @@ -310,7 +320,7 @@ export default { console.log("微信支付", data); let orderData = data; let reqBody = { - openId: this.$store.getters.openId || this.openId, //openId + openId: this.openId, //openId imei: this.params.imei, //imei iccid: this.params.iccid, productId: this.payProductId, //套餐id @@ -463,7 +473,7 @@ export default { }); let orderData = data; let reqBody = { - openId: this.$store.getters.openId, //openId + openId: this.openId, //openId imei: this.params.imei, //imei iccid: this.params.iccid, productId: this.payProductId, //套餐id