• 微信公众号爬坑(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 后添加 # 。

     
  • 相关阅读:
    python set
    python中%d %2d %02d %-2d% %.2d的区别
    python dict(字典)
    python 300本电子书合集
    python tuple元组
    python end用法
    python 找出第二大值
    GPU大百科全书 第二章 凝固生命的光栅化
    GPU大百科全书 第一章:美女 方程与几何
    Notepad++中调试用心lua程序
  • 原文地址:https://www.cnblogs.com/landmass/p/10063999.html
Copyright © 2020-2023  润新知