阿里云短信服务模板
作者:互联网
public interface SendSms {
public boolean sendSms(String phoneNum , String templateCode, Map<String,Object> code);
}
public class SendSmsImpl implements SendSms {
@Override
public boolean sendSms(String phoneNum, String templateCode, Map<String, Object> code) {
// 更换为自己的阿里云key
DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "", "");
IAcsClient client = new DefaultAcsClient(profile);
CommonRequest request = new CommonRequest();
request.setSysMethod(MethodType.POST);
request.setSysDomain("dysmsapi.aliyuncs.com");
request.setSysVersion("2017-05-25");
request.setSysAction("SendSms");
request.putQueryParameter("PhoneNumbers", phoneNum);
request.putQueryParameter("SignName", "小老弟科技");
request.putQueryParameter("TemplateCode", templateCode);
request.putQueryParameter("TemplateParam", JSONObject.toJSONString(code));
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;
}
}
标签:code,短信,String,phoneNum,putQueryParameter,request,阿里,public,模板 来源: https://www.cnblogs.com/xiaolaodi1999/p/13398861.html