标签:def success domain phone utils 模板 ram sign group
帮助文档:
https://help.aliyun.com/product/44282.html?spm=5176.10629532.0.0.38311cbeYzBm73
(1)添加模板管理
选择 国内消息 - 模板管理 - 添加模板
点击 添加模板,进入到添加页面,输入模板信息
点击提交,等待审核,审核通过后可以使用
(2)添加签名管理
选择 国内消息 - 签名管理 - 添加签名
点击添加签名,进入添加页面,填入相关信息
注意:签名要写的有实际意义
点击提交,等待审核,审核通过后可以使
<dependencies>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-core</artifactId>
</dependency>
</dependencies>
编写service
@Service
public class MsmServiceImpl implements MsmService {
/**
* 发送短信
*/
public boolean send(String PhoneNumbers, String templateCode, Map<String,Object> param) {
if(StringUtils.isEmpty(PhoneNumbers)) return false;
//regionId, accessKeyId, secret
DefaultProfile profile =
DefaultProfile.getProfile("default", "LTAIq6nIPY09VROj", "FQ7UcixT9wEqMv9F35nORPqKr8XkTF");
IAcsClient client = new DefaultAcsClient(profile);
CommonRequest request = new CommonRequest();
//request.setProtocol(ProtocolType.HTTPS);
request.setMethod(MethodType.POST);
request.setDomain("dysmsapi.aliyuncs.com");
request.setVersion("2017-05-25");
request.setAction("SendSms");
request.putQueryParameter("PhoneNumbers", PhoneNumbers);
request.putQueryParameter("SignName", "在线教育网站");
request.putQueryParameter("TemplateCode", templateCode);
request.putQueryParameter("TemplateParam", JSONObject.toJSONString(param));
try {
CommonResponse response = client.getCommonResponse(request);
System.out.println(response.getData());
return response.getHttpResponse().isSuccess();
} catch (ServerException e) {
e.printStackTrace();
} catch (ClientException e) {
e.printStackTrace();
}
return false;
}
}
标签:def success domain phone utils 模板 ram sign group
原文地址:https://www.cnblogs.com/royal6/p/12939559.html