wechat.config({ debug: false, appId: appId, timestamp: timestamp, nonceStr: nonceStr, signature: signature, jsApiList: ['scanQRCode'], });
invalid signature 通常都是后端签名有问题 后端的域名要在公众号上配置下
但问题是在iOS
下,若是个人另一个菜单入口是B
页面,我从B
页面跳转到A
页面,这时候个人入口连接被强制变成了A
页面,依然会产生签名失败的错误。
iOSBBAA
// if (navigator.userAgent.indexOf('iPhone') !== -1)
因此咱们还须要在微信公众号的每个入口菜单连接里加一个特殊的参数,例如wechat=1
,变成这样:https://www.abc.com/abc.html?abc=def&wechat=1
,css
而后咱们再增长一层判断,变成这样: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