?继承的sdk:?
? ? ? ??
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>dysmsapi20170525</artifactId>
<version>2.0.6</version>
</dependency>
工具类:
package com.lucp.businessCode.sendSms;
import com.aliyun.dysmsapi20170525.models.*;
import com.aliyun.teaopenapi.models.*;
/**
* @ProjectName: jiufeng
* @Package: com.lucp.businessCode.jiufeng.utils
* @ClassName: SampleUtils
* @Author: y
* @Description:
* @Date: 2021/10/27 21:16
* @Version: 1.0
*/
public class SampleUtils {
private static final String accessKeyId = "";
private static final String accessKeySecret = "";
public static com.aliyun.dysmsapi20170525.Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
Config config = new Config()
// 您的AccessKey ID
.setAccessKeyId(accessKeyId)
// 您的AccessKey Secret
.setAccessKeySecret(accessKeySecret);
// 访问的域名
config.endpoint = "dysmsapi.aliyuncs.com";
return new com.aliyun.dysmsapi20170525.Client(config);
}
public static void main(String[] args) throws Exception {
com.aliyun.dysmsapi20170525.Client client = SampleUtils.createClient("LTAI5tMQq4evLYsdBDkBhbeD", "FGZTWmgd6JxEmgE1CWxg9imdKZeQrY");
SendSmsRequest sendSmsRequest = new SendSmsRequest()
.setPhoneNumbers("") //手机号
.setSignName("") //短信签名 --阿里云短信控制台获取
.setTemplateCode(""); //短信模板--阿里云短信控制台获取
// 复制代码运行请自行打印 API 的返回值 请求失败这里会抛ClientException异常
SendSmsResponse response = client.sendSms(sendSmsRequest);
// System.out.println("请求成功、、、、"+response.getBody().getCode());
// System.out.println("请求成功、、、、"+response.getBody().getMessage());
// System.out.println("请求成功、、、、"+response.getBody().getBizId());
// System.out.println("请求成功、、、、"+response.getBody().getRequestId());
System.out.println("请求成功、、、、"+response.getHeaders());
}
}
|