Today, I accidentally opened the debugging of WeChat jssdk and found that the debugging information always prompted an error in signature. The "occasionally" of the API did not take effect two days ago, not because the code has not been executed, but because the signature is not correct! , this is a 100% reproducible error
But as long as the SPA has just been refreshed or does not jump in the middle after loading, the signature will be correct.
But when the route changes, after we re-signed the new "jump" page, we encountered a signature error. Our signature is obviously correct. It is the same to use various parameters to the WeChat JS signature verification tool (http://mp.weixin.qq.com/debug/cgi-bin/sandbox?t=jsapisign) for comparison!
A major discovery later. . . actually
Just sign once when loading the SPA entrance page, because the URL signed by WeChat seems to only recognize the URL of the first page loaded by the SPA. . . The window.location.href jump is actually quite similar to the SPA loading again
I thought that if the route was redirected, I should use the new URL to resign, but it was precisely because of this that I made a mistake in the signature verification. .
So the solution is:
Just sign the first loaded page. The jump using ui-router seems to have just changed the address. . And the modification of this address. . Wechat's signature seems to be unrecognized. . He recognized the URL of the first page loaded.
Through this article, I hope it can help friends who encounter this problem. Thank you for your support for this website!