出现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;
}