|
|
@ -91,16 +91,16 @@ public class AppletApiLoginService { |
|
|
log.info("微信登录成功,openid: {}", openid); |
|
|
log.info("微信登录成功,openid: {}", openid); |
|
|
|
|
|
|
|
|
// 查找或创建用户 |
|
|
// 查找或创建用户 |
|
|
AppletUser appletUser = findOrCreateUser(openid, unionid, inviter); |
|
|
|
|
|
|
|
|
AppletUser appletUser = findOrCreateUser(openid, unionid, inviter, type, jsonResponse); |
|
|
|
|
|
|
|
|
|
|
|
String token = null; |
|
|
|
|
|
|
|
|
if (LoginType.OFFICIAL.equals(type)){ |
|
|
if (LoginType.OFFICIAL.equals(type)){ |
|
|
String access_token = jsonResponse.getString("access_token"); |
|
|
|
|
|
setUserInfo(appletUser, access_token); |
|
|
|
|
|
|
|
|
token = JwtUtil.sign(appletUser.getOfficialId(), appletUser.getId()); |
|
|
|
|
|
}else { |
|
|
|
|
|
token = JwtUtil.sign(appletUser.getOpenid(), appletUser.getId()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 生成JWT token |
|
|
|
|
|
String token = JwtUtil.sign(appletUser.getOpenid(), appletUser.getId()); |
|
|
|
|
|
|
|
|
|
|
|
redisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, token); |
|
|
redisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, token); |
|
|
// 设置超时时间 |
|
|
// 设置超时时间 |
|
|
redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, JwtUtil.EXPIRE_TIME * 2 / 1000); |
|
|
redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, JwtUtil.EXPIRE_TIME * 2 / 1000); |
|
|
@ -133,6 +133,7 @@ public class AppletApiLoginService { |
|
|
String headimgurl = json_member.getString("headimgurl"); |
|
|
String headimgurl = json_member.getString("headimgurl"); |
|
|
user.setName(nickname); |
|
|
user.setName(nickname); |
|
|
user.setAvatar(headimgurl); |
|
|
user.setAvatar(headimgurl); |
|
|
|
|
|
appletUserService.updateById(user); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
@ -209,7 +210,7 @@ public class AppletApiLoginService { |
|
|
* @param unionid 微信unionid |
|
|
* @param unionid 微信unionid |
|
|
* @return 用户信息 |
|
|
* @return 用户信息 |
|
|
*/ |
|
|
*/ |
|
|
private AppletUser findOrCreateUser(String openid, String unionid, String inviter) { |
|
|
|
|
|
|
|
|
private AppletUser findOrCreateUser(String openid, String unionid, String inviter, String type, JSONObject jsonResponse) { |
|
|
try { |
|
|
try { |
|
|
// 根据openid查找用户 |
|
|
// 根据openid查找用户 |
|
|
AppletUser user = appletUserService.getByUnionId(openid, unionid); |
|
|
AppletUser user = appletUserService.getByUnionId(openid, unionid); |
|
|
@ -217,7 +218,13 @@ public class AppletApiLoginService { |
|
|
if (user == null) { |
|
|
if (user == null) { |
|
|
// 创建新用户 |
|
|
// 创建新用户 |
|
|
user = new AppletUser(); |
|
|
user = new AppletUser(); |
|
|
user.setOpenid(openid); |
|
|
|
|
|
|
|
|
if (LoginType.OFFICIAL.equals(type)){ |
|
|
|
|
|
user.setOfficialId(openid); |
|
|
|
|
|
String access_token = jsonResponse.getString("access_token"); |
|
|
|
|
|
setUserInfo(user, access_token); |
|
|
|
|
|
}else { |
|
|
|
|
|
user.setOpenid(openid); |
|
|
|
|
|
} |
|
|
user.setName("微信用户" + openid.substring(0, 8)); |
|
|
user.setName("微信用户" + openid.substring(0, 8)); |
|
|
user.setCreateTime(new Date()); |
|
|
user.setCreateTime(new Date()); |
|
|
user.setCreateBy("system"); |
|
|
user.setCreateBy("system"); |
|
|
|