The signature generated by the WeChat public account developed by uniapp is the same as the signature generated by the WeChat signature verification tool, but a signature error (invalid signature) is still reported.

The signature generated by the WeChat public account developed by uniapp is the same as the signature generated by the WeChat signature verification tool, but a signature error (invalid signature) is still reported.

If it is confirmed that the signature generated by the WeChat official account is the same as the signature generated by the WeChat signature verification tool, it is generally due to a problem with the URL that generates the signature.

Steps to get url:

1. Obtain the path of entering the page for the first time in main.js, and window.sessionStorage.setItemcache the obtained page path.

window.sessionStorage.setItem('firstEntryUrl',window.location.href.split('#')[0])

2. Write the methods on the page that need to be used. The last url is the obtained current page path.

Solve the problem that the Android registration config is normal but the ios registration config signature error is:原因是ios 无论路由跳转多少次,复制出来的链接都是首次进入的页面的链接

//安卓机型获取当前页面路径
let url = window.location.href.split('#')[0];

//ios机型获取当前页面路径
let ua = navigator.userAgent.toLowerCase();
let isWeixin = ua.indexOf('micromessenger') !== -1;
if (isWeixin) {
    
    
	let isiOS = /(iPhone|iPad|iPod|iOS)/i.test(navigator.userAgent); //ios终端
    if (isiOS && window.sessionStorage.getItem('firstEntryUrl')) {
    
    
        url = window.sessionStorage.getItem('firstEntryUrl').split('#')[0];
    }
}
console.log("当前页面url",url);

ps: WeChat signature verification tool

Insert image description here

Guess you like

Origin blog.csdn.net/m0_52459016/article/details/122243198