SoFunction
Updated on 2025-03-09

The page redirection is performed using router in the SPA application of WeChat + angularJS. The problem of jssdk verification failure is solved.

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 thisIf the SPA has just been refreshed, or it does not jump in the middle after loading, the signature will be correct.

But when the route changes, after we re-sign the new "jump" page, we have a signature error. Our signature is obviously correct, so we use various parameters to the WeChat JS signature verification tool (/debug/cgi-bin/sandbox?t=jsapisign) It's the same to compare!

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. . . Jump is actually quite loading the SPA again

I once thought that if the route is redirected, I should use the new URL to resign, but it is 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 disagreeing. . 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!