zoukankan      html  css  js  c++  java
  • 微信 jssdk 签名错误

     wechat.config({
          debug: false,
          appId: appId,
          timestamp: timestamp,
          nonceStr: nonceStr,
          signature: signature,
          jsApiList: ['scanQRCode'],
        });

    invalid signature 一般都是后端签名有问题 后端的域名要在公众号上配置下

    但问题是在iOS下,如果我的另外一个菜单入口是B页面,我从B页面跳转到A页面,这时候我的入口链接被强制变成了A页面,依然会产生签名失败的错误。
    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=1

    然后我们再增加一层判断,变成这样:

    if (navigator.userAgent.indexOf('iPhone') !== -1) {
      if (this.$route.query.wechat !== undefined && this.$route.query.wechat === '1') {
        window.wechaturl = window.location + '';
      }
    }
    

    这里我用了vue的写法,但原理是一样的。只有我检测到了wechat这个参数,我才认为当前页面是入口页面,如果没有检测到,则不必强行设置为入口页面。

     
    // 处理jssdk签名,兼容history模式
    if (!store.state.url) {
    store.commit('setUrl', document.URL)
    }
  • 相关阅读:
    raw_input() 与 input()对比
    你很熟悉CSS,却没掌握这些CSS技巧
    CSS样式设置
    javascript基本语法和变量(转)
    手机/移动前端开发需要注意的20个要点
    移动端”宴席知多少
    git第一次提交代码到远程仓库
    java对过反射调用方法
    站点收集
    别人抢红包,我们研究一下红包算法
  • 原文地址:https://www.cnblogs.com/guidan/p/10299740.html
Copyright © 2011-2022 走看看