微信 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)
}
相關文章
相關標籤/搜索