Skip to main content

企业微信

caution
  • 企业微信会话存档保存最长为 90 天
caution
  • access_token 是全局的,不能返回到前端
  • 授权认证时的 code 只是使用 access_token 去 校验 而不是为用户换取属于用户的 access_token
  • 默认 scope 为 snsapi_base

授权

  • 非标准 OAuth2
  • access_token 是全局
    • 默认 7200s
  • 换 token 需要 appid 和 agentid
  • code 只能用一次

网页授权

https://open.weixin.qq.com/connect/oauth2/authorize?
appid=wx10101&
response_type=code&
scope=snsapi_base&
redirect_uri=https%3A%2F%2Ftest.example.com%3A3000%2Fapi%2Fmyredirect
#wechat_redirect
https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo?
access_token=ACCESS_TOKEN&
code=CODE

Web 扫码授权登录

https://open.work.weixin.qq.com/wwopen/sso/qrConnect?
appid=wx10101&
agentid=1000000&
redirect_uri=https%3A%2F%2Ftest.example.com%3A3000%2Fapi%2Fmyredirect
https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo?
access_token=ACCESS_TOKEN&
code=CODE

会话存档

Note

  1. 会话存档保存 5
  2. 从 Sequence+1 拉取,不包含 Sequence
  3. limit 最大 1000
  4. 图片 jpg, 音频 amr, 视频 mp4
  5. MediaData 的 MD5 可能匹配不上,可以一直重试
  6. MediaData 单次最多返回 512K

获取 wr 和 wm 信息

  • 内部群 - inner room
    • POST /cgi-bin/msgaudit/groupchat/get {"roomid":""}
    • 会话存档 Secret 可调用
  • 外部客户群 - external contact group
    • POST /cgi-bin/externalcontact/groupchat/get {"chat_id":""}
  • 外部客户群列表
    • POST /cgi-bin/externalcontact/groupchat/list
  • 注意 有的群是无法取到信息的,由微信拉起的群

FAQ

redirect_uri 与配置的授权完成回调域名不一致

配置 Web 授权回调域名