|
@@ -1,8 +1,22 @@
|
|
|
package cn.tr.plugin.sms.config.ali;
|
|
package cn.tr.plugin.sms.config.ali;
|
|
|
|
|
|
|
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
|
|
+import cn.tr.core.exception.TRExcCode;
|
|
|
import cn.tr.core.pojo.CommonResult;
|
|
import cn.tr.core.pojo.CommonResult;
|
|
|
|
|
+import cn.tr.core.utils.JsonUtils;
|
|
|
import cn.tr.plugin.sms.bo.SmsSendRespBO;
|
|
import cn.tr.plugin.sms.bo.SmsSendRespBO;
|
|
|
import cn.tr.plugin.sms.config.AbstractSmsClient;
|
|
import cn.tr.plugin.sms.config.AbstractSmsClient;
|
|
|
|
|
+import com.aliyuncs.DefaultAcsClient;
|
|
|
|
|
+import com.aliyuncs.IAcsClient;
|
|
|
|
|
+import com.aliyuncs.exceptions.ClientException;
|
|
|
|
|
+import com.aliyuncs.profile.DefaultProfile;
|
|
|
|
|
+import com.google.gson.Gson;
|
|
|
|
|
+import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
|
|
|
|
|
+import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
|
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+
|
|
|
|
|
+import java.util.HashMap;
|
|
|
|
|
+import java.util.Map;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* @ClassName : AliSmsClient
|
|
* @ClassName : AliSmsClient
|
|
@@ -10,20 +24,40 @@ import cn.tr.plugin.sms.config.AbstractSmsClient;
|
|
|
* @Author : LF
|
|
* @Author : LF
|
|
|
* @Date: 2023年03月15日
|
|
* @Date: 2023年03月15日
|
|
|
*/
|
|
*/
|
|
|
-
|
|
|
|
|
|
|
+@Slf4j
|
|
|
public class AliSmsClient extends AbstractSmsClient<AliSmsClientConfig,AliSmsClientSendConfig> {
|
|
public class AliSmsClient extends AbstractSmsClient<AliSmsClientConfig,AliSmsClientSendConfig> {
|
|
|
-
|
|
|
|
|
|
|
+ private IAcsClient client;
|
|
|
public AliSmsClient(String id, AliSmsClientConfig clientConfig) {
|
|
public AliSmsClient(String id, AliSmsClientConfig clientConfig) {
|
|
|
super(id, clientConfig);
|
|
super(id, clientConfig);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public void doInit(AliSmsClientConfig config) {
|
|
public void doInit(AliSmsClientConfig config) {
|
|
|
-
|
|
|
|
|
|
|
+ DefaultProfile profile = DefaultProfile.getProfile(config.getRegionId(), config.getAccessKeyId(), config.getAccessKeySecret());
|
|
|
|
|
+ client = new DefaultAcsClient(profile);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public CommonResult<SmsSendRespBO> sendSms(AliSmsClientSendConfig sendConfig) {
|
|
public CommonResult<SmsSendRespBO> sendSms(AliSmsClientSendConfig sendConfig) {
|
|
|
- return null;
|
|
|
|
|
|
|
+ SendSmsRequest sendSmsRequest =new SendSmsRequest();
|
|
|
|
|
+ sendSmsRequest.setPhoneNumbers(sendConfig.getPhoneNumber());
|
|
|
|
|
+ sendSmsRequest.setSignName(sendConfig.getSignName());
|
|
|
|
|
+ sendSmsRequest.setTemplateCode(sendConfig.getTemplateCode());
|
|
|
|
|
+ sendSmsRequest.setTemplateParam(JsonUtils.toJsonString(sendConfig.getTemplateParam()));
|
|
|
|
|
+ sendSmsRequest.setSmsUpExtendCode(sendConfig.getSmsUpExtendCode());
|
|
|
|
|
+ sendSmsRequest.setOutId(sendConfig.getOutId());
|
|
|
|
|
+ try {
|
|
|
|
|
+ SendSmsResponse sendSmsResponse = client.getAcsResponse(sendSmsRequest);
|
|
|
|
|
+ } catch (ClientException e) {
|
|
|
|
|
+ if (StrUtil.equals(e.getErrCode(),"isv.ACCOUNT_NOT_EXISTS")) {
|
|
|
|
|
+ return CommonResult.error(TRExcCode.USER_ERROR_A0201,e.getErrMsg());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (StrUtil.equals(e.getErrCode(), "isv.AMOUNT_NOT_ENOUGH")) {
|
|
|
|
|
+ return CommonResult.error(TRExcCode.USER_ERROR_A0601,e.getErrMsg());
|
|
|
|
|
+ }
|
|
|
|
|
+ log.warn("[AliSms] send msg confront a error,",e);
|
|
|
|
|
+ }
|
|
|
|
|
+ return CommonResult.success();
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|