添加发送短信
parent
5af914837d
commit
3b90eb0ca9
|
|
@ -44,8 +44,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.alibaba</groupId>
|
<groupId>com.alibaba</groupId>
|
||||||
<artifactId>fastjson</artifactId>
|
<artifactId>fastjson</artifactId>
|
||||||
<version>1.2.68</version>
|
<version>1.2.71</version>
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
||||||
|
|
@ -1,36 +0,0 @@
|
||||||
package com.cowr.common.aliyun.sms;
|
|
||||||
|
|
||||||
import com.aliyuncs.CommonRequest;
|
|
||||||
import com.aliyuncs.CommonResponse;
|
|
||||||
import com.aliyuncs.DefaultAcsClient;
|
|
||||||
import com.aliyuncs.IAcsClient;
|
|
||||||
import com.aliyuncs.exceptions.ClientException;
|
|
||||||
import com.aliyuncs.exceptions.ServerException;
|
|
||||||
import com.aliyuncs.http.MethodType;
|
|
||||||
import com.aliyuncs.profile.DefaultProfile;
|
|
||||||
|
|
||||||
public class SendBatchSms {
|
|
||||||
public static void main(String[] args) {
|
|
||||||
DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "LTAI4GBjCx9Hjxg9LtaTLD43", "xsf8w9KUArVGiXIMcM94d0iIqL7q5O");
|
|
||||||
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("SendBatchSms");
|
|
||||||
request.putQueryParameter("RegionId", "cn-hangzhou");
|
|
||||||
request.putQueryParameter("PhoneNumberJson", "[\"13627293906\"]");
|
|
||||||
request.putQueryParameter("SignNameJson", "[\"智慧砂石\"]");
|
|
||||||
request.putQueryParameter("TemplateCode", "SMS_66850327");
|
|
||||||
request.putQueryParameter("TemplateParamJson", "[{\"time\":\"test time\", \"code\":\"test code\"}]");
|
|
||||||
try {
|
|
||||||
CommonResponse response = client.getCommonResponse(request);
|
|
||||||
System.out.println(response.getData());
|
|
||||||
} catch (ServerException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (ClientException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -0,0 +1,84 @@
|
||||||
|
package com.cowr.local.aliyun.sms;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.aliyuncs.CommonRequest;
|
||||||
|
import com.aliyuncs.CommonResponse;
|
||||||
|
import com.aliyuncs.DefaultAcsClient;
|
||||||
|
import com.aliyuncs.IAcsClient;
|
||||||
|
import com.aliyuncs.http.MethodType;
|
||||||
|
import com.aliyuncs.profile.DefaultProfile;
|
||||||
|
|
||||||
|
public class AliyunSmsService {
|
||||||
|
private static final String regionId = "cn-hangzhou"; // 短信 api 里面固定的
|
||||||
|
private static final String accessKeyId = "LTAI4GBjCx9Hjxg9LtaTLD43"; // 发短信专用,定死的
|
||||||
|
private static final String secret = "xsf8w9KUArVGiXIMcM94d0iIqL7q5O"; // 发短信专用,定死的
|
||||||
|
private static final String SignName = "智慧砂石"; // 阿里云申请的签名,定死的
|
||||||
|
private IAcsClient client;
|
||||||
|
|
||||||
|
public AliyunSmsService() {
|
||||||
|
this.client = new DefaultAcsClient(DefaultProfile.getProfile(regionId, accessKeyId, secret));
|
||||||
|
}
|
||||||
|
|
||||||
|
public JSONObject send(String phone, String temp_code, JSONObject param) {
|
||||||
|
CommonRequest request = new CommonRequest();
|
||||||
|
request.setSysMethod(MethodType.POST);
|
||||||
|
request.setSysDomain("dysmsapi.aliyuncs.com");
|
||||||
|
request.setSysVersion("2017-05-25");
|
||||||
|
request.setSysAction("SendSms");
|
||||||
|
request.putQueryParameter("SignName", SignName);
|
||||||
|
request.putQueryParameter("RegionId", regionId);
|
||||||
|
|
||||||
|
request.putQueryParameter("PhoneNumbers", phone);
|
||||||
|
request.putQueryParameter("TemplateCode", temp_code);
|
||||||
|
request.putQueryParameter("TemplateParam", param.toJSONString());
|
||||||
|
try {
|
||||||
|
CommonResponse response = client.getCommonResponse(request);
|
||||||
|
|
||||||
|
JSONObject responseData = JSONObject.parseObject(response.getData());
|
||||||
|
|
||||||
|
System.out.println(responseData);
|
||||||
|
|
||||||
|
return responseData;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JSONObject query(String phone, String send_date, String bizid) {
|
||||||
|
CommonRequest request = new CommonRequest();
|
||||||
|
request.setSysMethod(MethodType.POST);
|
||||||
|
request.setSysDomain("dysmsapi.aliyuncs.com");
|
||||||
|
request.setSysVersion("2017-05-25");
|
||||||
|
request.setSysAction("QuerySendDetails");
|
||||||
|
request.putQueryParameter("RegionId", regionId);
|
||||||
|
|
||||||
|
request.putQueryParameter("PhoneNumber", phone);
|
||||||
|
request.putQueryParameter("SendDate", send_date);
|
||||||
|
request.putQueryParameter("PageSize", "10");
|
||||||
|
request.putQueryParameter("CurrentPage", "1");
|
||||||
|
request.putQueryParameter("BizId", bizid);
|
||||||
|
try {
|
||||||
|
CommonResponse response = client.getCommonResponse(request);
|
||||||
|
JSONObject responseData = JSONObject.parseObject(response.getData());
|
||||||
|
|
||||||
|
System.out.println(responseData);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
AliyunSmsService sms = new AliyunSmsService();
|
||||||
|
// sms.send(
|
||||||
|
// "13388888888",
|
||||||
|
// "SMS_66850327",
|
||||||
|
// new JSONObject()
|
||||||
|
// .fluentPut("time", DateTimeUtil.sdf.get().format(new Date()))
|
||||||
|
// .fluentPut("code", System.getProperty("os.name")+System.getProperty("os.name")+System.getProperty("os.name")+System.getProperty("os.name")+System.getProperty("os.name")+System.getProperty("os.name")+System.getProperty("os.name")+System.getProperty("os.name")+System.getProperty("os.name"))
|
||||||
|
// );
|
||||||
|
sms.query("13388888888", "20200831", "777907498887368271^0");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,84 @@
|
||||||
|
package com.cowr.service.aliyun.sms;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.aliyuncs.CommonRequest;
|
||||||
|
import com.aliyuncs.CommonResponse;
|
||||||
|
import com.aliyuncs.DefaultAcsClient;
|
||||||
|
import com.aliyuncs.IAcsClient;
|
||||||
|
import com.aliyuncs.http.MethodType;
|
||||||
|
import com.aliyuncs.profile.DefaultProfile;
|
||||||
|
|
||||||
|
public class AliyunSmsService {
|
||||||
|
private static final String regionId = "cn-hangzhou"; // 短信 api 里面固定的
|
||||||
|
private static final String accessKeyId = "LTAI4GBjCx9Hjxg9LtaTLD43"; // 发短信专用,定死的
|
||||||
|
private static final String secret = "xsf8w9KUArVGiXIMcM94d0iIqL7q5O"; // 发短信专用,定死的
|
||||||
|
private static final String SignName = "智慧砂石"; // 阿里云申请的签名,定死的
|
||||||
|
private IAcsClient client;
|
||||||
|
|
||||||
|
public AliyunSmsService() {
|
||||||
|
this.client = new DefaultAcsClient(DefaultProfile.getProfile(regionId, accessKeyId, secret));
|
||||||
|
}
|
||||||
|
|
||||||
|
public JSONObject send(String phone, String temp_code, JSONObject param) {
|
||||||
|
CommonRequest request = new CommonRequest();
|
||||||
|
request.setSysMethod(MethodType.POST);
|
||||||
|
request.setSysDomain("dysmsapi.aliyuncs.com");
|
||||||
|
request.setSysVersion("2017-05-25");
|
||||||
|
request.setSysAction("SendSms");
|
||||||
|
request.putQueryParameter("SignName", SignName);
|
||||||
|
request.putQueryParameter("RegionId", regionId);
|
||||||
|
|
||||||
|
request.putQueryParameter("PhoneNumbers", phone);
|
||||||
|
request.putQueryParameter("TemplateCode", temp_code);
|
||||||
|
request.putQueryParameter("TemplateParam", param.toJSONString());
|
||||||
|
try {
|
||||||
|
CommonResponse response = client.getCommonResponse(request);
|
||||||
|
|
||||||
|
JSONObject responseData = JSONObject.parseObject(response.getData());
|
||||||
|
|
||||||
|
System.out.println(responseData);
|
||||||
|
|
||||||
|
return responseData;
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JSONObject query(String phone, String send_date, String bizid) {
|
||||||
|
CommonRequest request = new CommonRequest();
|
||||||
|
request.setSysMethod(MethodType.POST);
|
||||||
|
request.setSysDomain("dysmsapi.aliyuncs.com");
|
||||||
|
request.setSysVersion("2017-05-25");
|
||||||
|
request.setSysAction("QuerySendDetails");
|
||||||
|
request.putQueryParameter("RegionId", regionId);
|
||||||
|
|
||||||
|
request.putQueryParameter("PhoneNumber", phone);
|
||||||
|
request.putQueryParameter("SendDate", send_date);
|
||||||
|
request.putQueryParameter("PageSize", "10");
|
||||||
|
request.putQueryParameter("CurrentPage", "1");
|
||||||
|
request.putQueryParameter("BizId", bizid);
|
||||||
|
try {
|
||||||
|
CommonResponse response = client.getCommonResponse(request);
|
||||||
|
JSONObject responseData = JSONObject.parseObject(response.getData());
|
||||||
|
|
||||||
|
System.out.println(responseData);
|
||||||
|
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
AliyunSmsService sms = new AliyunSmsService();
|
||||||
|
// sms.send(
|
||||||
|
// "13388888888",
|
||||||
|
// "SMS_66850327",
|
||||||
|
// new JSONObject()
|
||||||
|
// .fluentPut("time", DateTimeUtil.sdf.get().format(new Date()))
|
||||||
|
// .fluentPut("code", System.getProperty("os.name")+System.getProperty("os.name")+System.getProperty("os.name")+System.getProperty("os.name")+System.getProperty("os.name")+System.getProperty("os.name")+System.getProperty("os.name")+System.getProperty("os.name")+System.getProperty("os.name"))
|
||||||
|
// );
|
||||||
|
sms.query("13388888888", "20200831", "777907498887368271^0");
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue