|
@ -1,17 +1,19 @@ |
|
|
package com.epmet.service.impl; |
|
|
package com.epmet.service.impl; |
|
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
import com.epmet.common.token.constant.LoginConstant; |
|
|
import com.epmet.common.token.constant.LoginConstant; |
|
|
import com.epmet.commons.tools.constant.NumConstant; |
|
|
|
|
|
import com.epmet.commons.tools.exception.EpmetErrorCode; |
|
|
import com.epmet.commons.tools.exception.EpmetErrorCode; |
|
|
import com.epmet.commons.tools.exception.RenException; |
|
|
import com.epmet.commons.tools.exception.RenException; |
|
|
import com.epmet.commons.tools.redis.RedisKeys; |
|
|
|
|
|
import com.epmet.commons.tools.security.dto.TokenDto; |
|
|
import com.epmet.commons.tools.security.dto.TokenDto; |
|
|
import com.epmet.commons.tools.utils.CpUserDetailRedis; |
|
|
import com.epmet.commons.tools.utils.CpUserDetailRedis; |
|
|
import com.epmet.commons.tools.utils.DateUtils; |
|
|
import com.epmet.commons.tools.utils.DateUtils; |
|
|
|
|
|
import com.epmet.commons.tools.utils.HttpClientManager; |
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
import com.epmet.commons.tools.validator.PhoneValidatorUtils; |
|
|
import com.epmet.commons.tools.validator.PhoneValidatorUtils; |
|
|
import com.epmet.constant.PublicUserLoginConstant; |
|
|
import com.epmet.constant.PublicUserLoginConstant; |
|
|
import com.epmet.constant.SmsTemplateConstant; |
|
|
import com.epmet.constant.SmsTemplateConstant; |
|
|
|
|
|
import com.epmet.constant.ThirdApiConstant; |
|
|
import com.epmet.dto.PaCustomerDTO; |
|
|
import com.epmet.dto.PaCustomerDTO; |
|
|
import com.epmet.dto.PaUserDTO; |
|
|
import com.epmet.dto.PaUserDTO; |
|
|
import com.epmet.dto.PaUserWechatDTO; |
|
|
import com.epmet.dto.PaUserWechatDTO; |
|
@ -32,10 +34,8 @@ import org.slf4j.Logger; |
|
|
import org.slf4j.LoggerFactory; |
|
|
import org.slf4j.LoggerFactory; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.HashMap; |
|
|
import java.util.HashMap; |
|
|
import java.util.List; |
|
|
|
|
|
import java.util.Map; |
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
@ -70,11 +70,12 @@ public class PublicUserLoginServiceImpl implements PublicUserLoginService { |
|
|
WxMpUser wxMpUser = this.getWxMpUser(formDTO.getWxCode()); |
|
|
WxMpUser wxMpUser = this.getWxMpUser(formDTO.getWxCode()); |
|
|
|
|
|
|
|
|
//2.将获取的用户基本信息初始化到数据库
|
|
|
//2.将获取的用户基本信息初始化到数据库
|
|
|
Result<SaveUserResultDTO> result = epmetThirdFeignClient.saveUser(wxMpUser); |
|
|
String url = ThirdApiConstant.THIRD_PAUSER_SAVEUSER; |
|
|
|
|
|
Result<String> result = HttpClientManager.getInstance().sendPostByJSON(url, JSON.toJSONString(wxMpUser)); |
|
|
if (!result.success()) { |
|
|
if (!result.success()) { |
|
|
throw new RenException(PublicUserLoginConstant.SAVE_USER_EXCEPTION); |
|
|
throw new RenException(PublicUserLoginConstant.SAVE_USER_EXCEPTION); |
|
|
} |
|
|
} |
|
|
SaveUserResultDTO resultDTO = result.getData(); |
|
|
SaveUserResultDTO resultDTO = JSONObject.parseObject(result.getData(), SaveUserResultDTO.class); |
|
|
|
|
|
|
|
|
//3.获取用户token
|
|
|
//3.获取用户token
|
|
|
String token = this.generateGovWxmpToken(resultDTO.getUserId()); |
|
|
String token = this.generateGovWxmpToken(resultDTO.getUserId()); |
|
@ -157,18 +158,19 @@ public class PublicUserLoginServiceImpl implements PublicUserLoginService { |
|
|
throw new RenException(EpmetErrorCode.ERROR_PHONE.getCode()); |
|
|
throw new RenException(EpmetErrorCode.ERROR_PHONE.getCode()); |
|
|
} |
|
|
} |
|
|
//2、根据手机号校验用户是否存在
|
|
|
//2、根据手机号校验用户是否存在
|
|
|
Result<CustomerUserResultDTO> Result = epmetThirdFeignClient.checkPaUser(formDTO.getPhone()); |
|
|
String url = ThirdApiConstant.THIRD_PAUSER_CHECKPAUSER + formDTO.getPhone(); |
|
|
if (!Result.success()) { |
|
|
Result<String> result = HttpClientManager.getInstance().sendPostByJSON(url, null); |
|
|
logger.error(String.format(SEND_SMS_CODE_ERROR, formDTO.getPhone(), Result.getCode(), Result.getMsg())); |
|
|
if (!result.success()) { |
|
|
throw new RenException(Result.getCode()); |
|
|
logger.error(String.format(SEND_SMS_CODE_ERROR, formDTO.getPhone(), result.getCode(), result.getMsg())); |
|
|
|
|
|
throw new RenException(result.getCode()); |
|
|
} |
|
|
} |
|
|
CustomerUserResultDTO ResultDTO = Result.getData(); |
|
|
CustomerUserResultDTO resultDTO = JSONObject.parseObject(result.getData(), CustomerUserResultDTO.class); |
|
|
//登陆
|
|
|
//登陆
|
|
|
if (formDTO.getIsLogon() && null == ResultDTO.getPaUserResult()) { |
|
|
if (formDTO.getIsLogon() && null == resultDTO.getPaUserResult()) { |
|
|
throw new RenException(EpmetErrorCode.PUBLIC_NOT_EXISTS.getCode()); |
|
|
throw new RenException(EpmetErrorCode.PUBLIC_NOT_EXISTS.getCode()); |
|
|
} |
|
|
} |
|
|
//注册
|
|
|
//注册
|
|
|
if (!formDTO.getIsLogon() && null != ResultDTO.getPaUserResult()) { |
|
|
if (!formDTO.getIsLogon() && null != resultDTO.getPaUserResult()) { |
|
|
throw new RenException(EpmetErrorCode.MOBILE_USED.getCode()); |
|
|
throw new RenException(EpmetErrorCode.MOBILE_USED.getCode()); |
|
|
} |
|
|
} |
|
|
//3、发送短信验证码
|
|
|
//3、发送短信验证码
|
|
@ -195,12 +197,13 @@ public class PublicUserLoginServiceImpl implements PublicUserLoginService { |
|
|
@Override |
|
|
@Override |
|
|
public UserTokenResultDTO loginByPhone(TokenDto tokenDTO, LoginByPhoneFormDTO formDTO) { |
|
|
public UserTokenResultDTO loginByPhone(TokenDto tokenDTO, LoginByPhoneFormDTO formDTO) { |
|
|
//1.根据手机号查询到用户、客户信息
|
|
|
//1.根据手机号查询到用户、客户信息
|
|
|
Result<CustomerUserResultDTO> result = epmetThirdFeignClient.checkPaUser(formDTO.getPhone()); |
|
|
String url = ThirdApiConstant.THIRD_PAUSER_CHECKPAUSER + formDTO.getPhone(); |
|
|
|
|
|
Result<String> result = HttpClientManager.getInstance().sendPostByJSON(url, null); |
|
|
if (!result.success()) { |
|
|
if (!result.success()) { |
|
|
logger.error(String.format("手机验证码登录异常,手机号[%s],code[%s],msg[%s]", formDTO.getPhone(), result.getCode(), result.getMsg())); |
|
|
logger.error(String.format("手机验证码登录异常,手机号[%s],code[%s],msg[%s]", formDTO.getPhone(), result.getCode(), result.getMsg())); |
|
|
throw new RenException(result.getCode()); |
|
|
throw new RenException(result.getCode()); |
|
|
} |
|
|
} |
|
|
CustomerUserResultDTO resultDTO = result.getData(); |
|
|
CustomerUserResultDTO resultDTO = JSONObject.parseObject(result.getData(), CustomerUserResultDTO.class); |
|
|
|
|
|
|
|
|
//2.用户不存在时不允许登陆
|
|
|
//2.用户不存在时不允许登陆
|
|
|
PaUserDTO userDTO = resultDTO.getPaUserResult(); |
|
|
PaUserDTO userDTO = resultDTO.getPaUserResult(); |
|
@ -236,7 +239,8 @@ public class PublicUserLoginServiceImpl implements PublicUserLoginService { |
|
|
visited.setUserId(userDTO.getId()); |
|
|
visited.setUserId(userDTO.getId()); |
|
|
visited.setLogonUserId(tokenDTO.getUserId()); |
|
|
visited.setLogonUserId(tokenDTO.getUserId()); |
|
|
visited.setPhone(formDTO.getPhone()); |
|
|
visited.setPhone(formDTO.getPhone()); |
|
|
Result visitedResult = epmetThirdFeignClient.saveUserVisited(visited); |
|
|
String saveUserVisitedUrl = ThirdApiConstant.THIRD_PAUSERVISITED_SAVEUSERVISITED; |
|
|
|
|
|
Result<String> visitedResult = HttpClientManager.getInstance().sendPostByJSON(saveUserVisitedUrl, JSON.toJSONString(visited)); |
|
|
if(!visitedResult.success()){ |
|
|
if(!visitedResult.success()){ |
|
|
logger.error(PublicUserLoginConstant.SAVE_VISITED_EXCEPTION); |
|
|
logger.error(PublicUserLoginConstant.SAVE_VISITED_EXCEPTION); |
|
|
} |
|
|
} |
|
|