Java发送阿里云短信接口
作者:互联网
public class AliyunSmsUtils {
static final String accessKeyId="xxx";
static final String accessKeySecret="xxx";
public static void sendSms(String telephone, String code) throws ClientException {
DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", accessKeyId, accessKeySecret);
IAcsClient client = new DefaultAcsClient(profile);
CommonRequest request = new CommonRequest();
request.setMethod(MethodType.POST);
request.setDomain("dysmsapi.aliyuncs.com");
request.setVersion("2017-05-25");
request.setAction("SendSms");
request.putQueryParameter("RegionId", "xxx");
request.putQueryParameter("PhoneNumbers", telephone);
request.putQueryParameter("SignName", "xxx");
request.putQueryParameter("TemplateCode", "xxx");
request.putQueryParameter("TemplateParam", "{\"code\":\""+code+"\"}");
try {
CommonResponse response = client.getCommonResponse(request);
System.out.println(response.getData());
} catch (ClientException e) {
e.printStackTrace();
}
}
}
后端比较简单就可以请求接口发送短信了。
但是关键的数据,还是需要再阿里云上进行注册配置才可以。
标签:code,短信,String,xxx,request,接口,putQueryParameter,static,Java 来源: https://blog.csdn.net/c601757850/article/details/122105623