Signature method
Sign
The back-end of the merchant requests palmpay open interface needs to be signed on the parameters, the signature process is as follows:
- Assume that the body data is a set M. Remove leading and trailing spaces from the parameters of non-empty parameter values in M, sort them in ascending order according to the ASCII code of the parameter name (lexicographic order), and concatenate them into a string strA using the correct format of the URL key value (key1=value1&key2=value2…)
- MD5 operation is performed on strA, and all characters of the obtained string are converted to uppercase to obtain the md5Str string.
- Use the merchant's private key (Base64 encoding) to sign md5Str with SHA1WithRSA to obtain the string sign, and put the sign string into the signature field in the request header information.
Signature parameters
Assume that the parameters to be signed are as follows:
Step 1
The parameters are sorted in the format of key = value and ASCII alphabetical order by parameter name as follows:
Step 2
MD5(strA), to uppercase:
Step 3
Merchant private key to generate signature:
Signing example
Signing the request with the private key saved by the merchant To facilitate access, we provide a demo project that generates signatures. You can use the PalmPayUtil.generateSig() method in the attachment 📎PalmpaySdkDemoNew to generate the signature. This signature method has implemented the three steps of the above Signature. You can directly copy the code and integrate it into the project.
Sample code
Signature Verification
In order to ensure data security, the merchant's back-end needs to authenticate palmpay's callback requests to the merchant.
Step 1
The parameters are sorted in the format of key = value and ASCII alphabetical order by parameter name as follows:
Step 2
MD5(strA), to uppercase:
Signature verification example
Use the public key provided by the PalmPay to verify PalmPay signature of the callback merchant interface. PalmPay notifies the callback request, the request parameters in @RequestBody that are non-null except sign get md5Str according to the rules in step 1 and step 2. Use the PalmPayUtil.verifySignForCallback method in the attachment 📎PalmpaySdkDemoNew to verify the signature
Sample code:
Notes on signature verification
- Callback interface signature verification a. Callback interface signature verification needs to be a full-field signature (remove all fields after the sign), the first Palmpay callback request parameters are parsed into a map for the signature verification, after the completion of the signature verification and then normal deserialization into a Java object as needed.
Other considerations
- Callback interface return value a. The return result of Palmpay callback should be success (not in json format, does not contain other characters), other return results will trigger 6 retries.