微信分享會根據分享的不同,為原始鏈接拼接如下參數:
對於IOS系統會自動增加如下參數:
朋友圈 from=timeline&isappinstalled=0
微信群 from=groupmessage&isappinstalled=0
好友分享 from=singlemessage&isappinstalled=0
對於安卓系統會自動添加如下參數:
朋友圈 from=timeline
微信群 from=groupmessage
好友分享 from=singlemessage
這樣導致請求頁面獲取地理位置wx.getLocation方法失敗,可通過wx.config設置debug : ture進行調試,發現究其原因是簽名計算錯誤了。
進入獲取簽名的方法中,需要在url上添加固定分享后的參數之后再進行簽名運行。
StringBuilder url = new StringBuilder(“XXXXXXXX”); //此處用於分享后多出來的參數加入一起參加簽名計算,不然會簽名計算錯誤,導致頁面無法獲取地理位置 String from = request.getParameter("from"); String isappinstalled = request.getParameter("isappinstalled"); if(StringUtils.isNotBlank(from)){ url.append("?from="+from); } if(StringUtils.isNotBlank(isappinstalled)){ url.append("&isappinstalled="+isappinstalled); }
問題解決!
微信分享部分可參考https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141115