企业微信接入过程

  • Post author:
  • Post category:其他


1.

官方文档 获取访问用户身份 – 接口文档 – 企业微信开发者中心


构造网页授权链接 – 接口文档 – 企业微信开发者中心


官方文档 获取访问用户身份 – 接口文档 – 企业微信开发者中心

记录接入流程

1.首页url附带appid&agentid ,前端获取参数后请求先后端接口startAuth?appid=’+ this.appid + ‘&agentid=’+ this.agentid + ‘&state=’+ this.state,(后端保存对应信息);

2.前端请求微信授权接口

redirectUrl 微信授权后跳转的url 可以设置为当前首页url

const redirectUrl = encodeURIComponent(document.location.origin + document.location.pathname + '#/');

oauth2Url = "https://open.weixin.qq.com/connect/oauth2/authorize" + '?appid=' + appid + '&agentid=' + agentid + '&redirect_uri=' + redirectUrl + '&response_type=' + responseType + '&scope=' + scope + '&state=' + state + end;

window.location.href = oauth2Url; 

注,这里试过直接用axios的get方法,web端可行,在手机端企业微信中失效了。

3.

window.location.hash,window.location.search从这里获取url里参数的值。

注,这里试过直接用vue的this.$route.query获取,失败了,因为微信返回的链接#/的位置异常。

根据state值判断,去请求oAuth2User?state=’ + this.state + ‘&code=’ + this.code后端返回用户信息。

4.后端会遇到code值失效问题,code=40029,重新授权

if(res.data.code === 200) {
                。。。。
            }else if(res.data.code === 40029){
                // code失效,重新授权
                this.appid = res.data.data.appid;
                this.agentid = res.data.data.agentid;
                this.state = UT.uuid();
                this.startAuth();
            } 



版权声明:本文为haifengxuxu原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。