Qeasy Cloud
Get Started
GEThttps://qyapi.weixin.qq.com/cgi-bin/gettokencorpid + corpsecret 换 access_token

Get access_token (gettoken)

企业微信服务端 API 鉴权接口:凭 corpid + corpsecret 换取 access_token(有效期 7200 秒),是调用审批、通讯录等接口的前置步骤。

## Overview Every WeCom (WeChat Work) server API authenticates with an access_token: an internal app exchanges corpid plus its corpsecret at this endpoint. The token is valid for 7200 seconds and reusable until expiry. corpsecret is shown under Apps > Self-built in the admin console; contact APIs require the separate secret of the Contact Sync assistant. ### Steps 1. Create a self-built app and note its AgentId and Secret; the corpid sits at the bottom of the My Company page. 2. Configure the app's trusted IPs — WeCom enforces this and rejects other egress IPs with error 60020. 3. Fetch and cache the token, refreshing ahead of expiry; different secrets (app secret vs contact secret) issue different tokens and must be cached separately. 4. Business calls append access_token to the URL query. ### Response Success: {"errcode":0,"errmsg":"ok","access_token":"xxxx","expires_in":7200}. Non-zero errcodes map to the global error-code reference. ### Production advice The Qeasy connector keeps a per-corpid+secret singleton token cache with concurrency control, so multiple apps/secrets never thrash each other's cached token. ### Managing multiple secrets An enterprise typically holds at least an app secret and a contact-sync secret, sometimes an external-contact secret too. Tokens issued from different secrets are not interchangeable — key the cache by corpid plus secret purpose. Cross-use surfaces as error 40014 and is easily misdiagnosed as an expired token, burning hours in troubleshooting.

Code examples

curl
curl "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=wwxxxx&corpsecret=yyyy"

Error codes

CodeMessageMeaning
40001invalid credentialcorpid/corpsecret 不正确或不匹配
40014invalid access_tokentoken 非法或已过期,重新获取
42001access_token expiredtoken 超时,刷新后重试
60020not allow to access from your ip出口 IP 未配置到应用可信 IP 列表