关于Vue调用微信扫一扫,IOS报错

安卓机可以正常使用扫一扫,ios会出现以下错误 {"errMsg":"config:invalid signature"},表示signature授权签名无效。

原因:一般获取signature授权签名需要取得当前调用wx.config页面的url,IOS的微信内置浏览器,验证签名,单页应用的路由是不行的,也就是说 到需要调用扫一扫的页面,必须是由window.location.href跳转过来,而不是this.$router.push,这主要问题在于安卓端和IOS端识别url编码不同的问题,这里不多赘述。

解决方案:

  1. 调用扫一扫的上一个页面 到 调用扫一扫的页面 必须 是window.location.href.
  2. 前端发送给后台,为了配置签名 需要用到url, 这个url = window.location.href。(路由模式为history
  3. 如果你使用的是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' })
  }
}
posted @ 2022-01-25 14:00  AvenCheung  阅读(294)  评论(0编辑  收藏  举报