iflytek/astron-agent · error · AesException
-40001
-40001
Error message
Signature validation error
What it means
WXBizMsgCrypt.verifyUrl computes the SHA-1 signature over (token, timestamp, nonce, echoStr) during WeChat server URL verification and compares it to the msgSignature sent by WeChat. When the two differ it throws AesException with code -40001 (ValidateSignatureError), meaning the callback request cannot be attributed to a sender holding the correct EncodingAESKey/token pair. This is the standard WeChat callback security check failing.
Solutions
- Verify the token value used to construct WXBizMsgCrypt exactly matches the Token set in the WeChat MP admin console (whitespace/case included).
- Confirm the controller passes the original msg_signature, timestamp, nonce and echostr query parameters verbatim to verifyUrl — check URL-decoding and any reverse-proxy rewrite rules.
- Log the locally computed signature vs the incoming msgSignature to identify which input diverges.
- Ensure you are responding to WeChat's GET verification (echostr) and not a POST message push with this code path.
Example fix
// before String sig = getSHA1(myToken, ts, nonce, echoStr); // myToken differs from MP console // after String sig = getSHA1(tokenFromConfigMatchingWechatConsole, ts, nonce, echoStr);
Defensive patterns
Strategy: try-catch
Validate before calling
if (msgSignature == null || timeStamp == null || nonce == null || echoStr == null) throw new IllegalArgumentException("missing WeChat verification params"); Try / catch
try { return crypto.verifyUrl(msgSignature, timestamp, nonce, echoStr); } catch (AesException e) { if (e.getCode() == -40001) { log.warn("signature mismatch"); return ResponseEntity.status(403).body("signature invalid"); } throw e; } Prevention
- Keep token config in sync with the WeChat MP console
- Forward query params verbatim; check proxy rewrites
- Log computed vs received signatures when debugging
- Never hardcode a different token in test environments
When it happens
Trigger: Calling verifyUrl(msgSignature, timeStamp, nonce, echoStr) when the computed SHA1(token, timeStamp, nonce, echoStr) does not equal the msgSignature query parameter WeChat appended to the verification URL.
Common situations: Token in application config differs from the token configured in the WeChat Official Account backend; the timestamp/nonce/echoStr query params were not passed through unchanged (URL decoding issues, reordered params, proxied requests stripping query strings); a replayed or forged callback request; testing the endpoint manually without WeChat's signature params.
Understand the failure class
Background: Checksum mismatch errors: "checksum verification failed", "digest mismatch", "expected vs actual checksum" — what they mean and how to fix them — this error's family across 41 libraries.
Related errors
- WeChat message signature verification functionality needs…
- Skill resource URL is not allowed
- exceeds size limit
- BOT_NOT_EXISTS
- PARAMS_ERROR
AI-assisted analysis of iflytek/astron-agent@5e758547a8 (2026-09-12).
Data as JSON: /api/errors/8d8aca577b300446.
Report an issue: GitHub.
Appendix: source
Thrown at console/backend/hub/src/main/java/com/iflytek/astron/console/hub/util/wechat/WXBizMsgCrypt.java:209
}
/**
* Verify URL
*
* @param msgSignature Signature string
* @param timeStamp Timestamp
* @param nonce Random number
* @param echoStr Random string
* @return Decrypted echostr
* @throws AesException Execution failed, please check the error code and specific error message of
* this exception
*/
public String verifyUrl(String msgSignature, String timeStamp, String nonce, String echoStr)
throws AesException {
String signature = getSHA1(token, timeStamp, nonce, echoStr);
if (!signature.equals(msgSignature)) {
throw new AesException(AesException.ValidateSignatureError);
}
String result = decrypt(echoStr);
return result;
}
/**
* Decrypt message
*
* @param msgSignature Signature string
* @param timeStamp Timestamp
* @param nonce Random number
* @param postData Encrypted XML
* @return Decrypted XML
* @throws AesException Execution failed, please check the error code and specific error message of
* this exception
*/
public String decryptMsg(String msgSignature, String timeStamp, String nonce, String postData)View on GitHub (pinned to 5e758547a8)