diff --git a/README.md b/README.md index 23e77b2..696a32f 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ @@ -341,3 +341,16 @@ update - 注释 获取微信jssdk接口 - packageHome - 修改 appId获取的方式,本地配置文件固定配置,不再从url路由获取 + + + + +## v1.0.40 +`2023.4.8` +update +- packageList + - 增加 微信授权code调用方式,在缓存的基础上在路由增加一个code +- packageHome + - 增加 微信授权code调用方式,缓存没有则从路由获取 +- appId + - 修改 测试环境appId \ No newline at end of file diff --git a/src/App.vue b/src/App.vue index ca320e5..f0b4f39 100644 --- a/src/App.vue +++ b/src/App.vue @@ -1,7 +1,7 @@ @@ -37,7 +37,7 @@ export default { }); }, debug() { - if (process.env.NODE_ENV !== 'production') { + if (process.env.NODE_ENV !== 'development') { const script = document.createElement('script'); script.src = "//cdn.jsdelivr.net/npm/eruda"; document.body.appendChild(script); diff --git a/src/config/appId.js b/src/config/appId.js index 185b799..d9a5f73 100644 --- a/src/config/appId.js +++ b/src/config/appId.js @@ -1,7 +1,7 @@ /* * @Date: 2022-03-19 19:57:20 * @LastEditors: JinxChen - * @LastEditTime: 2023-04-06 09:11:48 + * @LastEditTime: 2023-04-08 15:02:38 * @FilePath: \TelpoH5FrontendWeb\src\config\appId.js * @description: */ @@ -9,5 +9,5 @@ const AppId = process.env.NODE_ENV === 'production' ? 'wxd78b83bdb0b4df55' : process.env.VUE_APP_BASE_API.indexOf('ai.ssjlai.com') > -1 ? 'wxd78b83bdb0b4df55': - /* 'wx785c95a3e7f46f72' */'wxd78b83bdb0b4df55'; //wx5e26f0813859e5f6 2022.10.12 更改测试公众号 + 'wx785c95a3e7f46f72'/* 'wxd78b83bdb0b4df55' */; //wx5e26f0813859e5f6 2022.10.12 更改测试公众号 export default AppId; \ No newline at end of file diff --git a/src/config/models.js b/src/config/models.js index 0516076..a9be204 100644 --- a/src/config/models.js +++ b/src/config/models.js @@ -1,11 +1,11 @@ /* * @Date: 2021-11-20 10:26:39 * @LastEditors: JinxChen - * @LastEditTime: 2023-04-06 09:13:27 + * @LastEditTime: 2023-04-08 14:56:13 * @FilePath: \TelpoH5FrontendWeb\src\config\models.js * @description: */ -export const VERSION_MODEL = '1.0.39F'; //版本号 +export const VERSION_MODEL = '1.0.40F'; //版本号 export const IMAGE_URL = { production: 'http://zfb.ssjlai.com/web/', test: 'http://zfb.ssjlai.com/web/', diff --git a/src/views/package-home/index.vue b/src/views/package-home/index.vue index 88468f5..06d72b9 100644 --- a/src/views/package-home/index.vue +++ b/src/views/package-home/index.vue @@ -1,7 +1,7 @@ @@ -23,6 +23,7 @@ export default { return { params: {}, //获取路由的参数 isRecharge: null, //是否已经支付 + wxAuthCode: '' }; }, created() { @@ -50,6 +51,7 @@ export default { // checkBrowser 检查扫码的浏览器内核 checkBrowser() { const userAgent = window.navigator.userAgent; + this.$store.commit("wxAuthCode", ''); console.log("浏览器内核", userAgent); if (/AlipayClient/.test(userAgent)) { console.log("支付宝"); @@ -65,8 +67,11 @@ export default { let code = url.split("&")[0]; if (isNotNull(code)) { this.$store.commit("wxAuthCode", code); - /* this.getOpenId(); */ - this.getWxCode(); + this.wxAuthCode = code; + //this.getOpenId(); + setTimeout(() => { + this.getWxCode(); + },1000) } } else { this.getWxCode(); @@ -120,7 +125,7 @@ export default { } }) } else { - let redUrl = encodeURIComponent(`${commonUrl}/h5-frontendweb/#/${params.routerName}?imei=${params.imei}&appId=${AppId}&iccid=${params.iccid}`); + let redUrl = encodeURIComponent(`${commonUrl}/h5-frontendweb/#/${params.routerName}?imei=${params.imei}&appId=${AppId}&iccid=${params.iccid}&code=${this.wxAuthCode}`); let url = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${AppId}&redirect_uri=${redUrl}&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect`; window.location.href = url; } diff --git a/src/views/package-list/index.vue b/src/views/package-list/index.vue index ffc9cf0..635c2ac 100644 --- a/src/views/package-list/index.vue +++ b/src/views/package-list/index.vue @@ -1,7 +1,7 @@ @@ -107,6 +107,7 @@ import { APIPay } from "@/api/pay"; import APICore from "@/api/core"; let wx = require("weixin-js-sdk"); // TODO 再封装,可拦截错误提示等操作 import { isNotNull } from "@/utils/index"; +import { VERSION_MODEL } from '@/config/models'; export default { name: "packageList", data() { @@ -139,6 +140,7 @@ export default { payProductId: null, //套餐id packageIssue: null, //套餐分期 payType: '1', //支付方式 1 微信, 2 支付宝,支付宝又分为花呗和全额支付,全额支付分期数传0 或者1 ,花呗则传 3 6 12 + openId: '' }; }, created() { @@ -147,22 +149,19 @@ export default { //this.getWxAutograph(); // 套餐列表 this.getDevicePayPackage(); + console.log("当前版本", VERSION_MODEL); }, methods: { // 根据code获取openId getOpenId() { - let code = this.$store.getters.wxAuthCode; - let openId = this.$store.getters.openId; - if(isNotNull(openId)) { - console.log("已经存在openId"); - } else { - APIPay.getOpenId(code).then(res => { - let data= res.data; - if(data.code === 20000) { - this.$store.commit("openId", data.data.openId); - } - }) - } + let code = this.$store.getters.wxAuthCode ? this.$store.getters.wxAuthCode : this.params.code; + APIPay.getOpenId(code).then(res => { + let data= res.data; + if(data.code === 20000) { + this.openId = data.data.openId; + this.$store.commit("openId", data.data.openId); + } + }) }, // 获取b端接口的token getAuth() { @@ -175,15 +174,7 @@ export default { getParams() { let params = this.$route.query; if (params) { - let url = window.location.href.split("?code=")[1]; - if ( isNotNull(url) || window.location.href.indexOf("code") > -1) { - let timeStamp = new Date().getTime(); - let code = url.split("&")[0]; - if (isNotNull(code)) { - this.$store.commit("wxAuthCode", `${code}`); - this.getOpenId(); - } - } + this.getOpenId(); this.params = {...params}; } }, @@ -319,7 +310,7 @@ export default { console.log("微信支付", data); let orderData = data; let reqBody = { - openId: this.$store.getters.openId, //openId + openId: this.$store.getters.openId || this.openId, //openId imei: this.params.imei, //imei iccid: this.params.iccid, productId: this.payProductId, //套餐id