diff --git a/src/page/Home/Home.vue b/src/page/Home/Home.vue index dfea4ea..a2f939a 100644 --- a/src/page/Home/Home.vue +++ b/src/page/Home/Home.vue @@ -169,32 +169,21 @@ onBeforeMount(() => { console.log("code:", h5plugin.getQueryString("code")); + + + + // 微信环境授权 if (h5plugin.isWX()) { - // console.log("code:", h5plugin.getQueryString("code")); - // if (h5plugin.getQueryString("code")) { - // // 存在code的话去换取openid - // authCode.value = h5plugin.getQueryString("code"); - // getOpenId(authCode.value); - // } else { - // getCode(); - // } if (h5plugin.getQueryString("code")) { - getOpenId(h5plugin.getQueryString("code")); + // 存在code的话去换取openid + authCode.value = h5plugin.getQueryString("code"); + getOpenId(authCode.value); } else { - wxAuthGetCode(); + getCode(); } - - // 一步授权 - // if(h5plugin.getQueryString("openid")){ - // console.log("存在openid"); - // apiAll(); - // }else{ - // console.log("不存在openid"); - // getCode2(); - // } } }); @@ -209,40 +198,7 @@ const indexPage = (actions) => { console.log("来自index组件:", actions); }; -// 授权获取code -const getCode2 = () => { - let redirect_uri = window.location.href; - // service.post(process.env.VUE_APP_API + '/cms-activity/cms88/zsApi/xfhdAuthorize?redirect_uri='+redirect_uri, - service - .get( - "https://test.szxgl.cn/zszq-celebration/zsApi/xfhdAuthorize1" - // { - // params:{ - // // redirect_uri: redirect_uri, - // redirect_uri: 'https://test.szxgl.cn/zszq-celebration/activity/index.html', - // } - // } - ) - .then((res) => { - let code = res.data.data; - console.log("get code结果4", res); - // authCode.value = res.data.data; - // window.location.href = res.data.data; - // location.href = res.data.data; - // window.open(res.data.data) - }); -}; - -const wxAuthGetCode = () => { - var appId = "wx35766a64d73d08a9"; - // var appId = "wx41d80a1bb01f658d"; - - var url = encodeURI(window.location.href); - -window.location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appId}&redirect_uri=${url}&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect` - -}; const getCode = () => { let redirect_uri = window.location.href;