private static final String ACCESSKEY_ID = "LTAIBPzjrAhbdISO";
private static final String ACCESSKEY_SECRET = "qD0akARRo0dPD8arrZmWqH6yHMgOlQ";
private static final String SIGN_NAME = "智美";
private static final String SMS_TEMPLATE = "SMS_122281118";
private RedisUtil redisUtil;
@Override
public boolean sendMessage(String phone, String verifyCode) {
Map<String, Object> map = new HashMap<>();
map.put("code", verifyCode);
//链接阿里云
DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", ACCESSKEY_ID, ACCESSKEY_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("PhoneNumbers", phone);
request.putQueryParameter("SignName", SIGN_NAME);
request.putQueryParameter("TemplateCode", SMS_TEMPLATE);
request.putQueryParameter("TemplateParam", JSONObject.toJSONString(map));
try {
//发送
CommonResponse response = client.getCommonResponse(request);
return response.getHttpResponse().isSuccess();
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
阿里云短信
最新推荐文章于 2023-03-17 10:12:09 发布