授权绑定(获取 openToken)
chanjet.authorize
接口地址
授权页 https://market.chanjet.com/app/openApp ;换token https://openapi.chanjet.com/auth/v2/getToken ;刷新 https://openapi.chanjet.com/auth/v2/refreshToken
鉴权方式
OAuth2 授权码流程(应用级 appKey/appSecret + 用户级 openToken)
获取 openToken 后才能调业务接口;换/刷 token 时 Header 必须带 appKey+appSecret
请求头
appKey必填 — 开放平台应用IDappSecret必填 — 开放平台应用密钥
请求体说明
- 第1步:后端直接拼授权页 URL(market.chanjet.com/app/openApp?appKey=)返回前端,浏览器打开后用户登录授权
- 第2步:畅捷通回跳 redirect_uri?code=xxx&state=xxx,后端用 code 调 /auth/v2/getToken 换 openToken
- 第3步:openToken 快过期时(剩<2天)用 refresh_token 调 /auth/v2/refreshToken 续期,refresh_token 一并刷新且窗口重置(约29天)
请求示例
1) 后端返回:https://market.chanjet.com/app/openApp?appKey=TpCOEUuF&state=abc 2) 回跳 https://your-app/auth/chanjet/callback?code=AUTH_CODE&state=abc 3) GET https://openapi.chanjet.com/auth/v2/getToken?grantType=authorization_code&code=AUTH_CODE&redirectUri=https://your-app/auth/chanjet/callback Headers: appKey:TpCOEUuF, appSecret:****
响应示例
{
"code": "200",
"message": "成功",
"result": {
"access_token": "user_auth_token_xxx",
"refresh_token": "refresh_xxx",
"expires_in": 518400
}
}字段说明
access_tokenstring — 用户授权令牌(即 openToken,业务接口 Header 用)refresh_tokenstring — 刷新令牌,约 29 天有效,每次刷新重置窗口,必须持久化expires_innumber — access_token 有效期秒数,实测约 518400(6 天)
错误码
404 / code:50000误调 openapi.chanjet.com/account/auth/getAuthUrl 接口(接口不存在) → 不要调 getAuthUrl 接口!直接拼 market.chanjet.com/app/openApp 授权页给用户浏览器401 appSecret不能为空换/刷 token 未带 appSecret → Header 带 appSecret(后端需注入环境变量)token_expiredopenToken 失效 → 用 refresh_token 刷新;refresh 也过期则引导重新授权code不正确 / 400授权码流程参数错(曾误用永久码) → 走标准 authorization_code 流程;redirectUri 须与授权时、控制台登记完全一致
实战 tips
- 最常见坑:去 openapi.chanjet.com/account/auth/getAuthUrl 调'获取授权地址'会 404(code 50000 接口不存在)。标准做法就是拼 market.chanjet.com/app/openApp 授权页,不调该 API
- redirect_uri 必须在畅捷通开放平台白名单,且与授权时、换 token 时传的 redirectUri 逐字符一致(含路径、https、无多余斜杠)
- state 防 CSRF:后端生成、回调时校验,不匹配则拒绝
- openToken 约 6 天;refresh_token 约 29 天且每次刷新重置 → 只要 29 天内有调用就不掉线,自建应用无需'永久授权码'
- token 必须按用户隔离、加密落盘,不可明文、不可共享默认身份
