第一步、准备工作
1、登录阿里云,完成认证
注意,推广短信只有升级为企业认证之后才可启用
2、开通短信服务
搜索短信服务产品
3、充值余额或购买短信包
第二步、配置签名和模板(可选)
如果签名和模板是固定的,并不需要在自己的系统中进行配置的话,可以在阿里云上直接配置
第三步、代码集成
1、API文档
https://help.aliyun.com/document_detail/101300.html?spm=5176.12207334.0.0.14dd1cbeCdW42y
2、通过阿里云提供的OpenAPI Explorer,可以方便地生成SDK代码示例
3、发送短信(以Spring Boot项目为例)
阿里的发送短信接口分为两种:SendSms和SendBatchSms
SendSms接口支持在一次请求中向多个不同的手机号码发送同样内容的短信。
SendBatchSms接口支持一次请求中分别向多个不同的手机号码发送不同签名和模版内容的短信
PS:具体的入参和返回数据含义请查看文档
import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
/*
pom.xml
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-core</artifactId>
<version>4.0.3</version>
</dependency>
*/
public class SendSms {
public static void main(String[] args) {
DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "