first commit
This commit is contained in:
37
comm/Kernel/src/com/chuanglan/sms/request/SmsBalanceRequest.java
Executable file
37
comm/Kernel/src/com/chuanglan/sms/request/SmsBalanceRequest.java
Executable file
@@ -0,0 +1,37 @@
|
||||
package com.chuanglan.sms.request;
|
||||
|
||||
public class SmsBalanceRequest {
|
||||
/**
|
||||
* 用户账号,必填
|
||||
*/
|
||||
private String account;
|
||||
/**
|
||||
* 用户密码,必填
|
||||
*/
|
||||
private String password;
|
||||
|
||||
public SmsBalanceRequest() {
|
||||
|
||||
}
|
||||
public SmsBalanceRequest(String account, String password) {
|
||||
super();
|
||||
this.account = account;
|
||||
this.password = password;
|
||||
|
||||
}
|
||||
public String getAccount() {
|
||||
return account;
|
||||
}
|
||||
public void setAccount(String account) {
|
||||
this.account = account;
|
||||
}
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
48
comm/Kernel/src/com/chuanglan/sms/request/SmsPullRequest.java
Executable file
48
comm/Kernel/src/com/chuanglan/sms/request/SmsPullRequest.java
Executable file
@@ -0,0 +1,48 @@
|
||||
package com.chuanglan.sms.request;
|
||||
|
||||
public class SmsPullRequest {
|
||||
/**
|
||||
* 用户账号,必填
|
||||
*/
|
||||
private String account;
|
||||
/**
|
||||
* 用户密码,必填
|
||||
*/
|
||||
private String password;
|
||||
/**
|
||||
* 拉取个数(最大100,默认20),选填
|
||||
*/
|
||||
private String count;
|
||||
|
||||
public SmsPullRequest() {
|
||||
|
||||
}
|
||||
public SmsPullRequest(String account, String password,String count) {
|
||||
super();
|
||||
this.account = account;
|
||||
this.password = password;
|
||||
this.count = count;
|
||||
|
||||
}
|
||||
public String getAccount() {
|
||||
return account;
|
||||
}
|
||||
public void setAccount(String account) {
|
||||
this.account = account;
|
||||
}
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
public String getCount() {
|
||||
return count;
|
||||
}
|
||||
public void setCount(String count) {
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
48
comm/Kernel/src/com/chuanglan/sms/request/SmsReportRequest.java
Executable file
48
comm/Kernel/src/com/chuanglan/sms/request/SmsReportRequest.java
Executable file
@@ -0,0 +1,48 @@
|
||||
package com.chuanglan.sms.request;
|
||||
|
||||
public class SmsReportRequest {
|
||||
/**
|
||||
* 用户账号,必填
|
||||
*/
|
||||
private String account;
|
||||
/**
|
||||
* 用户密码,必填
|
||||
*/
|
||||
private String password;
|
||||
/**
|
||||
* 拉取个数(最大100,默认20),选填
|
||||
*/
|
||||
private String count;
|
||||
|
||||
public SmsReportRequest() {
|
||||
|
||||
}
|
||||
public SmsReportRequest(String account, String password,String count) {
|
||||
super();
|
||||
this.account = account;
|
||||
this.password = password;
|
||||
this.count = count;
|
||||
|
||||
}
|
||||
public String getAccount() {
|
||||
return account;
|
||||
}
|
||||
public void setAccount(String account) {
|
||||
this.account = account;
|
||||
}
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
public String getCount() {
|
||||
return count;
|
||||
}
|
||||
public void setCount(String count) {
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
127
comm/Kernel/src/com/chuanglan/sms/request/SmsSendRequest.java
Executable file
127
comm/Kernel/src/com/chuanglan/sms/request/SmsSendRequest.java
Executable file
@@ -0,0 +1,127 @@
|
||||
package com.chuanglan.sms.request;
|
||||
|
||||
public class SmsSendRequest {
|
||||
/**
|
||||
* 用户账号,必填
|
||||
*/
|
||||
private String account;
|
||||
/**
|
||||
* 用户密码,必填
|
||||
*/
|
||||
private String password;
|
||||
/**
|
||||
* 短信内容。长度不能超过536个字符,必填
|
||||
*/
|
||||
private String msg;
|
||||
/**
|
||||
* 机号码。多个手机号码使用英文逗号分隔,必填
|
||||
*/
|
||||
private String phone;
|
||||
|
||||
|
||||
/**
|
||||
* 定时发送短信时间。格式为yyyyMMddHHmm,值小于或等于当前时间则立即发送,默认立即发送,选填
|
||||
*/
|
||||
private String sendtime;
|
||||
/**
|
||||
* 是否需要状态报告(默认false),选填
|
||||
*/
|
||||
private String report;
|
||||
/**
|
||||
* 下发短信号码扩展码,纯数字,建议1-3位,选填
|
||||
*/
|
||||
private String extend;
|
||||
/**
|
||||
* 该条短信在您业务系统内的ID,如订单号或者短信发送记录流水号,选填
|
||||
*/
|
||||
private String uid;
|
||||
|
||||
public SmsSendRequest() {
|
||||
|
||||
}
|
||||
public SmsSendRequest(String account, String password, String msg, String phone) {
|
||||
super();
|
||||
this.account = account;
|
||||
this.password = password;
|
||||
this.msg = msg;
|
||||
this.phone = phone;
|
||||
}
|
||||
public SmsSendRequest(String account, String password, String msg, String phone, String report) {
|
||||
super();
|
||||
this.account = account;
|
||||
this.password = password;
|
||||
this.msg = msg;
|
||||
this.phone = phone;
|
||||
this.report=report;
|
||||
}
|
||||
|
||||
public SmsSendRequest(String account, String password, String msg, String phone, String report,String sendtime) {
|
||||
super();
|
||||
this.account = account;
|
||||
this.password = password;
|
||||
this.msg = msg;
|
||||
this.phone = phone;
|
||||
this.sendtime=sendtime;
|
||||
this.report=report;
|
||||
}
|
||||
public SmsSendRequest(String account, String password, String msg, String phone, String sendtime,String report,String uid) {
|
||||
super();
|
||||
this.account = account;
|
||||
this.password = password;
|
||||
this.msg = msg;
|
||||
this.phone = phone;
|
||||
this.sendtime=sendtime;
|
||||
this.report=report;
|
||||
this.uid=uid;
|
||||
}
|
||||
public String getAccount() {
|
||||
return account;
|
||||
}
|
||||
public void setAccount(String account) {
|
||||
this.account = account;
|
||||
}
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
public void setMsg(String msg) {
|
||||
this.msg = msg;
|
||||
}
|
||||
public String getPhone() {
|
||||
return phone;
|
||||
}
|
||||
public void setPhone(String phone) {
|
||||
this.phone = phone;
|
||||
}
|
||||
public String getSendtime() {
|
||||
return sendtime;
|
||||
}
|
||||
public void setSendtime(String sendtime) {
|
||||
this.sendtime = sendtime;
|
||||
}
|
||||
public String getReport() {
|
||||
return report;
|
||||
}
|
||||
public void setReport(String report) {
|
||||
this.report = report;
|
||||
}
|
||||
public String getExtend() {
|
||||
return extend;
|
||||
}
|
||||
public void setExtend(String extend) {
|
||||
this.extend = extend;
|
||||
}
|
||||
public String getUid() {
|
||||
return uid;
|
||||
}
|
||||
public void setUid(String uid) {
|
||||
this.uid = uid;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
118
comm/Kernel/src/com/chuanglan/sms/request/SmsVariableRequest.java
Executable file
118
comm/Kernel/src/com/chuanglan/sms/request/SmsVariableRequest.java
Executable file
@@ -0,0 +1,118 @@
|
||||
package com.chuanglan.sms.request;
|
||||
/**
|
||||
|
||||
* @Description:变量短信发送实体类
|
||||
*/
|
||||
public class SmsVariableRequest {
|
||||
/**
|
||||
* 用户账号,必填
|
||||
*/
|
||||
private String account;
|
||||
/**
|
||||
* 用户密码,必填
|
||||
*/
|
||||
private String password;
|
||||
/**
|
||||
* 短信内容。长度不能超过536个字符,必填
|
||||
*/
|
||||
private String msg;
|
||||
/**
|
||||
* 手机号码和变量参数,多组参数使用英文分号;区分,必填
|
||||
*/
|
||||
private String params;
|
||||
|
||||
/**
|
||||
* 定时发送短信时间。格式为yyyyMMddHHmm,值小于或等于当前时间则立即发送,默认立即发送,选填
|
||||
*/
|
||||
private String sendtime;
|
||||
/**
|
||||
* 是否需要状态报告(默认false),选填
|
||||
*/
|
||||
private String report;
|
||||
/**
|
||||
* 下发短信号码扩展码,纯数字,建议1-3位,选填
|
||||
*/
|
||||
private String extend;
|
||||
/**
|
||||
* 该条短信在您业务系统内的ID,如订单号或者短信发送记录流水号,选填
|
||||
*/
|
||||
private String uid;
|
||||
|
||||
public SmsVariableRequest() {
|
||||
|
||||
}
|
||||
public SmsVariableRequest(String account, String password, String msg, String params) {
|
||||
super();
|
||||
this.account = account;
|
||||
this.password = password;
|
||||
this.msg = msg;
|
||||
this.params = params;
|
||||
}
|
||||
public SmsVariableRequest(String account, String password, String msg, String params, String report) {
|
||||
super();
|
||||
this.account = account;
|
||||
this.password = password;
|
||||
this.msg = msg;
|
||||
this.params = params;
|
||||
this.report = report;
|
||||
}
|
||||
// public SmsVarableRequest(String account, String password, String msg, String params, String sendtime) {
|
||||
// super();
|
||||
// this.account = account;
|
||||
// this.password = password;
|
||||
// this.msg = msg;
|
||||
// this.params = params;
|
||||
// this.sendtime = sendtime;
|
||||
// }
|
||||
public String getAccount() {
|
||||
return account;
|
||||
}
|
||||
public void setAccount(String account) {
|
||||
this.account = account;
|
||||
}
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
public String getMsg() {
|
||||
return msg;
|
||||
}
|
||||
public void setMsg(String msg) {
|
||||
this.msg = msg;
|
||||
}
|
||||
|
||||
public String getSendtime() {
|
||||
return sendtime;
|
||||
}
|
||||
public void setSendtime(String sendtime) {
|
||||
this.sendtime = sendtime;
|
||||
}
|
||||
public String getReport() {
|
||||
return report;
|
||||
}
|
||||
public void setReport(String report) {
|
||||
this.report = report;
|
||||
}
|
||||
public String getExtend() {
|
||||
return extend;
|
||||
}
|
||||
public void setExtend(String extend) {
|
||||
this.extend = extend;
|
||||
}
|
||||
public String getUid() {
|
||||
return uid;
|
||||
}
|
||||
public void setUid(String uid) {
|
||||
this.uid = uid;
|
||||
}
|
||||
public String getParams() {
|
||||
return params;
|
||||
}
|
||||
public void setParams(String params) {
|
||||
this.params = params;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
58
comm/Kernel/src/com/chuanglan/sms/response/SmsBalanceResponse.java
Executable file
58
comm/Kernel/src/com/chuanglan/sms/response/SmsBalanceResponse.java
Executable file
@@ -0,0 +1,58 @@
|
||||
package com.chuanglan.sms.response;
|
||||
/**
|
||||
|
||||
* @Description:账号余额响应实体类
|
||||
*/
|
||||
public class SmsBalanceResponse {
|
||||
/**
|
||||
* 响应时间
|
||||
*/
|
||||
private String time;
|
||||
/**
|
||||
* 消息id
|
||||
*/
|
||||
private String balance;
|
||||
/**
|
||||
* 状态码说明(成功返回空)
|
||||
*/
|
||||
private String errorMsg;
|
||||
/**
|
||||
* 状态码(详细参考提交响应状态码)
|
||||
*/
|
||||
private String code;
|
||||
public String getTime() {
|
||||
return time;
|
||||
}
|
||||
public void setTime(String time) {
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
public String getBalance() {
|
||||
return balance;
|
||||
}
|
||||
public void setBalance(String balance) {
|
||||
this.balance = balance;
|
||||
}
|
||||
public String getErrorMsg() {
|
||||
return errorMsg;
|
||||
}
|
||||
public void setErrorMsg(String errorMsg) {
|
||||
this.errorMsg = errorMsg;
|
||||
}
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
public void setCode(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SmsBalanceResponse [time=" + time + ", balance=" + balance + ", errorMsg=" + errorMsg + ", code=" + code
|
||||
+ "]";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
103
comm/Kernel/src/com/chuanglan/sms/response/SmsPullResponse.java
Executable file
103
comm/Kernel/src/com/chuanglan/sms/response/SmsPullResponse.java
Executable file
@@ -0,0 +1,103 @@
|
||||
package com.chuanglan.sms.response;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
||||
* @Description:上行明细响应实体类
|
||||
*/
|
||||
public class SmsPullResponse {
|
||||
/**
|
||||
* 请求状态
|
||||
*/
|
||||
private String ret;
|
||||
/**
|
||||
* 请求错误描述
|
||||
*/
|
||||
private String error;
|
||||
/**
|
||||
* 上行明细结果
|
||||
*/
|
||||
private List<Result> result;
|
||||
|
||||
|
||||
public String getRet() {
|
||||
return ret;
|
||||
}
|
||||
|
||||
public void setRet(String ret) {
|
||||
this.ret = ret;
|
||||
}
|
||||
|
||||
public String getError() {
|
||||
return error;
|
||||
}
|
||||
|
||||
public void setError(String error) {
|
||||
this.error = error;
|
||||
}
|
||||
|
||||
public List<Result> getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setResult(List<Result> result) {
|
||||
this.result = result;
|
||||
}
|
||||
static class Result{
|
||||
/**
|
||||
* 上行时间
|
||||
*/
|
||||
private String moTime;
|
||||
/**
|
||||
* 平台通道码
|
||||
*/
|
||||
private String spCode;
|
||||
/**
|
||||
* 上行号码
|
||||
*/
|
||||
private String mobile;
|
||||
/**
|
||||
* 运营商通道码
|
||||
*/
|
||||
private String destCode;
|
||||
/**
|
||||
* 上行内容
|
||||
*/
|
||||
private String messageContent;
|
||||
public String getMoTime() {
|
||||
return moTime;
|
||||
}
|
||||
public void setMoTime(String moTime) {
|
||||
this.moTime = moTime;
|
||||
}
|
||||
public String getSpCode() {
|
||||
return spCode;
|
||||
}
|
||||
public void setSpCode(String spCode) {
|
||||
this.spCode = spCode;
|
||||
}
|
||||
public String getMobile() {
|
||||
return mobile;
|
||||
}
|
||||
public void setMobile(String mobile) {
|
||||
this.mobile = mobile;
|
||||
}
|
||||
public String getDestCode() {
|
||||
return destCode;
|
||||
}
|
||||
public void setDestCode(String destCode) {
|
||||
this.destCode = destCode;
|
||||
}
|
||||
public String getMessageContent() {
|
||||
return messageContent;
|
||||
}
|
||||
public void setMessageContent(String messageContent) {
|
||||
this.messageContent = messageContent;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
115
comm/Kernel/src/com/chuanglan/sms/response/SmsReportResponse.java
Executable file
115
comm/Kernel/src/com/chuanglan/sms/response/SmsReportResponse.java
Executable file
@@ -0,0 +1,115 @@
|
||||
package com.chuanglan.sms.response;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @Description:状态报告响应实体类
|
||||
*/
|
||||
public class SmsReportResponse {
|
||||
/**
|
||||
* 请求状态
|
||||
*/
|
||||
private String ret;
|
||||
/**
|
||||
* 请求错误描述
|
||||
*/
|
||||
private String error;
|
||||
/**
|
||||
* 上行明细结果
|
||||
*/
|
||||
private List<Result> result;
|
||||
|
||||
|
||||
|
||||
public String getRet() {
|
||||
return ret;
|
||||
}
|
||||
|
||||
public void setRet(String ret) {
|
||||
this.ret = ret;
|
||||
}
|
||||
|
||||
public String getError() {
|
||||
return error;
|
||||
}
|
||||
|
||||
public void setError(String error) {
|
||||
this.error = error;
|
||||
}
|
||||
|
||||
public List<Result> getResult() {
|
||||
return result;
|
||||
}
|
||||
|
||||
public void setResult(List<Result> result) {
|
||||
this.result = result;
|
||||
}
|
||||
static class Result{
|
||||
/**
|
||||
* 消息ID
|
||||
*/
|
||||
private String msgId;
|
||||
/**
|
||||
* 状态更新时间
|
||||
*/
|
||||
private String reportTime;
|
||||
/**
|
||||
* 接收短信的手机号码
|
||||
*/
|
||||
private String mobile;
|
||||
/**
|
||||
* 状态(详细参考状态报告状态码)
|
||||
*/
|
||||
private String status;
|
||||
/**
|
||||
* 状态说明
|
||||
*/
|
||||
private String statusDesc;
|
||||
/**
|
||||
* 拉取个数
|
||||
*/
|
||||
private String count;
|
||||
public String getMsgId() {
|
||||
return msgId;
|
||||
}
|
||||
public void setMsgId(String msgId) {
|
||||
this.msgId = msgId;
|
||||
}
|
||||
public String getReportTime() {
|
||||
return reportTime;
|
||||
}
|
||||
public void setReportTime(String reportTime) {
|
||||
this.reportTime = reportTime;
|
||||
}
|
||||
public String getMobile() {
|
||||
return mobile;
|
||||
}
|
||||
public void setMobile(String mobile) {
|
||||
this.mobile = mobile;
|
||||
}
|
||||
public String getStatus() {
|
||||
return status;
|
||||
}
|
||||
public void setStatus(String status) {
|
||||
this.status = status;
|
||||
}
|
||||
public String getStatusDesc() {
|
||||
return statusDesc;
|
||||
}
|
||||
public void setStatusDesc(String statusDesc) {
|
||||
this.statusDesc = statusDesc;
|
||||
}
|
||||
public String getCount() {
|
||||
return count;
|
||||
}
|
||||
public void setCount(String count) {
|
||||
this.count = count;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
56
comm/Kernel/src/com/chuanglan/sms/response/SmsSendResponse.java
Executable file
56
comm/Kernel/src/com/chuanglan/sms/response/SmsSendResponse.java
Executable file
@@ -0,0 +1,56 @@
|
||||
package com.chuanglan.sms.response;
|
||||
/**
|
||||
*
|
||||
* @Description:普通短信发送响应实体类
|
||||
*/
|
||||
public class SmsSendResponse {
|
||||
/**
|
||||
* 响应时间
|
||||
*/
|
||||
private String time;
|
||||
/**
|
||||
* 消息id
|
||||
*/
|
||||
private String msgId;
|
||||
/**
|
||||
* 状态码说明(成功返回空)
|
||||
*/
|
||||
private String errorMsg;
|
||||
/**
|
||||
* 状态码(详细参考提交响应状态码)
|
||||
*/
|
||||
private String code;
|
||||
public String getTime() {
|
||||
return time;
|
||||
}
|
||||
public void setTime(String time) {
|
||||
this.time = time;
|
||||
}
|
||||
public String getMsgId() {
|
||||
return msgId;
|
||||
}
|
||||
public void setMsgId(String msgId) {
|
||||
this.msgId = msgId;
|
||||
}
|
||||
public String getErrorMsg() {
|
||||
return errorMsg;
|
||||
}
|
||||
public void setErrorMsg(String errorMsg) {
|
||||
this.errorMsg = errorMsg;
|
||||
}
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
public void setCode(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SmsSingleResponse [time=" + time + ", msgId=" + msgId + ", errorMsg=" + errorMsg + ", code=" + code
|
||||
+ "]";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
77
comm/Kernel/src/com/chuanglan/sms/response/SmsVariableResponse.java
Executable file
77
comm/Kernel/src/com/chuanglan/sms/response/SmsVariableResponse.java
Executable file
@@ -0,0 +1,77 @@
|
||||
package com.chuanglan.sms.response;
|
||||
/**
|
||||
*
|
||||
* @Description:变量短信发送响应实体类
|
||||
*/
|
||||
public class SmsVariableResponse {
|
||||
/**
|
||||
* 响应时间
|
||||
*/
|
||||
private String time;
|
||||
/**
|
||||
* 消息id
|
||||
*/
|
||||
private String msgId;
|
||||
/**
|
||||
* 状态码说明(成功返回空)
|
||||
*/
|
||||
private String errorMsg;
|
||||
/**
|
||||
* 失败的个数
|
||||
*/
|
||||
private String failNum;
|
||||
/**
|
||||
* 成功的个数
|
||||
*/
|
||||
private String successNum;
|
||||
/**
|
||||
* 状态码(详细参考提交响应状态码)
|
||||
*/
|
||||
private String code;
|
||||
public String getTime() {
|
||||
return time;
|
||||
}
|
||||
public void setTime(String time) {
|
||||
this.time = time;
|
||||
}
|
||||
public String getMsgId() {
|
||||
return msgId;
|
||||
}
|
||||
public void setMsgId(String msgId) {
|
||||
this.msgId = msgId;
|
||||
}
|
||||
public String getErrorMsg() {
|
||||
return errorMsg;
|
||||
}
|
||||
public void setErrorMsg(String errorMsg) {
|
||||
this.errorMsg = errorMsg;
|
||||
}
|
||||
public String getCode() {
|
||||
return code;
|
||||
}
|
||||
public void setCode(String code) {
|
||||
this.code = code;
|
||||
}
|
||||
public String getFailNum() {
|
||||
return failNum;
|
||||
}
|
||||
public void setFailNum(String failNum) {
|
||||
this.failNum = failNum;
|
||||
}
|
||||
public String getSuccessNum() {
|
||||
return successNum;
|
||||
}
|
||||
public void setSuccessNum(String successNum) {
|
||||
this.successNum = successNum;
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SmsVarableResponse [time=" + time + ", msgId=" + msgId + ", errorMsg=" + errorMsg + ", failNum="
|
||||
+ failNum + ", successNum=" + successNum + ", code=" + code + "]";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
69
comm/Kernel/src/com/chuanglan/sms/util/ChuangLanSmsUtil.java
Executable file
69
comm/Kernel/src/com/chuanglan/sms/util/ChuangLanSmsUtil.java
Executable file
@@ -0,0 +1,69 @@
|
||||
package com.chuanglan.sms.util;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.OutputStream;
|
||||
//import java.io.PrintWriter;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
*
|
||||
* @Description:HTTP 请求
|
||||
*/
|
||||
public class ChuangLanSmsUtil {
|
||||
|
||||
/**
|
||||
*
|
||||
* @author tianyh
|
||||
* @Description
|
||||
* @param path
|
||||
* @param postContent
|
||||
* @return String
|
||||
* @throws
|
||||
*/
|
||||
public static String sendSmsByPost(String path, String postContent) {
|
||||
URL url = null;
|
||||
try {
|
||||
url = new URL(path);
|
||||
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
|
||||
httpURLConnection.setRequestMethod("POST");// 提交模式
|
||||
httpURLConnection.setConnectTimeout(10000);//连接超时 单位毫秒
|
||||
httpURLConnection.setReadTimeout(10000);//读取超时 单位毫秒
|
||||
// 发送POST请求必须设置如下两行
|
||||
httpURLConnection.setDoOutput(true);
|
||||
httpURLConnection.setDoInput(true);
|
||||
httpURLConnection.setRequestProperty("Charset", "UTF-8");
|
||||
httpURLConnection.setRequestProperty("Content-Type", "application/json");
|
||||
|
||||
// PrintWriter printWriter = new PrintWriter(httpURLConnection.getOutputStream());
|
||||
// printWriter.write(postContent);
|
||||
// printWriter.flush();
|
||||
|
||||
httpURLConnection.connect();
|
||||
OutputStream os=httpURLConnection.getOutputStream();
|
||||
os.write(postContent.getBytes("UTF-8"));
|
||||
os.flush();
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
int httpRspCode = httpURLConnection.getResponseCode();
|
||||
if (httpRspCode == HttpURLConnection.HTTP_OK) {
|
||||
// 开始获取数据
|
||||
BufferedReader br = new BufferedReader(
|
||||
new InputStreamReader(httpURLConnection.getInputStream(), "utf-8"));
|
||||
String line = null;
|
||||
while ((line = br.readLine()) != null) {
|
||||
sb.append(line);
|
||||
}
|
||||
br.close();
|
||||
return sb.toString();
|
||||
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user