This is the signature verification function of the official sample: privatefunctioncheckSignature () {$ signature =$ _ GET [& quot; signature & quot;];
This is the signature verification function of the official sample:
private function checkSignature(){ $signature = $_GET["signature"]; $timestamp = $_GET["timestamp"]; $nonce = $_GET["nonce"]; $token = TOKEN;$tmpArr = array($token, $timestamp, $nonce);sort($tmpArr);$tmpStr = implode( $tmpArr );$tmpStr = sha1( $tmpStr );if( $tmpStr == $signature ){return true;}else{return false;}}
The reason is as follows:
'74ea873b074a61f316a3ab6e78787787 ', 'timestamp' => '000000', 'nonce' => '000000'); sort ($ arr ); // sort print_r ($ arr) in the official demo; // Array ([0] => 963820356 [1] => 1393812476 [2] => 74ea873b074a61f397a3ab6e787787) sort ($ arr, SORT_STRING); // correct string-type sorting print_r ($ arr); // Array ([0] => 1393812476 [1] => 74ea873b074a61f397a3ab6e787787 [2] => 963820356)
Description of the sort function:
It sorts arrays, which has been explicitly stated in the manual:
If the sorting type is determined, the sort function provides the second function to specify the sorting type:
- SORT_REGULAR-normal comparison unit (without changing the type)
- SORT_NUMERIC-the unit is compared as a number.
- SORT_STRING-the unit is compared as a string
- SORT_LOCALE_STRING-compare the unit as a string based on the current region (locale) settings