阿里云短信发送
public static void sendSms(String phoneNumber) {
int code = new Random().nextInt(899999) + 100000;//随机生成验证码
DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "自己的accessKeyId", "自己的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", "cn-hangzhou");
request.putQueryParameter("PhoneNumbers",phoneNumber );
//phoneNumber为接收验证码的手机号
request.putQueryParameter("SignName", "验证码的前缀,一般用公司名");
request.putQueryParameter("TemplateCode", "验证码的模板");//SMS_178485589
request.putQueryParameter("TemplateParam", "{\"code\":"+ code + "}");
try {
CommonResponse response = client.getCommonResponse(request);
System.out.println(response.getData());
} catch (ServerException e) {
e.printStackTrace();
} catch (ClientException e) {
e.printStackTrace();
}
}
来源:CSDN
作者:凉兮、
链接:https://blog.csdn.net/qq_43549747/article/details/103879358