短信 code review 2020-02-25

pull/2/head
YunaiV 2021-02-25 01:24:06 +08:00
parent 2a4d9f43eb
commit cd2a01819b
10 changed files with 13 additions and 24 deletions

View File

@ -22,7 +22,7 @@ public abstract class AbstractSmsClient implements SmsClient {
protected final SmsChannelProperty channelVO; protected final SmsChannelProperty channelVO;
/** /**
* * TODO FROM to zzf
* *
* @param property * @param property
*/ */
@ -30,13 +30,12 @@ public abstract class AbstractSmsClient implements SmsClient {
this.channelVO = property; this.channelVO = property;
} }
public SmsChannelProperty getProperty() { public SmsChannelProperty getProperty() {
return channelVO; return channelVO;
} }
@Override @Override
public SmsResult send(String templateApiId, SmsBody smsBody, Collection<String> targets) { public final SmsResult send(String templateApiId, SmsBody smsBody, Collection<String> targets) {
SmsResult result; SmsResult result;
try { try {
beforeSend(templateApiId, smsBody, targets); beforeSend(templateApiId, smsBody, targets);
@ -50,13 +49,13 @@ public abstract class AbstractSmsClient implements SmsClient {
return result; return result;
} }
/** /**
* *
* *
* @param templateApiId * @param templateApiId
* @param smsBody * @param smsBody
* @param targets * @param targets
* @throws Exception
* @return * @return
*/ */
public abstract SmsResult doSend(String templateApiId, SmsBody smsBody, Collection<String> targets) throws Exception; public abstract SmsResult doSend(String templateApiId, SmsBody smsBody, Collection<String> targets) throws Exception;
@ -67,7 +66,7 @@ public abstract class AbstractSmsClient implements SmsClient {
protected void afterSend(String templateApiId, SmsBody smsBody, Collection<String> targets, SmsResult result) throws Exception { protected void afterSend(String templateApiId, SmsBody smsBody, Collection<String> targets, SmsResult result) throws Exception {
} }
// TODO FROM 芋艿 to zzf可以考虑抽到 SmsResult 里
SmsResult failResult(String message) { SmsResult failResult(String message) {
SmsResult resultBody = new SmsResult(); SmsResult resultBody = new SmsResult();
resultBody.setSuccess(false); resultBody.setSuccess(false);

View File

@ -58,16 +58,14 @@ public class AliyunSmsClient extends AbstractSmsClient {
acsClient = new DefaultAcsClient(profile); acsClient = new DefaultAcsClient(profile);
} }
@Override @Override
public SmsResult doSend(String templateApiId, SmsBody smsBody, Collection<String> targets) throws Exception { public SmsResult doSend(String templateApiId, SmsBody smsBody, Collection<String> targets) throws Exception {
SendSmsRequest request = new SendSmsRequest(); SendSmsRequest request = new SendSmsRequest();
request.setSysMethod(MethodType.POST); request.setSysMethod(MethodType.POST);
request.setPhoneNumbers(StringUtils.join(targets, ",")); request.setPhoneNumbers(StringUtils.join(targets, ",")); // TODO FROM 芋艿 to zzf统一使用 Hutool 工具类嘿。
request.setSignName(channelVO.getApiSignatureId()); request.setSignName(channelVO.getApiSignatureId());
request.setTemplateCode(templateApiId); request.setTemplateCode(templateApiId);
request.setTemplateParam(smsBody.getParamsStr()); request.setTemplateParam(smsBody.getParamsStr());
// TODO FROM 芋艿 TO zzftry catch 咱是不是可以交给 abstract 来做。这样,异常处理,重试,限流等等,都可以酱紫 DONE
SendSmsResponse sendSmsResponse = acsClient.getAcsResponse(request); SendSmsResponse sendSmsResponse = acsClient.getAcsResponse(request);
boolean result = OK.equals(sendSmsResponse.getCode()); boolean result = OK.equals(sendSmsResponse.getCode());
@ -78,7 +76,7 @@ public class AliyunSmsClient extends AbstractSmsClient {
resultBody.setSuccess(result); resultBody.setSuccess(result);
QuerySendDetailsRequest querySendDetailsRequest = new QuerySendDetailsRequest(); QuerySendDetailsRequest querySendDetailsRequest = new QuerySendDetailsRequest();
querySendDetailsRequest.setBizId(sendSmsResponse.getBizId()); querySendDetailsRequest.setBizId(sendSmsResponse.getBizId());
// TODO FROM 芋艿 to zzf发送完之后基于短信平台回调去更新回执状态。短信发送是否成功和最终用户收到是两个维度。这块有困惑可以微信我给个截图哈。
QuerySendDetailsResponse acsResponse = acsClient.getAcsResponse(querySendDetailsRequest); QuerySendDetailsResponse acsResponse = acsClient.getAcsResponse(querySendDetailsRequest);
List<SmsResultDetail> resultDetailList = new ArrayList<>(Integer.parseInt(acsResponse.getTotalCount())); List<SmsResultDetail> resultDetailList = new ArrayList<>(Integer.parseInt(acsResponse.getTotalCount()));
acsResponse.getSmsSendDetailDTOs().forEach(s -> { acsResponse.getSmsSendDetailDTOs().forEach(s -> {

View File

@ -42,7 +42,6 @@ public class SmsClientFactory {
* @return id(channelId) * @return id(channelId)
*/ */
public Long createClient(SmsChannelProperty propertyVO) { public Long createClient(SmsChannelProperty propertyVO) {
// TODO FROM 芋艿 TO zzf参数的校验可以考虑统一使用 validation。 DONE
AbstractSmsClient sender = createClient(SmsChannelEnum.getByCode(propertyVO.getCode()), propertyVO); AbstractSmsClient sender = createClient(SmsChannelEnum.getByCode(propertyVO.getCode()), propertyVO);
smsSenderMap.put(propertyVO.getId(), sender); smsSenderMap.put(propertyVO.getId(), sender);
return propertyVO.getId(); return propertyVO.getId();
@ -77,7 +76,7 @@ public class SmsClientFactory {
* *
*/ */
public void addOrUpdateTemplateCache(Collection<SmsTemplateProperty> templateProperties) { public void addOrUpdateTemplateCache(Collection<SmsTemplateProperty> templateProperties) {
templateProperties.forEach(s -> templatePropertyMap.put(s.getCode(), s)); templateProperties.forEach(s -> addOrUpdateTemplateCache(templateProperties));
} }
@ -102,4 +101,5 @@ public class SmsClientFactory {
} }
return smsTemplateProperty.getApiTemplateId(); return smsTemplateProperty.getApiTemplateId();
} }
} }

View File

@ -14,7 +14,6 @@ public class SmsResult implements Serializable {
/** /**
* () * ()
*/ */
// TODO FROM 芋艿 to zzf未来要加一个 code将不同平台的短信失败的情况做一次统一的收敛。 DONE
private Boolean success; private Boolean success;
/** /**
@ -30,7 +29,6 @@ public class SmsResult implements Serializable {
/** /**
* *
*/ */
// TODO FROM 芋艿 to zzf是不是统一各个平台的返回结果这样对调用方来说统一。因为作为统一的短信客户端最好让上层不太需要知道太具体。黑河诶 DONE
private List<SmsResultDetail> result; private List<SmsResultDetail> result;
} }

View File

@ -4,7 +4,7 @@ import lombok.AllArgsConstructor;
import lombok.Getter; import lombok.Getter;
/** /**
* TODO FROM TO zzf framework/sms DONE *
* *
* @author zzf * @author zzf
* @date 2021/1/25 10:56 * @date 2021/1/25 10:56
@ -16,7 +16,7 @@ public enum SmsChannelEnum {
ALI("ALI", "阿里"), ALI("ALI", "阿里"),
HUA_WEI("HUA_WEI", "华为"), HUA_WEI("HUA_WEI", "华为"),
QI_NIU("QI_NIU", "七牛"), QI_NIU("QI_NIU", "七牛"),
TENCENT("TENCENT", "腾讯"); // TODO FROM 芋艿 to zzfTEN 有后鼻音哈,要被马爸爸打了。。。 DONE TENCENT("TENCENT", "腾讯");
private final String code; private final String code;
@ -30,4 +30,5 @@ public enum SmsChannelEnum {
} }
return null; return null;
} }
} }

View File

@ -7,8 +7,6 @@ import javax.validation.constraints.NotEmpty;
/** /**
* VO * VO
* TODO FROM TO zzf client factory client DONE
*
* *
* @author zzf * @author zzf
* @date 2021/1/25 17:03 * @date 2021/1/25 17:03

View File

@ -37,12 +37,10 @@ public class SmsChannelController {
return success(service.getSmsChannelEnums()); return success(service.getSmsChannelEnums());
} }
@ApiOperation("添加消息渠道") @ApiOperation("添加消息渠道")
@PostMapping("/create") @PostMapping("/create")
public CommonResult<Long> add(@Validated @RequestBody SmsChannelCreateReqVO reqVO) { public CommonResult<Long> add(@Validated @RequestBody SmsChannelCreateReqVO reqVO) {
return success(service.createSmsChannel(reqVO)); return success(service.createSmsChannel(reqVO));
} }
} }

View File

@ -24,7 +24,7 @@ public class SmsSendConsumer extends AbstractChannelMessageListener<SmsSendMessa
@Override @Override
public void onMessage(SmsSendMessage message) { public void onMessage(SmsSendMessage message) {
log.info("[onMessage][收到 发送短信 消息]"); log.info("[onMessage][收到 发送短信 消息]"); // TODO FROM 芋艿 to zzflog 如果要打,这里要内容打上。其他 Consumer 没打的原因,是没内容。。。
SmsResult send = sysSmsService.send(message.getSmsBody(), message.getTargetPhones()); SmsResult send = sysSmsService.send(message.getSmsBody(), message.getTargetPhones());
} }

View File

@ -18,9 +18,6 @@ import java.util.List;
*/ */
public interface SysSmsChannelService { public interface SysSmsChannelService {
// TODO FROM 芋艿 to ZZFSmsChannelService=》SysSmsChannelService增加 Sys 前缀,算在系统模块里
// TODO FROM 芋艿 to ZZF方法名保持不去掉 Sms 前缀。虽然长点,嘿嘿
/** /**
* *
*/ */

View File

@ -42,6 +42,7 @@ public class SysSmsChannelServiceImpl implements SysSmsChannelService {
@Autowired @Autowired
private SmsClientFactory clientFactory; private SmsClientFactory clientFactory;
// TODO FROM 芋艿 to zzf方法要放在成员变量下面
/** /**
* *
*/ */
@ -65,7 +66,6 @@ public class SysSmsChannelServiceImpl implements SysSmsChannelService {
}); });
} }
// TODO FROM 芋艿 to ZZFchannelMapper 嘿,保持命名统一。 DONE
@Resource @Resource
private SysSmsChannelMapper channelMapper; private SysSmsChannelMapper channelMapper;