关于Vue调用微信扫一扫,IOS报错
安卓机可以正常使用扫一扫,
ios
会出现以下错误{"errMsg":"config:invalid signature"}
,表示signature授权签名无效。
原因:一般获取signature授权签名需要取得当前调用wx.config页面的url,IOS
的微信内置浏览器,验证签名,单页应用的路由是不行的,也就是说 到需要调用扫一扫的页面,必须是由window.location.href
跳转过来,而不是this.$router.push
,这主要问题在于安卓端和IOS
端识别url
编码不同的问题,这里不多赘述。
解决方案:
- 调用扫一扫的上一个页面 到 调用扫一扫的页面 必须 是
window.location.href
. - 前端发送给后台,为了配置签名 需要用到
url
, 这个url = window.location.href
。(路由模式为history
) - 如果你使用的是hash路由模式则
url = window.location.href.split('#')
解决方案:判断下机型
// 路由模式 history
appSource () {
const u = navigator.userAgent;
const isiOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
if (isiOS) {
window.location.href = '/home'
} else {
this.$router.push({ path: '/home' })
}
}