阿里云短信服务
阿里云开通短信服务
新建用户组
填写用户组信息
添加权限
搜索sms
创建用户
添加用户组
进入短信服务
添加签名
新建短信模板
编码测试
添加依赖
编写代码
public static void main(String[] args) {
DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "liufucheng2@1577308013267446.onaliyun.com", "阿里云登录密码");
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("RegionId", "cn-hangzhou");
//自定义的参数(手机号,验证码,签名,模板)
request.putQueryParameter("PhoneNumbers", "手机号");
request.putQueryParameter("SignName", "短信签名");
request.putQueryParameter("TemplateCode", "短信模板 SMS_208915239");
HashMap<String, Object> map = new HashMap<>();
map.put("code","验证码");
request.putQueryParameter("TemplateParam", JSONObject.toJSONString(map));
try {
CommonResponse response = client.getCommonResponse(request);
System.out.println(response.getData());
} catch (ServerException e) {
e.printStackTrace();
} catch (ClientException e) {
e.printStackTrace();
}
}
参数使用