大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。
Jetbrains全家桶1年46,售后保障稳定
1.导入
<!--阿里云短信-->
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-core</artifactId>
<version>4.0.3</version>
</dependency>
单条发送
/**
* 阿里云短信发送
*/
public String sendALMSM(String content, String mobile,String temNo) {
DefaultProfile profile = DefaultProfile.getProfile(PropertiesUtils.getInstance().getProperty("regionId"), PropertiesUtils.getInstance().getProperty("accessKeyId"), PropertiesUtils.getInstance().getProperty("secret"));
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", PropertiesUtils.getInstance().getProperty("regionId"));
request.putQueryParameter("PhoneNumbers", mobile); //接收短信的手机号码。
request.putQueryParameter("SignName", PropertiesUtils.getInstance().getProperty("signName"));//短信签名名称
request.putQueryParameter("TemplateCode", temNo);//短信模板ID
request.putQueryParameter("TemplateParam", content);//短信模板变量对应的实际值,JSON格式 {"code":"1111"}
CommonResponse response= null;
try {
response = client.getCommonResponse(request);
System.out.println("短信接口返回的数据----------------");
System.out.println(response.getData());
} catch (ServerException e) {
e.printStackTrace();
} catch (ClientException e) {
e.printStackTrace();
}
return response.getData();
}
批量发送
public static String sendALMSMPl(String mobile,String SignNameJson,String temNo,String content) {
DefaultProfileprofile = DefaultProfile.getProfile("cn-hangzhou", "", "");
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("SendBatchSms");
request.putQueryParameter("RegionId", "cn-hangzhou");
request.putQueryParameter("PhoneNumberJson", mobile);
request.putQueryParameter("SignNameJson", SignNameJson);
request.putQueryParameter("TemplateCode", temNo);
request.putQueryParameter("TemplateParamJson", content);
CommonResponse response= null;
try {
response = client.getCommonResponse(request);
System.out.println(response.getData());
} catch (ServerException e) {
e.printStackTrace();
} catch (ClientException e) {
e.printStackTrace();
}
return response.getData();
}
发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/226759.html原文链接:https://javaforall.cn
【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛
【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...