# 获取预授权码
接口应在服务器端调用,不可在前端(小程序、网页、APP等)直接调用,具体可参考接口调用指南
接口英文名:getPreAuthCode
该接口用于获取预授权码(pre_auth_code)是第三方平台方实现授权托管的必备信息,每个预授权码有效期为 1800秒。使用过程中如遇到问题,可在开放平台服务商专区发帖交流。
# 1. 调用方式
# HTTPS 调用
POST https://api.weixin.qq.com/cgi-bin/component/api_create_preauthcode?access_token=ACCESS_TOKEN
# 云调用
- 本接口不支持云调用
# 第三方调用
- 本接口仅支持第三方平台使用 component_access_token 自己调用。
# 2. 请求参数
# 查询参数 Query String parameters
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| access_token | string | 是 | 接口调用凭证,可使用 component_access_token |
# 请求体 Request Payload
| 参数名 | 类型 | 必填 | 说明 |
|---|---|---|---|
| component_appid | string | 是 | 第三方平台 appid |
# 3. 返回参数
# 返回体 Response Payload
| 参数名 | 类型 | 说明 |
|---|---|---|
| pre_auth_code | string | 预授权码 |
| expires_in | number | 有效期,单位:秒 |
# 4. 注意事项
本接口无特殊注意事项
# 5. 代码示例
请求示例
{
"component_appid": "appid_value"
}
返回示例
{
"pre_auth_code": "Cx_Dk6qiBE0Dmx4EmlT3oRfArPvwSQ-oa3NL_fwHM7VI08r52wazoZX2Rhpz1dEw",
"expires_in": 600
}
# 6. 错误码
以下是本接口的错误码列表,其他错误码可参考 通用错误码;调用接口遇到报错,可使用官方提供的 API 诊断工具 辅助定位和分析问题。
| 错误码 | 错误描述 | 解决方案 |
|---|---|---|
| -1 | system error | 系统繁忙,此时请开发者稍候再试 |
| 40001 | invalid credential access_token isinvalid or not latest | 获取 access_token 时 AppSecret 错误,或者 access_token 无效。请开发者认真比对 AppSecret 的正确性,或查看是否正在为恰当的公众号调用接口 |
| 40013 | invalid appid | 不合法的 AppID ,请开发者检查 AppID 的正确性,避免异常字符,注意大小写 |
| 40125 | invalid appsecret view more at http://t.cn/RAEkdVq | 无效的appsecret |
| 41001 | access_token missing | 缺少 access_token 参数 |
| 41004 | appsecret missing | 缺少 secret 参数 |
| 42001 | access_token expired | access_token 超时,请检查 access_token 的有效期,请参考基础支持 - 获取 access_token 中,对 access_token 的详细机制说明 |
| 45009 | reach max api daily quota limit | 调用超过天级别频率限制。可调用clear_quota接口恢复调用额度。 |
| 47001 | data format error | 解析 JSON/XML 内容错误;post 数据中参数缺失;检查修正后重试。 |
| 48001 | api unauthorized | api 功能未授权,请确认公众号已获得该接口,可以在公众平台官网 - 开发者中心页中查看接口权限 |
| 61004 | access clientip is not registered | 第三方平台出口IP未设置 |
| 61005 | component ticket is expired | |
| 61006 | component ticket is invalid | |
| 61011 | invalid component |
# 7. 适用范围
本接口支持「第三方平台」账号类型调用。其他账号类型如无特殊说明,均不可调用。