|
|
@@ -158,25 +158,36 @@ public class SysLoginService
|
|
|
/**
|
|
|
* 登录
|
|
|
*/
|
|
|
- public LoginUser openIdLogin(String username, String openId)
|
|
|
+ public LoginUser openIdLogin(String jsCode, String code)
|
|
|
{
|
|
|
// 用户名或密码为空 错误
|
|
|
- if (StringUtils.isAnyBlank(username, openId))
|
|
|
+ if (StringUtils.isAnyBlank(jsCode, code))
|
|
|
{
|
|
|
- recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "用户/openId必须填写");
|
|
|
- throw new ServiceException("用户/openId必须填写");
|
|
|
+ recordLogService.recordLogininfor("", Constants.LOGIN_FAIL, "微信小程序登录失败");
|
|
|
+ throw new ServiceException("登录失败,请联系管理员");
|
|
|
}
|
|
|
// IP黑名单校验
|
|
|
String blackStr = Convert.toStr(redisService.getCacheObject(CacheConstants.SYS_LOGIN_BLACKIPLIST));
|
|
|
if (IpUtils.isMatchedIp(blackStr, IpUtils.getIpAddr()))
|
|
|
{
|
|
|
- recordLogService.recordLogininfor(username, Constants.LOGIN_FAIL, "很遗憾,访问IP已被列入系统黑名单");
|
|
|
+ recordLogService.recordLogininfor("", Constants.LOGIN_FAIL, "很遗憾,访问IP已被列入系统黑名单");
|
|
|
throw new ServiceException("很遗憾,访问IP已被列入系统黑名单");
|
|
|
}
|
|
|
- // 查询用户信息
|
|
|
+ R<String> openIdData = remoteUserService.getOpenId(jsCode, SecurityConstants.INNER);
|
|
|
+ if (StringUtils.isBlank(openIdData.getData())) {
|
|
|
+ throw new ServiceException("登录失败,请联系管理员");
|
|
|
+ }
|
|
|
+ R<String> phoneNumber = remoteUserService.getPhoneNumber(code, SecurityConstants.INNER);
|
|
|
+ if (StringUtils.isBlank(phoneNumber.getData())) {
|
|
|
+ throw new ServiceException("登录失败,请联系管理员");
|
|
|
+ }
|
|
|
+
|
|
|
SysUser sysUser = new SysUser();
|
|
|
- sysUser.setUserName(username);
|
|
|
+ String username = phoneNumber.getData();
|
|
|
+ String openId = openIdData.getData();
|
|
|
sysUser.setOpenId(openId);
|
|
|
+ sysUser.setUserName(username);
|
|
|
+ // 查询用户信息
|
|
|
R<LoginUser> userResult = remoteUserService.getUserByOpenId(sysUser, SecurityConstants.INNER);
|
|
|
|
|
|
if (R.FAIL == userResult.getCode())
|
|
|
@@ -198,6 +209,9 @@ public class SysLoginService
|
|
|
}
|
|
|
recordLogService.recordLogininfor(username, Constants.LOGIN_SUCCESS, "登录成功");
|
|
|
recordLoginInfo(user.getUserId());
|
|
|
+
|
|
|
return userInfo;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
}
|