|
|
@@ -1,23 +1,18 @@
|
|
|
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.utils.JsonUtils;
|
|
|
+import cn.tr.plugin.sms.bo.SmsCommonResult;
|
|
|
import cn.tr.plugin.sms.bo.SmsSendRespBO;
|
|
|
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
|
|
|
* @Description :
|
|
|
@@ -27,8 +22,10 @@ import java.util.Map;
|
|
|
@Slf4j
|
|
|
public class AliSmsClient extends AbstractSmsClient<AliSmsClientConfig,AliSmsClientSendConfig> {
|
|
|
private IAcsClient client;
|
|
|
+ private final AliyunSmsCodeMapping smsCodeMapping;
|
|
|
public AliSmsClient(String id, AliSmsClientConfig clientConfig) {
|
|
|
super(id, clientConfig);
|
|
|
+ this.smsCodeMapping=new AliyunSmsCodeMapping();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -38,7 +35,7 @@ public class AliSmsClient extends AbstractSmsClient<AliSmsClientConfig,AliSmsCli
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public CommonResult<SmsSendRespBO> sendSms(AliSmsClientSendConfig sendConfig) {
|
|
|
+ public SmsCommonResult<SmsSendRespBO> sendSms(AliSmsClientSendConfig sendConfig) {
|
|
|
SendSmsRequest sendSmsRequest =new SendSmsRequest();
|
|
|
sendSmsRequest.setPhoneNumbers(sendConfig.getPhoneNumber());
|
|
|
sendSmsRequest.setSignName(sendConfig.getSignName());
|
|
|
@@ -46,18 +43,21 @@ public class AliSmsClient extends AbstractSmsClient<AliSmsClientConfig,AliSmsCli
|
|
|
sendSmsRequest.setTemplateParam(JsonUtils.toJsonString(sendConfig.getTemplateParam()));
|
|
|
sendSmsRequest.setSmsUpExtendCode(sendConfig.getSmsUpExtendCode());
|
|
|
sendSmsRequest.setOutId(sendConfig.getOutId());
|
|
|
+ SendSmsResponse response=null;
|
|
|
try {
|
|
|
- SendSmsResponse sendSmsResponse = client.getAcsResponse(sendSmsRequest);
|
|
|
+ response = 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 SmsCommonResult.build(e.getErrCode(), formatResultMsg(e), e.getRequestId(), null, smsCodeMapping);
|
|
|
}
|
|
|
- return CommonResult.success();
|
|
|
|
|
|
+ return SmsCommonResult.build(response.getCode(), response.getMessage(), response.getRequestId(), new SmsSendRespBO().setSerialNo(response.getBizId()), smsCodeMapping);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ private static String formatResultMsg(ClientException ex) {
|
|
|
+ if (StrUtil.isEmpty(ex.getErrorDescription())) {
|
|
|
+ return ex.getErrMsg();
|
|
|
+ }
|
|
|
+ return ex.getErrMsg() + " => " + ex.getErrorDescription();
|
|
|
}
|
|
|
}
|