-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMessageSendUtils.java
More file actions
67 lines (56 loc) · 2.74 KB
/
Copy pathMessageSendUtils.java
File metadata and controls
67 lines (56 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package com.stkj.pperty.util;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
import com.stkj.pperty.common.SystemConfig;
/**
* @author HUANGP
* @date 2018年1月23日
* @des 验证码发送
*/
public class MessageSendUtils {
/**
* @author HUANGP
* @des 密码修改短信验证码发送
* @date 2018年1月23日
* @param phoneNo 电话号码
* @param code 短信验证码
* @return
* @throws ClientException
*/
public static SendSmsResponse sendSmsUpdateLoginPassword(String phoneNo,String code) throws ClientException {
//可自助调整超时时间
System.setProperty("sun.net.client.defaultConnectTimeout", SystemConfig.defaultConnectTimeout);
System.setProperty("sun.net.client.defaultReadTimeout",SystemConfig.defaultReadTimeout);
//初始化acsClient,暂不支持region化
IClientProfile profile = DefaultProfile.getProfile("cn-hangzhou", SystemConfig.accessKeyId, SystemConfig.accessKeySecret);
DefaultProfile.addEndpoint("cn-hangzhou", "cn-hangzhou", SystemConfig.product, SystemConfig.domain);
IAcsClient acsClient = new DefaultAcsClient(profile);
//组装请求对象-具体描述见控制台-文档部分内容
SendSmsRequest request = new SendSmsRequest();
//必填:待发送手机号
request.setPhoneNumbers(phoneNo);
//必填:短信签名-可在短信控制台中找到
request.setSignName(SystemConfig.signName);
//必填:短信模板-可在短信控制台中找到
request.setTemplateCode(SystemConfig.templateCodeOfUpdateLoginPassword);
//可选:模板中的变量替换JSON串,如模板内容为"您的验证码为${code}"时,此处的值为
request.setTemplateParam("{\"code\":\""+code+"\"}");
//hint 此处可能会抛出异常,注意catch
SendSmsResponse sendSmsResponse = acsClient.getAcsResponse(request);
return sendSmsResponse;
}
public static void main(String[] args) throws ClientException, InterruptedException {
//发短信
SendSmsResponse response = sendSmsUpdateLoginPassword("15223576075","555555");
System.out.println("短信接口返回的数据----------------");
System.out.println("Code=" + response.getCode());
System.out.println("Message=" + response.getMessage());
System.out.println("RequestId=" + response.getRequestId());
System.out.println("BizId=" + response.getBizId());
}
}