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