|
@ -8,12 +8,18 @@ import com.epmet.common.token.dto.form.LoginByPassWordFormDTO; |
|
|
import com.epmet.common.token.dto.form.LoginByWxCodeFormDTO; |
|
|
import com.epmet.common.token.dto.form.LoginByWxCodeFormDTO; |
|
|
import com.epmet.common.token.dto.result.UserTokenResultDTO; |
|
|
import com.epmet.common.token.dto.result.UserTokenResultDTO; |
|
|
import com.epmet.common.token.util.CpUserDetailRedis; |
|
|
import com.epmet.common.token.util.CpUserDetailRedis; |
|
|
|
|
|
import com.epmet.commons.tools.exception.ErrorCode; |
|
|
import com.epmet.commons.tools.exception.RenException; |
|
|
import com.epmet.commons.tools.exception.RenException; |
|
|
|
|
|
import com.epmet.commons.tools.security.password.PasswordUtils; |
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
import com.epmet.commons.tools.utils.Result; |
|
|
import com.epmet.dao.CustomerUserDao; |
|
|
import com.epmet.dto.CustomerUserDTO; |
|
|
import com.epmet.entity.CustomerUserEntity; |
|
|
import com.epmet.dto.form.PasswordLoginUserInfoFormDTO; |
|
|
|
|
|
import com.epmet.dto.form.WxLoginUserInfoFormDTO; |
|
|
|
|
|
import com.epmet.dto.result.PasswordLoginUserInfoResultDTO; |
|
|
|
|
|
import com.epmet.feign.EpmetUserFeignClient; |
|
|
import com.epmet.jwt.JwtTokenProperties; |
|
|
import com.epmet.jwt.JwtTokenProperties; |
|
|
import com.epmet.jwt.JwtTokenUtils; |
|
|
import com.epmet.jwt.JwtTokenUtils; |
|
|
|
|
|
import com.epmet.service.CaptchaService; |
|
|
import com.epmet.service.LoginService; |
|
|
import com.epmet.service.LoginService; |
|
|
import com.epmet.utils.WxMaServiceUtils; |
|
|
import com.epmet.utils.WxMaServiceUtils; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
@ -38,7 +44,7 @@ public class LoginServiceImpl implements LoginService { |
|
|
private static final Logger logger = LoggerFactory.getLogger(AuthServiceImpl.class); |
|
|
private static final Logger logger = LoggerFactory.getLogger(AuthServiceImpl.class); |
|
|
|
|
|
|
|
|
@Autowired |
|
|
@Autowired |
|
|
private CustomerUserDao customerUserDao; |
|
|
private EpmetUserFeignClient epmetUserFeignClient; |
|
|
|
|
|
|
|
|
@Autowired |
|
|
@Autowired |
|
|
private WxMaServiceUtils wxMaServiceUtils; |
|
|
private WxMaServiceUtils wxMaServiceUtils; |
|
@ -52,6 +58,9 @@ public class LoginServiceImpl implements LoginService { |
|
|
@Autowired |
|
|
@Autowired |
|
|
private CpUserDetailRedis cpUserDetailRedis; |
|
|
private CpUserDetailRedis cpUserDetailRedis; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
private CaptchaService captchaService; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 微信小程序登录 |
|
|
* 微信小程序登录 |
|
|
* |
|
|
* |
|
@ -115,31 +124,39 @@ public class LoginServiceImpl implements LoginService { |
|
|
* @since 2020/3/14 19:34 |
|
|
* @since 2020/3/14 19:34 |
|
|
*/ |
|
|
*/ |
|
|
private String getUserId(LoginByWxCodeFormDTO formDTO, WxMaJscode2SessionResult wxMaJscode2SessionResult) { |
|
|
private String getUserId(LoginByWxCodeFormDTO formDTO, WxMaJscode2SessionResult wxMaJscode2SessionResult) { |
|
|
String userId = ""; |
|
|
WxLoginUserInfoFormDTO wxLoginUserInfoFormDTO=new WxLoginUserInfoFormDTO(); |
|
|
if (LoginConstant.APP_GOV.equals(formDTO.getApp())) { |
|
|
wxLoginUserInfoFormDTO.setApp(formDTO.getApp()); |
|
|
|
|
|
wxLoginUserInfoFormDTO.setOpenId(wxMaJscode2SessionResult.getOpenid()); |
|
|
|
|
|
Result userResult=epmetUserFeignClient.selecWxLoginUserInfo(wxLoginUserInfoFormDTO); |
|
|
|
|
|
String userId=""; |
|
|
|
|
|
if(!userResult.success()){ |
|
|
|
|
|
throw new RenException("获取用户信息失败"+userResult.getMsg()); |
|
|
|
|
|
} |
|
|
|
|
|
userId= (String) userResult.getData(); |
|
|
|
|
|
if (StringUtils.isBlank(userId)&&LoginConstant.APP_GOV.equals(formDTO.getApp())) { |
|
|
//查询customer_staff待完善
|
|
|
//查询customer_staff待完善
|
|
|
} else if (LoginConstant.APP_OPER.equals(formDTO.getApp())) { |
|
|
} else if (StringUtils.isBlank(userId)&&LoginConstant.APP_OPER.equals(formDTO.getApp())) { |
|
|
//查询oper_staff待完善
|
|
|
//查询oper_staff待完善
|
|
|
} else if (LoginConstant.APP_RESI.equals(formDTO.getApp())) { |
|
|
} else if (StringUtils.isBlank(userId)&&LoginConstant.APP_RESI.equals(formDTO.getApp())) { |
|
|
//查询customer_user
|
|
|
//查询customer_user
|
|
|
userId = customerUserDao.selectByWxOpenId(wxMaJscode2SessionResult.getOpenid()); |
|
|
WxMaUserInfo wxMaUserInfo = wxMaServiceUtils.resiWxMaService().getUserService() |
|
|
if (StringUtils.isBlank(userId)) { |
|
|
.getUserInfo(wxMaJscode2SessionResult.getSessionKey(), |
|
|
WxMaUserInfo wxMaUserInfo = wxMaServiceUtils.resiWxMaService().getUserService() |
|
|
formDTO.getEncryptedData(), |
|
|
.getUserInfo(wxMaJscode2SessionResult.getSessionKey(), |
|
|
formDTO.getIv()); |
|
|
formDTO.getEncryptedData(), |
|
|
CustomerUserDTO customerUserDTO = new CustomerUserDTO(); |
|
|
formDTO.getIv()); |
|
|
customerUserDTO.setCity(wxMaUserInfo.getCity()); |
|
|
CustomerUserEntity customerUserEntity = new CustomerUserEntity(); |
|
|
customerUserDTO.setWxOpenId(wxMaUserInfo.getOpenId()); |
|
|
customerUserEntity.setCity(wxMaUserInfo.getCity()); |
|
|
customerUserDTO.setNickname(wxMaUserInfo.getNickName()); |
|
|
customerUserEntity.setWxOpenId(wxMaUserInfo.getOpenId()); |
|
|
customerUserDTO.setCountry(wxMaUserInfo.getCountry()); |
|
|
customerUserEntity.setNickname(wxMaUserInfo.getNickName()); |
|
|
customerUserDTO.setHeadImgUrl(wxMaUserInfo.getAvatarUrl()); |
|
|
customerUserEntity.setCountry(wxMaUserInfo.getCountry()); |
|
|
customerUserDTO.setCountry(wxMaUserInfo.getCountry()); |
|
|
customerUserEntity.setHeadImgUrl(wxMaUserInfo.getAvatarUrl()); |
|
|
customerUserDTO.setProvince(wxMaUserInfo.getProvince()); |
|
|
customerUserEntity.setCountry(wxMaUserInfo.getCountry()); |
|
|
customerUserDTO.setSex(Integer.valueOf(wxMaUserInfo.getGender())); |
|
|
customerUserEntity.setProvince(wxMaUserInfo.getProvince()); |
|
|
Result<String> saveCustomerUserResult=epmetUserFeignClient.saveCustomerUser(customerUserDTO); |
|
|
customerUserEntity.setSex(Integer.valueOf(wxMaUserInfo.getGender())); |
|
|
if(!saveCustomerUserResult.success()){ |
|
|
customerUserDao.insert(customerUserEntity); |
|
|
throw new RenException("创建用户失败"+userResult.getMsg()); |
|
|
userId = customerUserEntity.getId(); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
userId = saveCustomerUserResult.getData(); |
|
|
} |
|
|
} |
|
|
return userId; |
|
|
return userId; |
|
|
} |
|
|
} |
|
@ -163,6 +180,7 @@ public class LoginServiceImpl implements LoginService { |
|
|
map.put("client", formDTO.getClient()); |
|
|
map.put("client", formDTO.getClient()); |
|
|
map.put("userId", userId); |
|
|
map.put("userId", userId); |
|
|
String token = jwtTokenUtils.createToken(map); |
|
|
String token = jwtTokenUtils.createToken(map); |
|
|
|
|
|
logger.info("日志输出token="+token); |
|
|
int expire = jwtTokenProperties.getExpire(); |
|
|
int expire = jwtTokenProperties.getExpire(); |
|
|
TokenDto tokenDto = new TokenDto(); |
|
|
TokenDto tokenDto = new TokenDto(); |
|
|
tokenDto.setApp(formDTO.getApp()); |
|
|
tokenDto.setApp(formDTO.getApp()); |
|
@ -185,9 +203,59 @@ public class LoginServiceImpl implements LoginService { |
|
|
*/ |
|
|
*/ |
|
|
@Override |
|
|
@Override |
|
|
public Result<UserTokenResultDTO> loginByPassword(LoginByPassWordFormDTO formDTO) { |
|
|
public Result<UserTokenResultDTO> loginByPassword(LoginByPassWordFormDTO formDTO) { |
|
|
|
|
|
//验证码是否正确
|
|
|
|
|
|
boolean flag = captchaService.validate(formDTO.getUuid(), formDTO.getCaptcha()); |
|
|
|
|
|
if(!flag){ |
|
|
|
|
|
return new Result<UserTokenResultDTO>().error(ErrorCode.CAPTCHA_ERROR); |
|
|
|
|
|
} |
|
|
//1、账号是否存在
|
|
|
//1、账号是否存在
|
|
|
|
|
|
//获取用户信息
|
|
|
|
|
|
PasswordLoginUserInfoFormDTO passwordLoginUserInfoFormDTO=new PasswordLoginUserInfoFormDTO(); |
|
|
|
|
|
passwordLoginUserInfoFormDTO.setApp(formDTO.getApp()); |
|
|
|
|
|
passwordLoginUserInfoFormDTO.setPhone(formDTO.getPhone()); |
|
|
|
|
|
Result<PasswordLoginUserInfoResultDTO> userInfoResult=epmetUserFeignClient.selectLoginUserInfoByPassword(passwordLoginUserInfoFormDTO); |
|
|
|
|
|
logger.info(userInfoResult.getCode()+userInfoResult.getMsg()); |
|
|
|
|
|
if(!userInfoResult.success()||null==userInfoResult.getData()){ |
|
|
|
|
|
return new Result<UserTokenResultDTO>().error("账号不存在"); |
|
|
|
|
|
} |
|
|
//2、密码是否正确
|
|
|
//2、密码是否正确
|
|
|
|
|
|
//密码错误
|
|
|
|
|
|
if(!PasswordUtils.matches(userInfoResult.getData().getPassword(), formDTO.getPassword())){ |
|
|
|
|
|
throw new RenException(ErrorCode.ACCOUNT_PASSWORD_ERROR); |
|
|
|
|
|
} |
|
|
|
|
|
if(!userInfoResult.getData().getPassword().equals(formDTO.getPassword())){ |
|
|
|
|
|
throw new RenException(ErrorCode.ACCOUNT_PASSWORD_ERROR); |
|
|
|
|
|
} |
|
|
//3、生成token返回,且将TokenDto存到redis
|
|
|
//3、生成token返回,且将TokenDto存到redis
|
|
|
return null; |
|
|
UserTokenResultDTO userTokenResultDTO = new UserTokenResultDTO(); |
|
|
|
|
|
userTokenResultDTO.setToken(this.packagingUserToken(formDTO, userInfoResult.getData().getUserId())); |
|
|
|
|
|
return new Result<UserTokenResultDTO>().ok(userTokenResultDTO); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
* 封装用户token值 |
|
|
|
|
|
* |
|
|
|
|
|
* @param formDTO |
|
|
|
|
|
* @param userId |
|
|
|
|
|
* @return java.lang.String |
|
|
|
|
|
* @author yinzuomei |
|
|
|
|
|
* @since 2020/3/14 19:34 |
|
|
|
|
|
*/ |
|
|
|
|
|
private String packagingUserToken(LoginByPassWordFormDTO formDTO, |
|
|
|
|
|
String userId) { |
|
|
|
|
|
// 生成token
|
|
|
|
|
|
Map<String, Object> map = new HashMap<>(); |
|
|
|
|
|
map.put("app", formDTO.getApp()); |
|
|
|
|
|
map.put("client", formDTO.getClient()); |
|
|
|
|
|
map.put("userId", userId); |
|
|
|
|
|
String token = jwtTokenUtils.createToken(map); |
|
|
|
|
|
logger.info("日志输出token="+token); |
|
|
|
|
|
int expire = jwtTokenProperties.getExpire(); |
|
|
|
|
|
TokenDto tokenDto = new TokenDto(); |
|
|
|
|
|
tokenDto.setApp(formDTO.getApp()); |
|
|
|
|
|
tokenDto.setClient(formDTO.getClient()); |
|
|
|
|
|
tokenDto.setUserId(userId); |
|
|
|
|
|
cpUserDetailRedis.set(tokenDto, expire); |
|
|
|
|
|
return token; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|