短信代码的 code review 2020-02-22
This commit is contained in:
parent
0fd757fbbd
commit
a50db6bf7f
@ -3,8 +3,11 @@ package cn.iocoder.dashboard.common.enums;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* 短信渠道枚举
|
||||
* 短信渠道枚举 TODO FROM 芋艿 TO zzf:属于短信的枚举类,可以放到 framework/sms 下
|
||||
*
|
||||
* @author zzf
|
||||
* @date 2021/1/25 10:56
|
||||
@ -16,7 +19,7 @@ public enum SmsChannelEnum {
|
||||
ALI("ALI", "阿里"),
|
||||
HUA_WEI("HUA_WEI", "华为"),
|
||||
QI_NIU("QI_NIU", "七牛"),
|
||||
TEN_XUN("TEN_XUN", "腾讯");
|
||||
TEN_XUN("TEN_XUN", "腾讯"); // TODO FROM 芋艿 to zzf:TEN 有后鼻音哈,要被马爸爸打了。。。
|
||||
|
||||
private final String code;
|
||||
|
||||
|
@ -60,7 +60,7 @@ public class AliyunSmsClient extends AbstractSmsClient<SendSmsResponse> {
|
||||
request.setSignName(channelVO.getApiSignatureId());
|
||||
request.setTemplateCode(channelVO.getTemplateByTemplateCode(smsBody.getTemplateCode()).getApiTemplateId());
|
||||
request.setTemplateParam(smsBody.getParamsStr());
|
||||
|
||||
// TODO FROM 芋艿 TO zzf:try catch 咱是不是可以交给 abstract 来做。这样,异常处理,重试,限流等等,都可以酱紫
|
||||
try {
|
||||
SendSmsResponse sendSmsResponse = acsClient.getAcsResponse(request);
|
||||
|
||||
|
@ -33,6 +33,7 @@ public class SmsClientFactory {
|
||||
* @return 客户端id(默认channelId)
|
||||
*/
|
||||
public Long createClient(SmsChannelProperty propertyVO) {
|
||||
// TODO FROM 芋艿 TO zzf:参数的校验,可以考虑统一使用 validation。
|
||||
if (StrUtil.isBlank(propertyVO.getCode())) {
|
||||
throw ServiceExceptionUtil.exception(PARAM_VALUE_IS_NULL, "短信渠道编码");
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ public class SmsResult<T> implements Serializable {
|
||||
/**
|
||||
* 是否成功
|
||||
*/
|
||||
private Boolean success;
|
||||
private Boolean success; // TODO FROM 芋艿 to zzf:未来要加一个 code,将不同平台的短信失败的情况,做一次统一的收敛。
|
||||
|
||||
/**
|
||||
* 提示
|
||||
@ -23,5 +23,5 @@ public class SmsResult<T> implements Serializable {
|
||||
/**
|
||||
* 返回值
|
||||
*/
|
||||
private T result;
|
||||
private T result; // TODO FROM 芋艿 to zzf:是不是统一各个平台的返回结果,这样对调用方来说统一。因为作为统一的短信客户端,最好让上层不太需要知道太具体。黑河诶
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
/**
|
||||
* 渠道模板VO类
|
||||
* 渠道模板VO类 TODO FROM 芋艿 TO zzf:模板是不是不要提供到 client 里面,而是交给 factory 统一维护就好。不然,模板修改时候,刷新 client 会比较麻烦。
|
||||
*
|
||||
* @author zzf
|
||||
* @date 2021/1/25 17:03
|
||||
|
@ -25,6 +25,7 @@ public class SmsProducer {
|
||||
SmsSendMessage message = new SmsSendMessage();
|
||||
message.setSmsBody(smsBody);
|
||||
message.setTargetPhones(targetPhoneList);
|
||||
// TODO FROM 芋艿 TO ZZF:这块等未来改哈。这个方法目前是广播消费,会导致每个节点都发送一次。等后续封装出 redis stream 消息
|
||||
RedisMessageUtils.sendChannelMessage(stringRedisTemplate, message);
|
||||
}
|
||||
|
||||
|
@ -18,6 +18,9 @@ import java.util.List;
|
||||
*/
|
||||
public interface SmsChannelService {
|
||||
|
||||
// TODO FROM 芋艿 to ZZF:SmsChannelService=》SysSmsChannelService,增加 Sys 前缀,算在系统模块里
|
||||
// TODO FROM 芋艿 to ZZF:方法名,保持不去掉 Sms 前缀。虽然长点,嘿嘿
|
||||
|
||||
/**
|
||||
* 初始化短信渠道
|
||||
*/
|
||||
|
@ -22,6 +22,8 @@ public interface SmsLogService {
|
||||
* @param isAsync 是否异步发送
|
||||
* @return 生成的日志id
|
||||
*/
|
||||
// TODO FROM 芋艿 to ZZF: async 是针对发送的方式,对于日志不一定需要关心。这样,短信日志,实际就发送前插入,发送后更新结果
|
||||
// TODO FROM 芋艿 to ZZF:短信日志,群发的情况,应该是每个手机一条哈。虽然是群发,但是可能部分成功,部分失败;对应到短信平台,实际也是多条。
|
||||
Long beforeSendLog(SmsBody smsBody, List<String> targetPhones, AbstractSmsClient<?> client, Boolean isAsync);
|
||||
|
||||
/**
|
||||
|
@ -61,7 +61,7 @@ public class SmsChannelServiceImpl implements SmsChannelService {
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// TODO FROM 芋艿 to ZZF:channelMapper 嘿,保持命名统一。
|
||||
@Resource
|
||||
private SmsChannelMapper mapper;
|
||||
|
||||
|
@ -42,6 +42,7 @@ public class SmsServiceImpl implements SmsService {
|
||||
return result;
|
||||
}
|
||||
|
||||
// TODO FROM 芋艿 to ZZF:可能要讨论下,对于短信发送来说,貌似只提供异步发送即可。对于业务来说,一定不能依赖短信的发送结果。
|
||||
@Override
|
||||
public void sendAsync(SmsBody smsBody, List<String> targetPhones) {
|
||||
AbstractSmsClient<?> client = channelService.getClient(smsBody.getTemplateCode());
|
||||
|
Loading…
Reference in New Issue
Block a user