简单大气的网站模板,设计必备网站,桂林漓江游船票价格,网页翻译插件哪个好用1.需求#xff1a;在企业微信里面添加h5页面 进行登录授权#xff0c;获取到用户的code#xff0c;进行登入id的验证
2.步骤#xff1a;
根据企业微信开发者中心中构造网页授权链接进行授权 在企业微信内部进行配置#xff0c;拿到appid#xff0c;redirect_uri#x…1.需求在企业微信里面添加h5页面 进行登录授权获取到用户的code进行登入id的验证
2.步骤
根据企业微信开发者中心中构造网页授权链接进行授权 在企业微信内部进行配置拿到appidredirect_uriagentid参数步骤参考这篇文章 由于企业微信进入页面之前会进行授权然后再进行跳转咱们系统的首页也是就redirect_uri中的地址那么就会有两种解决方案 ① 有一个页面用于授权然后在跳转首页 ② 直接将授权的操作写在首页中在首页进行授权然后再跳转首页我用的是这种方式 首页进行授权的代码如下 //判断是否授权const CORPID ; //appid参数const REDIRECT_URI encodeURI( ); //redirect_uri参数const AGENTID ; //agentid 参数const searchParams new URLSearchParams(window.location.search);const code (route.query.code as string) || (searchParams.get(code) as string);const state (route.query.state as string) || (searchParams.get(state) as string);const token computed(() userStore.getToken);//路由上没有code的情况下进行企业微信授权if (!code) {const authUrl https://open.weixin.qq.com/connect/oauth2/authorize?appid${CORPID}redirect_uri${REDIRECT_URI}/index.htmlresponse_typecodescopesnsapi_basestate1agentid${AGENTID}#wechat_redirect;window.location.href authUrl;}//存在code且不存在token的情况下走登录的接口if (code (token.value null || token.value null)) { userStore.resetUserStore();login({code: code,state: state,}).then((res) {userStore.setToken(res.token);});}