Signature generation
Preparation
Merchants need to register with a merchant number and create a payment application through the merchant backstage to obtain APP_ID and APP_SECRECT.
Condition
All interfaces of the POST method in this document need to validate the signature, and other interfaces do not need to validate for the moment.
Generation
The signature string has four lines, one parameter per action. The line ends with \n (line break, The ASCII encoding value is 0x0A), and don't add \n on the last line. If the parameter itself ends in \n , you also need to attach an \n .
URL\n
Request timestamp\n
Request random string\n
Request message bodyLet's take order inquiry as an example.
The first step is to get the absolute URL of the request and remove the domain name part to get the participating signed URL. If there are query parameters in the request, the URL should be appended with '? 'and the corresponding query string.
/v1/transaction/queryThe second step is to obtain the current timestamp (milliseconds) of the system when the request is initiated. That is to say, the total number of seconds from 00:00 00 GMT on January 1, 1970, to the present, as the request timestamp. The platform will refuse to process requests made long ago, please keep the time of the merchant's own system accurate.
The third step is to generate a 32-bit random string.
The fourth step is to obtain the request message body in the request(request body).
The fifth step is to construct the request signature string according to the previous rules as follows:
Encryption
Take the javascript encryption process as an example:
Example after encryption:
Concatenate
The splice format of signature information is as follows:
app_id=APP_ID, mch_id=Merchant ID, nonce_str=The random string generated in step 3,timestamp=The timestamp generated in step 2, signature=Cryptographic signature string.
HTTP header
The document API passes the signature through an HTTP Authorization header. Authorization consists of two parts: authentication type and signature information. authentication type only supports TTPAY-AES-256-ECB for the moment.
Authorization header as follows: (Notes: Example because typesetting may contain line breaks, the actual data should be on one line)
Finally, we can create an HTTP request that contains a signature.
Demo code
Last updated