企业微信授权官方文档
企业如果需要员工在跳转到企业网页时带上员工的身份信息,需构造如下的链接:
https://open.weixin.qq.com/connect/oauth2/authorize?appid=CORPID&redirect_uri=REDIRECT_URI&response_type=code&scope=SCOPE&agentid=AGENTID&state=STATE#wechat_redirect
员工点击后,页面将跳转至 redirect_uri?code=CODE&state=STATE,企业可根据code参数获得员工的userid。
参数 | 必须 | 说明 |
---|---|---|
appid | 是 | 企业的CorpID |
redirect_uri | 是 | 授权后重定向的回调链接地址,请使用urlencode对链接进行处理 |
response_type | 是 | 返回类型,此时固定为:code |
scope | 是 | 应用授权作用域。 snsapi_base:静默授权,可获取成员的基础信息; snsapi_userinfo:静默授权,可获取成员的详细信息,但不包含手机、邮箱; snsapi_privateinfo:手动授权,可获取成员的详细信息,包含手机、邮箱。 |
agentid | 是 | 企业应用的id。 当scope是snsapi_userinfo或snsapi_privateinfo时,该参数必填。 注意redirect_uri的域名必须与该应用的可信域名一致。 |
state | 否 | 重定向后会带上state参数,企业可以填写a-zA-Z0-9的参数值,长度不可超过128个字节 |
#wechat_redirect | 是 | 微信终端使用此参数判断是否需要带上身份信息 |
// 授权后重定向的回调链接地址,请使用urlencode对链接进行处理
let redirect_uri = encodeURIComponent('https://此URL的域名,必须完全匹配企业应用设置项中的可信域名')
window.location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=appid&redirect_uri=${redirect_uri}&response_type=code&scope=snsapi_base&state=status#wechat_redirect`