|
@@ -3,8 +3,7 @@ package com.caimei365.user.service.impl;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.caimei365.user.components.WeChatService;
|
|
import com.caimei365.user.components.WeChatService;
|
|
import com.caimei365.user.mapper.LoginMapper;
|
|
import com.caimei365.user.mapper.LoginMapper;
|
|
-import com.caimei365.user.model.BaseUser;
|
|
|
|
-import com.caimei365.user.model.JsonModel;
|
|
|
|
|
|
+import com.caimei365.user.model.ResponseJsonVo;
|
|
import com.caimei365.user.model.UserLoginVo;
|
|
import com.caimei365.user.model.UserLoginVo;
|
|
import com.caimei365.user.service.LoginService;
|
|
import com.caimei365.user.service.LoginService;
|
|
import com.caimei365.user.components.RedisService;
|
|
import com.caimei365.user.components.RedisService;
|
|
@@ -44,12 +43,12 @@ public class LoginServiceImpl implements LoginService {
|
|
* @return BaseUser
|
|
* @return BaseUser
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
- public JsonModel<UserLoginVo> passwordLogin(String mobileOrEmail, String password) {
|
|
|
|
|
|
+ public ResponseJsonVo<UserLoginVo> passwordLogin(String mobileOrEmail, String password) {
|
|
if (mobileOrEmail.isEmpty()) {
|
|
if (mobileOrEmail.isEmpty()) {
|
|
- return JsonModel.error("请填写账户名", null);
|
|
|
|
|
|
+ return ResponseJsonVo.error("请填写账户名", null);
|
|
}
|
|
}
|
|
if (password.isEmpty()) {
|
|
if (password.isEmpty()) {
|
|
- return JsonModel.error("请填写密码", null);
|
|
|
|
|
|
+ return ResponseJsonVo.error("请填写密码", null);
|
|
}
|
|
}
|
|
//处理比对密码
|
|
//处理比对密码
|
|
UserLoginVo baseUser = loginMapper.getLoginUserByMobileOrEmail(mobileOrEmail);
|
|
UserLoginVo baseUser = loginMapper.getLoginUserByMobileOrEmail(mobileOrEmail);
|
|
@@ -59,14 +58,14 @@ public class LoginServiceImpl implements LoginService {
|
|
if (md5Password.equals(dbPassword)) {
|
|
if (md5Password.equals(dbPassword)) {
|
|
if (baseUser.getUserIdentity() == 1) {
|
|
if (baseUser.getUserIdentity() == 1) {
|
|
// 协销登录
|
|
// 协销登录
|
|
- return JsonModel.success(baseUser);
|
|
|
|
|
|
+ return ResponseJsonVo.success(baseUser);
|
|
} else {
|
|
} else {
|
|
// 返回登录校验结果
|
|
// 返回登录校验结果
|
|
return logonVerify(baseUser);
|
|
return logonVerify(baseUser);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- return JsonModel.error("输入的密码和账户名不匹配", null);
|
|
|
|
|
|
+ return ResponseJsonVo.error("输入的密码和账户名不匹配", null);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -78,14 +77,14 @@ public class LoginServiceImpl implements LoginService {
|
|
* @param serverWebExchange ServerWebExchange
|
|
* @param serverWebExchange ServerWebExchange
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
- public JsonModel<UserLoginVo> appletsAuthorization(String code, String encryptedData, String iv, ServerWebExchange serverWebExchange) {
|
|
|
|
|
|
+ public ResponseJsonVo<UserLoginVo> appletsAuthorization(String code, String encryptedData, String iv, ServerWebExchange serverWebExchange) {
|
|
if (StringUtils.isBlank(code)) {
|
|
if (StringUtils.isBlank(code)) {
|
|
- return JsonModel.error("没有获取到微信授权code", null);
|
|
|
|
|
|
+ return ResponseJsonVo.error("没有获取到微信授权code", null);
|
|
}
|
|
}
|
|
// 小程序微信授权获取登录信息
|
|
// 小程序微信授权获取登录信息
|
|
- JsonModel<Map<String, Object>> appletsInfo = weChatService.getInfoMapByApplets(code, serverWebExchange);
|
|
|
|
|
|
+ ResponseJsonVo<Map<String, Object>> appletsInfo = weChatService.getInfoMapByApplets(code, serverWebExchange);
|
|
if (appletsInfo.getCode() == -1) {
|
|
if (appletsInfo.getCode() == -1) {
|
|
- return JsonModel.error(appletsInfo.getMsg(), null);
|
|
|
|
|
|
+ return ResponseJsonVo.error(appletsInfo.getMsg(), null);
|
|
}
|
|
}
|
|
Map<String, Object> infoData = appletsInfo.getData();
|
|
Map<String, Object> infoData = appletsInfo.getData();
|
|
String openId = (String) infoData.get("openId");
|
|
String openId = (String) infoData.get("openId");
|
|
@@ -102,7 +101,7 @@ public class LoginServiceImpl implements LoginService {
|
|
}
|
|
}
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
- return JsonModel.error("微信解密失败", null);
|
|
|
|
|
|
+ return ResponseJsonVo.error("微信解密失败", null);
|
|
}
|
|
}
|
|
// 用户数据存入Redis,key前缀:wxInfo:applets:
|
|
// 用户数据存入Redis,key前缀:wxInfo:applets:
|
|
redisService.setMap("wxInfo:applets:" + unionId, infoData);
|
|
redisService.setMap("wxInfo:applets:" + unionId, infoData);
|
|
@@ -115,7 +114,7 @@ public class LoginServiceImpl implements LoginService {
|
|
seller.setToken(token);
|
|
seller.setToken(token);
|
|
seller.setUnionId(unionId);
|
|
seller.setUnionId(unionId);
|
|
seller.setOpenId(openId);
|
|
seller.setOpenId(openId);
|
|
- return JsonModel.success(seller);
|
|
|
|
|
|
+ return ResponseJsonVo.success(seller);
|
|
}
|
|
}
|
|
// 运营人员授权登录
|
|
// 运营人员授权登录
|
|
return operationAuthLogin(openId, unionId, "mini");
|
|
return operationAuthLogin(openId, unionId, "mini");
|
|
@@ -128,12 +127,12 @@ public class LoginServiceImpl implements LoginService {
|
|
* @param mode 授权方式:1静默授权,其他手动同意授权
|
|
* @param mode 授权方式:1静默授权,其他手动同意授权
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
- public JsonModel<String> getAuthorizationLink(String redirectUri, Integer mode) {
|
|
|
|
|
|
+ public ResponseJsonVo<String> getAuthorizationLink(String redirectUri, Integer mode) {
|
|
String link = weChatService.getAuthorizationLink(redirectUri, mode);
|
|
String link = weChatService.getAuthorizationLink(redirectUri, mode);
|
|
String state = UUID.randomUUID().toString();
|
|
String state = UUID.randomUUID().toString();
|
|
redisService.set(state, state, 1800L);
|
|
redisService.set(state, state, 1800L);
|
|
link = link.replace("STATE", state);
|
|
link = link.replace("STATE", state);
|
|
- return JsonModel.success(link);
|
|
|
|
|
|
+ return ResponseJsonVo.success(link);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -147,9 +146,9 @@ public class LoginServiceImpl implements LoginService {
|
|
* @param serverWebExchange ServerWebExchange
|
|
* @param serverWebExchange ServerWebExchange
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
- public JsonModel<UserLoginVo> websiteAuthorization(String code, String state, Integer mode, ServerWebExchange serverWebExchange) {
|
|
|
|
|
|
+ public ResponseJsonVo<UserLoginVo> websiteAuthorization(String code, String state, Integer mode, ServerWebExchange serverWebExchange) {
|
|
if (StringUtils.isBlank(code) || StringUtils.isBlank(state)) {
|
|
if (StringUtils.isBlank(code) || StringUtils.isBlank(state)) {
|
|
- return JsonModel.error("参数异常", null);
|
|
|
|
|
|
+ return ResponseJsonVo.error("参数异常", null);
|
|
}
|
|
}
|
|
String wxState = (String) redisService.get(state);
|
|
String wxState = (String) redisService.get(state);
|
|
log.info("微信code>>>" + code + "state>>>" + wxState + "----" + state + "mode>>>" + mode);
|
|
log.info("微信code>>>" + code + "state>>>" + wxState + "----" + state + "mode>>>" + mode);
|
|
@@ -166,7 +165,7 @@ public class LoginServiceImpl implements LoginService {
|
|
// 返回登录用户
|
|
// 返回登录用户
|
|
return logonVerify(user);
|
|
return logonVerify(user);
|
|
} else {
|
|
} else {
|
|
- return JsonModel.error(-4, "您的微信尚未绑定任何机构", null);
|
|
|
|
|
|
+ return ResponseJsonVo.error(-4, "您的微信尚未绑定任何机构", null);
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
// 获取access_token
|
|
// 获取access_token
|
|
@@ -182,10 +181,10 @@ public class LoginServiceImpl implements LoginService {
|
|
}
|
|
}
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
e.printStackTrace();
|
|
- return JsonModel.error("获取微信信息异常", null);
|
|
|
|
|
|
+ return ResponseJsonVo.error("获取微信信息异常", null);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- return JsonModel.error("请从正确的途径打开链接", null);
|
|
|
|
|
|
+ return ResponseJsonVo.error("请从正确的途径打开链接", null);
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -195,7 +194,7 @@ public class LoginServiceImpl implements LoginService {
|
|
* @param source 来源:www网站, mini小程序
|
|
* @param source 来源:www网站, mini小程序
|
|
* @return BaseUser
|
|
* @return BaseUser
|
|
*/
|
|
*/
|
|
- private JsonModel<UserLoginVo> operationAuthLogin(String openId, String unionId, String source) {
|
|
|
|
|
|
+ private ResponseJsonVo<UserLoginVo> operationAuthLogin(String openId, String unionId, String source) {
|
|
UserLoginVo operation = loginMapper.getOperationUserByUnionId(unionId, source);
|
|
UserLoginVo operation = loginMapper.getOperationUserByUnionId(unionId, source);
|
|
if (null == operation) {
|
|
if (null == operation) {
|
|
operation = loginMapper.getOperationUserByOpenId(openId, source);
|
|
operation = loginMapper.getOperationUserByOpenId(openId, source);
|
|
@@ -203,7 +202,7 @@ public class LoginServiceImpl implements LoginService {
|
|
operation = new UserLoginVo();
|
|
operation = new UserLoginVo();
|
|
operation.setOpenId(openId);
|
|
operation.setOpenId(openId);
|
|
operation.setUnionId(unionId);
|
|
operation.setUnionId(unionId);
|
|
- return JsonModel.error("您的微信尚未绑定任何机构", operation);
|
|
|
|
|
|
+ return ResponseJsonVo.error("您的微信尚未绑定任何机构", operation);
|
|
} else {
|
|
} else {
|
|
// 表示 openId存在, unionId不存在
|
|
// 表示 openId存在, unionId不存在
|
|
loginMapper.updateOperationUnionId(operation.getUserId(), unionId);
|
|
loginMapper.updateOperationUnionId(operation.getUserId(), unionId);
|
|
@@ -223,7 +222,7 @@ public class LoginServiceImpl implements LoginService {
|
|
* @param baseUser 用户信息
|
|
* @param baseUser 用户信息
|
|
* @return BaseUser
|
|
* @return BaseUser
|
|
*/
|
|
*/
|
|
- private JsonModel<UserLoginVo> logonVerify(UserLoginVo baseUser) {
|
|
|
|
|
|
+ private ResponseJsonVo<UserLoginVo> logonVerify(UserLoginVo baseUser) {
|
|
// 生成token给用户
|
|
// 生成token给用户
|
|
String token = JwtUtil.createToken(baseUser.getUserId());
|
|
String token = JwtUtil.createToken(baseUser.getUserId());
|
|
// 为了过期续签,将token存入redis,并设置超时时间
|
|
// 为了过期续签,将token存入redis,并设置超时时间
|
|
@@ -231,18 +230,18 @@ public class LoginServiceImpl implements LoginService {
|
|
baseUser.setToken(token);
|
|
baseUser.setToken(token);
|
|
if (baseUser.getStatus() == 91) {
|
|
if (baseUser.getStatus() == 91) {
|
|
//机构 / 供应商
|
|
//机构 / 供应商
|
|
- return JsonModel.error(-2, "您的企业账号已被冻结,请联系客服处理", null);
|
|
|
|
|
|
+ return ResponseJsonVo.error(-2, "您的企业账号已被冻结,请联系客服处理", null);
|
|
}
|
|
}
|
|
// 供应商
|
|
// 供应商
|
|
if (baseUser.getUserIdentity() == 3) {
|
|
if (baseUser.getUserIdentity() == 3) {
|
|
if (baseUser.getStatus() == 3) {
|
|
if (baseUser.getStatus() == 3) {
|
|
- return JsonModel.error(-2, "您的企业账号正在加速审核中,审核通过后即可登录", null);
|
|
|
|
|
|
+ return ResponseJsonVo.error(-2, "您的企业账号正在加速审核中,审核通过后即可登录", null);
|
|
}
|
|
}
|
|
if (baseUser.getStatus() == 92) {
|
|
if (baseUser.getStatus() == 92) {
|
|
- return JsonModel.error(-3, "您的企业账号审核未通过", baseUser);
|
|
|
|
|
|
+ return ResponseJsonVo.error(-3, "您的企业账号审核未通过", baseUser);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- return JsonModel.success("登录成功", baseUser);
|
|
|
|
|
|
+ return ResponseJsonVo.success("登录成功", baseUser);
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|