zoukankan      html  css  js  c++  java
  • 微信公众号爬坑(react)

      1. wx is not undefined 

    解决方案: 在引入微信 JS-SDK 前,设置 define 和 require 值为 null。代码如下:

    1 <script type="text/javascript">
    2         define = null;
    3         require = null;
    4 </script>
    5 <script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>

      2. 微信授权,获取 code。使用 window.location.href 重定向

    1 // 此地址需要公众号后台管理中,接口权限==>网页授权==>网页授权域名 设置; 使用 encodeURIComponent 编码回调地址
    2 let backUrl = '微信授权后的回调地址'; // 例如 test.com/authorize, 
    3 let WXUrl = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' + APPID 
    4 +"&redirect_uri = " + encodeURIComponent(backUrl) +
    5 "&response_type = code" +
    6 "&scope = snsapi_userinfo" +
    7 "&state = STATE#wechat_redirect";
    8 
    9 window.location.href = WXUrl;

      3. 通过 config 接口注入权限验证配置 iOS 平台必须保证 timestamp 参数是字符串

    1 wx.config({
    2     debug: true, 
    3     appId: '', 
    4     timestamp: timestamp + ‘’, // 必填,生成签名的时间戳。保证是字符串类型
    5     nonceStr: '', 
    6     signature: '',
    7     jsApiList: [] 
    8 });

      4. iPhone 平台使用 H5 的 history 路由模式,页面跳转之后,window.location.href 方法获取的地址始终是第一次进入页面的 url ,导致调用 JS-SDK API 时失败。可以使用 hash 路由模式解决这个问题,但是 hash 路由会在 url 后添加 # 。

     
  • 相关阅读:
    HotSpot VM执行引擎的实现
    解释器与JIT编译器
    执行引擎(Execution Engine)基础知识
    堆、栈、方法区的详细图解
    方法区的垃圾回收
    方法区的演进
    方法区的内部结构
    方法区内存配置
    设计模式简记-设计原则之迪米特法则
    设计模式简记-设计原则之DRY原则
  • 原文地址:https://www.cnblogs.com/landmass/p/10063999.html
Copyright © 2011-2022 走看看