forked from luyan/epmet-cloud-lingshan
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
67 lines
2.8 KiB
67 lines
2.8 KiB
package com.epmet.service.impl;
|
|
|
|
import com.epmet.commons.tools.exception.EpmetErrorCode;
|
|
import com.epmet.commons.tools.utils.Result;
|
|
import com.epmet.commons.tools.validator.PhoneValidatorUtils;
|
|
import com.epmet.dto.form.SendSmsCodeFormDTO;
|
|
import com.epmet.feign.EpmetUserFeignClient;
|
|
import com.epmet.feign.MessageFeignClient;
|
|
import com.epmet.redis.CaptchaRedis;
|
|
import com.epmet.service.GovLoginService;
|
|
import org.apache.logging.log4j.LogManager;
|
|
import org.apache.logging.log4j.Logger;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import java.util.Map;
|
|
|
|
/**
|
|
* @Description 政府端登录
|
|
* @Author yinzuomei
|
|
* @Date 2020/4/18 10:33
|
|
*/
|
|
@Service
|
|
public class GovLoginServiceImpl implements GovLoginService {
|
|
private Logger logger = LogManager.getLogger(getClass());
|
|
@Autowired
|
|
private EpmetUserFeignClient epmetUserFeignClient;
|
|
@Autowired
|
|
private MessageFeignClient messageFeignClient;
|
|
@Autowired
|
|
private CaptchaRedis captchaRedis;
|
|
|
|
private static final String SEND_SMS_CODE_ERROR="发送短信验证码异常,手机号[%s],code[%s],msg[%s]";
|
|
|
|
/**
|
|
* @param formDTO
|
|
* @return com.epmet.commons.tools.utils.Result
|
|
* @Author yinzuomei
|
|
* @Description 登录-发送验证码
|
|
* @Date 2020/4/18 10:59
|
|
**/
|
|
@Override
|
|
public Result sendSmsCode(SendSmsCodeFormDTO formDTO) {
|
|
//1、校验手机号是否符合规范
|
|
if(!PhoneValidatorUtils.isMobile(formDTO.getPhone())){
|
|
logger.error(String.format(SEND_SMS_CODE_ERROR,formDTO.getPhone(),EpmetErrorCode.ERROR_PHONE.getCode(),EpmetErrorCode.ERROR_PHONE.getMsg()));
|
|
return new Result().error(EpmetErrorCode.ERROR_PHONE.getCode());
|
|
}
|
|
//2、根据手机号校验用户是否存在
|
|
Result customerStaffResult=epmetUserFeignClient.checkCustomerStaff(formDTO.getPhone());
|
|
if(!customerStaffResult.success()){
|
|
logger.error(String.format(SEND_SMS_CODE_ERROR,formDTO.getPhone(),EpmetErrorCode.GOV_STAFF_NOT_EXISTS.getCode(),EpmetErrorCode.GOV_STAFF_NOT_EXISTS.getMsg()));
|
|
return new Result().error(customerStaffResult.getCode());
|
|
}
|
|
//3、发送短信验证码
|
|
Result<Map<String, String>> smsCodeResult=messageFeignClient.sendSmsCaptcha(formDTO.getPhone());
|
|
if(!smsCodeResult.success()){
|
|
logger.error(String.format(SEND_SMS_CODE_ERROR,formDTO.getPhone(),smsCodeResult.getCode(),smsCodeResult.getMsg()));
|
|
return new Result().error(smsCodeResult.getCode());
|
|
}
|
|
//4、保存短信验证码(删除现有短信验证码、将新的短信验证码存入Redis)
|
|
captchaRedis.saveSmsCode(formDTO,smsCodeResult.getData().get("code"));
|
|
logger.info(String.format("发送短信验证码成功,手机号[%s]",formDTO.getPhone()));
|
|
return new Result();
|
|
}
|
|
}
|
|
|
|
|