WeChat config: invalidsignature

Source: Internet
Author: User
Provides various official and user-released code examples. For code reference, you are welcome to exchange and learn about the public platform. config: invalid signature has been the solution to this error.


If it is an invalid signature error. Check in the following order:

1. confirm that the signature algorithm is correct, available http://mp.weixin.qq.com/debug/cgi-bin/sandbox? T = jsapisign page tool for verification.

2. Check that the nonceStr in config (standard upper-case S in js) and timestamp are consistent with the corresponding noncestr and timestamp in the signature.

3. confirm that the url is the complete url of the page (please go to the current page alert (location. href. split ('#') [0]), including 'HTTP (s): // ', and '? 'Get parameter section, but does not include the section after '#' hash.

4. Check that the appid in config is consistent with the appid used to obtain jsapi_ticket.

5. Make sure that access_token and jsapi_ticket are cached.

This is the focus:
Make sure that you obtain the signed url dynamically. For details about the dynamic page, see the php implementation method in the instance code. If the html static page uploads the url to the background signature through ajax at the front end, the front end needs to use js to obtain the link for removing the '#' hash part of the current page (available location. href. split ('#') [0], and encodeURIComponent is required), because once the page is shared, the client adds other parameters to the end of your link. If it does not dynamically obtain the current link, the shared page signature will fail.

How to verify the correct method:
The dynamic url acquisition method is as follows:
$protocol = (!empty($_SERVER[HTTPS]) && $_SERVER[HTTPS] !== off || $_SERVER[SERVER_PORT] == 443) ? "https://" : "http://";
$url = $protocol.$_SERVER[HTTP_HOST].$_SERVER[REQUEST_URI];
Steps:
First, go to the alert (location. href. split ('#') [0]) page.
Then you can print out whether the dynamically obtained url is the same as your alert url. Must be exactly the same, including case.
If you find the difference, you can change it as needed. It should be the same. The signature must be verified.
If you have any questions, I will reply to them one by one.

AD: truly free, domain name + VM + enterprise mailbox = 0 RMB

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.