微信 jssdk 签名错误

wechat.config({ debug: false, appId: appId, timestamp: timestamp, nonceStr: nonceStr, signature: signature, jsApiList: ['scanQRCode'], });

invalid signature 通常都是后端签名有问题 后端的域名要在公众号上配置下

但问题是在iOS下,若是个人另一个菜单入口是B页面,我从B页面跳转到A页面,这时候个人入口连接被强制变成了A页面,依然会产生签名失败的错误。
iOSBBAA
let url = "";
// 判断是不是ios微信浏览器 ios要使用当前的url
// if (navigator.userAgent.indexOf('iPhone') !== -1)
if (window.__wxjs_is_wkwebview === true) {
url = this.$store.state.url.split("#")[0];
} else {
url = window.location.href.split("#")[0];
}


因此咱们还须要在微信公众号的每个入口菜单连接里加一个特殊的参数,例如wechat=1,变成这样:https://www.abc.com/abc.html?abc=def&wechat=1css

而后咱们再增长一层判断,变成这样:html

if (navigator.userAgent.indexOf('iPhone') !== -1) { if (this.$route.query.wechat !== undefined && this.$route.query.wechat === '1') { window.wechaturl = window.location + ''; } } 

这里我用了vue的写法,但原理是同样的。只有我检测到了wechat这个参数,我才认为当前页面是入口页面,若是没有检测到,则没必要强行设置为入口页面。vue

 
// 处理jssdk签名,兼容history模式
if (!store.state.url) {
store.commit('setUrl', document.URL)
}
相关文章
相关标签/搜索