阿里云短信服务申请和集成

阿里云短信服务申请和集成

登录阿里云官网.找到短信服务,网址: https://dysms.console.aliyun.com/quickstart

1、查看快速学习

阿里云短信服务申请和集成_第1张图片

2、申请签名

阿里云短信服务申请和集成_第2张图片

3、申请短信模板

阿里云短信服务申请和集成_第3张图片

4、短信集成文档查看

阿里云官网不好找文档, 链接地址: https://help.aliyun.com/document_detail/112148.html

1、添加依赖

<dependency>
  <groupId>com.aliyungroupId>
  <artifactId>aliyun-java-sdk-coreartifactId>
  <version>4.5.16version>
dependency>

2、集成代码

创建DefaultProfile的说明

 "",           // The region ID        				     区域
 "",       // The AccessKey ID of the RAM account    密匙id 
 "",   // The AccessKey Secret of the RAM account密匙密码 
 "");          // STS Token                              令牌
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.profile.DefaultProfile;
import com.google.gson.Gson;
import java.util.*;
import com.aliyuncs.dysmsapi.model.v20170525.*;

public class SendSms {

    public static void main(String[] args) {
        DefaultProfile profile = DefaultProfile.getProfile("cn-beijing", "LTAI4G2Jr26FmDUWJS5qLCpk", "FzyW3zqpZvO7SRsbgDMdc44Cd45m8n");
        /** use STS Token
        DefaultProfile profile = DefaultProfile.getProfile(
            "",           // The region ID
            "",       // The AccessKey ID of the RAM account
            "",   // The AccessKey Secret of the RAM account
            "");          // STS Token
        **/
        IAcsClient client = new DefaultAcsClient(profile);

        SendSmsRequest request = new SendSmsRequest();
        request.setPhoneNumbers("1368846****");//接收短信的手机号码
        request.setSignName("阿里云");			  //短信签名名称
        request.setTemplateCode("SMS_20933****");//短信模板CODE
        request.setTemplateParam("张三");//短信模板变量对应的实际值

        try {
            SendSmsResponse response = client.getAcsResponse(request);
            System.out.println(new Gson().toJson(response));
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            System.out.println("ErrCode:" + e.getErrCode());
            System.out.println("ErrMsg:" + e.getErrMsg());
            System.out.println("RequestId:" + e.getRequestId());
        }

    }
}

你可能感兴趣的:(工具,阿里云,java)