|
@@ -16,6 +16,7 @@ import com.example.xiaoshiweixinback.business.redis.RedisService;
|
|
|
import com.example.xiaoshiweixinback.business.utils.*;
|
|
|
import com.example.xiaoshiweixinback.domain.Person;
|
|
|
import com.example.xiaoshiweixinback.entity.dto.person.*;
|
|
|
+import com.example.xiaoshiweixinback.entity.vo.PersonnelVO;
|
|
|
import com.example.xiaoshiweixinback.entity.vo.person.Jscode2SessionWo;
|
|
|
import com.example.xiaoshiweixinback.entity.vo.person.LoginByWxVO;
|
|
|
import com.example.xiaoshiweixinback.entity.vo.person.LoginVO;
|
|
@@ -51,9 +52,12 @@ public class LoginService {
|
|
|
|
|
|
@Value("${WeChat.appSecret}")
|
|
|
private String appSecret;
|
|
|
-//
|
|
|
-// @Autowired
|
|
|
-// private Environment environment;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private CacheUtil cacheUtil;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private LoginUtils loginUtils;
|
|
|
|
|
|
@Autowired
|
|
|
private JwtTokenUtil jwtTokenUtil;
|
|
@@ -76,33 +80,24 @@ public class LoginService {
|
|
|
@Transactional(propagation = Propagation.REQUIRED, rollbackFor = Throwable.class)
|
|
|
public LoginVO loginByPhone(LoginDTO dto) {
|
|
|
LogHelper.log("登录开始");
|
|
|
- if (!dto.getPhoneCode().equals("123456")) {
|
|
|
- //获取缓存中验证码
|
|
|
- Object codeObj = redisService.get(AppCacheKeyUtil.getLoginMessageCode(dto.getPhoneNum()));
|
|
|
- if (ToolUtil.isEmpty(codeObj)) {
|
|
|
- throw new BusinessException(ExceptionEnum.CODE_WRONG);
|
|
|
- }
|
|
|
+ //获取缓存中验证码
|
|
|
+ Object codeObj = redisService.get(AppCacheKeyUtil.getLoginMessageCode(dto.getPhoneNum()));
|
|
|
+ if (ToolUtil.isEmpty(codeObj)) {
|
|
|
+ throw new BusinessException(ExceptionEnum.CODE_WRONG);
|
|
|
+ }
|
|
|
|
|
|
- //校验验证码
|
|
|
- if (ToolUtil.isEmpty(dto.getPhoneCode())) {
|
|
|
- throw new BusinessException(ExceptionEnum.THE_CODE_IS_NOT_NULL);
|
|
|
- }
|
|
|
+ //校验验证码
|
|
|
+ if (ToolUtil.isEmpty(dto.getPhoneCode())) {
|
|
|
+ throw new BusinessException(ExceptionEnum.THE_CODE_IS_NOT_NULL);
|
|
|
+ }
|
|
|
|
|
|
- if (!ToolUtil.equals(codeObj.toString(), dto.getPhoneCode())) {
|
|
|
- throw new BusinessException(ExceptionEnum.CODE_WRONG);
|
|
|
- }
|
|
|
- //校验验证码成功后使其失效
|
|
|
- redisService.delete(AppCacheKeyUtil.getLoginMessageCode(dto.getPhoneNum()));
|
|
|
+ if (!ToolUtil.equals(codeObj.toString(), dto.getPhoneCode())) {
|
|
|
+ throw new BusinessException(ExceptionEnum.CODE_WRONG);
|
|
|
}
|
|
|
+ //校验验证码成功后使其失效
|
|
|
+ redisService.delete(AppCacheKeyUtil.getLoginMessageCode(dto.getPhoneNum()));
|
|
|
//查询用户
|
|
|
LambdaQueryWrapper<Person> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
-// if (ToolUtil.isNotEmpty(dto.getAccount())) {
|
|
|
-// queryWrapper.eq(Person::getEmail, dto.getAccount());
|
|
|
-// }
|
|
|
-// if (ToolUtil.isNotEmpty(dto.getPassword())) {
|
|
|
-// String password = SecureUtil.md5(dto.getPassword());
|
|
|
-// queryWrapper.eq(Person::getUserPassword, password);
|
|
|
-// }
|
|
|
if (ToolUtil.isNotEmpty(dto.getPhoneNum())) {
|
|
|
queryWrapper.eq(Person::getPhoneNum, dto.getPhoneNum());
|
|
|
}
|
|
@@ -113,6 +108,12 @@ public class LoginService {
|
|
|
person.setPhoneNum(dto.getPhoneNum());
|
|
|
String uid = IdUtil.simpleUUID();
|
|
|
person.setUuid(uid);
|
|
|
+ PersonnelVO personnelVO = cacheUtil.getLoginUser(loginUtils.getId());
|
|
|
+ if (ToolUtil.isNotEmpty(personnelVO)) {
|
|
|
+ Integer personId = personnelVO.getId();
|
|
|
+ person.setCreateId(personId.toString());
|
|
|
+ }
|
|
|
+ person.setCreateTime(new Date());
|
|
|
personMapper.insert(person);
|
|
|
|
|
|
loginVO.setId(person.getId());
|
|
@@ -147,13 +148,6 @@ public class LoginService {
|
|
|
// //1.根据code 获取微信小程序的openid和session_key
|
|
|
JSONObject result = this.getSessionKeyAndOpenId(code);
|
|
|
Jscode2SessionWo jscode2SessionWo = ResponseManager.parseObject(result.toString(), Jscode2SessionWo.class);
|
|
|
-// HashMap<String, String> map = new HashMap<String, String>();
|
|
|
-// map.put("appid", appId);
|
|
|
-// map.put("secret", appSecret);
|
|
|
-// map.put("js_code", code);
|
|
|
-// map.put("grant_type", "authorization_code");
|
|
|
-// String result = RequestManager.getInstance().requestPostBySynWithForm("https://api.weixin.qq.com/sns/jscode2session", map);
|
|
|
-// Jscode2SessionWo jscode2SessionWo = ResponseManager.parseObject(result, Jscode2SessionWo.class);
|
|
|
if (ToolUtil.isNotEmpty(jscode2SessionWo)) {
|
|
|
// 2. 解密用户数据
|
|
|
String decryptedData = decrypt(encryptedData, jscode2SessionWo.getSession_key(), iv);
|
|
@@ -183,6 +177,12 @@ public class LoginService {
|
|
|
person.setOpenId(jscode2SessionWo.getOpenid());
|
|
|
String uid = IdUtil.simpleUUID();
|
|
|
person.setUuid(uid);
|
|
|
+ PersonnelVO personnelVO = cacheUtil.getLoginUser(loginUtils.getId());
|
|
|
+ if (ToolUtil.isNotEmpty(personnelVO)) {
|
|
|
+ Integer personId = personnelVO.getId();
|
|
|
+ person.setCreateId(personId.toString());
|
|
|
+ }
|
|
|
+ person.setCreateTime(new Date());
|
|
|
person.insert();
|
|
|
|
|
|
wxVO.setIfFirst(true);
|
|
@@ -372,32 +372,4 @@ public class LoginService {
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
- /*public String getAccessToken() {
|
|
|
- String appId = environment.getProperty("wx.appId");
|
|
|
- String appSecret = environment.getProperty("wx.appSecret");
|
|
|
- if (lock.tryLock()) {
|
|
|
- try {
|
|
|
- HashMap<String, String> map = new HashMap<>();
|
|
|
- map.put("appid", appId);
|
|
|
- map.put("secret", appSecret);
|
|
|
- map.put("grant_type", "client_credential");
|
|
|
-
|
|
|
- String result = RequestManager.getInstance().requestGetBySyn("https://api.weixin.qq.com/cgi-bin/token", map);
|
|
|
- LogHelper.log(MiniAppService.class, "申请Token结果:" + result);
|
|
|
- ApplyAccessWo applyAccessWo = ResponseManager.parseObject(result, ApplyAccessWo.class);
|
|
|
- if (StringUtils.hasLength(applyAccessWo.getAccess_token())) {//成功得到access_token
|
|
|
- return applyAccessWo.getAccess_token();
|
|
|
- } else {//获取access_token失败
|
|
|
- throw new BusinessException(ExceptionEnum.WX_APPLY_ACCESS_TOKEN_ERROR);
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- throw new BusinessException(ExceptionEnum.WX_APPLY_ACCESS_TOKEN_ERROR);
|
|
|
- } finally {
|
|
|
- lock.unlock();
|
|
|
- }
|
|
|
- }
|
|
|
- return null;
|
|
|
- }*/
|
|
|
}
|