About the WeChat interface exception, the reason for verification failure [recent: 2.28 days later]

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.