Browse Source

修改 获取openId的方式

feat
JinxChen 1 year ago
parent
commit
d3468f2344
2 changed files with 6 additions and 7 deletions
  1. +4
    -5
      src/views/package-home/index.vue
  2. +2
    -2
      src/views/package-list/index.vue

+ 4
- 5
src/views/package-home/index.vue View File

@@ -51,7 +51,6 @@ export default {
// checkBrowser 检查扫码的浏览器内核 // checkBrowser 检查扫码的浏览器内核
checkBrowser() { checkBrowser() {
const userAgent = window.navigator.userAgent; const userAgent = window.navigator.userAgent;
this.$store.commit("wxAuthCode", '');
console.log("浏览器内核", userAgent); console.log("浏览器内核", userAgent);
if (/AlipayClient/.test(userAgent)) { if (/AlipayClient/.test(userAgent)) {
console.log("支付宝"); console.log("支付宝");
@@ -68,7 +67,7 @@ export default {
if (isNotNull(code)) { if (isNotNull(code)) {
this.$store.commit("wxAuthCode", code); this.$store.commit("wxAuthCode", code);
this.wxAuthCode = code; this.wxAuthCode = code;
//this.getOpenId();
this.getOpenId(code);
setTimeout(() => { setTimeout(() => {
this.getWxCode(); this.getWxCode();
},1000) },1000)
@@ -101,8 +100,8 @@ export default {
}) })
}, },
// 根据code获取openId // 根据code获取openId
getOpenId() {
let code = this.$store.getters.wxAuthCode;
getOpenId(code) {
//let code = this.$store.getters.wxAuthCode;
APIPay.getOpenId(code).then(res => { APIPay.getOpenId(code).then(res => {
let data= res.data; let data= res.data;
if(data.code === 20000) { if(data.code === 20000) {
@@ -125,7 +124,7 @@ export default {
} }
}) })
} else { } else {
let redUrl = encodeURIComponent(`${commonUrl}/h5-frontendweb/#/${params.routerName}?imei=${params.imei}&appId=${AppId}&iccid=${params.iccid}&code=${this.wxAuthCode}`);
let redUrl = encodeURIComponent(`${commonUrl}/h5-frontendweb/#/${params.routerName}?imei=${params.imei}&iccid=${params.iccid}`);
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`; 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; window.location.href = url;
} }


+ 2
- 2
src/views/package-list/index.vue View File

@@ -154,7 +154,7 @@ export default {
methods: { methods: {
// 根据code获取openId // 根据code获取openId
getOpenId() { getOpenId() {
let code = this.$store.getters.wxAuthCode ? this.$store.getters.wxAuthCode : this.params.code;
let code = this.$store.getters.wxAuthCode;
APIPay.getOpenId(code).then(res => { APIPay.getOpenId(code).then(res => {
let data= res.data; let data= res.data;
if(data.code === 20000) { if(data.code === 20000) {
@@ -174,7 +174,7 @@ export default {
getParams() { getParams() {
let params = this.$route.query; let params = this.$route.query;
if (params) { if (params) {
this.getOpenId();
//this.getOpenId();
this.params = {...params}; this.params = {...params};
} }
}, },


Loading…
Cancel
Save