WeChat Pay v3 asynchronous verification failed
Here we receive the parameters (the body of the message) generally through the request that comes with the framework.
For example, TP6: $this->request->param();
Here, if you use this receiving method, the json conversion verification will fail.
We need to use the native receiving method: file_get_contents('php://input');
after receiving it, directly take this data for signature verification.
Attach the following code:
public function verifySign() { $timestamp = "The timestamp in the header"; $nonce = "The random string in the header"; $signature = "The signature in the header"; $certZs = "Platform Certificate";// $data = $this->request->param(); $data = file_get_contents('php://input'); $message = "$timestamp\n$nonce\n$data\n"; //Verify signature if (!$this->verify($message, $signature, $certZs)) { throw new \Exception('Signature verification failed', 123456); } }123456789101112131415161718