2019阿里云短信Demo

@TOCming

记录下自己学习的笔记

maven

>
  >com.aliyun>
  >aliyun-java-sdk-core>
  >4.0.3>
>

jar包下载
2019阿里云短信Demo_第1张图片直接上代码把:
`package utils;

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

com.aliyun
aliyun-java-sdk-core
4.0.3

/
public class SendSms {
private static final String accessKey = "LTAI4FiiXkVk3
Ymgn";
private static final String secret = "nPK4
***68PO081";

public static void main(String[] args) {
    DefaultProfile profile = DefaultProfile.getProfile("default", accessKey,
            secret);
    // 初始化client对象
    IAcsClient client = new DefaultAcsClient(profile);

    CommonRequest request = new CommonRequest();
    request.setMethod(MethodType.POST);
    // 产品域名,开发者无需替换
    request.setDomain("dysmsapi.aliyuncs.com");
    // 系统参数  不可以自己改动时间 new SimpleDateFormat("yyyy-MM-dd").format(new Date()) 必须是2017-5-25
    request.setVersion("2017-05-25");
    // 系统规定参数
    request.setAction("SendSms");
    // 发送的电话号码
    request.putQueryParameter("PhoneNumbers", "130*******6");
    // 签名管理->签名名称
    request.putQueryParameter("SignName", "XXX");
    // 模版管理->模版CODE
    request.putQueryParameter("TemplateCode", "SMS_16*****255");
    try {
        CommonResponse response = client.getCommonResponse(request);
        System.out.println(response.getData());
    } catch (ServerException e) {
        e.printStackTrace();
    } catch (ClientException e) {
        e.printStackTrace();
    }
}

}`

你可能感兴趣的:(2019阿里云短信Demo)