23 changed files with 724 additions and 107 deletions
@ -0,0 +1,12 @@
|
||||
package com.biutag.outer.domain.vo; |
||||
|
||||
import lombok.Getter; |
||||
import lombok.Setter; |
||||
|
||||
@Getter |
||||
@Setter |
||||
public class ReqImsApi { |
||||
private String userName;//用户名
|
||||
private String signStr;//签名字符
|
||||
private String signTime;//提交时间
|
||||
} |
||||
@ -0,0 +1,12 @@
|
||||
package com.biutag.outer.domain.vo.balance; |
||||
|
||||
import lombok.Getter; |
||||
import lombok.Setter; |
||||
|
||||
@Getter |
||||
@Setter |
||||
public class JsonQueryBalance { |
||||
private int state = -999;//0 正常 -1通用异常 -999程序EXCEPTION -998非JSON字符
|
||||
private String message = "服务器忙,响应超时 "; |
||||
private int balance; |
||||
} |
||||
@ -0,0 +1,14 @@
|
||||
package com.biutag.outer.domain.vo.mo; |
||||
|
||||
import lombok.Getter; |
||||
import lombok.Setter; |
||||
|
||||
import java.util.List; |
||||
|
||||
@Getter |
||||
@Setter |
||||
public class JsonMo { |
||||
private int state = -1; |
||||
private String message = "系统超时"; |
||||
private List<SmsMo> object; |
||||
} |
||||
@ -0,0 +1,12 @@
|
||||
package com.biutag.outer.domain.vo.mo; |
||||
|
||||
import lombok.Getter; |
||||
import lombok.Setter; |
||||
|
||||
@Getter |
||||
@Setter |
||||
public class ReqMo { |
||||
private String userName; |
||||
private String signStr; |
||||
private String signTime; |
||||
} |
||||
@ -0,0 +1,14 @@
|
||||
package com.biutag.outer.domain.vo.mo; |
||||
|
||||
import lombok.Getter; |
||||
import lombok.Setter; |
||||
|
||||
@Getter |
||||
@Setter |
||||
public class SmsMo { |
||||
private String moId;//上行ID
|
||||
private String mobileNo;//上行电话号码
|
||||
private String spCode;//子码
|
||||
private String moStr;//上行内容
|
||||
private String moTime;//上行时
|
||||
} |
||||
@ -0,0 +1,12 @@
|
||||
package com.biutag.outer.domain.vo.mt; |
||||
|
||||
import lombok.Getter; |
||||
import lombok.Setter; |
||||
|
||||
@Getter |
||||
@Setter |
||||
public class JsonSmsSend { |
||||
private int state=-1; |
||||
private String message="系统超时"; |
||||
private String smsId; |
||||
} |
||||
@ -0,0 +1,12 @@
|
||||
package com.biutag.outer.domain.vo.mt; |
||||
|
||||
import lombok.Getter; |
||||
import lombok.Setter; |
||||
import lombok.experimental.Accessors; |
||||
|
||||
@Accessors(chain = true) |
||||
@Getter |
||||
@Setter |
||||
public class Mobile { |
||||
private String mobile;//接收单个手机号码
|
||||
} |
||||
@ -0,0 +1,15 @@
|
||||
package com.biutag.outer.domain.vo.mt; |
||||
|
||||
import lombok.Getter; |
||||
import lombok.Setter; |
||||
|
||||
import java.util.List; |
||||
@Getter |
||||
@Setter |
||||
public class SendSms { |
||||
private String userName;//用户名
|
||||
private String signStr;//签名字符
|
||||
private String signTime;//提交时间
|
||||
private String smsStr;//短信内容转BASE64
|
||||
private List<Mobile> mobileList;//发送号码列表 最多2000个
|
||||
} |
||||
@ -0,0 +1,14 @@
|
||||
package com.biutag.outer.domain.vo.rpt; |
||||
|
||||
import lombok.Getter; |
||||
import lombok.Setter; |
||||
|
||||
import java.util.List; |
||||
|
||||
@Getter |
||||
@Setter |
||||
public class JsonRpt { |
||||
private int state=-1; |
||||
private String message="系统超时"; |
||||
private List<SmsRpt> object; |
||||
} |
||||
@ -0,0 +1,12 @@
|
||||
package com.biutag.outer.domain.vo.rpt; |
||||
|
||||
import lombok.Getter; |
||||
import lombok.Setter; |
||||
|
||||
@Getter |
||||
@Setter |
||||
public class ReqRpt { |
||||
private String userName; |
||||
private String signStr; |
||||
private String signTime; |
||||
} |
||||
@ -0,0 +1,14 @@
|
||||
package com.biutag.outer.domain.vo.rpt; |
||||
|
||||
import lombok.Getter; |
||||
import lombok.Setter; |
||||
|
||||
@Getter |
||||
@Setter |
||||
public class SmsRpt { |
||||
private String smsId;//任务ID
|
||||
private String mobileNo;//号码
|
||||
private int rptState;//发送状态
|
||||
private String rptNote;//回执备注
|
||||
private String rptTime;//回执时间
|
||||
} |
||||
@ -1,55 +0,0 @@
|
||||
package com.biutag.outer.util; |
||||
import com.google.gson.*; |
||||
|
||||
import java.lang.reflect.Type; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
public class JsonUtil { |
||||
public static Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").create(); |
||||
|
||||
public static String toJson(Object msg) { |
||||
return gson.toJson(msg); |
||||
} |
||||
|
||||
public static <T> T returnObj(String json,Class<T> clazz){ |
||||
return gson.fromJson(json, clazz); |
||||
} |
||||
|
||||
public static <T> T returnObj(String json, Type type){ |
||||
return gson.fromJson(json, type); |
||||
} |
||||
|
||||
//验证是不是JSON字符串
|
||||
public static boolean isJsonStr(String jsonInString) { |
||||
try { |
||||
if (jsonInString!=null && !jsonInString.isEmpty()){ |
||||
gson.fromJson(jsonInString, Object.class); |
||||
return true; |
||||
}else { |
||||
return false; |
||||
} |
||||
} catch(JsonSyntaxException ex) { |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
public static <T> List<T> toList(String string,Class<T> clz){ |
||||
if(string == null || string.length() < 1){ |
||||
return null; |
||||
}else { |
||||
List<T> list = new ArrayList<>(); |
||||
if(!string.startsWith("[")){ |
||||
string = "[" + string +"]"; |
||||
} |
||||
JsonArray array = new JsonParser().parse(string).getAsJsonArray(); |
||||
for(final JsonElement elem : array){ |
||||
if(elem != null){ |
||||
String mo = elem.toString().replace("\"{","{").replace("}\"","}").replace("\\", ""); |
||||
list.add(gson.fromJson(mo, clz)); |
||||
} |
||||
} |
||||
return list; |
||||
} |
||||
} |
||||
} |
||||
@ -1,30 +0,0 @@
|
||||
package com.biutag.outer.util; |
||||
|
||||
import java.security.MessageDigest; |
||||
|
||||
public class Md5Util { |
||||
public static final String strToMD5(String s) { |
||||
char[] hexDigits = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', |
||||
'f' }; |
||||
try { |
||||
byte[] btInput = s.getBytes("UTF-8"); |
||||
MessageDigest mdInst = MessageDigest.getInstance("MD5"); |
||||
mdInst.update(btInput); |
||||
byte[] md = mdInst.digest(); |
||||
int j = md.length; |
||||
char[] str = new char[j * 2]; |
||||
int k = 0; |
||||
|
||||
for (int i = 0; i < j; ++i) { |
||||
byte byte0 = md[i]; |
||||
str[k++] = hexDigits[byte0 >>> 4 & 15]; |
||||
str[k++] = hexDigits[byte0 & 15]; |
||||
} |
||||
|
||||
return new String(str); |
||||
} catch (Exception var10) { |
||||
var10.printStackTrace(); |
||||
return null; |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,39 @@
|
||||
package com.biutag.outer.util; |
||||
|
||||
import com.biutag.outer.domain.vo.mo.JsonMo; |
||||
import com.biutag.outer.domain.vo.mo.ReqMo; |
||||
import com.biutag.outer.util.sms.JsonUtil; |
||||
import com.biutag.outer.util.sms.Md5Util; |
||||
import com.biutag.outer.util.sms.SmsConf; |
||||
import com.biutag.outer.util.sms.SmsHttp; |
||||
|
||||
public class MoSync { |
||||
//拿取上行
|
||||
public static void main(String args[]) { |
||||
System.out.println("取上行启动成功"); |
||||
try { |
||||
String userName = SmsConf.smsUserName; |
||||
String password = SmsConf.smsPasswd; |
||||
String signTime = SmsConf.getSysTime(); |
||||
String signStr = Md5Util.strToMD5(userName + Md5Util.strToMD5(password) + signTime); |
||||
ReqMo reqMo = new ReqMo(); |
||||
reqMo.setSignStr(signStr); |
||||
reqMo.setSignTime(signTime); |
||||
reqMo.setUserName(userName); |
||||
String reqJsonStr = JsonUtil.toJson(reqMo); |
||||
String resultJsonStr = SmsHttp.postJson(SmsConf.smsMoUrl, reqJsonStr); |
||||
if (JsonUtil.isJsonStr(resultJsonStr)) { |
||||
JsonMo jsonMo = JsonUtil.returnObj(resultJsonStr, JsonMo.class); |
||||
if(jsonMo!=null){ |
||||
//进入数据处理流程
|
||||
//saveMo(jsonRpt);
|
||||
} |
||||
} else { |
||||
System.out.println("取回执:"+resultJsonStr); |
||||
} |
||||
|
||||
} catch (Exception e) { |
||||
e.printStackTrace(); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,39 @@
|
||||
package com.biutag.outer.util; |
||||
|
||||
import com.biutag.outer.domain.vo.rpt.JsonRpt; |
||||
import com.biutag.outer.domain.vo.rpt.ReqRpt; |
||||
import com.biutag.outer.util.sms.JsonUtil; |
||||
import com.biutag.outer.util.sms.Md5Util; |
||||
import com.biutag.outer.util.sms.SmsConf; |
||||
import com.biutag.outer.util.sms.SmsHttp; |
||||
|
||||
public class RptSync { |
||||
//拿取回执
|
||||
public static void main(String args[]) { |
||||
System.out.println("取回执启动成功"); |
||||
try { |
||||
String userName = SmsConf.smsUserName; |
||||
String password = SmsConf.smsPasswd; |
||||
String signTime = SmsConf.getSysTime(); |
||||
String signStr = Md5Util.strToMD5(userName + Md5Util.strToMD5(password) + signTime); |
||||
ReqRpt reqRpt = new ReqRpt(); |
||||
reqRpt.setSignStr(signStr); |
||||
reqRpt.setSignTime(signTime); |
||||
reqRpt.setUserName(userName); |
||||
String reqJsonStr = JsonUtil.toJson(reqRpt); |
||||
String resultJsonStr = SmsHttp.postJson(SmsConf.smsRptUrl, reqJsonStr); |
||||
if (JsonUtil.isJsonStr(resultJsonStr)) { |
||||
JsonRpt jsonRpt = JsonUtil.returnObj(resultJsonStr, JsonRpt.class); |
||||
if(jsonRpt!=null){ |
||||
//进入数据处理流程
|
||||
//saveRpt(jsonRpt);
|
||||
} |
||||
} else { |
||||
System.out.println("取回执:"+resultJsonStr); |
||||
} |
||||
|
||||
} catch (Exception e) { |
||||
e.printStackTrace(); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,49 @@
|
||||
package com.biutag.outer.util.sms; |
||||
|
||||
import java.io.UnsupportedEncodingException; |
||||
import java.nio.charset.StandardCharsets; |
||||
import java.util.Arrays; |
||||
import java.util.Base64; |
||||
import java.util.regex.Matcher; |
||||
import java.util.regex.Pattern; |
||||
|
||||
public class Base64Util { |
||||
public static String encodeData(String str) { |
||||
//L.p("str-->"+str);
|
||||
byte[] b = null; |
||||
String s = null; |
||||
if (str != null && !str.trim().isEmpty()) { |
||||
b = str.getBytes(StandardCharsets.UTF_8); |
||||
if (b != null) { |
||||
s = Base64.getMimeEncoder().encodeToString(b); |
||||
} |
||||
} |
||||
return replaceBlank(s); |
||||
} |
||||
|
||||
// 解密
|
||||
public static String decodeData(String s) { |
||||
byte[] b = null; |
||||
String result = null; |
||||
if (s != null) { |
||||
try { |
||||
b = Base64.getMimeDecoder().decode(s); |
||||
result = new String(b, StandardCharsets.UTF_8); |
||||
} catch (Exception e) { |
||||
e.printStackTrace(); |
||||
} |
||||
} |
||||
return result; |
||||
} |
||||
|
||||
//去掉换行符
|
||||
public static String replaceBlank(String str) { |
||||
String dest = ""; |
||||
if (str != null) { |
||||
Pattern p = Pattern.compile("\\s*|\t|\r|\n"); |
||||
Matcher m = p.matcher(str); |
||||
dest = m.replaceAll(""); |
||||
} |
||||
return dest; |
||||
} |
||||
} |
||||
@ -0,0 +1,56 @@
|
||||
package com.biutag.outer.util.sms; |
||||
|
||||
import com.google.gson.*; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
import java.lang.reflect.Type; |
||||
|
||||
public class JsonUtil { |
||||
public static Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").create(); |
||||
|
||||
public static String toJson(Object msg) { |
||||
return gson.toJson(msg); |
||||
} |
||||
|
||||
public static <T> T returnObj(String json, Class<T> clazz) { |
||||
return gson.fromJson(json, clazz); |
||||
} |
||||
|
||||
public static <T> T returnObj(String json, Type type) { |
||||
return gson.fromJson(json, type); |
||||
} |
||||
|
||||
//验证是不是JSON字符串
|
||||
public static boolean isJsonStr(String jsonInString) { |
||||
try { |
||||
if (jsonInString != null && !jsonInString.isEmpty()) { |
||||
gson.fromJson(jsonInString, Object.class); |
||||
return true; |
||||
} else { |
||||
return false; |
||||
} |
||||
} catch (JsonSyntaxException ex) { |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
public static <T> List<T> toList(String string, Class<T> clz) { |
||||
if (string == null || string.length() < 1) { |
||||
return null; |
||||
} else { |
||||
List<T> list = new ArrayList<>(); |
||||
if (!string.startsWith("[")) { |
||||
string = "[" + string + "]"; |
||||
} |
||||
JsonArray array = new JsonParser().parse(string).getAsJsonArray(); |
||||
for (final JsonElement elem : array) { |
||||
if (elem != null) { |
||||
String mo = elem.toString().replace("\"{", "{").replace("}\"", "}").replace("\\", ""); |
||||
list.add(gson.fromJson(mo, clz)); |
||||
} |
||||
} |
||||
return list; |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,30 @@
|
||||
package com.biutag.outer.util.sms; |
||||
|
||||
import java.security.MessageDigest; |
||||
|
||||
public class Md5Util { |
||||
public static final String strToMD5(String s) { |
||||
char[] hexDigits = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', |
||||
'f' }; |
||||
try { |
||||
byte[] btInput = s.getBytes("UTF-8"); |
||||
MessageDigest mdInst = MessageDigest.getInstance("MD5"); |
||||
mdInst.update(btInput); |
||||
byte[] md = mdInst.digest(); |
||||
int j = md.length; |
||||
char[] str = new char[j * 2]; |
||||
int k = 0; |
||||
|
||||
for (int i = 0; i < j; ++i) { |
||||
byte byte0 = md[i]; |
||||
str[k++] = hexDigits[byte0 >>> 4 & 15]; |
||||
str[k++] = hexDigits[byte0 & 15]; |
||||
} |
||||
|
||||
return new String(str); |
||||
} catch (Exception var10) { |
||||
var10.printStackTrace(); |
||||
return null; |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,188 @@
|
||||
package com.biutag.outer.util.sms; |
||||
|
||||
import com.biutag.outer.domain.vo.balance.JsonQueryBalance; |
||||
import com.biutag.outer.domain.vo.mo.JsonMo; |
||||
import com.biutag.outer.domain.vo.mt.JsonSmsSend; |
||||
import com.biutag.outer.domain.vo.mt.Mobile; |
||||
import com.biutag.outer.domain.vo.mt.SendSms; |
||||
import com.biutag.outer.domain.vo.rpt.JsonRpt; |
||||
import com.biutag.outer.util.ReqImsApi; |
||||
import lombok.extern.slf4j.Slf4j; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
|
||||
@Slf4j |
||||
public class PostSms { |
||||
//查询发送
|
||||
public static int queryBalanceNum() { |
||||
String userName = SmsConf.smsUserName; |
||||
String password = SmsConf.smsPasswd; |
||||
String signTime = SmsConf.getSysTime(); |
||||
int balanceNum = 0; |
||||
try { |
||||
String signStr = Md5Util.strToMD5(userName + Md5Util.strToMD5(password) + signTime); |
||||
ReqImsApi reqImsApi = new ReqImsApi(); |
||||
reqImsApi.setUserName(userName); |
||||
reqImsApi.setSignStr(signStr); |
||||
reqImsApi.setSignTime(signTime); |
||||
String reqJsonStr = JsonUtil.toJson(reqImsApi); |
||||
String resultJsonStr = SmsHttp.postJson(SmsConf.queyrbalanceUrl, reqJsonStr); |
||||
if (JsonUtil.isJsonStr(resultJsonStr)) { |
||||
JsonQueryBalance jonQueryBalance = JsonUtil.returnObj(resultJsonStr, JsonQueryBalance.class); |
||||
if (jonQueryBalance != null) { |
||||
balanceNum = jonQueryBalance.getBalance(); |
||||
} |
||||
} |
||||
} catch (Exception e) { |
||||
e.printStackTrace(); |
||||
} |
||||
return balanceNum; |
||||
} |
||||
|
||||
//提交短信
|
||||
public static JsonSmsSend sendSms(List<Mobile> mobileList, String smsStr) { |
||||
String userName = SmsConf.smsUserName; |
||||
String password = SmsConf.smsPasswd; |
||||
String signTime = SmsConf.getSysTime(); |
||||
JsonSmsSend jsonSmsSend = new JsonSmsSend(); |
||||
try { |
||||
String signStr = Md5Util.strToMD5(userName + Md5Util.strToMD5(password) + signTime); |
||||
if (smsStr != null && !smsStr.isEmpty()) { |
||||
if (mobileList != null && !mobileList.isEmpty()) { |
||||
if (PostSms.queryBalanceNum() >= mobileList.size()) { |
||||
SendSms sendSms = new SendSms(); |
||||
sendSms.setUserName(userName); |
||||
sendSms.setSignStr(signStr); |
||||
sendSms.setSignTime(signTime); |
||||
sendSms.setSignStr(signStr); |
||||
sendSms.setSmsStr(Base64Util.encodeData(smsStr)); |
||||
sendSms.setMobileList(mobileList); |
||||
String reqJsonStr = JsonUtil.toJson(sendSms); |
||||
String resultJsonStr = SmsHttp.postJson(SmsConf.smsSendUrl, reqJsonStr); |
||||
log.info("smsStr: " + smsStr); |
||||
log.info("smsStr: " + sendSms.getSmsStr()); |
||||
log.info("decodeStr: " + Base64Util.decodeData(sendSms.getSmsStr())); |
||||
if (JsonUtil.isJsonStr(resultJsonStr)) { |
||||
jsonSmsSend = JsonUtil.returnObj(resultJsonStr, JsonSmsSend.class); |
||||
} else { |
||||
jsonSmsSend.setState(-1); |
||||
jsonSmsSend.setMessage(resultJsonStr); |
||||
} |
||||
} else { |
||||
jsonSmsSend.setState(-1); |
||||
jsonSmsSend.setMessage("账户余额不够"); |
||||
} |
||||
} else { |
||||
jsonSmsSend.setState(-1); |
||||
jsonSmsSend.setMessage("发送号码不能空"); |
||||
} |
||||
} else { |
||||
jsonSmsSend.setState(-1); |
||||
jsonSmsSend.setMessage("发送内容不能空"); |
||||
} |
||||
} catch (Exception e) { |
||||
jsonSmsSend.setState(-1); |
||||
jsonSmsSend.setMessage(e.toString()); |
||||
e.printStackTrace(); |
||||
} |
||||
return jsonSmsSend; |
||||
} |
||||
|
||||
//接收短信状态回执
|
||||
public static JsonRpt getSmsRpt() { |
||||
String userName = SmsConf.smsUserName; |
||||
String password = SmsConf.smsPasswd; |
||||
String signTime = SmsConf.getSysTime(); |
||||
JsonRpt jsonRpt = new JsonRpt(); |
||||
try { |
||||
String signStr = Md5Util.strToMD5(userName + Md5Util.strToMD5(password) + signTime); |
||||
ReqImsApi reqImsApi = new ReqImsApi(); |
||||
reqImsApi.setUserName(userName); |
||||
reqImsApi.setSignStr(signStr); |
||||
reqImsApi.setSignTime(signTime); |
||||
String reqJsonStr = JsonUtil.toJson(reqImsApi); |
||||
String resultJsonStr = SmsHttp.postJson(SmsConf.smsRptUrl, reqJsonStr); |
||||
if (JsonUtil.isJsonStr(resultJsonStr)) { |
||||
jsonRpt = JsonUtil.returnObj(resultJsonStr, JsonRpt.class); |
||||
} else { |
||||
jsonRpt.setState(-1); |
||||
jsonRpt.setMessage(resultJsonStr); |
||||
} |
||||
} catch (Exception e) { |
||||
jsonRpt.setMessage(e.toString()); |
||||
e.printStackTrace(); |
||||
} |
||||
return jsonRpt; |
||||
} |
||||
|
||||
//接收短信上行
|
||||
public static JsonMo getSmsMo() { |
||||
String userName = SmsConf.smsUserName; |
||||
String password = SmsConf.smsPasswd; |
||||
String signTime = SmsConf.getSysTime(); |
||||
String balanceUrl = SmsConf.smsMoUrl; |
||||
JsonMo jsonMo = new JsonMo(); |
||||
try { |
||||
String signStr = Md5Util.strToMD5(userName + Md5Util.strToMD5(password) + signTime); |
||||
ReqImsApi reqImsApi = new ReqImsApi(); |
||||
reqImsApi.setUserName(userName); |
||||
reqImsApi.setSignStr(signStr); |
||||
reqImsApi.setSignTime(signTime); |
||||
String reqJsonStr = JsonUtil.toJson(reqImsApi); |
||||
String resultJsonStr = SmsHttp.postJson(balanceUrl, reqJsonStr); |
||||
if (JsonUtil.isJsonStr(resultJsonStr)) { |
||||
jsonMo = JsonUtil.returnObj(resultJsonStr, JsonMo.class); |
||||
} else { |
||||
jsonMo.setState(-1); |
||||
jsonMo.setMessage(resultJsonStr); |
||||
} |
||||
} catch (Exception e) { |
||||
jsonMo.setMessage(e.toString()); |
||||
e.printStackTrace(); |
||||
} |
||||
|
||||
return jsonMo; |
||||
} |
||||
|
||||
public static void main(String arg[]) throws Exception { |
||||
//测试取余额
|
||||
//L.p(""+PostSms.queryBalanceNum());
|
||||
//测试发送
|
||||
|
||||
List<Mobile> mobileList = new ArrayList<Mobile>(); |
||||
Mobile mobile = new Mobile(); |
||||
mobile.setMobile("13974908181"); |
||||
mobileList.add(mobile); |
||||
String smsStr = "验证码1234"; |
||||
JsonSmsSend jsonSmsSend = sendSms(mobileList, smsStr); |
||||
// if(jsonSmsSend!=null){
|
||||
// L.p(jsonSmsSend.getSmsId());
|
||||
// }
|
||||
//测试取回执
|
||||
|
||||
// JsonRpt jsonRpt=getSmsRpt();
|
||||
// L.p(""+jsonRpt.getMessage());
|
||||
// List<SmsRpt> rptList=jsonRpt.getObject();
|
||||
// if(rptList!=null && !rptList.isEmpty()){
|
||||
// L.p(rptList.size()+"");
|
||||
// }else{
|
||||
// L.p("123");
|
||||
// }
|
||||
|
||||
//测试取上行
|
||||
|
||||
// JsonMo jsonMo=getSmsMo();
|
||||
// List<SmsMo> moList=jsonMo.getObject();
|
||||
// System.out.println(""+jsonMo.getMessage());
|
||||
// if(moList!=null && !moList.isEmpty()){
|
||||
// System.out.println(""+moList.size());
|
||||
// }else{
|
||||
// System.out.println("123");
|
||||
// }
|
||||
|
||||
|
||||
} |
||||
|
||||
|
||||
} |
||||
@ -0,0 +1,32 @@
|
||||
package com.biutag.outer.util.sms; |
||||
|
||||
import java.util.Calendar; |
||||
|
||||
public class SmsConf { |
||||
//基础地址 请参文档填写
|
||||
public static String smsSendUrl = "http://172.31.253.178:5050/ims/sms/sendSms";//发送地址
|
||||
public static String queyrbalanceUrl = "http://172.31.253.178:5050/ims/sms/queryBalance";//查询发送能力地址
|
||||
public static String smsMoUrl = "http://172.31.253.178:9090/ims/sms/queryMo";//取上行地址
|
||||
public static String smsRptUrl = "http://172.31.253.178:9090/ims/sms/queryRpt";//取回执地址
|
||||
public static String smsUserName="cxxjjjbxt";//账户名
|
||||
public static String smsPasswd="rfrlnK@98";//账号密码
|
||||
|
||||
|
||||
|
||||
public static String getSysTime() { |
||||
Calendar now = Calendar.getInstance(); |
||||
String year = Integer.toString(now.get(Calendar.YEAR)); |
||||
String mon = Integer.toString(now.get(Calendar.MONTH) + 1); |
||||
String day = Integer.toString(now.get(Calendar.DATE)); |
||||
String hour = Integer.toString(now.get(Calendar.HOUR_OF_DAY)); |
||||
String min = Integer.toString(now.get(Calendar.MINUTE)); |
||||
String sec = Integer.toString(now.get(Calendar.SECOND)); |
||||
|
||||
mon = (mon.length() == 1) ? "0" + mon : mon; |
||||
day = (day.length() == 1) ? "0" + day : day; |
||||
hour = (hour.length() == 1) ? "0" + hour : hour; |
||||
min = (min.length() == 1) ? "0" + min : min; |
||||
sec = (sec.length() == 1) ? "0" + sec : sec; |
||||
return (year + mon + day + hour + min + sec); |
||||
} |
||||
} |
||||
@ -0,0 +1,87 @@
|
||||
package com.biutag.outer.util.sms; |
||||
|
||||
import java.io.BufferedReader; |
||||
import java.io.InputStreamReader; |
||||
import java.io.PrintWriter; |
||||
import java.net.HttpURLConnection; |
||||
import java.net.URL; |
||||
|
||||
public class SmsHttp { |
||||
//发送生信
|
||||
public static String postJson(String submitUrl, String json) { |
||||
URL url = null; |
||||
String postResponseStr = null; |
||||
HttpURLConnection httpURLConnection = null; |
||||
BufferedReader getResponseBytes = null; |
||||
PrintWriter printWriter = null; |
||||
StringBuilder sb = null; |
||||
try { |
||||
url = new URL(submitUrl); |
||||
httpURLConnection = (HttpURLConnection) url.openConnection(); |
||||
httpURLConnection.setRequestMethod("POST");// 提交模式
|
||||
httpURLConnection.setConnectTimeout(10000);//连接超时 单位毫秒
|
||||
httpURLConnection.setReadTimeout(60000);//读取超时 单位毫秒
|
||||
// 发送POST请求必须设置如下两行
|
||||
httpURLConnection.setDoOutput(true); |
||||
httpURLConnection.setDoInput(true); |
||||
//httpURLConnection.setRequestProperty("Accept", "application/json");
|
||||
|
||||
|
||||
httpURLConnection.setRequestProperty("Content-Type", "text/plain"); |
||||
httpURLConnection.setRequestProperty("connection", "Keep-Alive"); |
||||
httpURLConnection.setRequestProperty("Charsert", "UTF-8"); |
||||
//httpURLConnection.setRequestProperty("Content-type", "application/json; charset=utf-8");
|
||||
// 获取URLConnection对象对应的输出流
|
||||
printWriter = new PrintWriter(httpURLConnection.getOutputStream()); |
||||
printWriter.write(json); |
||||
printWriter.flush(); |
||||
//printWriter.close();
|
||||
int httpRspCode = httpURLConnection.getResponseCode(); |
||||
if (httpRspCode == HttpURLConnection.HTTP_OK) { |
||||
sb = new StringBuilder(); |
||||
// 开始获取数据
|
||||
getResponseBytes = new BufferedReader( |
||||
new InputStreamReader(httpURLConnection.getInputStream(), "utf-8")); |
||||
String line = null; |
||||
while ((line = getResponseBytes.readLine()) != null) { |
||||
sb.append(line); |
||||
} |
||||
getResponseBytes.close(); |
||||
postResponseStr = sb.toString(); |
||||
} else { |
||||
postResponseStr = "ERR:" + httpRspCode; |
||||
} |
||||
} catch (Exception e) { |
||||
postResponseStr = "ERR:" + e.getMessage(); |
||||
e.printStackTrace(); |
||||
} finally { |
||||
if (httpURLConnection != null) { |
||||
try { |
||||
httpURLConnection.disconnect(); |
||||
} catch (Exception eee) { |
||||
} |
||||
} |
||||
if (getResponseBytes != null) { |
||||
try { |
||||
getResponseBytes.close(); |
||||
} catch (Exception ee) { |
||||
} |
||||
} |
||||
if (printWriter != null) { |
||||
try { |
||||
printWriter.close(); |
||||
} catch (Exception eeee) { |
||||
} |
||||
} |
||||
if (sb != null) { |
||||
try { |
||||
sb = null; |
||||
} catch (Exception eeeee) { |
||||
} |
||||
} |
||||
} |
||||
System.out.print("sms sends post-->[" + postResponseStr + "] json:" + json); |
||||
return postResponseStr; |
||||
} |
||||
|
||||
} |
||||
Loading…
Reference in new issue