Commit 97265603183fbeefad33f595d3b2c0d18b8b7d1d
1 parent
6fd52dfb
code review 腾讯短信的实现
Showing
2 changed files
with
11 additions
and
6 deletions
yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/collection/CollectionUtils.java
| ... | ... | @@ -2,12 +2,9 @@ package cn.iocoder.yudao.framework.common.util.collection; |
| 2 | 2 | |
| 3 | 3 | import cn.hutool.core.collection.CollUtil; |
| 4 | 4 | import cn.hutool.core.collection.CollectionUtil; |
| 5 | -import com.fasterxml.jackson.core.type.TypeReference; | |
| 6 | 5 | import com.google.common.collect.ImmutableMap; |
| 7 | 6 | |
| 8 | 7 | import java.lang.reflect.Array; |
| 9 | -import java.lang.reflect.GenericArrayType; | |
| 10 | -import java.lang.reflect.Type; | |
| 11 | 8 | import java.util.*; |
| 12 | 9 | import java.util.function.BinaryOperator; |
| 13 | 10 | import java.util.function.Function; |
| ... | ... | @@ -174,6 +171,7 @@ public class CollectionUtils { |
| 174 | 171 | return deptId == null ? Collections.emptyList() : Collections.singleton(deptId); |
| 175 | 172 | } |
| 176 | 173 | |
| 174 | + // TODO @FinallySays:建议放在 ArrayUtils 里,和 hutool 对齐 | |
| 177 | 175 | public static <T, V> V[] toArray(List<T> from, Function<T, V> mapper) { |
| 178 | 176 | return toArray(convertList(from, mapper)); |
| 179 | 177 | } | ... | ... |
yudao-framework/yudao-spring-boot-starter-biz-sms/src/main/java/cn/iocoder/yudao/framework/sms/core/client/impl/tencent/TencentSmsClient.java
| ... | ... | @@ -39,11 +39,13 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.TIME_ZONE_DE |
| 39 | 39 | * |
| 40 | 40 | * @author : shiwp |
| 41 | 41 | */ |
| 42 | +// TODO @author 后面,空格即可 | |
| 42 | 43 | public class TencentSmsClient extends AbstractSmsClient { |
| 43 | 44 | |
| 44 | 45 | private SmsClient client; |
| 45 | 46 | |
| 46 | 47 | public TencentSmsClient(SmsChannelProperties properties) { |
| 48 | + // TODO @FinallySays:注释的时候,中英文之间要空格哈 | |
| 47 | 49 | // 腾讯云发放短信的时候需要额外的参数sdkAppId, 所以和secretId组合在一起放到apiKey字段中,格式为[secretId sdkAppId], |
| 48 | 50 | // 这边需要做拆分重新封装到properties内 |
| 49 | 51 | super(TencentSmsChannelProperties.build(properties), new TencentSmsCodeMapping()); |
| ... | ... | @@ -53,6 +55,7 @@ public class TencentSmsClient extends AbstractSmsClient { |
| 53 | 55 | @Override |
| 54 | 56 | protected void doInit() { |
| 55 | 57 | // init或者refresh时需要重新封装properties |
| 58 | + // TODO @FinallySays:是不是不用这个变量呀?p | |
| 56 | 59 | final SmsChannelProperties p = properties; |
| 57 | 60 | properties = TencentSmsChannelProperties.build(p); |
| 58 | 61 | // 实例化一个认证对象,入参需要传入腾讯云账户密钥对secretId,secretKey。 |
| ... | ... | @@ -66,7 +69,7 @@ public class TencentSmsClient extends AbstractSmsClient { |
| 66 | 69 | String apiTemplateId, |
| 67 | 70 | List<KeyValue<String, Object>> templateParams) throws Throwable { |
| 68 | 71 | |
| 69 | - return invoke(() -> buildSendSmsRequest(sendLogId, mobile, apiTemplateId, templateParams), | |
| 72 | + return invoke(() -> buildSendSmsRequest(sendLogId, mobile, apiTemplateId, templateParams), // TODO @FinallySays:上面不用空行 | |
| 70 | 73 | this::doSendSms0, |
| 71 | 74 | response -> { |
| 72 | 75 | SendStatus sendStatus = response.getSendStatusSet()[0]; |
| ... | ... | @@ -117,6 +120,7 @@ public class TencentSmsClient extends AbstractSmsClient { |
| 117 | 120 | data.setErrorCode(status.getErrCode()).setErrorMsg(status.getDescription()); |
| 118 | 121 | data.setReceiveTime(status.getReceiveTime()).setSuccess("SUCCESS".equalsIgnoreCase(status.getStatus())); |
| 119 | 122 | data.setMobile(status.getMobile()).setSerialNo(status.getSerialNo()); |
| 123 | + // TODO @FinallySays:建议直接判断是否为空,酱紫更易读一些 | |
| 120 | 124 | Optional.ofNullable(status.getSessionContext()).map(SessionContext::getLogId) |
| 121 | 125 | .ifPresentOrElse(data::setLogId, () -> { |
| 122 | 126 | throw new IllegalStateException(StrUtil.format("未回传logId,需联系腾讯云解决。")); |
| ... | ... | @@ -170,9 +174,10 @@ public class TencentSmsClient extends AbstractSmsClient { |
| 170 | 174 | */ |
| 171 | 175 | private DescribeSmsTemplateListRequest buildSmsTemplateStatusRequest(String apiTemplateId) { |
| 172 | 176 | DescribeSmsTemplateListRequest request = new DescribeSmsTemplateListRequest(); |
| 177 | + // TODO TODO @FinallySays: new Long[]{Long.parseLong(apiTemplateId)} 就 ok 啦 | |
| 173 | 178 | request.setTemplateIdSet(CollectionUtils.toArray(Collections.singletonList(apiTemplateId), Long::parseLong)); |
| 174 | 179 | // 地区 |
| 175 | - request.setInternational(0L); | |
| 180 | + request.setInternational(0L); // TODO @FinallySays:0L 最好说明下哈; | |
| 176 | 181 | return request; |
| 177 | 182 | } |
| 178 | 183 | |
| ... | ... | @@ -280,9 +285,11 @@ public class TencentSmsClient extends AbstractSmsClient { |
| 280 | 285 | return (TencentSmsChannelProperties) properties; |
| 281 | 286 | } |
| 282 | 287 | TencentSmsChannelProperties result = BeanUtil.toBean(properties, TencentSmsChannelProperties.class); |
| 288 | + // TODO @FinallySays:comb=》combine,不缩写好点哈 | |
| 283 | 289 | String combKey = properties.getApiKey(); |
| 284 | 290 | Assert.notEmpty(combKey, "apiKey 不能为空"); |
| 285 | 291 | String[] keys = combKey.trim().split(" "); |
| 292 | + // TODO @FinallySays:建议写多个断言好点,嘿嘿。然后 Assert 支持占位符 | |
| 286 | 293 | Assert.isTrue(keys.length == 2 && StrUtil.isNotBlank(keys[0]) && StrUtil.isNotBlank(keys[1]), |
| 287 | 294 | "腾讯云短信api配置格式错误,请配置为[secretId sdkAppId]"); |
| 288 | 295 | result.setSdkAppId(keys[1]).setApiKey(keys[0]); |
| ... | ... | @@ -291,4 +298,4 @@ public class TencentSmsClient extends AbstractSmsClient { |
| 291 | 298 | } |
| 292 | 299 | |
| 293 | 300 | |
| 294 | -} | |
| 295 | 301 | \ No newline at end of file |
| 302 | +} | ... | ... |