微信开发中的坑

出现redirect URL 错误时

需要检查appId和公众号配置(1个是js域名配置, 一个是js接口回调域名设置). 如果是ip,并且有端口号,需要是: ip+端口号

微信分享时,不显示图片

设置的图片要用英文的名字,否则在微信分享时就不行

title: sessionService.getSellerInfo().nickname + '的店铺',// 分享标题
desc: '只卖最优质的商品', // 分享描述'
imgUrl: 'http://wd.pinzhi365.com/wxbuyer/img/homePage/logo.png',

在ios上,微信退出,但是localStorage的变量依然还存在, 造成新用户登录后, 点进链接进去,结果还是上一个用户的信息

在安卓上,退出账号会清空cookie和缓存, 而ios上则保留缓存, cookie会删除.

用到的几个公共方法:

 //1. 查找cookie, 用cookie代替缓存
 function getCookie(cookieName)
  {
    if (document.cookie.length>0)
    {
      var cookie_string = document.cookie;
      c_start = cookie_string.indexOf(cookieName+ "=");
      if (c_start ==-1)
      {
          return ""
      }
      c_start=c_start + c_name.length+1;
      c_end=document.cookie.indexOf(";", c_start);
      //如果只有一条cookie,结尾index就是和字符串的长度相等
      if (c_end == -1)
      {
        c_end = document.cookie.length;
      }
      return unescape(document.cookie.substring(c_start,c_end));
    }

  }
//判断是否是ios
 function isIOS(){
    var u = navigator.userAgent;
    var isIOS = !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/);
    return isIOS;
  }
//可以获取各种url中参数值
getParameterByName:function(name, url) {
        if (!url) url = window.location.href;

        name = name.replace(/[\[\]]/g, "\\$&");
        var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
        results = regex.exec(url);
        if (!results) return null;
        if (!results[2]) return '';
        return decodeURIComponent(results[2].replace(/\+/g, " "));
      },

  setCookie:function(c_name, value, expiredays)
      {
        var exdate=new Date();
        exdate.setDate(exdate.getDate()+expiredays);
        document.cookie=c_name+ "=" +escape(value)+ ((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
      }

首先在controller中获取到个人信息后,把微信的unionCode作为value, ‘unionCode’作为key, 存在cookie中和localStorage中.
在index.html中的script中分别获取cookie和localStorage中的unionCode, 进行对比,看值是否一致
部分代码如下:

if(!weixinInfo ||  (weixinInfo.openid != openid && isIOS())){
      //设定微信验证地址
      locationParameters.OAuthLocation = 'https://open.weixin.qq.com/connect/oauth2/authorize?' +
        'appid=' + locationParameters.appid +
        '&redirect_uri='+ encodeURIComponent(redirectUrl) +
        '&response_type=code' +
        '&scope=snsapi_userinfo' +
        '&state=exodus' +
        '#wechat_redirect';
      location.href = locationParameters.OAuthLocation;
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值