|
|
@ -13,6 +13,7 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
|
|
import com.baomidou.mybatisplus.core.metadata.IPage; |
|
|
|
import com.epmet.commons.mybatis.service.impl.BaseServiceImpl; |
|
|
|
import com.epmet.commons.tools.constant.Constant; |
|
|
|
import com.epmet.commons.tools.exception.EpmetErrorCode; |
|
|
|
import com.epmet.commons.tools.exception.ErrorCode; |
|
|
|
import com.epmet.commons.tools.exception.RenException; |
|
|
|
import com.epmet.commons.tools.page.PageData; |
|
|
@ -28,6 +29,8 @@ import com.epmet.sms.SmsFactory; |
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException; |
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.stereotype.Service; |
|
|
|
|
|
|
@ -36,6 +39,8 @@ import java.util.*; |
|
|
|
@Service |
|
|
|
public class SysSmsServiceImpl extends BaseServiceImpl<SysSmsDao, SysSmsEntity> implements SysSmsService { |
|
|
|
|
|
|
|
private Logger logger = LoggerFactory.getLogger(getClass()); |
|
|
|
|
|
|
|
@Autowired |
|
|
|
private MessageFeignClient messageFeignClient; |
|
|
|
|
|
|
@ -107,7 +112,7 @@ public class SysSmsServiceImpl extends BaseServiceImpl<SysSmsDao, SysSmsEntity> |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public String sendSmsCaptcha(String mobile) { |
|
|
|
public Result sendSmsCaptcha(String mobile) { |
|
|
|
Integer code = (int) ((Math.random() * 9 + 1) * 100000); |
|
|
|
String codeStr = String.valueOf(code); |
|
|
|
HashMap<String, String> map = new HashMap<>(); |
|
|
@ -121,10 +126,17 @@ public class SysSmsServiceImpl extends BaseServiceImpl<SysSmsDao, SysSmsEntity> |
|
|
|
sysSmsDTO.setParams(paramJson); |
|
|
|
|
|
|
|
Result result = messageFeignClient.send(sysSmsDTO); |
|
|
|
System.out.println(result); |
|
|
|
if (result != null && result.success()) { |
|
|
|
HashMap<String, String> data = new HashMap<>(); |
|
|
|
data.put("code", codeStr); |
|
|
|
return new Result().ok(data); |
|
|
|
} else { |
|
|
|
logger.error(String.format("短信验证码发送失败,手机号:%s。code:%d,msg:%s", mobile, result.getCode(), result.getMsg())); |
|
|
|
} |
|
|
|
} catch (JsonProcessingException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
logger.error(String.format("短信验证码发送失败,手机号:%s。errorMessage:%s", mobile, e.getMessage())); |
|
|
|
} |
|
|
|
return codeStr; |
|
|
|
return new Result().error(EpmetErrorCode.MESSAGE_SMS_SEND_ERROR.getValue(), EpmetErrorCode.MESSAGE_SMS_SEND_ERROR.getName()); |
|
|
|
} |
|
|
|
} |
|
|
|