# 获取预授权码

调试诊断

接口应在服务器端调用,不可在前端(小程序、网页、APP等)直接调用,具体可参考接口调用指南

接口英文名:getPreAuthCode

该接口用于获取预授权码(pre_auth_code)是第三方平台方实现授权托管的必备信息,每个预授权码有效期为 1800秒。使用过程中如遇到问题,可在开放平台服务商专区发帖交流。

# 1. 调用方式

# HTTPS 调用

POST https://api.weixin.qq.com/cgi-bin/component/api_create_preauthcode?access_token=ACCESS_TOKEN

# 云调用

  • 本接口不支持云调用

# 第三方调用

# 2. 请求参数

# 查询参数 Query String parameters

参数名类型必填说明
access_tokenstring接口调用凭证,可使用 component_access_token

# 请求体 Request Payload

参数名类型必填说明
component_appidstring第三方平台 appid

# 3. 返回参数

# 返回体 Response Payload

参数名类型说明
pre_auth_codestring预授权码
expires_innumber有效期,单位:秒

# 4. 注意事项

本接口无特殊注意事项

# 5. 代码示例

请求示例

{
  "component_appid": "appid_value"
}

返回示例

{
  "pre_auth_code": "Cx_Dk6qiBE0Dmx4EmlT3oRfArPvwSQ-oa3NL_fwHM7VI08r52wazoZX2Rhpz1dEw",
  "expires_in": 600
}

# 6. 错误码

以下是本接口的错误码列表,其他错误码可参考 通用错误码;调用接口遇到报错,可使用官方提供的 API 诊断工具 辅助定位和分析问题。

错误码错误描述解决方案
-1system error系统繁忙,此时请开发者稍候再试
40001invalid credential  access_token isinvalid or not latest获取 access_token 时 AppSecret 错误,或者 access_token 无效。请开发者认真比对 AppSecret 的正确性,或查看是否正在为恰当的公众号调用接口
40013invalid appid不合法的 AppID ,请开发者检查 AppID 的正确性,避免异常字符,注意大小写
40125invalid appsecret view more at http://t.cn/RAEkdVq无效的appsecret
41001access_token missing缺少 access_token 参数
41004appsecret missing缺少 secret 参数
42001access_token expiredaccess_token 超时,请检查 access_token 的有效期,请参考基础支持 - 获取 access_token 中,对 access_token 的详细机制说明
45009reach max api daily quota limit调用超过天级别频率限制。可调用clear_quota接口恢复调用额度。
47001data format error解析 JSON/XML 内容错误;post 数据中参数缺失;检查修正后重试。
48001api unauthorizedapi 功能未授权,请确认公众号已获得该接口,可以在公众平台官网 - 开发者中心页中查看接口权限
61004access clientip is not registered第三方平台出口IP未设置
61005component ticket is expired
61006component ticket is invalid
61011invalid component

# 7. 适用范围

本接口支持「第三方平台」账号类型调用。其他账号类型如无特殊说明,均不可调用。