|
|
@@ -7,7 +7,6 @@ import com.aliyun.tea.TeaException;
|
|
|
import com.aliyun.teaopenapi.models.Config;
|
|
|
import com.aliyun.teautil.models.RuntimeOptions;
|
|
|
import com.ydtech.exception.SystemException;
|
|
|
-import com.ydtech.utils.aliyun.SendSms;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Component;
|
|
|
@@ -18,11 +17,11 @@ import org.springframework.stereotype.Component;
|
|
|
@RequiredArgsConstructor
|
|
|
public class SendSmsComponents {
|
|
|
|
|
|
- private final AliyunApiSmsProperties properties;
|
|
|
+ private final AliyunApiProperties properties;
|
|
|
|
|
|
/**
|
|
|
- * @description: TODO
|
|
|
- * @author: wenks
|
|
|
+ * @description: 创建请求
|
|
|
+ * @author: wenks
|
|
|
* @date: 2024/11/6 8:46
|
|
|
* @return:
|
|
|
**/
|
|
|
@@ -33,23 +32,27 @@ public class SendSmsComponents {
|
|
|
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_ID。
|
|
|
.setAccessKeyId(properties.getAccessKeyId())
|
|
|
// 必填,请确保代码运行环境设置了环境变量 ALIBABA_CLOUD_ACCESS_KEY_SECRET。
|
|
|
- .setAccessKeySecret(properties.getAccessKeyId());
|
|
|
+ .setAccessKeySecret(properties.getAccessKeySecret());
|
|
|
// Endpoint 请参考 https://api.aliyun.com/product/Dysmsapi
|
|
|
config.endpoint = "dysmsapi.aliyuncs.com";
|
|
|
return new Client(config);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
- public void sendSms(String phoneNumber, SendSmsEnum sendSmsEnum) throws Exception {
|
|
|
- Client client = SendSms.createClient();
|
|
|
+ public void sendSms(String phoneNumber, SendSmsEnum sendSmsEnum, String templateParam) throws Exception {
|
|
|
+ Client client = createClient();
|
|
|
SendSmsRequest sendSmsRequest = new SendSmsRequest()
|
|
|
.setPhoneNumbers(phoneNumber)
|
|
|
- .setSignName(properties.getSignName())
|
|
|
- .setTemplateCode(sendSmsEnum.getCode());
|
|
|
+ .setSignName(sendSmsEnum.getSignName())
|
|
|
+ .setTemplateCode(sendSmsEnum.getCode())
|
|
|
+ .setTemplateParam(templateParam);
|
|
|
+
|
|
|
+ sendSmsData(client, sendSmsRequest);
|
|
|
+ }
|
|
|
|
|
|
+ private void sendSmsData(Client client, SendSmsRequest sendSmsRequest) {
|
|
|
try {
|
|
|
// 复制代码运行请自行打印 API 的返回值
|
|
|
- client.sendSmsWithOptions(sendSmsRequest, new RuntimeOptions());
|
|
|
+ client.sendSms(sendSmsRequest);
|
|
|
} catch (TeaException error) {
|
|
|
// 此处仅做打印展示,请谨慎对待异常处理,在工程项目中切勿直接忽略异常。
|
|
|
// 错误 message
|
|
|
@@ -64,6 +67,5 @@ public class SendSmsComponents {
|
|
|
// 诊断地址
|
|
|
log.info((String) error.getData().get("Recommend"));
|
|
|
}
|
|
|
- throw new SystemException("发送短信异常请重试");
|
|
|
}
|
|
|
}
|