整合阿里云短信服务
- 一、开通阿里云短信服务步骤
-
- 1.1登录阿里云找到短信服务
- 1.2申请模板管理
- 1.3申请签名管理
- 1.4(看是否需要)创建阿里云OSS许可证
- [1.5创建Access Key](#1.5创建Access Key)
- 二、代码实现
一、开通阿里云短信服务步骤
1.1登录阿里云找到短信服务

1.2申请模板管理

1.3申请签名管理

1.4(看是否需要)创建阿里云OSS许可证
阿里云颁发ID与秘钥,如果要使用OSS对象存储,要使用OSS许可证,首先需要创建Bucket



1.5创建Access Key


二、代码实现


2.1依赖
xml
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>tea-openapi</artifactId>
<version>0.0.19</version>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>dysmsapi20170525</artifactId>
<version>2.0.6</version>
</dependency>
编写test
还会在学习的,到时候完善
https://blog.csdn.net/Serendipity_o/article/details/124369637


java
package com.gxa.test;// This file is auto-generated, don't edit it. Thanks.
import com.aliyun.tea.*;
import com.aliyun.dysmsapi20170525.*;
import com.aliyun.dysmsapi20170525.models.*;
import com.aliyun.teaopenapi.*;
import com.aliyun.teaopenapi.models.*;
import com.aliyun.teaconsole.*;
import com.aliyun.teautil.*;
import com.aliyun.teautil.models.*;
public class Sample {
/**
* 使用AK&SK初始化账号Client
* @param accessKeyId
* @param accessKeySecret
* @return Client
* @throws Exception
*/
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 {
java.util.List<String> args = java.util.Arrays.asList(args_);
com.aliyun.dysmsapi20170525.Client client = Sample.createClient("ACCESS_KEY_ID", "ACCESS_KEY_SECRET");
SendSmsRequest sendSmsRequest = new SendSmsRequest()
.setPhoneNumbers("15884226919")
.setSignName("刀锋之影")
.setTemplateCode("SMS_199796966")
.setTemplateParam("{\"code\":\"1234\"}");
RuntimeOptions runtime = new RuntimeOptions();
SendSmsResponse resp = client.sendSmsWithOptions(sendSmsRequest, runtime);
com.aliyun.teaconsole.Client.log(com.aliyun.teautil.Common.toJSONString(TeaModel.buildMap(resp)));
}
}