阿里云短信服务JAVA版对接
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-core</artifactId>
<version>4.4.6</version>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-ecs</artifactId>
<version>4.17.6</version>
</dependency>
测试类
public class Demo {
public static void main(String[] args) {
// 创建DefaultAcsClient实例并初始化
DefaultProfile profile = DefaultProfile.getProfile(
"cn-hangzhou", // 地域ID
"填AccessKey ID", // RAM账号的AccessKey ID
"填AccessKey Secret"); // RAM账号AccessKey Secret
IAcsClient client = new DefaultAcsClient(profile);
CommonRequest request = new CommonRequest();
request.setSysDomain("dysmsapi.aliyuncs.com");
request.setSysAction("SendSms");
request.setSysVersion("2017-05-25");
request.putQueryParameter("RegionId", "cn-hangzhou");
request.putQueryParameter("PhoneNumbers", "接收手机号码");
request.putQueryParameter("SignName", "签名名称");
request.putQueryParameter("TemplateCode", "模板名称");
request.putQueryParameter("TemplateParam", "{\"code\":\"1111\"}");
try {
CommonResponse response = client.getCommonResponse(request);
System.out.println(response.getData());
} catch (ServerException e) {
e.printStackTrace();
} catch (ClientException e) {
e.printStackTrace();
}
}
}