|
|
@@ -0,0 +1,61 @@
|
|
|
+
|
|
|
+package cn.tr.module.smart.common.service.impl;
|
|
|
+
|
|
|
+import cn.hutool.core.util.ObjectUtil;
|
|
|
+import cn.hutool.core.util.RandomUtil;
|
|
|
+import cn.tr.core.exception.ServiceException;
|
|
|
+import cn.tr.core.exception.TRExcCode;
|
|
|
+import cn.tr.module.api.sys.sms.BizSmsPOJO;
|
|
|
+import cn.tr.module.api.sys.sms.SmsApi;
|
|
|
+import cn.tr.module.smart.common.enums.SmsCodeEnums;
|
|
|
+import cn.tr.module.smart.common.service.IBizSmsService;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.cache.annotation.CachePut;
|
|
|
+import org.springframework.cache.annotation.Cacheable;
|
|
|
+import org.springframework.context.annotation.Lazy;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class BizSmsServiceImpl implements IBizSmsService {
|
|
|
+ @Autowired
|
|
|
+ private SmsApi smsApi;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ @Lazy
|
|
|
+ private BizSmsServiceImpl self;
|
|
|
+ @Override
|
|
|
+ public Boolean sendSingleSms(BizSmsPOJO source) {
|
|
|
+ if(ObjectUtil.isNull(source.getType())){
|
|
|
+ throw new ServiceException(TRExcCode.SYSTEM_ERROR_B0001,"短信类型不能为空");
|
|
|
+ }
|
|
|
+ int validateCode = RandomUtil.randomInt(1000,9999);
|
|
|
+ Map<String, Object> param = new HashMap<>();
|
|
|
+ param.put("code",validateCode);
|
|
|
+ switch (source.getType()){
|
|
|
+ case "1":
|
|
|
+ smsApi.sendSms(source.getPhone(), SmsCodeEnums.LOGIN,param);
|
|
|
+ self.refreshSmsCode(source.getType(),source.getPhone(),String.valueOf(validateCode));
|
|
|
+ return Boolean.TRUE;
|
|
|
+ case "2":
|
|
|
+ smsApi.sendSms(source.getPhone(), SmsCodeEnums.RESET,param);
|
|
|
+ self.refreshSmsCode(source.getType(),source.getPhone(),String.valueOf(validateCode));
|
|
|
+ return Boolean.TRUE;
|
|
|
+ default:
|
|
|
+ throw new ServiceException(TRExcCode.SYSTEM_ERROR_B0001,"短信类型不支持");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Cacheable(value = "sms:code", key = "#type+#phone")
|
|
|
+ @Override
|
|
|
+ public String getSmsCode(String type, String phone){
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ @CachePut(value = "sms:code",key = "#type+#phone")
|
|
|
+ public String refreshSmsCode(String type,String phone,String code){
|
|
|
+ return code;
|
|
|
+ }
|
|
|
+}
|