Appearance
Signature Algorithm
Step One
- All the paramters sent to the server is treated as a key-value Map. Sort the map M by the ASCII values of keys in ascending order(0->9,a->z,A->Z).
- Concatenate them into a string named stringA using the URL key-value pair format (i.e., key1=value1&key2=value2…).
- add &key=secret_key at the end of the StringA
- the whole
StringAis like"key1=value1&key2=value2&key={your_secret_key}"
Please pay Special Attention to the following important rules:
- make sure all values in key-values pair are non-empty, if some value is empty, remove this key-value from the Map;
- Parameter names are sorted in ascending order by their ASCII values (0->9,a->z,A->Z);
- Parameter names are case-sensitive;
Step Two
Calculate the MD5 hashed value on stringA, and convert the md5 hashed value to uppercase, add the md5_hashed_value into the original M-map within the key named sign={md5_hashed_value}
- the whole map is like :
php
$params = [
"key1"=>"value1",
"key2"=>"value2",
"key3"=>"value3",
"sign"=>"{md5_hashed_value}"
]Md5 signautre sample Code
php
function md5_sign($data,$key){
ksort($data);
$string = http_build_query($data);
$string = urldecode($string);
$string=trim($string) . "&key=" . $key;
return strtoupper(md5($string));
}