Print the signature string
The APIv3 signature string has five lines: method, URL path including query, timestamp, nonce, and the request body. Each line ends with a newline, and the final line is the raw body. One missing newline or an extra space invalidates it.
The fastest diagnosis is to print the exact string you signed next to the exact bytes you sent and compare them character by character. Most problems become obvious immediately.
Keys and serial numbers
The merchant private key is the content of apiclient_key.pem with the header, footer and all newlines removed before use. Passing the raw multi-line string to the signing function never works.
The certificate serial number in the request header must be your merchant API certificate, not the platform certificate. Both are downloaded from the merchant platform and are easy to mix up.
Check the verification direction
Callback verification uses the platform certificate or WeChat Pay public key, which is a different key pair from your merchant private key. Using the wrong direction looks like requests succeed but callbacks fail.
Platform certificates rotate. Load them by serial number at runtime instead of hardcoding one, which will eventually expire.
FAQ
Are APIv2 and APIv3 signatures the same?
No. APIv2 uses MD5 or HMAC-SHA256 over a parameter string; APIv3 uses SHA256-RSA2048 with certificates. Do not mix them.
My signature differs from the official tool. Why?
Compare the raw signature string. Differences are almost always newlines, spaces or field order.
Does an expired certificate look like a signature error?
It reports certificate errors. Certificates have validity periods; replace them and update paths and serial numbers before expiry.
Related questions
Further reading
- WeChat Pay Merchant Setup Service details
- Debugging WeChat Pay Callbacks: Did the Request Arrive
- What Are the Common API Configuration Errors in Official Account Development? A Checklist Approach
- What to Do When Alipay Merchant Setup Documents Are Rejected? Correction Tips and Document Checklist
- Why WeChat Pay Settlements Get Delayed: Checking Order, Records and Bank Side
Sources & References
The following are public sources. Always check the latest requirements on the official authority or platform page.
