diff --git a/austin-handler/src/main/java/com/java3y/austin/script/TencentSmsScript.java b/austin-handler/src/main/java/com/java3y/austin/script/TencentSmsScript.java index 4703a0d..c2134af 100644 --- a/austin-handler/src/main/java/com/java3y/austin/script/TencentSmsScript.java +++ b/austin-handler/src/main/java/com/java3y/austin/script/TencentSmsScript.java @@ -11,14 +11,17 @@ import com.tencentcloudapi.common.profile.HttpProfile; import com.tencentcloudapi.sms.v20210111.SmsClient; import com.tencentcloudapi.sms.v20210111.models.SendSmsRequest; import com.tencentcloudapi.sms.v20210111.models.SendSmsResponse; +import lombok.Getter; import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.PropertySource; import org.springframework.stereotype.Service; /** * @author 3y * @date 2021/11/6 * 1. 发送短信接入文档:https://cloud.tencent.com/document/api/382/55981 - * 2. 推荐直接使用SDK + * 2. 推荐直接使用SDK调用 * 3. 推荐使用API Explorer 生成代码 */ @Service @@ -32,13 +35,23 @@ public class TencentSmsScript { private static final String REGION = "ap-guangzhou"; /** - * 账号相关 TODO + * 账号相关 */ - private final static String SECRET_ID = "//"; - private final static String SECRET_KEY = "//"; - private static final String SMS_SDK_APP_ID = "//"; - private static final String TEMPLATE_ID = "//"; - private static final String SIGN_NAME = "//"; + @Value("${tencent.sms.account.secret-id}") + private String SECRET_ID; + + @Value("${tencent.sms.account.secret-key}") + private String SECRET_KEY; + + @Value("${tencent.sms.account.sms-sdk-app-id}") + private String SMS_SDK_APP_ID; + + @Value("${tencent.sms.account.template-id}") + private String TEMPLATE_ID; + + @Value("${tencent.sms.account.sign_name}") + private String SIGN_NAME; + public String send(SmsParam smsParam) { try { diff --git a/austin-web/src/main/java/com/java3y/austin/AustinApplication.java b/austin-web/src/main/java/com/java3y/austin/AustinApplication.java index cbee8e3..5f5f217 100644 --- a/austin-web/src/main/java/com/java3y/austin/AustinApplication.java +++ b/austin-web/src/main/java/com/java3y/austin/AustinApplication.java @@ -22,12 +22,19 @@ public class AustinApplication { SpringApplication.run(AustinApplication.class, args); } - @GetMapping("/hello") - public String hello() { - + /** + * @param phone 手机号 + * @return + */ + @GetMapping("/sendSms") + public String sendSms(String phone,String content) { + + /** + * 这里的content指的是模板占位符的参数值 + */ SmsParam smsParam = SmsParam.builder() - .phones(new HashSet<>(Arrays.asList("//TODO PHONE "))) - .content("3333") + .phones(new HashSet<>(Arrays.asList(phone))) + .content(content) .build(); return tencentSmsScript.send(smsParam); diff --git a/austin-web/src/main/resources/application.properties b/austin-web/src/main/resources/application.properties deleted file mode 100644 index 82ec95a..0000000 --- a/austin-web/src/main/resources/application.properties +++ /dev/null @@ -1,6 +0,0 @@ -# ok http配置信息 TODO -ok.http.connect-timeout=30 -ok.http.read-timeout=30 -ok.http.write-timeout=30 -ok.http.max-idle-connections=200 -ok.http.keep-alive-duration=300 diff --git a/austin-web/src/main/resources/application.yml b/austin-web/src/main/resources/application.yml new file mode 100644 index 0000000..c831477 --- /dev/null +++ b/austin-web/src/main/resources/application.yml @@ -0,0 +1,18 @@ +# HTTP 连接配置 TODO +ok: + http: + connect-timeout: 30 + keep-alive-duration: 300 + max-idle-connections: 200 + read-timeout: 30 + write-timeout: 30 + +# 腾讯云账号相关的信息配置 TODO +tencent: + sms: + account: + secret-id: + secret-key: + sign_name: + sms-sdk-app-id: + template-id: diff --git a/austin-web/src/main/resources/logback.xml b/austin-web/src/main/resources/logback.xml index ef49c0c..abccc6a 100644 --- a/austin-web/src/main/resources/logback.xml +++ b/austin-web/src/main/resources/logback.xml @@ -4,7 +4,7 @@ austin - +