|
|
|
@ -1,16 +1,18 @@
|
|
|
|
package cn.iocoder.mall.admin.client;
|
|
|
|
package cn.iocoder.mall.admin.client;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
import com.aliyuncs.CommonRequest;
|
|
|
|
import com.aliyuncs.CommonRequest;
|
|
|
|
import com.aliyuncs.CommonResponse;
|
|
|
|
import com.aliyuncs.CommonResponse;
|
|
|
|
import com.aliyuncs.DefaultAcsClient;
|
|
|
|
import com.aliyuncs.DefaultAcsClient;
|
|
|
|
import com.aliyuncs.IAcsClient;
|
|
|
|
import com.aliyuncs.IAcsClient;
|
|
|
|
import com.aliyuncs.exceptions.ClientException;
|
|
|
|
import com.aliyuncs.exceptions.ClientException;
|
|
|
|
import com.aliyuncs.exceptions.ServerException;
|
|
|
|
|
|
|
|
import com.aliyuncs.http.MethodType;
|
|
|
|
import com.aliyuncs.http.MethodType;
|
|
|
|
import com.aliyuncs.profile.DefaultProfile;
|
|
|
|
import com.aliyuncs.profile.DefaultProfile;
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
import org.springframework.stereotype.Component;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
|
|
|
import java.util.Collections;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Map;
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
|
|
@ -23,21 +25,26 @@ import java.util.Map;
|
|
|
|
@Component
|
|
|
|
@Component
|
|
|
|
public class SmsAliYunClient implements SmsClient {
|
|
|
|
public class SmsAliYunClient implements SmsClient {
|
|
|
|
|
|
|
|
|
|
|
|
@Value("sms.aliYun.accessKeyId")
|
|
|
|
@Value("${sms.aliYun.accessKeyId}")
|
|
|
|
private String accessKeyId;
|
|
|
|
private String accessKeyId;
|
|
|
|
@Value("sms.aliYun.accessSecret")
|
|
|
|
@Value("${sms.aliYun.accessSecret}")
|
|
|
|
private String accessSecret;
|
|
|
|
private String accessSecret;
|
|
|
|
|
|
|
|
|
|
|
|
private static final String DOMAIN = "dysmsapi.aliyuncs.com";
|
|
|
|
private static final String DOMAIN = "dysmsapi.aliyuncs.com";
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public SendResult singleSend(String mobile, String sign, String template, Map<String, String> params) {
|
|
|
|
public SendResult singleSend(String mobile, String sign, String templateCode,
|
|
|
|
|
|
|
|
String template, Map<String, String> templateParams) {
|
|
|
|
IAcsClient client = getClient();
|
|
|
|
IAcsClient client = getClient();
|
|
|
|
CommonRequest request = new CommonRequest();
|
|
|
|
CommonRequest request = new CommonRequest();
|
|
|
|
request.setMethod(MethodType.POST);
|
|
|
|
request.setMethod(MethodType.POST);
|
|
|
|
request.setDomain(DOMAIN);
|
|
|
|
request.setDomain(DOMAIN);
|
|
|
|
request.setVersion("2017-05-25");
|
|
|
|
request.setVersion("2017-05-25");
|
|
|
|
request.setAction("SendSms");
|
|
|
|
request.setAction("SendSms");
|
|
|
|
|
|
|
|
request.putQueryParameter("PhoneNumbers", mobile);
|
|
|
|
|
|
|
|
request.putQueryParameter("SignName", sign);
|
|
|
|
|
|
|
|
request.putQueryParameter("TemplateCode", templateCode);
|
|
|
|
|
|
|
|
request.putQueryParameter("TemplateParam", JSON.toJSONString(templateParams));
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
CommonResponse response = client.getCommonResponse(request);
|
|
|
|
CommonResponse response = client.getCommonResponse(request);
|
|
|
|
@ -49,8 +56,8 @@ public class SmsAliYunClient implements SmsClient {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public SendResult batchSend(List<String> mobileList, String sign, String template, Map<String, String> params) {
|
|
|
|
public SendResult batchSend(List<String> mobileList, String sign, String templateCode,
|
|
|
|
|
|
|
|
String template, Map<String, String> templateParams) {
|
|
|
|
// 获取 client
|
|
|
|
// 获取 client
|
|
|
|
IAcsClient client = getClient();
|
|
|
|
IAcsClient client = getClient();
|
|
|
|
|
|
|
|
|
|
|
|
@ -60,12 +67,14 @@ public class SmsAliYunClient implements SmsClient {
|
|
|
|
request.setDomain(DOMAIN);
|
|
|
|
request.setDomain(DOMAIN);
|
|
|
|
request.setVersion("2017-05-25");
|
|
|
|
request.setVersion("2017-05-25");
|
|
|
|
request.setAction("SendBatchSms");
|
|
|
|
request.setAction("SendBatchSms");
|
|
|
|
|
|
|
|
request.putQueryParameter("PhoneNumberJson", JSON.toJSONString(mobileList));
|
|
|
|
|
|
|
|
request.putQueryParameter("SignNameJson", JSON.toJSONString(Collections.singletonList(sign)));
|
|
|
|
|
|
|
|
request.putQueryParameter("TemplateCode", templateCode);
|
|
|
|
|
|
|
|
request.putQueryParameter("TemplateParamJson", JSON.toJSONString(Collections.singletonList(templateParams)));
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
CommonResponse response = client.getCommonResponse(request);
|
|
|
|
CommonResponse response = client.getCommonResponse(request);
|
|
|
|
System.out.println(response.getData());
|
|
|
|
System.out.println(response.getData());
|
|
|
|
} catch (ServerException e) {
|
|
|
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
|
|
|
} catch (ClientException e) {
|
|
|
|
} catch (ClientException e) {
|
|
|
|
e.printStackTrace();
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|