w7corp/easywechat · error · HttpException
Failed to get authorization_info: %s
Error message
Failed to get authorization_info: %s
What it means
OpenPlatform\Application::handleAuthorizationCode() POSTs the one-time authorization_code to cgi-bin/component/api_query_auth and throws HttpException (raw JSON embedded) when authorization_info is missing. The authorization_code is issued once in the auth-callback URL, is single-use, and expires within minutes, so a failed exchange usually means the code was bad, reused, or the component credentials were stale.
Source
Thrown at src/OpenPlatform/Application.php:189
/**
* @throws HttpException
*/
public function getAuthorization(string $authorizationCode): Authorization
{
$response = $this->getClient()->request(
'POST',
'cgi-bin/component/api_query_auth',
[
'json' => [
'component_appid' => $this->getAccount()->getAppId(),
'authorization_code' => $authorizationCode,
],
]
)->toArray(false);
if (empty($response['authorization_info'])) {
throw new HttpException('Failed to get authorization_info: '.json_encode(
$response,
JSON_UNESCAPED_UNICODE
));
}
return new Authorization($response);
}
/**
* @throws HttpException
*/
public function refreshAuthorizerToken(string $authorizerAppId, string $authorizerRefreshToken): array
{
$response = $this->getClient()->request(
'POST',
'cgi-bin/component/api_authorizer_token',
[
'json' => [View on GitHub (pinned to f0cf0a8b83)
Solutions
- Decode the embedded errcode/errmsg — invalid/expired code errors mean the authorizer must click through the auth page again
- Exchange the code exactly once, immediately inside the callback handler, and persist the returned authorizer tokens
- If it was already consumed, restart the flow: createPreAuthorizationCode() and send the authorizer a new pre-authorization URL
- For systemic errcodes, fix the component ticket/token layer (see VerifyTicket) before retrying
Example fix
// before: retrying or refreshing the callback reuses a consumed code
$auth = $openPlatform->handleAuthorizationCode($authorizationCode);
// after: exchange once and idempotently re-initiate on failure
if (! $cache->has("authcode:{$authorizationCode}")) {
$cache->set("authcode:{$authorizationCode}", 1, 600);
$auth = $openPlatform->handleAuthorizationCode($authorizationCode);
} else {
return redirect($openPlatform->createPreAuthorizationUrl($callbackUrl));
} Defensive patterns
Strategy: try-catch
Validate before calling
if ($cache->has("authcode:{$authorizationCode}")) {
// already consumed once: skip straight to issuing a new pre-auth URL
return redirect($openPlatform->createPreAuthorizationUrl($callbackUrl));
} Try / catch
try {
$auth = $openPlatform->handleAuthorizationCode($authorizationCode);
} catch (\EasyWeChat\Kernel\Exceptions\HttpException $e) {
$payload = json_decode(strstr($e->getMessage(), '{') ?: '[]', true) ?: [];
// invalid/expired-code errcodes → send the authorizer a fresh pre-auth URL instead of retrying
report($e);
} Prevention
- Exchange the authorization_code exactly once, synchronously in the callback handler
- Mark codes consumed in a short-TTL cache to make handler retries idempotent
- Persist authorizer tokens immediately after a successful exchange
When it happens
Trigger: Replaying the authorization callback URL (refresh, double-submit, retry job) after the code was consumed; processing the callback later than the code's TTL; stale component_verify_ticket/component_access_token; wrong component appid in the request.
Common situations: An admin refreshes the callback page after completing authorization; queue workers process the same callback event twice; dev and prod both consume a code meant for one environment; long delay between WeChat's redirect and the server-side exchange.
Related errors
- Failed to get authorizer_access_token: %s
- getPhoneNumber error: %s
- No component_verify_ticket found.
- Failed to get component_access_token: %s
- Failed to get auth_corp_info: %s
AI-assisted analysis of w7corp/easywechat@f0cf0a8b83 (2026-08-21).
Data as JSON: /api/errors/6320ae9f7575161f.
Report an issue: GitHub.