Browse Source

提交开源任务材料

10.0
LAPTOP-SB56SG4Q\86185 3 years ago
parent
commit
9e53f806b3
  1. BIN
      JSD-8493配置使用文档.docx
  2. 5
      README.md
  3. BIN
      lib/gson-2.8.6.jar
  4. 28
      plugin.xml
  5. 29
      src/main/java/com/fr/plugin/ymrt/sms/OutputPluginLifecycleMonitor.java
  6. 33
      src/main/java/com/fr/plugin/ymrt/sms/ResultModel.java
  7. 343
      src/main/java/com/fr/plugin/ymrt/sms/SimpleExample.java
  8. 43
      src/main/java/com/fr/plugin/ymrt/sms/SmsDBAccess.java
  9. 26
      src/main/java/com/fr/plugin/ymrt/sms/SmsFormulaProvider.java
  10. 22
      src/main/java/com/fr/plugin/ymrt/sms/SmsLocaleFinder.java
  11. 27
      src/main/java/com/fr/plugin/ymrt/sms/SmsOutputFormulaExtractor.java
  12. 63
      src/main/java/com/fr/plugin/ymrt/sms/bean/OutputSmsAction.java
  13. 21
      src/main/java/com/fr/plugin/ymrt/sms/dao/SmsDao.java
  14. 49
      src/main/java/com/fr/plugin/ymrt/sms/entity/SmsEntity.java
  15. 43
      src/main/java/com/fr/plugin/ymrt/sms/eucp/inter/framework/dto/CustomSmsIdAndMobile.java
  16. 54
      src/main/java/com/fr/plugin/ymrt/sms/eucp/inter/framework/dto/CustomSmsIdAndMobileAndContent.java
  17. 76
      src/main/java/com/fr/plugin/ymrt/sms/eucp/inter/framework/dto/PersonalityParams.java
  18. 59
      src/main/java/com/fr/plugin/ymrt/sms/eucp/inter/framework/dto/TemplateSmsIdAndMobile.java
  19. 12
      src/main/java/com/fr/plugin/ymrt/sms/eucp/inter/http/v1/dto/request/BalanceRequest.java
  20. 42
      src/main/java/com/fr/plugin/ymrt/sms/eucp/inter/http/v1/dto/request/BaseRequest.java
  21. 32
      src/main/java/com/fr/plugin/ymrt/sms/eucp/inter/http/v1/dto/request/MoRequest.java
  22. 32
      src/main/java/com/fr/plugin/ymrt/sms/eucp/inter/http/v1/dto/request/ReportRequest.java
  23. 32
      src/main/java/com/fr/plugin/ymrt/sms/eucp/inter/http/v1/dto/request/ShortLinkRequest.java
  24. 39
      src/main/java/com/fr/plugin/ymrt/sms/eucp/inter/http/v1/dto/request/SmsBaseRequest.java
  25. 40
      src/main/java/com/fr/plugin/ymrt/sms/eucp/inter/http/v1/dto/request/SmsBatchOnlyRequest.java
  26. 41
      src/main/java/com/fr/plugin/ymrt/sms/eucp/inter/http/v1/dto/request/SmsBatchRequest.java
  27. 26
      src/main/java/com/fr/plugin/ymrt/sms/eucp/inter/http/v1/dto/request/SmsPersonalityAllRequest.java
  28. 26
      src/main/java/com/fr/plugin/ymrt/sms/eucp/inter/http/v1/dto/request/SmsPersonalityRequest.java
  29. 60
      src/main/java/com/fr/plugin/ymrt/sms/eucp/inter/http/v1/dto/request/SmsShortLinkBatchRequest.java
  30. 53
      src/main/java/com/fr/plugin/ymrt/sms/eucp/inter/http/v1/dto/request/SmsSingleRequest.java
  31. 34
      src/main/java/com/fr/plugin/ymrt/sms/eucp/inter/http/v1/dto/request/TemplateSmsSendRequest.java
  32. 34
      src/main/java/com/fr/plugin/ymrt/sms/eucp/inter/http/v1/dto/response/BalanceResponse.java
  33. 65
      src/main/java/com/fr/plugin/ymrt/sms/eucp/inter/http/v1/dto/response/MoResponse.java
  34. 94
      src/main/java/com/fr/plugin/ymrt/sms/eucp/inter/http/v1/dto/response/ReportResponse.java
  35. 44
      src/main/java/com/fr/plugin/ymrt/sms/eucp/inter/http/v1/dto/response/ResponseData.java
  36. 89
      src/main/java/com/fr/plugin/ymrt/sms/eucp/inter/http/v1/dto/response/ShortLinkReportResponse.java
  37. 57
      src/main/java/com/fr/plugin/ymrt/sms/eucp/inter/http/v1/dto/response/SmsResponse.java
  38. 57
      src/main/java/com/fr/plugin/ymrt/sms/eucp/inter/http/v1/dto/response/SmsTemplateResponse.java
  39. 173
      src/main/java/com/fr/plugin/ymrt/sms/handle/SmsOutputActionHandler.java
  40. 55
      src/main/java/com/fr/plugin/ymrt/sms/js/FileDef.java
  41. 28
      src/main/java/com/fr/plugin/ymrt/sms/js/JSCSSBridge.java
  42. 140
      src/main/java/com/fr/plugin/ymrt/sms/util/AES.java
  43. 133
      src/main/java/com/fr/plugin/ymrt/sms/util/DateUtil.java
  44. 105
      src/main/java/com/fr/plugin/ymrt/sms/util/GZIPUtils.java
  45. 129
      src/main/java/com/fr/plugin/ymrt/sms/util/JsonHelper.java
  46. 51
      src/main/java/com/fr/plugin/ymrt/sms/util/Md5.java
  47. 451
      src/main/java/com/fr/plugin/ymrt/sms/util/http/HttpClient.java
  48. 94
      src/main/java/com/fr/plugin/ymrt/sms/util/http/HttpRequest.java
  49. 18
      src/main/java/com/fr/plugin/ymrt/sms/util/http/HttpRequestBytes.java
  50. 22
      src/main/java/com/fr/plugin/ymrt/sms/util/http/HttpRequestKV.java
  51. 67
      src/main/java/com/fr/plugin/ymrt/sms/util/http/HttpRequestParams.java
  52. 40
      src/main/java/com/fr/plugin/ymrt/sms/util/http/HttpRequestPraser.java
  53. 44
      src/main/java/com/fr/plugin/ymrt/sms/util/http/HttpRequestPraserBytes.java
  54. 71
      src/main/java/com/fr/plugin/ymrt/sms/util/http/HttpRequestPraserKV.java
  55. 46
      src/main/java/com/fr/plugin/ymrt/sms/util/http/HttpRequestPraserString.java
  56. 19
      src/main/java/com/fr/plugin/ymrt/sms/util/http/HttpRequestString.java
  57. 113
      src/main/java/com/fr/plugin/ymrt/sms/util/http/HttpResponse.java
  58. 32
      src/main/java/com/fr/plugin/ymrt/sms/util/http/HttpResponseBytes.java
  59. 19
      src/main/java/com/fr/plugin/ymrt/sms/util/http/HttpResponseBytesPraser.java
  60. 32
      src/main/java/com/fr/plugin/ymrt/sms/util/http/HttpResponsePraser.java
  61. 33
      src/main/java/com/fr/plugin/ymrt/sms/util/http/HttpResponseString.java
  62. 30
      src/main/java/com/fr/plugin/ymrt/sms/util/http/HttpResponseStringPraser.java
  63. 69
      src/main/java/com/fr/plugin/ymrt/sms/util/http/HttpResultCode.java
  64. 47
      src/main/java/com/fr/plugin/ymrt/sms/util/http/HttpsParams.java
  65. 21
      src/main/java/com/fr/plugin/ymrt/sms/util/http/HttpsRequestBytes.java
  66. 22
      src/main/java/com/fr/plugin/ymrt/sms/util/http/HttpsRequestKV.java
  67. 21
      src/main/java/com/fr/plugin/ymrt/sms/util/http/HttpsRequestString.java
  68. 2
      src/main/resources/com/fr/plugin/ymrt/sms/locale/sms.properties
  69. 1
      src/main/resources/com/fr/plugin/ymrt/sms/locale/sms_zh_CN.properties
  70. 187
      src/main/resources/com/fr/plugin/ymrt/sms/theme.js
  71. 5
      ymrt.properties

BIN
JSD-8493配置使用文档.docx

Binary file not shown.

5
README.md

@ -1,3 +1,6 @@
# open-JSD-8493
JSD-8493 开源任务材料
JSD-8493 短信推送\
免责说明:该源码为第三方爱好者提供,不保证源码和方案的可靠性,也不提供任何形式的源码教学指导和协助!\
仅作为开发者学习参考使用!禁止用于任何商业用途!\
为保护开发者隐私,开发者信息已隐去!若原开发者希望公开自己的信息,可联系hugh处理。

BIN
lib/gson-2.8.6.jar

Binary file not shown.

28
plugin.xml

@ -0,0 +1,28 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?><plugin>
<id>com.fr.plugin.ymrt.sms</id>
<name><![CDATA[短信集成]]></name>
<active>yes</active>
<version>1.1</version>
<env-version>10.0</env-version>
<jartime>2018-07-31</jartime>
<vendor>fr.open</vendor>
<description><![CDATA[短信]]></description>
<change-notes><![CDATA[
[2021-09-07]【1.0】初始化接口。<br/>
[2021-09-14]【1.0】重新打包。<br/>
]]></change-notes>
<lifecycle-monitor class="com.fr.plugin.ymrt.sms.OutputPluginLifecycleMonitor"/>
<extra-core>
<!--插件注入国际化-->
<LocaleFinder class="com.fr.plugin.ymrt.sms.SmsLocaleFinder"/>
</extra-core>
<extra-decision>
<!--插件注入处理公式的类-->
<OutputFormulaProvider class="com.fr.plugin.ymrt.sms.SmsFormulaProvider"/>
<!--插件注入提取公式的类-->
<OutputFormulaExtractorProvider class="com.fr.plugin.ymrt.sms.SmsOutputFormulaExtractor"/>
<WebResourceProvider class="com.fr.plugin.ymrt.sms.js.JSCSSBridge"/>
<DecisionDBAccessProvider class="com.fr.plugin.ymrt.sms.SmsDBAccess"/>
</extra-decision>
<function-recorder class="com.fr.plugin.ymrt.sms.js.JSCSSBridge"/>
</plugin>

29
src/main/java/com/fr/plugin/ymrt/sms/OutputPluginLifecycleMonitor.java

@ -0,0 +1,29 @@
package com.fr.plugin.ymrt.sms;
import com.fr.plugin.context.PluginContext;
import com.fr.plugin.observer.inner.AbstractPluginLifecycleMonitor;
import com.fr.plugin.ymrt.sms.bean.OutputSmsAction;
import com.fr.plugin.ymrt.sms.entity.SmsEntity;
import com.fr.plugin.ymrt.sms.handle.SmsOutputActionHandler;
import com.fr.schedule.feature.ScheduleOutputActionEntityRegister;
import com.fr.schedule.feature.output.OutputActionHandler;
/**
* @Author fr.open
* @Date 2020/9/15
* @Description
**/
public class OutputPluginLifecycleMonitor extends AbstractPluginLifecycleMonitor {
@Override
public void afterRun(PluginContext pluginContext) {
OutputActionHandler.registerHandler(new SmsOutputActionHandler(), OutputSmsAction.class.getName());
ScheduleOutputActionEntityRegister.getInstance().addClass(SmsEntity.class);
}
@Override
public void beforeStop(PluginContext pluginContext) {
OutputActionHandler.removeOutputHandler(OutputSmsAction.class.getName());
ScheduleOutputActionEntityRegister.getInstance().removeClass(SmsEntity.class);
}
}

33
src/main/java/com/fr/plugin/ymrt/sms/ResultModel.java

@ -0,0 +1,33 @@
package com.fr.plugin.ymrt.sms;
/**
* @Author fr.open
* @Date 2020/9/15
* @Description
**/
public class ResultModel {
private String code;
private String result;
public ResultModel(String code, String result) {
this.code = code;
this.result = result;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getResult() {
return result;
}
public void setResult(String result) {
this.result = result;
}
}

343
src/main/java/com/fr/plugin/ymrt/sms/SimpleExample.java

@ -0,0 +1,343 @@
package com.fr.plugin.ymrt.sms;
import com.fr.plugin.ymrt.sms.eucp.inter.http.v1.dto.request.SmsSingleRequest;
import com.fr.plugin.ymrt.sms.eucp.inter.http.v1.dto.response.*;
import com.fr.plugin.ymrt.sms.util.AES;
import com.fr.plugin.ymrt.sms.util.GZIPUtils;
import com.fr.plugin.ymrt.sms.util.JsonHelper;
import com.fr.plugin.ymrt.sms.util.Md5;
import com.fr.plugin.ymrt.sms.util.http.*;
import com.google.gson.reflect.TypeToken;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;
/**
* @Author fr.open
* @Date 2020/9/15
* @Description
**/
public class SimpleExample {
public static void main(String[] args) {
// appId
String appId = "xxxx";// 请联系销售,或者在页面中 获取
// 密钥
String secretKey = "xxxx";// 请联系销售,或者在页面中 获取
// 接口地址
String host = "http://xxxx";// 请联系销售获取
// 时间戳
String timestamp = "xxxx";
// 签名
String sign = Md5.md5((appId + secretKey + timestamp).getBytes());
// 加密算法
String algorithm = "AES/ECB/PKCS5Padding";
// 编码
String encode = "UTF-8";
// 是否压缩
boolean isGizp = true;
// // 获取余额
// getBalance(appId, secretKey, host, algorithm, isGizp, encode);
// // 获取状态报告
// getReport(appId, secretKey, host, algorithm, isGizp, encode);
// // 获取上行
// getMo(appId, secretKey, host, algorithm, isGizp, encode);
// // 发送单条短信
setSingleSms(appId, secretKey, host, algorithm,
"【某某公司】asdfasdfasd111", null, null, "13026172889", isGizp,
encode);
}
private static void setSingleSms(String appId, String secretKey, String host, String algorithm, String content, String customSmsId, String extendCode, String mobile, boolean isGzip, String encode) {
System.out.println("=============begin setSingleSms==================");
SmsSingleRequest pamars = new SmsSingleRequest();
pamars.setContent(content);
pamars.setCustomSmsId(customSmsId);
pamars.setExtendedCode(extendCode);
pamars.setMobile(mobile);
ResultModel result = request(appId, secretKey, algorithm, pamars, host + "/inter/sendSingleSMS", isGzip, encode);
System.out.println("result code :" + result.getCode());
if ("SUCCESS".equals(result.getCode())) {
SmsResponse response = JsonHelper.fromJson(SmsResponse.class, result.getResult());
if (response != null) {
System.out.println("data : " + response.getMobile() + "," + response.getSmsId() + "," + response.getCustomSmsId());
}
}
System.out.println("=============end setSingleSms==================");
}
/**
* 公共请求方法
*/
public static ResultModel request(String appId, String secretKey, String algorithm, Object content, String url, final boolean isGzip, String encode) {
Map<String, String> headers = new HashMap<String, String>();
HttpRequest<byte[]> request = null;
try {
headers.put("appId", appId);
headers.put("encode", encode);
String requestJson = JsonHelper.toJsonString(content);
System.out.println("result json: " + requestJson);
byte[] bytes = requestJson.getBytes(encode);
System.out.println("request data size : " + bytes.length);
if (isGzip) {
headers.put("gzip", "on");
bytes = GZIPUtils.compress(bytes);
System.out.println("request data size [com]: " + bytes.length);
}
byte[] parambytes = AES.encrypt(bytes, secretKey.getBytes(), algorithm);
System.out.println("request data size [en] : " + parambytes.length);
HttpRequestParams<byte[]> params = new HttpRequestParams<byte[]>();
params.setCharSet("UTF-8");
params.setMethod("POST");
params.setHeaders(headers);
params.setParams(parambytes);
params.setUrl(url);
if (url.startsWith("https://")) {
request = new HttpsRequestBytes(params, null);
} else {
request = new HttpRequestBytes(params);
}
} catch (Exception e) {
System.out.println("加密异常");
e.printStackTrace();
}
HttpClient client = new HttpClient();
String code = null;
String result = null;
try {
HttpResponseBytes res = client.service(request, new HttpResponseBytesPraser());
if (res == null) {
System.out.println("请求接口异常");
return new ResultModel(code, result);
}
if (res.getResultCode().equals(HttpResultCode.SUCCESS)) {
if (res.getHttpCode() == 200) {
code = res.getHeaders().get("result");
if (code.equals("SUCCESS")) {
byte[] data = res.getResult();
System.out.println("response data size [en and com] : " + data.length);
data = AES.decrypt(data, secretKey.getBytes(), algorithm);
if (isGzip) {
data = GZIPUtils.decompress(data);
}
System.out.println("response data size : " + data.length);
result = new String(data, encode);
System.out.println("response json: " + result);
}
} else {
System.out.println("请求接口异常,请求码:" + res.getHttpCode());
}
} else {
System.out.println("请求接口网络异常:" + res.getResultCode().getCode());
}
} catch (Exception e) {
System.out.println("解析失败");
e.printStackTrace();
}
ResultModel re = new ResultModel(code, result);
return re;
}
/**
* 获取余额
*/
private static void getBalance(String appId, String sign, String timestamp, String host) {
System.out.println("=============begin getBalance==================");
Map<String, String> params = new HashMap<String, String>();
params.put("appId", appId);
params.put("sign", sign);
params.put("timestamp", timestamp);
String json = request(params, host + "/simpleinter/getBalance");
if (json != null) {
ResponseData<BalanceResponse> data = JsonHelper.fromJson(new TypeToken<ResponseData<BalanceResponse>>() {
}, json);
String code = data.getCode();
if ("SUCCESS".equals(code)) {
System.out.println("result data : " + data.getData().getBalance());
}
}
System.out.println("=============end getBalance==================");
}
/**
* 获取状态报告
*/
private static void getReport(String appId, String sign, String timestamp, String host) {
System.out.println("=============begin getReport==================");
Map<String, String> params = new HashMap<String, String>();
params.put("appId", appId);
params.put("sign", sign);
params.put("timestamp", timestamp);
params.put("number", "500");
String json = request(params, host + "/simpleinter/getReport");
if (json != null) {
ResponseData<ReportResponse[]> data = JsonHelper.fromJson(new TypeToken<ResponseData<ReportResponse[]>>() {
}, json);
String code = data.getCode();
if ("SUCCESS".equals(code)) {
for (ReportResponse d : data.getData()) {
System.out.println("result data : " + d.getMobile() + "," + d.getExtendedCode() + "," + d.getMobile() + "," + d.getCustomSmsId() + "," + d.getSmsId() + "," + d.getState() + ","
+ d.getDesc() + "," + d.getSubmitTime() + "," + d.getReceiveTime());
}
}
}
System.out.println("=============end getReport==================");
}
/**
* 获取上行
*/
private static void getMo(String appId, String sign, String timestamp, String host) {
System.out.println("=============begin getMo==================");
Map<String, String> params = new HashMap<String, String>();
params.put("appId", appId);
params.put("sign", sign);
params.put("timestamp", timestamp);
params.put("number", "500");
String json = request(params, host + "/simpleinter/getMo");
if (json != null) {
ResponseData<MoResponse[]> data = JsonHelper.fromJson(new TypeToken<ResponseData<MoResponse[]>>() {
}, json);
String code = data.getCode();
if ("SUCCESS".equals(code)) {
for (MoResponse d : data.getData()) {
System.out.println("result data:" + d.getMobile() + "," + d.getExtendedCode() + "," + d.getMobile() + "," + d.getMoTime());
}
}
}
System.out.println("=============end getMo==================");
}
/**
* 发送批次短信
*/
private static void setSms(String appId, String sign, String timestamp, String host, String content, String mobiles, String customSmsId, String extendedCode, String timerTime) {
System.out.println("============= setSms==================");
Map<String, String> params = new HashMap<String, String>();
try {
params.put("appId", appId);
params.put("sign", sign);
params.put("timestamp", timestamp);
params.put("mobiles", mobiles);
params.put("content", URLEncoder.encode(content, "utf-8"));
if (customSmsId != null) {
params.put("customSmsId", customSmsId);
}
if (timerTime != null) {
params.put("timerTime", timerTime);
}
if (extendedCode != null) {
params.put("extendedCode", extendedCode);
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
String json = request(params, host + "/simpleinter/sendSMS");
if (json != null) {
ResponseData<SmsResponse[]> data = JsonHelper.fromJson(new TypeToken<ResponseData<SmsResponse[]>>() {
}, json);
String code = data.getCode();
if ("SUCCESS".equals(code)) {
for (SmsResponse d : data.getData()) {
System.out.println("data:" + d.getMobile() + "," + d.getSmsId() + "," + d.getCustomSmsId());
}
}
}
System.out.println("=============end setSms==================");
}
/**
* 发送个性短信
*/
private static void setPersonalitySms(String appId, String sign, String timestamp, String host, Map<String, String> mobileAndContents, String customSmsId, String extendedCode, String timerTime) {
System.out.println("=============setPersonalitySms ==================");
Map<String, String> params = new HashMap<String, String>();
try {
params.put("appId", appId);
params.put("sign", sign);
params.put("timestamp", timestamp);
for (String mobile : mobileAndContents.keySet()) {
params.put(mobile, URLEncoder.encode(mobileAndContents.get(mobile), "utf-8"));
}
if (customSmsId != null) {
params.put("customSmsId", customSmsId);
}
if (timerTime != null) {
params.put("timerTime", timerTime);
}
if (extendedCode != null) {
params.put("extendedCode", extendedCode);
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
String json = request(params, host + "/simpleinter/sendPersonalitySMS");
if (json != null) {
ResponseData<SmsResponse[]> data = JsonHelper.fromJson(new TypeToken<ResponseData<SmsResponse[]>>() {
}, json);
String code = data.getCode();
if ("SUCCESS".equals(code)) {
for (SmsResponse d : data.getData()) {
System.out.println("data:" + d.getMobile() + "," + d.getSmsId() + "," + d.getCustomSmsId());
}
}
}
System.out.println("=============end setPersonalitySms==================");
}
/**
* 公共请求方法
*/
public static String request(Map<String, String> params, String url) {
HttpRequestParams<Map<String, String>> requestparams = new HttpRequestParams<Map<String, String>>();
requestparams.setCharSet("UTF-8");
requestparams.setMethod("POST");
requestparams.setParams(params);
requestparams.setUrl(url);
HttpRequest<Map<String, String>> request;
if (url.startsWith("https://")) {
request = new HttpsRequestKV(requestparams, null);
} else {
request = new HttpRequestKV(requestparams);
}
HttpClient client = new HttpClient();
String json = null;
try {
String mapst = "";
for (String key : params.keySet()) {
String value = params.get(key);
mapst += key + "=" + value + "&";
}
mapst = mapst.substring(0, mapst.length() - 1);
System.out.println("request params: " + mapst);
HttpResponseString res = client.service(request,
new HttpResponseStringPraser());
if (res == null) {
System.err.println("请求接口异常");
return null;
}
if (res.getResultCode().equals(HttpResultCode.SUCCESS)) {
if (res.getHttpCode() == 200) {
json = res.getResult();
System.out.println("response json: " + json);
} else {
System.out.println("请求接口异常,请求码:" + res.getHttpCode());
}
} else {
System.out.println("请求接口网络异常:" + res.getResultCode().getCode());
}
} catch (Exception e) {
System.err.println("解析失败");
e.printStackTrace();
}
return json;
}
}

43
src/main/java/com/fr/plugin/ymrt/sms/SmsDBAccess.java

@ -0,0 +1,43 @@
package com.fr.plugin.ymrt.sms;
import com.fr.decision.plugin.db.AbstractDecisionDBAccessProvider;
import com.fr.plugin.ymrt.sms.dao.SmsDao;
import com.fr.plugin.ymrt.sms.entity.SmsEntity;
import com.fr.stable.db.accessor.DBAccessor;
import com.fr.stable.db.dao.BaseDAO;
import com.fr.stable.db.dao.DAOProvider;
/**
* @Author fr.open
* @Date 2020/9/15
* @Description
**/
public class SmsDBAccess extends AbstractDecisionDBAccessProvider {
private static DBAccessor dbAccessor;
public DBAccessor getDbAccessor() {
return dbAccessor;
}
@Override
public DAOProvider[] registerDAO() {
return new DAOProvider[]{
new DAOProvider() {
@Override
public Class getEntityClass() {
return SmsEntity.class;
}
@Override
public Class<? extends BaseDAO> getDAOClass() {
return SmsDao.class;
}
}
};
}
@Override
public void onDBAvailable(DBAccessor dbAccessor) {
SmsDBAccess.dbAccessor = dbAccessor;
}
}

26
src/main/java/com/fr/plugin/ymrt/sms/SmsFormulaProvider.java

@ -0,0 +1,26 @@
package com.fr.plugin.ymrt.sms;
import com.fr.main.workbook.ResultWorkBook;
import com.fr.plugin.ymrt.sms.bean.OutputSmsAction;
import com.fr.schedule.base.provider.impl.AbstractOutputFormulaProvider;
import com.fr.schedule.extension.report.util.ScheduleParameterUtils;
import java.util.List;
import java.util.Map;
/**
* @Author fr.open
* @Date 2020/9/15
* @Description
**/
public class SmsFormulaProvider extends AbstractOutputFormulaProvider<OutputSmsAction, ResultWorkBook> {
@Override
public void dealWithFormulaParam(OutputSmsAction action, ResultWorkBook result, List<Map<String, Object>> mapList) throws Exception {
action.setContent(ScheduleParameterUtils.dealWithParameter(action.getContent(), mapList.get(0), result));
}
@Override
public String getActionClassName() {
return OutputSmsAction.class.getName();
}
}

22
src/main/java/com/fr/plugin/ymrt/sms/SmsLocaleFinder.java

@ -0,0 +1,22 @@
package com.fr.plugin.ymrt.sms;
import com.fr.stable.fun.impl.AbstractLocaleFinder;
/**
* @Author fr.open
* @Date 2020/9/15
* @Description
**/
public class SmsLocaleFinder extends AbstractLocaleFinder {
private static final int CURRENT_LEVEL = 1;
@Override
public int currentAPILevel() {
return CURRENT_LEVEL;
}
@Override
public String find() {
return "com/fr/plugin/ymrt/sms/locale/sms";
}
}

27
src/main/java/com/fr/plugin/ymrt/sms/SmsOutputFormulaExtractor.java

@ -0,0 +1,27 @@
package com.fr.plugin.ymrt.sms;
import com.fr.plugin.ymrt.sms.bean.OutputSmsAction;
import com.fr.schedule.extension.report.job.output.formula.extract.impl.AbstractOutputFormulaExtractorProvider;
import com.fr.schedule.extension.report.util.ScheduleParameterUtils;
import java.util.Map;
import java.util.regex.Pattern;
/**
* @Author fr.open
* @Date 2020/9/15
* @Description
**/
public class SmsOutputFormulaExtractor extends AbstractOutputFormulaExtractorProvider<OutputSmsAction> {
@Override
public String getActionClassName() {
return OutputSmsAction.class.getName();
}
@Override
public void addFormulaToMap(OutputSmsAction action, Pattern pattern, Map map) {
ScheduleParameterUtils.addFormulaToMap(action.getContent(), pattern, map);
ScheduleParameterUtils.addFormulaToMap(action.getContent(), pattern, map);
}
}

63
src/main/java/com/fr/plugin/ymrt/sms/bean/OutputSmsAction.java

@ -0,0 +1,63 @@
package com.fr.plugin.ymrt.sms.bean;
import com.fr.plugin.ymrt.sms.entity.SmsEntity;
import com.fr.schedule.base.bean.output.BaseOutputAction;
import com.fr.schedule.base.entity.AbstractScheduleEntity;
import com.fr.schedule.base.type.RunType;
import com.fr.third.fasterxml.jackson.annotation.JsonSubTypes;
/**
* @Author fr.open
* @Date 2020/9/15
* @Description
**/
@JsonSubTypes.Type(value = OutputSmsAction.class, name = "OutputSmsAction")
public class OutputSmsAction extends BaseOutputAction {
private static final long serialVersionUID = 8921116228585639504L;
private String content = null;
public OutputSmsAction() {
super();
}
@Override
public boolean willExecuteByUser() {
return true;
}
@Override
public RunType runType() {
return RunType.SEND_FILE;
}
@Override
public Class<? extends AbstractScheduleEntity> outputActionEntityClass() {
return SmsEntity.class;
}
@Override
public AbstractScheduleEntity createOutputActionEntity() {
return (new SmsEntity()).id(this.getId()).content(this.content);
}
@Override
public OutputSmsAction id(String id) {
setId(id);
return this;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public OutputSmsAction content(String content) {
setContent(content);
return this;
}
}

21
src/main/java/com/fr/plugin/ymrt/sms/dao/SmsDao.java

@ -0,0 +1,21 @@
package com.fr.plugin.ymrt.sms.dao;
import com.fr.plugin.ymrt.sms.entity.SmsEntity;
import com.fr.stable.db.dao.BaseDAO;
import com.fr.stable.db.session.DAOSession;
/**
* @Author fr.open
* @Date 2020/9/15
* @Description
**/
public class SmsDao extends BaseDAO<SmsEntity> {
public SmsDao(DAOSession daoSession) {
super(daoSession);
}
@Override
protected Class<SmsEntity> getEntityClass() {
return SmsEntity.class;
}
}

49
src/main/java/com/fr/plugin/ymrt/sms/entity/SmsEntity.java

@ -0,0 +1,49 @@
package com.fr.plugin.ymrt.sms.entity;
import com.fr.plugin.ymrt.sms.bean.OutputSmsAction;
import com.fr.schedule.base.bean.BaseBean;
import com.fr.schedule.base.entity.AbstractScheduleEntity;
import com.fr.stable.db.entity.TableAssociation;
import com.fr.third.javax.persistence.Column;
import com.fr.third.javax.persistence.Entity;
import com.fr.third.javax.persistence.Table;
/**
* @Author fr.open
* @Date 2020/9/15
* @Description
**/
@Entity
@Table(name = "fine_output_schedule_sms") //表名
@TableAssociation(associated = true)
public class SmsEntity extends AbstractScheduleEntity {
@Column(name = "content",length = 1000)
private String content;
public SmsEntity() {
}
@Override
public BaseBean createBean() {
return new OutputSmsAction().id(this.getId()).content(this.content);
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public SmsEntity content(String content) {
setContent(content);
return this;
}
public SmsEntity id(String id) {
setId(id);
return this;
}
}

43
src/main/java/com/fr/plugin/ymrt/sms/eucp/inter/framework/dto/CustomSmsIdAndMobile.java

@ -0,0 +1,43 @@
package com.fr.plugin.ymrt.sms.eucp.inter.framework.dto;
import java.io.Serializable;
/**
* @Author fr.open
* @Date 2020/9/15
* @Description
**/
public class CustomSmsIdAndMobile implements Serializable {
private static final long serialVersionUID = 1L;
private String customSmsId;
private String mobile;
public CustomSmsIdAndMobile(){
}
public CustomSmsIdAndMobile(String customSmsId,String mobile){
this.customSmsId = customSmsId;
this.mobile = mobile;
}
public String getCustomSmsId() {
return customSmsId;
}
public void setCustomSmsId(String customSmsId) {
this.customSmsId = customSmsId;
}
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
}

54
src/main/java/com/fr/plugin/ymrt/sms/eucp/inter/framework/dto/CustomSmsIdAndMobileAndContent.java

@ -0,0 +1,54 @@
package com.fr.plugin.ymrt.sms.eucp.inter.framework.dto;
import java.io.Serializable;
/**
* @Author fr.open
* @Date 2020/9/15
* @Description
**/
public class CustomSmsIdAndMobileAndContent implements Serializable {
private static final long serialVersionUID = 1L;
private String customSmsId;
private String mobile;
private String content;
public CustomSmsIdAndMobileAndContent(){
}
public CustomSmsIdAndMobileAndContent(String customSmsId,String mobile,String content){
this.customSmsId = customSmsId;
this.mobile = mobile;
this.content = content;
}
public String getCustomSmsId() {
return customSmsId;
}
public void setCustomSmsId(String customSmsId) {
this.customSmsId = customSmsId;
}
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
}

76
src/main/java/com/fr/plugin/ymrt/sms/eucp/inter/framework/dto/PersonalityParams.java

@ -0,0 +1,76 @@
package com.fr.plugin.ymrt.sms.eucp.inter.framework.dto;
import java.io.Serializable;
/**
* @Author fr.open
* @Date 2020/9/15
* @Description
**/
public class PersonalityParams implements Serializable {
private static final long serialVersionUID = 1L;
private String customSmsId;
private String mobile;
private String content;
private String extendedCode;
private String timerTime;
public PersonalityParams(){
}
public PersonalityParams(String customSmsId,String mobile,String content,String extendedCode,String timerTime){
this.customSmsId = customSmsId;
this.mobile = mobile;
this.content = content;
this.timerTime = timerTime;
this.extendedCode = extendedCode;
}
public String getCustomSmsId() {
return customSmsId;
}
public void setCustomSmsId(String customSmsId) {
this.customSmsId = customSmsId;
}
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getExtendedCode() {
return extendedCode;
}
public void setExtendedCode(String extendedCode) {
this.extendedCode = extendedCode;
}
public String getTimerTime() {
return timerTime;
}
public void setTimerTime(String timerTime) {
this.timerTime = timerTime;
}
}

59
src/main/java/com/fr/plugin/ymrt/sms/eucp/inter/framework/dto/TemplateSmsIdAndMobile.java

@ -0,0 +1,59 @@
package com.fr.plugin.ymrt.sms.eucp.inter.framework.dto;
import java.io.Serializable;
import java.util.Map;
/**
* @Author fr.open
* @Date 2020/9/15
* @Description
**/
public class TemplateSmsIdAndMobile implements Serializable {
/**
*/
private static final long serialVersionUID = 1L;
private String mobile;
private String customSmsId;
private Map<String, String> content;
public TemplateSmsIdAndMobile() {
}
public TemplateSmsIdAndMobile(String mobile, String customSmsId) {
this.mobile = mobile;
this.customSmsId = customSmsId;
}
public TemplateSmsIdAndMobile(String mobile, String customSmsId, Map<String, String> content) {
this.mobile = mobile;
this.customSmsId = customSmsId;
this.content = content;
}
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
public Map<String, String> getContent() {
return content;
}
public void setContent(Map<String, String> content) {
this.content = content;
}
public String getCustomSmsId() {
return customSmsId;
}
public void setCustomSmsId(String customSmsId) {
this.customSmsId = customSmsId;
}
}

12
src/main/java/com/fr/plugin/ymrt/sms/eucp/inter/http/v1/dto/request/BalanceRequest.java

@ -0,0 +1,12 @@
package com.fr.plugin.ymrt.sms.eucp.inter.http.v1.dto.request;
/**
* @Author fr.open
* @Date 2020/9/15
* @Description
**/
public class BalanceRequest extends BaseRequest {
private static final long serialVersionUID = 1L;
}

42
src/main/java/com/fr/plugin/ymrt/sms/eucp/inter/http/v1/dto/request/BaseRequest.java

@ -0,0 +1,42 @@
package com.fr.plugin.ymrt.sms.eucp.inter.http.v1.dto.request;
import java.io.Serializable;
/**
* @Author fr.open
* @Date 2020/9/15
* @Description
**/
public class BaseRequest implements Serializable{
private static final long serialVersionUID = 1L;
/**
* 请求时间
*/
private long requestTime = System.currentTimeMillis();
/**
* 请求有效时间()<br/>
* 服务器接受时间与请求时间对比如果超过有效时间拒绝此次请求<br/>
* 防止被网络抓包不断发送同一条请求<br/>
* 默认1分钟有效期
*/
private int requestValidPeriod = 60;
public long getRequestTime() {
return requestTime;
}
public void setRequestTime(long requestTime) {
this.requestTime = requestTime;
}
public int getRequestValidPeriod() {
return requestValidPeriod;
}
public void setRequestValidPeriod(int requestValidPeriod) {
this.requestValidPeriod = requestValidPeriod;
}
}

32
src/main/java/com/fr/plugin/ymrt/sms/eucp/inter/http/v1/dto/request/MoRequest.java

@ -0,0 +1,32 @@
package com.fr.plugin.ymrt.sms.eucp.inter.http.v1.dto.request;
/**
* @Author fr.open
* @Date 2020/9/15
* @Description
**/
public class MoRequest extends BaseRequest {
private static final long serialVersionUID = 1L;
/**
* 请求数量<br/>
* 最大500
*/
private int number = 500;
public int getNumber() {
if(number <= 0 || number > 500){
number = 500;
}
return number;
}
public void setNumber(int number) {
if(number > 500){
number = 500;
}
this.number = number;
}
}

32
src/main/java/com/fr/plugin/ymrt/sms/eucp/inter/http/v1/dto/request/ReportRequest.java

@ -0,0 +1,32 @@
package com.fr.plugin.ymrt.sms.eucp.inter.http.v1.dto.request;
/**
* @Author fr.open
* @Date 2020/9/15
* @Description
**/
public class ReportRequest extends BaseRequest {
private static final long serialVersionUID = 1L;
/**
* 请求数量<br/>
* 最大500
*/
private int number = 500;
public int getNumber() {
if(number <= 0 || number > 500){
number = 500;
}
return number;
}
public void setNumber(int number) {
if(number > 500){
number = 500;
}
this.number = number;
}
}

32
src/main/java/com/fr/plugin/ymrt/sms/eucp/inter/http/v1/dto/request/ShortLinkRequest.java

@ -0,0 +1,32 @@
package com.fr.plugin.ymrt.sms.eucp.inter.http.v1.dto.request;
/**
* @Author fr.open
* @Date 2020/9/15
* @Description
**/
public class ShortLinkRequest extends BaseRequest {
private static final long serialVersionUID = 1L;
/**
* 请求数量<br/>
* 最大500
*/
private int number = 500;
public int getNumber() {
if(number <= 0 || number > 500){
number = 500;
}
return number;
}
public void setNumber(int number) {
if(number > 500){
number = 500;
}
this.number = number;
}
}

39
src/main/java/com/fr/plugin/ymrt/sms/eucp/inter/http/v1/dto/request/SmsBaseRequest.java

@ -0,0 +1,39 @@
package com.fr.plugin.ymrt.sms.eucp.inter.http.v1.dto.request;
/**
* @Author fr.open
* @Date 2020/9/15
* @Description
**/
public class SmsBaseRequest extends BaseRequest {
private static final long serialVersionUID = 1L;
/**
* 定时时间
* yyyy-MM-dd HH:mm:ss
*/
private String timerTime;
/**
* 扩展码
*/
private String extendedCode;
public String getTimerTime() {
return timerTime;
}
public void setTimerTime(String timerTime) {
this.timerTime = timerTime;
}
public String getExtendedCode() {
return extendedCode;
}
public void setExtendedCode(String extendedCode) {
this.extendedCode = extendedCode;
}
}

40
src/main/java/com/fr/plugin/ymrt/sms/eucp/inter/http/v1/dto/request/SmsBatchOnlyRequest.java

@ -0,0 +1,40 @@
package com.fr.plugin.ymrt.sms.eucp.inter.http.v1.dto.request;
/**
* @Author fr.open
* @Date 2020/9/15
* @Description
**/
public class SmsBatchOnlyRequest extends SmsBaseRequest {
private static final long serialVersionUID = 1L;
/**
* 手机号与自定义SmsId
*/
private String[] mobiles;
/**
* 短信内容
*/
private String content;
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String[] getMobiles() {
return mobiles;
}
public void setMobiles(String[] mobiles) {
this.mobiles = mobiles;
}
}

41
src/main/java/com/fr/plugin/ymrt/sms/eucp/inter/http/v1/dto/request/SmsBatchRequest.java

@ -0,0 +1,41 @@
package com.fr.plugin.ymrt.sms.eucp.inter.http.v1.dto.request;
import com.fr.plugin.ymrt.sms.eucp.inter.framework.dto.CustomSmsIdAndMobile;
/**
* @Author fr.open
* @Date 2020/9/15
* @Description
**/
public class SmsBatchRequest extends SmsBaseRequest {
private static final long serialVersionUID = 1L;
/**
* 手机号与自定义SmsId
*/
private CustomSmsIdAndMobile[] smses;
/**
* 短信内容
*/
private String content;
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public CustomSmsIdAndMobile[] getSmses() {
return smses;
}
public void setSmses(CustomSmsIdAndMobile[] smses) {
this.smses = smses;
}
}

26
src/main/java/com/fr/plugin/ymrt/sms/eucp/inter/http/v1/dto/request/SmsPersonalityAllRequest.java

@ -0,0 +1,26 @@
package com.fr.plugin.ymrt.sms.eucp.inter.http.v1.dto.request;
import com.fr.plugin.ymrt.sms.eucp.inter.framework.dto.PersonalityParams;
/**
* @Author fr.open
* @Date 2020/9/15
* @Description
**/
public class SmsPersonalityAllRequest extends BaseRequest {
private static final long serialVersionUID = 1L;
private PersonalityParams[] smses;
public PersonalityParams[] getSmses() {
return smses;
}
public void setSmses(PersonalityParams[] smses) {
this.smses = smses;
}
}

26
src/main/java/com/fr/plugin/ymrt/sms/eucp/inter/http/v1/dto/request/SmsPersonalityRequest.java

@ -0,0 +1,26 @@
package com.fr.plugin.ymrt.sms.eucp.inter.http.v1.dto.request;
import com.fr.plugin.ymrt.sms.eucp.inter.framework.dto.CustomSmsIdAndMobileAndContent;
/**
* @Author fr.open
* @Date 2020/9/15
* @Description
**/
public class SmsPersonalityRequest extends SmsBaseRequest {
private static final long serialVersionUID = 1L;
private CustomSmsIdAndMobileAndContent[] smses;
public CustomSmsIdAndMobileAndContent[] getSmses() {
return smses;
}
public void setSmses(CustomSmsIdAndMobileAndContent[] smses) {
this.smses = smses;
}
}

60
src/main/java/com/fr/plugin/ymrt/sms/eucp/inter/http/v1/dto/request/SmsShortLinkBatchRequest.java

@ -0,0 +1,60 @@
package com.fr.plugin.ymrt.sms.eucp.inter.http.v1.dto.request;
import com.fr.plugin.ymrt.sms.eucp.inter.framework.dto.CustomSmsIdAndMobile;
/**
* @Author fr.open
* @Date 2020/9/15
* @Description
**/
public class SmsShortLinkBatchRequest extends SmsBaseRequest {
private static final long serialVersionUID = 1L;
private String url;
private String shortLinkRule;
/**
* 手机号与自定义SmsId
*/
private CustomSmsIdAndMobile[] smses;
/**
* 短信内容
*/
private String content;
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public CustomSmsIdAndMobile[] getSmses() {
return smses;
}
public void setSmses(CustomSmsIdAndMobile[] smses) {
this.smses = smses;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getShortLinkRule() {
return shortLinkRule;
}
public void setShortLinkRule(String shortLinkRule) {
this.shortLinkRule = shortLinkRule;
}
}

53
src/main/java/com/fr/plugin/ymrt/sms/eucp/inter/http/v1/dto/request/SmsSingleRequest.java

@ -0,0 +1,53 @@
package com.fr.plugin.ymrt.sms.eucp.inter.http.v1.dto.request;
/**
* @Author fr.open
* @Date 2020/9/15
* @Description
**/
public class SmsSingleRequest extends SmsBaseRequest {
private static final long serialVersionUID = 1L;
/**
* 电话号码
*/
private String mobile;
/**
* 短信内容
*/
private String content;
/**
* 自定义smsid
*/
private String customSmsId;
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getCustomSmsId() {
return customSmsId;
}
public void setCustomSmsId(String customSmsId) {
this.customSmsId = customSmsId;
}
}

34
src/main/java/com/fr/plugin/ymrt/sms/eucp/inter/http/v1/dto/request/TemplateSmsSendRequest.java

@ -0,0 +1,34 @@
package com.fr.plugin.ymrt.sms.eucp.inter.http.v1.dto.request;
import com.fr.plugin.ymrt.sms.eucp.inter.framework.dto.TemplateSmsIdAndMobile;
/**
* @Author fr.open
* @Date 2020/9/15
* @Description
**/
public class TemplateSmsSendRequest extends SmsBaseRequest {
/**
*/
private static final long serialVersionUID = 1L;
private TemplateSmsIdAndMobile[] smses;
private String templateId;
public String getTemplateId() {
return templateId;
}
public void setTemplateId(String templateId) {
this.templateId = templateId;
}
public TemplateSmsIdAndMobile[] getSmses() {
return smses;
}
public void setSmses(TemplateSmsIdAndMobile[] smses) {
this.smses = smses;
}
}

34
src/main/java/com/fr/plugin/ymrt/sms/eucp/inter/http/v1/dto/response/BalanceResponse.java

@ -0,0 +1,34 @@
package com.fr.plugin.ymrt.sms.eucp.inter.http.v1.dto.response;
import java.io.Serializable;
/**
* @Author fr.open
* @Date 2020/9/15
* @Description
**/
public class BalanceResponse implements Serializable{
private static final long serialVersionUID = 1L;
private long balance;// 余额
public BalanceResponse() {
}
public BalanceResponse(long balance) {
this.balance = balance;
}
public long getBalance() {
return balance;
}
public void setBalance(long balance) {
this.balance = balance;
}
}

65
src/main/java/com/fr/plugin/ymrt/sms/eucp/inter/http/v1/dto/response/MoResponse.java

@ -0,0 +1,65 @@
package com.fr.plugin.ymrt.sms.eucp.inter.http.v1.dto.response;
import java.io.Serializable;
/**
* @Author fr.open
* @Date 2020/9/15
* @Description
**/
public class MoResponse implements Serializable {
private static final long serialVersionUID = 1L;
private String mobile;// 手机号
private String extendedCode; // 扩展码
private String content;// 内容
private String moTime;// 手机上行时间
public MoResponse(){
}
public MoResponse(String mobile,String extendedCode,String content,String moTime){
this.mobile = mobile;
this.extendedCode = extendedCode;
this.content = content;
this.moTime = moTime;
}
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
public String getExtendedCode() {
return extendedCode;
}
public void setExtendedCode(String extendedCode) {
this.extendedCode = extendedCode;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getMoTime() {
return moTime;
}
public void setMoTime(String moTime) {
this.moTime = moTime;
}
}

94
src/main/java/com/fr/plugin/ymrt/sms/eucp/inter/http/v1/dto/response/ReportResponse.java

@ -0,0 +1,94 @@
package com.fr.plugin.ymrt.sms.eucp.inter.http.v1.dto.response;
import java.io.Serializable;
/**
* @Author fr.open
* @Date 2020/9/15
* @Description
**/
public class ReportResponse implements Serializable {
private static final long serialVersionUID = 1L;
private String smsId;// 短信唯一标识
private String customSmsId;// 客户自定义SmsId
private String state;// 成功失败标识
private String desc;// 状态报告描述
private String mobile;// 手机号
private String receiveTime;// 状态报告返回时间
private String submitTime;// 信息提交时间
private String extendedCode;// 扩展码
public String getCustomSmsId() {
return customSmsId;
}
public void setCustomSmsId(String customSmsId) {
this.customSmsId = customSmsId;
}
public String getState() {
return state;
}
public void setState(String state) {
this.state = state;
}
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
public String getReceiveTime() {
return receiveTime;
}
public void setReceiveTime(String receiveTime) {
this.receiveTime = receiveTime;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
public String getSmsId() {
return smsId;
}
public void setSmsId(String smsId) {
this.smsId = smsId;
}
public String getSubmitTime() {
return submitTime;
}
public void setSubmitTime(String submitTime) {
this.submitTime = submitTime;
}
public String getExtendedCode() {
return extendedCode;
}
public void setExtendedCode(String extendedCode) {
this.extendedCode = extendedCode;
}
}

44
src/main/java/com/fr/plugin/ymrt/sms/eucp/inter/http/v1/dto/response/ResponseData.java

@ -0,0 +1,44 @@
package com.fr.plugin.ymrt.sms.eucp.inter.http.v1.dto.response;
import java.io.Serializable;
/**
* @Author fr.open
* @Date 2020/9/15
* @Description
**/
public class ResponseData<T> implements Serializable {
private static final long serialVersionUID = 1L;
private String code;
private T data;
public ResponseData(String code,T data){
this.code = code;
this.data = data;
}
public ResponseData(){
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public T getData() {
return data;
}
public void setData(T data) {
this.data = data;
}
}

89
src/main/java/com/fr/plugin/ymrt/sms/eucp/inter/http/v1/dto/response/ShortLinkReportResponse.java

@ -0,0 +1,89 @@
package com.fr.plugin.ymrt.sms.eucp.inter.http.v1.dto.response;
import java.io.Serializable;
import java.util.Date;
/**
* @Author fr.open
* @Date 2020/9/15
* @Description
**/
public class ShortLinkReportResponse implements Serializable {
/**
*/
private static final long serialVersionUID = 1L;
private String mobile;// 手机号
private Date accessTime;// 访问时间
private String equipment;// 设备
private String browser;// 浏览器
private String longLink;// 长链接
private String accessAddress;// 访问地址
private String userAgent;// user-agent
private String appId;
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
public Date getAccessTime() {
return accessTime;
}
public void setAccessTime(Date accessTime) {
this.accessTime = accessTime;
}
public String getEquipment() {
return equipment;
}
public void setEquipment(String equipment) {
this.equipment = equipment;
}
public String getBrowser() {
return browser;
}
public void setBrowser(String browser) {
this.browser = browser;
}
public String getLongLink() {
return longLink;
}
public void setLongLink(String longLink) {
this.longLink = longLink;
}
public String getAccessAddress() {
return accessAddress;
}
public void setAccessAddress(String accessAddress) {
this.accessAddress = accessAddress;
}
public String getUserAgent() {
return userAgent;
}
public void setUserAgent(String userAgent) {
this.userAgent = userAgent;
}
public String getAppId() {
return appId;
}
public void setAppId(String appId) {
this.appId = appId;
}
}

57
src/main/java/com/fr/plugin/ymrt/sms/eucp/inter/http/v1/dto/response/SmsResponse.java

@ -0,0 +1,57 @@
package com.fr.plugin.ymrt.sms.eucp.inter.http.v1.dto.response;
import java.io.Serializable;
/**
* @Author fr.open
* @Date 2020/9/15
* @Description
**/
public class SmsResponse implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 系统唯一smsId
*/
private String smsId;
private String mobile;
private String customSmsId;
public SmsResponse(){
}
public SmsResponse(String smsId,String mobile,String customSmsId){
this.smsId = smsId;
this.mobile = mobile;
this.customSmsId = customSmsId;
}
public String getSmsId() {
return smsId;
}
public void setSmsId(String smsId) {
this.smsId = smsId;
}
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
public String getCustomSmsId() {
return customSmsId;
}
public void setCustomSmsId(String customSmsId) {
this.customSmsId = customSmsId;
}
}

57
src/main/java/com/fr/plugin/ymrt/sms/eucp/inter/http/v1/dto/response/SmsTemplateResponse.java

@ -0,0 +1,57 @@
package com.fr.plugin.ymrt.sms.eucp.inter.http.v1.dto.response;
import java.io.Serializable;
/**
* @Author fr.open
* @Date 2020/9/15
* @Description
**/
public class SmsTemplateResponse implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 系统唯一smsId
*/
private String smsId;
private String mobile;
private String customSmsId;
public SmsTemplateResponse(){
}
public SmsTemplateResponse(String smsId,String mobile,String customSmsId){
this.smsId = smsId;
this.mobile = mobile;
this.customSmsId = customSmsId;
}
public String getSmsId() {
return smsId;
}
public void setSmsId(String smsId) {
this.smsId = smsId;
}
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
public String getCustomSmsId() {
return customSmsId;
}
public void setCustomSmsId(String customSmsId) {
this.customSmsId = customSmsId;
}
}

173
src/main/java/com/fr/plugin/ymrt/sms/handle/SmsOutputActionHandler.java

@ -0,0 +1,173 @@
package com.fr.plugin.ymrt.sms.handle;
import com.fr.decision.authority.AuthorityContext;
import com.fr.decision.authority.data.User;
import com.fr.general.PropertiesUtils;
import com.fr.log.FineLoggerFactory;
import com.fr.plugin.ymrt.sms.ResultModel;
import com.fr.plugin.ymrt.sms.bean.OutputSmsAction;
import com.fr.plugin.ymrt.sms.eucp.inter.http.v1.dto.request.SmsSingleRequest;
import com.fr.plugin.ymrt.sms.eucp.inter.http.v1.dto.response.SmsResponse;
import com.fr.plugin.ymrt.sms.util.AES;
import com.fr.plugin.ymrt.sms.util.GZIPUtils;
import com.fr.plugin.ymrt.sms.util.JsonHelper;
import com.fr.plugin.ymrt.sms.util.http.*;
import com.fr.schedule.base.constant.ScheduleConstants;
import com.fr.schedule.feature.output.OutputActionHandler;
import com.fr.stable.StringUtils;
import com.fr.stable.query.QueryFactory;
import com.fr.stable.query.restriction.RestrictionFactory;
import java.util.*;
import java.util.stream.Collectors;
/**
* @Author fr.open
* @Date 2020/9/15
* @Description
**/
public class SmsOutputActionHandler extends OutputActionHandler<OutputSmsAction> {
private String appId;
private String secretKey;
private String host;
private String customSmsId;
private String extendedCode;
private final String algorithm = "AES/ECB/PKCS5Padding";
// 编码
private final String encode = "UTF-8";
// 是否压缩
private final boolean isGizp = true;
public SmsOutputActionHandler() {
String appid = PropertiesUtils.getProperties("ymrt").getProperty("appId");
FineLoggerFactory.getLogger().info("get appid is {}", appid);
this.appId = appid;
String key = PropertiesUtils.getProperties("ymrt").getProperty("secretKey");
FineLoggerFactory.getLogger().info("get key is {}", key);
this.secretKey = key;
String host = PropertiesUtils.getProperties("ymrt").getProperty("host");
FineLoggerFactory.getLogger().info("get host is {}", host);
this.host = host;
String customSmsId = PropertiesUtils.getProperties("ymrt").getProperty("customSmsId");
FineLoggerFactory.getLogger().info("get customSmsId is {}", customSmsId);
this.customSmsId = customSmsId;
String extendedCode = PropertiesUtils.getProperties("ymrt").getProperty("extendedCode");
FineLoggerFactory.getLogger().info("get extendedCode is {}", extendedCode);
this.extendedCode = extendedCode;
}
@Override
public void doAction(OutputSmsAction action, Map<String, Object> map) throws Exception {
FineLoggerFactory.getLogger().info("sam content is {}",action.getContent());
String[] users = (String[]) map.get(ScheduleConstants.USERNAMES);
String scheduleUsername = (String) map.get(ScheduleConstants.USERNAME);
Set<String> userSet = new HashSet();
if (StringUtils.isNotBlank(scheduleUsername)) {
userSet.add(scheduleUsername);
} else {
userSet.addAll(Arrays.asList(users));
}
FineLoggerFactory.getLogger().info("config users is {}",userSet);
List<User> userList = AuthorityContext.getInstance().getUserController().find(QueryFactory.create().addRestriction(RestrictionFactory.in("userName", userSet)));
List<String> mobiles = userList.stream().filter(e -> StringUtils.isNotBlank(e.getMobile())).map(e -> e.getMobile()).collect(Collectors.toList());
if(mobiles.isEmpty()){
throw new Exception("config user mobile is null");
}
FineLoggerFactory.getLogger().info("send sms mobile is {}",mobiles);
setSingleSms(appId,secretKey,host,algorithm,action.getContent(),customSmsId,extendedCode, com.fr.third.org.apache.commons.lang3.StringUtils.join(mobiles,","),isGizp,encode);
}
private static void setSingleSms(String appId, String secretKey, String host, String algorithm, String content, String customSmsId, String extendCode, String mobile, boolean isGzip, String encode) {
FineLoggerFactory.getLogger().info("=============begin setSingleSms==================");
SmsSingleRequest pamars = new SmsSingleRequest();
pamars.setContent(content);
pamars.setCustomSmsId(customSmsId);
pamars.setExtendedCode(extendCode);
pamars.setMobile(mobile);
ResultModel result = request(appId, secretKey, algorithm, pamars, host + "/inter/sendSingleSMS", isGzip, encode);
FineLoggerFactory.getLogger().info("result code :" + result.getCode());
if ("SUCCESS".equals(result.getCode())) {
SmsResponse response = JsonHelper.fromJson(SmsResponse.class, result.getResult());
if (response != null) {
FineLoggerFactory.getLogger().info("data : " + response.getMobile() + "," + response.getSmsId() + "," + response.getCustomSmsId());
}
}
FineLoggerFactory.getLogger().info("=============end setSingleSms==================");
}
/**
* 公共请求方法
*/
public static ResultModel request(String appId, String secretKey, String algorithm, Object content, String url, final boolean isGzip, String encode) {
Map<String, String> headers = new HashMap<String, String>();
HttpRequest<byte[]> request = null;
try {
headers.put("appId", appId);
headers.put("encode", encode);
String requestJson = JsonHelper.toJsonString(content);
FineLoggerFactory.getLogger().info("result json: " + requestJson);
byte[] bytes = requestJson.getBytes(encode);
FineLoggerFactory.getLogger().info("request data size : " + bytes.length);
if (isGzip) {
headers.put("gzip", "on");
bytes = GZIPUtils.compress(bytes);
FineLoggerFactory.getLogger().info("request data size [com]: " + bytes.length);
}
byte[] parambytes = AES.encrypt(bytes, secretKey.getBytes(), algorithm);
FineLoggerFactory.getLogger().info("request data size [en] : " + parambytes.length);
HttpRequestParams<byte[]> params = new HttpRequestParams<byte[]>();
params.setCharSet("UTF-8");
params.setMethod("POST");
params.setHeaders(headers);
params.setParams(parambytes);
params.setUrl(url);
if (url.startsWith("https://")) {
request = new HttpsRequestBytes(params, null);
} else {
request = new HttpRequestBytes(params);
}
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(),e);
}
HttpClient client = new HttpClient();
String code = null;
String result = null;
try {
HttpResponseBytes res = client.service(request, new HttpResponseBytesPraser());
if (res == null) {
FineLoggerFactory.getLogger().info("请求接口异常");
return new ResultModel(code, result);
}
if (res.getResultCode().equals(HttpResultCode.SUCCESS)) {
if (res.getHttpCode() == 200) {
code = res.getHeaders().get("result");
if (code.equals("SUCCESS")) {
byte[] data = res.getResult();
FineLoggerFactory.getLogger().info("response data size [en and com] : " + data.length);
data = AES.decrypt(data, secretKey.getBytes(), algorithm);
if (isGzip) {
data = GZIPUtils.decompress(data);
}
FineLoggerFactory.getLogger().info("response data size : " + data.length);
result = new String(data, encode);
FineLoggerFactory.getLogger().info("response json: " + result);
}
} else {
FineLoggerFactory.getLogger().info("请求接口异常,请求码:" + res.getHttpCode());
}
} else {
FineLoggerFactory.getLogger().info("请求接口网络异常:" + res.getResultCode().getCode());
}
} catch (Exception e) {
FineLoggerFactory.getLogger().error(e.getMessage(),e);
}
ResultModel re = new ResultModel(code, result);
return re;
}
}

55
src/main/java/com/fr/plugin/ymrt/sms/js/FileDef.java

@ -0,0 +1,55 @@
package com.fr.plugin.ymrt.sms.js;
import com.fr.plugin.transform.ExecuteFunctionRecord;
import com.fr.web.struct.Component;
import com.fr.web.struct.Filter;
import com.fr.web.struct.browser.RequestClient;
import com.fr.web.struct.category.ScriptPath;
import com.fr.web.struct.category.StylePath;
/**
* @Author fr.open
* @Date 2020/9/15
* @Description
**/
public class FileDef extends Component {
public static final FileDef KEY = new FileDef();
private FileDef(){}
/**
* 返回需要引入的JS脚本路径
* @param client 请求客户端描述
* @return JS脚本路径
*/
@Override
public ScriptPath script(RequestClient client ) {
//如果不需要就直接返回 ScriptPath.EMPTY
return ScriptPath.build("com/fr/plugin/ymrt/sms/theme.js");
}
/**
* 返回需要引入的CSS样式路径
* @param client 请求客户端描述
* @return CSS样式路径
*/
@Override
public StylePath style(RequestClient client ) {
//如果不需要就直接返回 StylePath.EMPTY;
return StylePath.EMPTY;
}
/**
* 通过给定的资源过滤器控制是否加载这个资源
* @return 资源过滤器
*/
@ExecuteFunctionRecord
@Override
public Filter filter() {
return new Filter(){
@Override
public boolean accept() {
//任何情况下我们都在平台组件加载时加载我们的组件
return true;
}
};
}
}

28
src/main/java/com/fr/plugin/ymrt/sms/js/JSCSSBridge.java

@ -0,0 +1,28 @@
package com.fr.plugin.ymrt.sms.js;
import com.fr.decision.fun.impl.AbstractWebResourceProvider;
import com.fr.decision.web.MainComponent;
import com.fr.plugin.transform.FunctionRecorder;
import com.fr.web.struct.Atom;
/**
* @Author fr.open
* @Date 2020/9/15
* @Description
**/
@FunctionRecorder
public class JSCSSBridge extends AbstractWebResourceProvider {
@Override
public Atom attach() {
//在平台主组件加载时添加我们自己的组件
return MainComponent.KEY;
}
@Override
public Atom[] clients() {
return new Atom[]{
FileDef.KEY,
};
}
}

140
src/main/java/com/fr/plugin/ymrt/sms/util/AES.java

@ -0,0 +1,140 @@
package com.fr.plugin.ymrt.sms.util;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
/**
* @Author fr.open
* @Date 2020/9/15
* @Description
**/
public class AES {
public final static String ALGORITHM_AEPP = "AES/ECB/PKCS5Padding";
/**
* AES加密
*
* @param content
* 内容
* @param password
* 密钥
* @param algorithm
* 算法
* @return 加密后数据
*/
public static byte[] encrypt(byte[] content, byte[] password, String algorithm) {
if (content == null || password == null)
return null;
try {
Cipher cipher = null;
if (algorithm.endsWith("PKCS7Padding")) {
cipher = Cipher.getInstance(algorithm, "BC");
} else {
cipher = Cipher.getInstance(algorithm);
}
cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(password, "AES"));
return cipher.doFinal(content);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
/**
* AES解密
*
* @param content
* 加密内容
* @param password
* 密钥
* @param algorithm
* 算法
* @return 解密后数据
*/
public static byte[] decrypt(byte[] content, byte[] password, String algorithm) {
if (content == null || password == null)
return null;
try {
Cipher cipher = null;
if (algorithm.endsWith("PKCS7Padding")) {
cipher = Cipher.getInstance(algorithm, "BC");
} else {
cipher = Cipher.getInstance(algorithm);
}
cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(password, "AES"));
byte[] bytes = cipher.doFinal(content);
return bytes;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
/**
* AES加密
*
* @param content
* 内容
* @param password
* 密钥
* @param algorithm
* 算法
* @param ivStr
* 向量
* @return 加密后数据
*/
public static byte[] encrypt(byte[] content, byte[] password, byte[] ivStr, String algorithm) {
if (content == null || password == null)
return null;
try {
Cipher cipher = null;
if (algorithm.endsWith("PKCS7Padding")) {
cipher = Cipher.getInstance(algorithm, "BC");
} else {
cipher = Cipher.getInstance(algorithm);
}
IvParameterSpec iv = new IvParameterSpec(ivStr);
cipher.init(Cipher.ENCRYPT_MODE, new SecretKeySpec(password, "AES"), iv);
return cipher.doFinal(content);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
/**
* AES解密
*
* @param content
* 加密内容
* @param password
* 密钥
* @param algorithm
* 算法
* @param ivStr
* 向量
* @return 解密后数据
*/
public static byte[] decrypt(byte[] content, byte[] password, byte[] ivStr, String algorithm) {
if (content == null || password == null)
return null;
try {
Cipher cipher = null;
if (algorithm.endsWith("PKCS7Padding")) {
cipher = Cipher.getInstance(algorithm, "BC");
} else {
cipher = Cipher.getInstance(algorithm);
}
IvParameterSpec iv = new IvParameterSpec(ivStr);
cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(password, "AES"), iv);
byte[] bytes = cipher.doFinal(content);
return bytes;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
}

133
src/main/java/com/fr/plugin/ymrt/sms/util/DateUtil.java

@ -0,0 +1,133 @@
package com.fr.plugin.ymrt.sms.util;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
/**
* @Author fr.open
* @Date 2020/9/15
* @Description
**/
public class DateUtil {
public static final long ONE_HOUR_TIME_LONG = 3600000;
public static String toString(Date date, String format) {
String dateStr = null;
try {
SimpleDateFormat sdf = new SimpleDateFormat(format);
dateStr = sdf.format(date);
} catch (Exception e) {
}
return dateStr;
}
public static Date parseDate(String dateStr, String format) {
Date date = null;
try {
SimpleDateFormat sdf = new SimpleDateFormat(format);
date = sdf.parse(dateStr);
} catch (Exception e) {
}
return date;
}
/**
* 获取日期当天的最小时间日期,0点
*/
public static Date getMinTimeDateByDate(Date date) {
if (date == null)
return null;
String datestr = toString(date, "yyyyMMdd");
return parseDate(datestr, "yyyyMMdd");
}
/**
* 获取日期当天的最大时间日期,12点整
*/
public static Date getMaxTimeDateByDate(Date date) {
if (date == null)
return null;
String datestr = toString(date, "yyyyMMdd");
Date d = parseDate(datestr, "yyyyMMdd");
return new Date(d.getTime() + 24l * 60l * 60l * 1000l - 1l);
}
public static long subTime(Date startDate, Date endDate) {
return endDate.getTime() - startDate.getTime();
}
/**
* 获取上月第一天最早时间
* @return Date
*/
public static Date getLastMonthFirstDay() {
Calendar cal_1 = Calendar.getInstance();// 获取当前日期
cal_1.setTime(getMinTimeDateByDate(new Date()));
cal_1.add(Calendar.MONTH, -1);
cal_1.set(Calendar.DAY_OF_MONTH, 1);
return cal_1.getTime();
}
/**
* 获取上月最后一天最晚时间
* @return Date
*/
public static Date getLastMonthLastDay() {
Calendar cale = Calendar.getInstance();
cale.setTime(getMinTimeDateByDate(new Date()));
cale.add(Calendar.MONTH, -1);
cale.set(Calendar.DAY_OF_MONTH, cale.getActualMaximum(Calendar.DAY_OF_MONTH));
return new Date(cale.getTime().getTime() + 1000l * 60l * 60l * 24l - 1l);
}
/**
* 获取本月第一天最早时间
* @return Date
*/
public static Date getNowMonthFirstDay() {
Calendar cal_1 = Calendar.getInstance();// 获取当前日期
cal_1.setTime(getMinTimeDateByDate(new Date()));
cal_1.add(Calendar.MONTH, 0);
cal_1.set(Calendar.DAY_OF_MONTH, 1);
return cal_1.getTime();
}
/**
* 获取本月最后一天最晚时间
* @return Date
*/
public static Date getNowMonthLastDay() {
Calendar cale = Calendar.getInstance();
cale.setTime(getMinTimeDateByDate(new Date()));
cale.set(Calendar.DAY_OF_MONTH, cale.getActualMaximum(Calendar.DAY_OF_MONTH));
return new Date(cale.getTime().getTime() + 1000l * 60l * 60l * 24l - 1l);
}
/**
* 获取本月最后一天
* @return Date
*/
public static Date getTheMonthLastDay(Date date) {
if(date == null){
return null;
}
Calendar cale = Calendar.getInstance();
cale.setTime(date);
cale.set(Calendar.DAY_OF_MONTH, cale.getActualMaximum(Calendar.DAY_OF_MONTH));
cale.set(Calendar.HOUR, 0);
cale.set(Calendar.HOUR_OF_DAY, 0);
cale.set(Calendar.MINUTE, 0);
cale.set(Calendar.SECOND, 0);
cale.set(Calendar.MILLISECOND, 0);
return cale.getTime();
}
public static void main(String[] args) {
// System.out.println(toString(getTheMonthLastDay(new Date()), "yyyy-MM-dd HH:mm:ss"));
// System.out.println(toString(getLastMonthLastDay(), "yyyy-MM-dd HH:mm:ss"));
// System.out.println(toString(getNowMonthFirstDay(), "yyyy-MM-dd HH:mm:ss"));
// System.out.println(toString(getNowMonthLastDay(), "yyyy-MM-dd HH:mm:ss"));
}
}

105
src/main/java/com/fr/plugin/ymrt/sms/util/GZIPUtils.java

@ -0,0 +1,105 @@
package com.fr.plugin.ymrt.sms.util;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
/**
* @Author fr.open
* @Date 2020/9/15
* @Description
**/
public class GZIPUtils {
public static void main(String[] args) throws IOException {
String sst = "hahahah";
System.out.println(sst);
System.out.println(System.currentTimeMillis());
System.out.println("size:" + sst.length());
byte[] bytes = sst.getBytes();
System.out.println("length:" + bytes.length);
System.out.println(System.currentTimeMillis());
byte[] end = compress(bytes);
System.out.println(System.currentTimeMillis());
System.out.println("length:" + end.length);
System.out.println(System.currentTimeMillis());
byte[] start = decompress(end);
System.out.println(System.currentTimeMillis());
System.out.println("length:" + start.length);
System.out.println(new String(start));
}
/**
* 数据压缩传输
*
* @param is
* @param os
* @throws Exception
*/
public static void compressTransfe(byte[] bytes, OutputStream out) throws IOException {
GZIPOutputStream gos = null;
try {
gos = new GZIPOutputStream(out);
gos.write(bytes);
gos.finish();
gos.flush();
} finally{
if(gos != null){
gos.close();
}
}
}
/**
* 数据压缩
*
* @param is
* @param os
* @throws Exception
*/
public static byte[] compress(byte[] bytes) throws IOException {
ByteArrayOutputStream out = null;
GZIPOutputStream gos = null;
try {
out = new ByteArrayOutputStream();
gos = new GZIPOutputStream(out);
gos.write(bytes);
gos.finish();
gos.flush();
} finally{
if(gos != null){
gos.close();
}
if(out != null){
out.close();
}
}
return out.toByteArray();
}
/**
* 数据解压
*
* @param in
* @return
* @throws IOException
*/
public static byte[] decompress(byte[] bytes) throws IOException {
ByteArrayInputStream in = new ByteArrayInputStream(bytes);
GZIPInputStream gin = new GZIPInputStream(in);
ByteArrayOutputStream out = new ByteArrayOutputStream();
int count;
byte data[] = new byte[1024];
while ((count = gin.read(data, 0, 1024)) != -1) {
out.write(data, 0, count);
}
out.flush();
out.close();
gin.close();
return out.toByteArray();
}
}

129
src/main/java/com/fr/plugin/ymrt/sms/util/JsonHelper.java

@ -0,0 +1,129 @@
package com.fr.plugin.ymrt.sms.util;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import java.util.HashMap;
import java.util.Map;
/**
* @Author fr.open
* @Date 2020/9/15
* @Description
**/
public class JsonHelper {
private static Map<String,Gson> gsons = new HashMap<String, Gson>();
private static String DEFAULT_DATE_PATTERN = "yyyy-MM-dd HH:mm:ss";
static {
gsons.put(DEFAULT_DATE_PATTERN, createGson(DEFAULT_DATE_PATTERN));
}
private static Gson createGson(String datePattern){
return new GsonBuilder().setDateFormat(datePattern).disableHtmlEscaping().serializeNulls().create();
}
public static Gson getGson() {
return gsons.get(DEFAULT_DATE_PATTERN);
}
public static Gson getGson(String datePattern) {
Gson gson = gsons.get(datePattern);
if(gson == null){
gson = createGson(datePattern);
gsons.put(datePattern, gson);
}
return gson;
}
public static GsonBuilder newGsonBuilder() {
return new GsonBuilder();
}
/**
* 将对象转换为json串
*
* @param obj
* @return
*/
public static String toJsonString(Object obj) {
if (obj == null) {
return null;
}
return getGson().toJson(obj);
}
/**
* 将对象转换为json串自定义日期转换规则
*
* @param obj
* @param datePattern
* @return
*/
public static String toJsonString(Object obj, String datePattern) {
if (obj == null) {
return null;
}
return getGson(datePattern).toJson(obj);
}
/**
* 将json串转换为对象
*
* @param clazz
* @param jsonString
* @return
*/
public static <T> T fromJson(Class<T> clazz, String jsonString) {
if (jsonString == null) {
return null;
}
return getGson().fromJson(jsonString, clazz);
}
/**
* 将json串转换为对象
*
* @Type type
* @param jsonString
* @return
*/
public static <T> T fromJson(TypeToken<T> token, String jsonString) {
if (jsonString == null) {
return null;
}
return getGson().fromJson(jsonString, token.getType());
}
/**
* 将json串转换为对象
*
* @Type type
* @param jsonString
* @return
*/
public static <T> T fromJson(TypeToken<T> token, String jsonString, String datePattern) {
if (jsonString == null) {
return null;
}
return getGson(datePattern).fromJson(jsonString, token.getType());
}
/**
* 将json串转换为对象
*
* @param clazz
* @param jsonString
* @return
*/
public static <T> T fromJson(Class<T> clazz, String jsonString, String datePattern) {
if (jsonString == null) {
return null;
}
return getGson(datePattern).fromJson(jsonString, clazz);
}
}

51
src/main/java/com/fr/plugin/ymrt/sms/util/Md5.java

@ -0,0 +1,51 @@
package com.fr.plugin.ymrt.sms.util;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/**
* @Author fr.open
* @Date 2020/9/15
* @Description
**/
public class Md5 {
/**
* MD5
* @param bytes
* @return
*/
public static String md5(byte[] bytes) {
if (bytes == null || bytes.length == 0)
return null;
String s = null;
char hexDigits[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
try {
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(bytes);
byte tmp[] = md.digest();
char str[] = new char[16 * 2];
int k = 0;
for (int i = 0; i < 16; i++) {
byte byte0 = tmp[i];
str[k++] = hexDigits[byte0 >>> 4 & 0xf];
str[k++] = hexDigits[byte0 & 0xf];
}
s = new String(str);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return s;
}
/**
* MD5[16位]
*
* @param bytes
* @return
*/
public static String md5For16(byte[] bytes) {
return md5(bytes).substring(8,24);
}
}

451
src/main/java/com/fr/plugin/ymrt/sms/util/http/HttpClient.java

@ -0,0 +1,451 @@
package com.fr.plugin.ymrt.sms.util.http;
import javax.net.ssl.*;
import java.io.*;
import java.net.*;
import java.security.*;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
/**
* @Author fr.open
* @Date 2020/9/15
* @Description
**/
public class HttpClient {
/**
* 链接超时时间(s)
*/
private int httpConnectionTimeOut = 30;
/**
* 数据传输超时时间(s)
*/
private int httpReadTimeOut = 30;
public HttpClient() {
}
/**
*
* @param httpConnectionTimeOut
* 链接超时时间(s)
* @param httpReadTimeOut
* 数据传输超时时间(s)
*/
public HttpClient(int httpConnectionTimeOut, int httpReadTimeOut) {
this.httpConnectionTimeOut = httpConnectionTimeOut;
this.httpReadTimeOut = httpReadTimeOut;
}
/**
* 发送HTTP请求
*
* @param request
* 请求
* @param praser
* 响应解析器
* @return T 响应
*/
public <T> T service(HttpRequest<?> request, HttpResponsePraser<T> praser) {
HttpResultCode code = HttpResultCode.SUCCESS;
if (request.getHttpParams().getUrl() == null || request.getHttpParams().getUrl().length() == 0) {
code = HttpResultCode.ERROR_URL_NULL;
return praser.prase(code, 0, null, null, request.getHttpParams().getCharSet(), null);
}
HttpURLConnection conn = null;
int httpCode = 0;
Map<String, String> headers = null;
List<String> cookies = null;
ByteArrayOutputStream outputStream = null;
try {
String realUrl = this.genUrl(request);
conn = this.createConnection(request, realUrl);
this.fillConnection(conn, request);
this.request(conn, request);
httpCode = conn.getResponseCode();
headers = this.getHeaders(conn, request.getHttpParams().getCharSet());
cookies = this.getCookies(conn, request.getHttpParams().getCharSet());
outputStream = this.getResultOutputStream(conn);
} catch (SocketTimeoutException e) {
code = HttpResultCode.ERROR_TIMEOUT;
e.printStackTrace();
} catch (KeyManagementException e) {
code = HttpResultCode.ERROR_HTTPS_SSL;
e.printStackTrace();
} catch (NoSuchAlgorithmException e) {
code = HttpResultCode.ERROR_HTTPS_SSL;
e.printStackTrace();
} catch (ProtocolException e) {
code = HttpResultCode.ERROR_METHOD;
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
code = HttpResultCode.ERROR_CHARSET;
e.printStackTrace();
} catch (MalformedURLException e) {
code = HttpResultCode.ERROR_URL;
httpCode = 500;
e.printStackTrace();
} catch (IOException e) {
code = HttpResultCode.ERROR_CONNECT;
e.printStackTrace();
} catch (UnrecoverableKeyException e) {
code = HttpResultCode.ERROR_HTTPS_SSL;
e.printStackTrace();
} catch (KeyStoreException e) {
code = HttpResultCode.ERROR_HTTPS_SSL;
e.printStackTrace();
} catch (CertificateException e) {
code = HttpResultCode.ERROR_HTTPS_SSL;
e.printStackTrace();
} finally {
if (conn != null) {
conn.disconnect();
}
}
T t = null;
try {
t = praser.prase(code, httpCode, headers, cookies, request.getHttpParams().getCharSet(), outputStream);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (outputStream != null) {
try {
outputStream.flush();
outputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return t;
}
private <T> String genUrl(HttpRequest<T> request) {
if (request.getHttpParams().getMethod().equalsIgnoreCase("GET")) {
String getprams = request.getContentPraser().praseRqeuestContentToString(request.getHttpParams());
if (getprams != null) {
String url = null;
if (request.getHttpParams().getUrl().indexOf("?") > 0) {
url = request.getHttpParams().getUrl() + "&" + getprams;
} else {
url = request.getHttpParams().getUrl() + "?" + getprams;
}
return url;
} else {
return request.getHttpParams().getUrl();
}
} else {
return request.getHttpParams().getUrl();
}
}
/**
* 获取HTTP响应头
*
* @param conn
* @param charSet
* @return
* @throws UnsupportedEncodingException
*/
private Map<String, String> getHeaders(HttpURLConnection conn, String charSet) throws UnsupportedEncodingException {
Map<String, String> resultHeaders = new HashMap<String, String>();
Map<String, List<String>> header = conn.getHeaderFields();
if (header != null && header.size() > 0) {
for (Entry<String, List<String>> entry : header.entrySet()) {
if (!"Set-Cookie".equalsIgnoreCase(entry.getKey())) {
String valuer = "";
if (entry.getValue() != null && entry.getValue().size() > 0) {
for (String value : entry.getValue()) {
valuer += new String(value.getBytes("ISO-8859-1"), charSet) + ",";
}
valuer = valuer.substring(0, valuer.length() - 1);
}
resultHeaders.put(entry.getKey(), valuer);
}
}
}
return resultHeaders;
}
/**
* 获取HTTP响应Cookies
*
* @param conn
* @param charSet
* @return
* @throws UnsupportedEncodingException
*/
private List<String> getCookies(HttpURLConnection conn, String charSet) throws UnsupportedEncodingException {
List<String> resultC = new ArrayList<String>();
List<String> cookies = null;
Map<String, List<String>> header = conn.getHeaderFields();
if (header != null && header.size() > 0) {
cookies = header.get("Set-Cookie");
}
if (cookies != null) {
for (String cookie : cookies) {
resultC.add(new String(cookie.getBytes("ISO-8859-1"), charSet));
}
}
return cookies;
}
/**
* 获取HTTP响应数据流
*
* @param conn
* @return
* @throws IOException
*/
private ByteArrayOutputStream getResultOutputStream(HttpURLConnection conn) throws IOException {
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
InputStream is = conn.getInputStream();
try {
if (is != null) {
byte[] buffer = new byte[1024];
int len = 0;
while ((len = is.read(buffer)) != -1) {
outStream.write(buffer, 0, len);
}
}
} catch (IOException e) {
throw e;
} finally {
if (is != null) {
is.close();
}
}
return outStream;
}
/**
* 发送Http请求
*
* @param conn
* @param request
* @throws IOException
*/
private <T> void request(HttpURLConnection conn, HttpRequest<T> request) throws IOException {
if (request.getHttpParams().getMethod().equalsIgnoreCase("POST")) {
conn.setDoOutput(true);
// conn.connect();
if (request.getHttpParams().getParams() != null) {
byte[] content = request.getContentPraser().praseRqeuestContentToBytes(request.getHttpParams());
fillHeader(conn, "Content-Length", String.valueOf(request.getContentPraser().praseRqeuestContentLength(request.getHttpParams())));
DataOutputStream out = new DataOutputStream(conn.getOutputStream());
out.write(content);
out.flush();
out.close();
}
} else {
conn.connect();
}
}
/**
* 添加请求信息
*
* @param conn
* @param request
* @throws ProtocolException
*/
private void fillConnection(HttpURLConnection conn, HttpRequest<?> request) throws ProtocolException {
this.fillTimeout(conn);
this.filleMethod(conn, request);
this.fillHeaders(conn, request);
this.fillCookies(conn, request);
}
/**
* 添加超时时间
*
* @param conn
*/
private void fillTimeout(HttpURLConnection conn) {
if (httpConnectionTimeOut != 0) {
conn.setConnectTimeout(httpConnectionTimeOut * 1000);
}
if (httpReadTimeOut != 0) {
conn.setReadTimeout(httpReadTimeOut * 1000);
}
}
/**
* 指定HTTP方法
*
* @param conn
* @param request
* @throws ProtocolException
*/
private void filleMethod(HttpURLConnection conn, HttpRequest<?> request) throws ProtocolException {
conn.setRequestMethod(request.getHttpParams().getMethod().toUpperCase());
}
/**
* 添加头信息
*
* @param conn
* @param request
*/
private void fillHeaders(HttpURLConnection conn, HttpRequest<?> request) {
if (request.getHttpParams().getHeaders() != null) {
for (Entry<String, String> entry : request.getHttpParams().getHeaders().entrySet()) {
fillHeader(conn, entry.getKey(), entry.getValue());
}
}
}
/**
* 添加头信息
*
* @param conn
* @param request
*/
private void fillHeader(HttpURLConnection conn, String key, String value) {
conn.setRequestProperty(key, value);
}
/**
* 添加Cookies
*
* @param conn
* @param request
*/
private void fillCookies(HttpURLConnection conn, HttpRequest<?> request) {
if (request.getHttpParams().getCookies() != null) {
conn.setRequestProperty("Cookie", request.getHttpParams().getCookies());
}
}
/**
* 创建Http链接
*
* @param request
* @return
* @throws NoSuchAlgorithmException
* @throws KeyManagementException
* @throws MalformedURLException
* @throws IOException
* @throws CertificateException
* @throws KeyStoreException
* @throws UnrecoverableKeyException
*/
private HttpURLConnection createConnection(HttpRequest<?> request, String realUrl)
throws NoSuchAlgorithmException, KeyManagementException, MalformedURLException, IOException, UnrecoverableKeyException, KeyStoreException, CertificateException {
URL console = new URL(realUrl);
HttpURLConnection conn;
if (request.isHttps()) {
conn = genHttpsConn(console, request);
} else {
conn = (HttpURLConnection) console.openConnection();
}
return conn;
}
private HttpURLConnection genHttpsConn(URL console, HttpRequest<?> request)
throws UnrecoverableKeyException, KeyManagementException, NoSuchAlgorithmException, KeyStoreException, CertificateException, IOException {
SSLContext ctx = getSSLContext(request.getHttpsParams());
HttpsURLConnection sconn = (HttpsURLConnection) console.openConnection();
sconn.setSSLSocketFactory(ctx.getSocketFactory());
sconn.setHostnameVerifier(new HostnameVerifier() {
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
return sconn;
}
/**
* 获得KeyStore.
*
* @param keyStorePath
* 密钥库路径
* @param password
* 密码
* @return 密钥库
* @throws KeyStoreException
* @throws IOException
* @throws CertificateException
* @throws NoSuchAlgorithmException
* @throws Exception
*/
private KeyStore getKeyStore(HttpsParams params) throws KeyStoreException, NoSuchAlgorithmException, CertificateException, IOException {
// 实例化密钥库 KeyStore用于存放证书,创建对象时 指定交换数字证书的加密标准
// 指定交换数字证书的加密标准
KeyStore ks = KeyStore.getInstance(params.getAlgorithm());
// 获得密钥库文件流
FileInputStream is = new FileInputStream(params.getKeyStorePath());
// 加载密钥库
ks.load(is, params.getPassword().toCharArray());
// 关闭密钥库文件流
is.close();
return ks;
}
/**
* 获得SSLSocketFactory.
*
* @param password
* 密码
* @param keyStorePath
* 密钥库路径
* @param trustStorePath
* 信任库路径
* @return SSLSocketFactory
* @throws NoSuchAlgorithmException
* @throws IOException
* @throws CertificateException
* @throws KeyStoreException
* @throws UnrecoverableKeyException
* @throws KeyManagementException
* @throws Exception
*/
private SSLContext getSSLContext(HttpsParams params) throws NoSuchAlgorithmException, KeyStoreException, CertificateException, IOException, UnrecoverableKeyException, KeyManagementException {
// 实例化SSL上下文
SSLContext ctx = SSLContext.getInstance("TLS");
if (params != null) {
// 实例化密钥库 KeyManager选择证书证明自己的身份
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
// 实例化信任库 TrustManager决定是否信任对方的证书
TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
// 获得密钥库
KeyStore keyStore = getKeyStore(params);
// 初始化密钥工厂
keyManagerFactory.init(keyStore, params.getPassword().toCharArray());
// 获得信任库
KeyStore trustStore = getKeyStore(params);
// 初始化信任库
trustManagerFactory.init(trustStore);
// 初始化SSL上下文
ctx.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), new java.security.SecureRandom());
} else {
ctx.init(null, new TrustManager[] { myX509TrustManager }, new java.security.SecureRandom());
}
return ctx;
}
private TrustManager myX509TrustManager = new X509TrustManager() {
@Override
public X509Certificate[] getAcceptedIssuers() {
return null;
}
@Override
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
@Override
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
};
}

94
src/main/java/com/fr/plugin/ymrt/sms/util/http/HttpRequest.java

@ -0,0 +1,94 @@
package com.fr.plugin.ymrt.sms.util.http;
/**
* @Author fr.open
* @Date 2020/9/15
* @Description
**/
public class HttpRequest<T> {
/**
* http参数
*/
private HttpRequestParams<T> httpParams;
/**
* https参数
*/
private HttpsParams httpsParams;
/**
* 内容解析器
*/
private HttpRequestPraser<T> contentPraser;
/**
* 是否https请求
*/
private boolean isHttps;
/**
*
*/
protected HttpRequest() {
}
/**
*
* @param httpParams
* http参数
* @param contentPraser
* 内容解析器
*/
protected HttpRequest(HttpRequestParams<T> httpParams, HttpRequestPraser<T> contentPraser) {
this.httpParams = httpParams;
this.contentPraser = contentPraser;
this.isHttps = false;
}
/**
*
* @param httpParams
* http参数
* @param httpsParams
* https参数
* @param contentPraser
* 内容解析器
*/
protected HttpRequest(HttpRequestParams<T> httpParams, HttpsParams httpsParams, HttpRequestPraser<T> contentPraser) {
this.httpParams = httpParams;
this.httpsParams = httpsParams;
this.contentPraser = contentPraser;
this.isHttps = true;
}
public boolean isHttps() {
return isHttps;
}
public HttpRequestParams<T> getHttpParams() {
return httpParams;
}
public void setHttpParams(HttpRequestParams<T> httpParams) {
this.httpParams = httpParams;
}
public HttpsParams getHttpsParams() {
return httpsParams;
}
public void setHttpsParams(HttpsParams httpsParams) {
this.httpsParams = httpsParams;
}
public HttpRequestPraser<T> getContentPraser() {
return contentPraser;
}
public void setContentPraser(HttpRequestPraser<T> contentPraser) {
this.contentPraser = contentPraser;
}
}

18
src/main/java/com/fr/plugin/ymrt/sms/util/http/HttpRequestBytes.java

@ -0,0 +1,18 @@
package com.fr.plugin.ymrt.sms.util.http;
/**
* @Author fr.open
* @Date 2020/9/15
* @Description
**/
public class HttpRequestBytes extends HttpRequest<byte[]> {
/**
*
* @param httpParams
* 请求参数
*/
public HttpRequestBytes(HttpRequestParams<byte[]> httpParams) {
super(httpParams, new HttpRequestPraserBytes());
}
}

22
src/main/java/com/fr/plugin/ymrt/sms/util/http/HttpRequestKV.java

@ -0,0 +1,22 @@
package com.fr.plugin.ymrt.sms.util.http;
import java.util.Map;
/**
* @Author fr.open
* @Date 2020/9/15
* @Description
**/
public class HttpRequestKV extends HttpRequest<Map<String, String>> {
/**
*
* @param httpParams
* 请求参数
*/
public HttpRequestKV(HttpRequestParams<Map<String, String>> httpParams) {
super(httpParams, new HttpRequestPraserKV());
}
}

67
src/main/java/com/fr/plugin/ymrt/sms/util/http/HttpRequestParams.java

@ -0,0 +1,67 @@
package com.fr.plugin.ymrt.sms.util.http;
import java.util.Map;
/**
* @Author fr.open
* @Date 2020/9/15
* @Description
**/
public class HttpRequestParams<T> {
private String url;// URL
private String charSet = "UTF-8";// 编码
private String method = "GET";// Http方法
private Map<String, String> headers;// 头信息
private String cookies;// cookie信息
private T params;// 传输数据
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
public String getCharSet() {
return charSet;
}
public void setCharSet(String charSet) {
this.charSet = charSet;
}
public String getMethod() {
return method;
}
public void setMethod(String method) {
this.method = method;
}
public Map<String, String> getHeaders() {
return headers;
}
public void setHeaders(Map<String, String> headers) {
this.headers = headers;
}
public String getCookies() {
return cookies;
}
public void setCookies(String cookies) {
this.cookies = cookies;
}
public T getParams() {
return params;
}
public void setParams(T params) {
this.params = params;
}
}

40
src/main/java/com/fr/plugin/ymrt/sms/util/http/HttpRequestPraser.java

@ -0,0 +1,40 @@
package com.fr.plugin.ymrt.sms.util.http;
/**
* @Author fr.open
* @Date 2020/9/15
* @Description
**/
public interface HttpRequestPraser<T> {
/**
* 将请求参数转换为String<br/>
* 主要用于get方法传输
*
* @param httpParams
* 请求参数
* @return
*/
public String praseRqeuestContentToString(HttpRequestParams<T> httpParams);
/**
* 将请求参数转换为byte[]<br/>
* 主要用于post方法传输
*
* @param httpParams
* 请求参数
* @return
*/
public byte[] praseRqeuestContentToBytes(HttpRequestParams<T> httpParams);
/**
* 获取请求参数大小<br/>
* 主要用于post方法传输
*
* @param httpParams
* 请求参数
* @return
*/
public int praseRqeuestContentLength(HttpRequestParams<T> httpParams);
}

44
src/main/java/com/fr/plugin/ymrt/sms/util/http/HttpRequestPraserBytes.java

@ -0,0 +1,44 @@
package com.fr.plugin.ymrt.sms.util.http;
import java.io.UnsupportedEncodingException;
/**
* @Author fr.open
* @Date 2020/9/15
* @Description
**/
public class HttpRequestPraserBytes implements HttpRequestPraser<byte[]> {
/**
* 请求内容字符串
*/
private String contentString;
@Override
public String praseRqeuestContentToString(HttpRequestParams<byte[]> httpParams) {
if (contentString != null) {
return contentString;
}
try {
contentString = new String(httpParams.getParams(), httpParams.getCharSet());
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return contentString;
}
@Override
public byte[] praseRqeuestContentToBytes(HttpRequestParams<byte[]> httpParams) {
return httpParams.getParams();
}
@Override
public int praseRqeuestContentLength(HttpRequestParams<byte[]> httpParams) {
if (httpParams.getParams() != null) {
return httpParams.getParams().length;
} else {
return 0;
}
}
}

71
src/main/java/com/fr/plugin/ymrt/sms/util/http/HttpRequestPraserKV.java

@ -0,0 +1,71 @@
package com.fr.plugin.ymrt.sms.util.http;
import java.io.UnsupportedEncodingException;
import java.util.Map;
import java.util.Map.Entry;
/**
* @Author fr.open
* @Date 2020/9/15
* @Description
**/
public class HttpRequestPraserKV implements HttpRequestPraser<Map<String, String>> {
/**
* 请求内容byte数组
*/
private byte[] contentBytes;
/**
* 请求内容字符串
*/
private String contentString;
@Override
public String praseRqeuestContentToString(HttpRequestParams<Map<String, String>> httpParams) {
if (contentString != null) {
return contentString;
}
Map<String, String> params = httpParams.getParams();
if (params == null || params.size() == 0) {
return null;
}
StringBuffer buffer = new StringBuffer();
for (Entry<String, String> entry : params.entrySet()) {
if (entry.getValue() != null) {
buffer.append(entry.getKey()).append("=").append(entry.getValue()).append("&");
}
}
String param = buffer.toString();
contentString = param.substring(0, param.length() - 1);
return contentString;
}
@Override
public byte[] praseRqeuestContentToBytes(HttpRequestParams<Map<String, String>> httpParams) {
if (contentBytes != null) {
return contentBytes;
}
String paramStr = praseRqeuestContentToString(httpParams);
if (paramStr == null) {
return null;
}
try {
contentBytes = paramStr.getBytes(httpParams.getCharSet());
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return contentBytes;
}
@Override
public int praseRqeuestContentLength(HttpRequestParams<Map<String, String>> httpParams) {
praseRqeuestContentToBytes(httpParams);
if (contentBytes != null) {
return contentBytes.length;
} else {
return 0;
}
}
}

46
src/main/java/com/fr/plugin/ymrt/sms/util/http/HttpRequestPraserString.java

@ -0,0 +1,46 @@
package com.fr.plugin.ymrt.sms.util.http;
import java.io.UnsupportedEncodingException;
/**
* @Author fr.open
* @Date 2020/9/15
* @Description
**/
public class HttpRequestPraserString implements HttpRequestPraser<String> {
/**
* 请求内容byte数组
*/
private byte[] contentBytes;
@Override
public String praseRqeuestContentToString(HttpRequestParams<String> httpParams) {
return httpParams.getParams();
}
@Override
public byte[] praseRqeuestContentToBytes(HttpRequestParams<String> httpParams) {
if (contentBytes != null) {
return contentBytes;
}
try {
contentBytes = httpParams.getParams().getBytes(httpParams.getCharSet());
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
contentBytes = null;
}
return contentBytes;
}
@Override
public int praseRqeuestContentLength(HttpRequestParams<String> httpParams) {
praseRqeuestContentToBytes(httpParams);
if (contentBytes != null) {
return contentBytes.length;
} else {
return 0;
}
}
}

19
src/main/java/com/fr/plugin/ymrt/sms/util/http/HttpRequestString.java

@ -0,0 +1,19 @@
package com.fr.plugin.ymrt.sms.util.http;
/**
* @Author fr.open
* @Date 2020/9/15
* @Description
**/
public class HttpRequestString extends HttpRequest<String> {
/**
*
* @param httpParams
* 请求参数
*/
public HttpRequestString(HttpRequestParams<String> httpParams) {
super(httpParams, new HttpRequestPraserString());
}
}

113
src/main/java/com/fr/plugin/ymrt/sms/util/http/HttpResponse.java

@ -0,0 +1,113 @@
package com.fr.plugin.ymrt.sms.util.http;
import java.util.List;
import java.util.Map;
/**
* @Author fr.open
* @Date 2020/9/15
* @Description
**/
public class HttpResponse<T> {
/**
* Http 结果代码
*/
private HttpResultCode resultCode;
/**
* Http链接Code
*/
private int httpCode;
/**
* Http响应头
*/
private Map<String, String> headers;
/**
* http响应Cookies
*/
private List<String> cookies;
/**
* http字符集
*/
private String charSet;
/**
* http响应数据
*/
private T result;
/**
*
* @param resultCode
* Http 结果代码
* @param httpCode
* Http链接Code
* @param headers
* Http响应头
* @param cookies
* http响应Cookies
* @param charSet
* http字符集
* @param result
* http响应数据
*/
public HttpResponse(HttpResultCode resultCode, int httpCode, Map<String, String> headers, List<String> cookies, String charSet, T result) {
this.resultCode = resultCode;
this.httpCode = httpCode;
this.headers = headers;
this.cookies = cookies;
this.charSet = charSet;
this.result = result;
}
public HttpResultCode getResultCode() {
return resultCode;
}
public void setResultCode(HttpResultCode resultCode) {
this.resultCode = resultCode;
}
public int getHttpCode() {
return httpCode;
}
public void setHttpCode(int httpCode) {
this.httpCode = httpCode;
}
public Map<String, String> getHeaders() {
return headers;
}
public void setHeaders(Map<String, String> headers) {
this.headers = headers;
}
public List<String> getCookies() {
return cookies;
}
public void setCookies(List<String> cookies) {
this.cookies = cookies;
}
public String getCharSet() {
return charSet;
}
public void setCharSet(String charSet) {
this.charSet = charSet;
}
public T getResult() {
return result;
}
public void setResult(T result) {
this.result = result;
}
}

32
src/main/java/com/fr/plugin/ymrt/sms/util/http/HttpResponseBytes.java

@ -0,0 +1,32 @@
package com.fr.plugin.ymrt.sms.util.http;
import java.util.List;
import java.util.Map;
/**
* @Author fr.open
* @Date 2020/9/15
* @Description
**/
public class HttpResponseBytes extends HttpResponse<byte[]> {
/**
*
* @param resultCode
* Http 结果代码
* @param httpCode
* Http链接Code
* @param headers
* Http响应头
* @param cookies
* http响应Cookies
* @param charSet
* http字符集
* @param result
* http响应数据
*/
public HttpResponseBytes(HttpResultCode resultCode, int httpCode, Map<String, String> headers, List<String> cookies, String charSet, byte[] result) {
super(resultCode, httpCode, headers, cookies, charSet, result);
}
}

19
src/main/java/com/fr/plugin/ymrt/sms/util/http/HttpResponseBytesPraser.java

@ -0,0 +1,19 @@
package com.fr.plugin.ymrt.sms.util.http;
import java.io.ByteArrayOutputStream;
import java.util.List;
import java.util.Map;
/**
* @Author fr.open
* @Date 2020/9/15
* @Description
**/
public class HttpResponseBytesPraser implements HttpResponsePraser<HttpResponseBytes> {
@Override
public HttpResponseBytes prase(HttpResultCode resultCode, int httpCode, Map<String, String> headers, List<String> cookies, String charSet, ByteArrayOutputStream outputStream) {
return new HttpResponseBytes(resultCode, httpCode, headers, cookies, charSet, outputStream == null ? null : outputStream.toByteArray());
}
}

32
src/main/java/com/fr/plugin/ymrt/sms/util/http/HttpResponsePraser.java

@ -0,0 +1,32 @@
package com.fr.plugin.ymrt.sms.util.http;
import java.io.ByteArrayOutputStream;
import java.util.List;
import java.util.Map;
/**
* @Author fr.open
* @Date 2020/9/15
* @Description
**/
public interface HttpResponsePraser<T> {
/**
* 解析
*
* @param resultCode
* Http 结果代码
* @param httpCode
* Http链接Code
* @param headers
* Http响应头
* @param cookies
* http响应Cookies
* @param charSet
* http字符集
* @param result
* http响应数据
*/
public T prase(HttpResultCode resultCode, int httpCode, Map<String, String> headers, List<String> cookies, String charSet, ByteArrayOutputStream outputStream);
}

33
src/main/java/com/fr/plugin/ymrt/sms/util/http/HttpResponseString.java

@ -0,0 +1,33 @@
package com.fr.plugin.ymrt.sms.util.http;
import java.util.List;
import java.util.Map;
/**
* @Author fr.open
* @Date 2020/9/15
* @Description
**/
public class HttpResponseString extends HttpResponse<String> {
/**
*
* @param resultCode
* Http 结果代码
* @param httpCode
* Http链接Code
* @param headers
* Http响应头
* @param cookies
* http响应Cookies
* @param charSet
* http字符集
* @param result
* http响应数据
*/
public HttpResponseString(HttpResultCode resultCode, int httpCode, Map<String, String> headers, List<String> cookies, String charSet, String result) {
super(resultCode, httpCode, headers, cookies, charSet, result);
}
}

30
src/main/java/com/fr/plugin/ymrt/sms/util/http/HttpResponseStringPraser.java

@ -0,0 +1,30 @@
package com.fr.plugin.ymrt.sms.util.http;
import java.io.ByteArrayOutputStream;
import java.io.UnsupportedEncodingException;
import java.util.List;
import java.util.Map;
/**
* @Author fr.open
* @Date 2020/9/15
* @Description
**/
public class HttpResponseStringPraser implements HttpResponsePraser<HttpResponseString>{
@Override
public HttpResponseString prase(HttpResultCode resultCode, int httpCode, Map<String, String> headers, List<String> cookies, String charSet, ByteArrayOutputStream outputStream) {
String st = null;
try {
if(outputStream != null){
byte[] resultBytes = outputStream.toByteArray();
st = new String(resultBytes, charSet);
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return new HttpResponseString(resultCode, httpCode, headers, cookies, charSet, st);
}
}

69
src/main/java/com/fr/plugin/ymrt/sms/util/http/HttpResultCode.java

@ -0,0 +1,69 @@
package com.fr.plugin.ymrt.sms.util.http;
/**
* @Author fr.open
* @Date 2020/9/15
* @Description
**/
public enum HttpResultCode {
SUCCESS("成功", "SUCCESS"), //
ERROR_URL_NULL("URL为空", "ERROR-URL-NULL"), //
ERROR_URL("URL访问失败", "ERROR-URL"), //
ERROR_HTTPS_SSL("HTTPS异常", "ERROR-HTTPS-SSL"), //
ERROR_METHOD("HTTP方法无法识别", "ERROR-METHOD"), //
ERROR_CHARSET("编码错误", "ERROR-CHARSET"), //
ERROR_CONNECT("访问失败", "ERROR-CONNECT"), //
ERROR_TIMEOUT("访问超时", "ERROR-TIMEOUT"), //
;
/**
* 名称
*/
private String name;
/**
* 编码
*/
private String code;
private HttpResultCode(String name, String code) {
this.name = name;
this.code = code;
}
public static String findNameByCode(String code) {
for (HttpResultCode oc : HttpResultCode.values()) {
if (oc.getCode().equals(code)) {
return oc.getName();
}
}
return null;
}
public static String findCodeByName(String name) {
for (HttpResultCode oc : HttpResultCode.values()) {
if (oc.getName().equals(name)) {
return oc.getCode();
}
}
return null;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
}

47
src/main/java/com/fr/plugin/ymrt/sms/util/http/HttpsParams.java

@ -0,0 +1,47 @@
package com.fr.plugin.ymrt.sms.util.http;
/**
* @Author fr.open
* @Date 2020/9/15
* @Description
**/
public class HttpsParams {
private String password;// 密钥库密钥
private String keyStorePath;// 密钥库文件地址
private String trustStorePath;// 信任库文件地址
private String algorithm;// 指定交换数字证书的加密标准:JKS
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getKeyStorePath() {
return keyStorePath;
}
public void setKeyStorePath(String keyStorePath) {
this.keyStorePath = keyStorePath;
}
public String getTrustStorePath() {
return trustStorePath;
}
public void setTrustStorePath(String trustStorePath) {
this.trustStorePath = trustStorePath;
}
public String getAlgorithm() {
return algorithm;
}
public void setAlgorithm(String algorithm) {
this.algorithm = algorithm;
}
}

21
src/main/java/com/fr/plugin/ymrt/sms/util/http/HttpsRequestBytes.java

@ -0,0 +1,21 @@
package com.fr.plugin.ymrt.sms.util.http;
/**
* @Author fr.open
* @Date 2020/9/15
* @Description
**/
public class HttpsRequestBytes extends HttpRequest<byte[]> {
/**
*
* @param httpParams
* http请求参数
* @param httpsParams
* https参数
*/
public HttpsRequestBytes(HttpRequestParams<byte[]> httpParams, HttpsParams httpsParams) {
super(httpParams, httpsParams, new HttpRequestPraserBytes());
}
}

22
src/main/java/com/fr/plugin/ymrt/sms/util/http/HttpsRequestKV.java

@ -0,0 +1,22 @@
package com.fr.plugin.ymrt.sms.util.http;
import java.util.Map;
/**
* @Author fr.open
* @Date 2020/9/15
* @Description
**/
public class HttpsRequestKV extends HttpRequest<Map<String, String>> {
/**
*
* @param httpParams
* http请求参数
* @param httpsParams
* https参数
*/
public HttpsRequestKV(HttpRequestParams<Map<String, String>> httpParams, HttpsParams httpsParams) {
super(httpParams, httpsParams, new HttpRequestPraserKV());
}
}

21
src/main/java/com/fr/plugin/ymrt/sms/util/http/HttpsRequestString.java

@ -0,0 +1,21 @@
package com.fr.plugin.ymrt.sms.util.http;
/**
* @Author fr.open
* @Date 2020/9/15
* @Description
**/
public class HttpsRequestString extends HttpRequest<String> {
/**
*
* @param httpParams
* http请求参数
* @param httpsParams
* https参数
*/
public HttpsRequestString(HttpRequestParams<String> httpParams, HttpsParams httpsParams) {
super(httpParams, httpsParams, new HttpRequestPraserString());
}
}

2
src/main/resources/com/fr/plugin/ymrt/sms/locale/sms.properties

@ -0,0 +1,2 @@
Dec-Module-DingTalk_Manager=Dec-Module-DingTalk_Manager

1
src/main/resources/com/fr/plugin/ymrt/sms/locale/sms_zh_CN.properties

@ -0,0 +1 @@
Dec-Module-DingTalk_Manager=\u9489\u9489\u7BA1\u7406

187
src/main/resources/com/fr/plugin/ymrt/sms/theme.js

@ -0,0 +1,187 @@
!(function () {
/*var Item = BI.inherit(BI.Widget, {
props: {
text: "",
textWidth: 115,
textAlign: "left",
textCls: "",
validationChecker: BI.emptyFn,
value: "",
allowBlank: true,
inputType: "text",
editorWidth: 300,
errorTop: 0,
el: {},
bubbleError: true,
},
render: function () {
var self = this, o = this.options;
return {
type: "bi.vertical_adapt",
height: 24,
items: [{
el: {
type: "bi.label",
cls: o.textCls,
text: o.text,
title: o.text,
textHeight: 24,
width: o.textWidth,
textAlign: o.textAlign,
},
rgap: o.textRGap,
}, {
type: "dec.error_label",
width: o.editorWidth,
errorTop: o.errorTop,
el: BI.extend({
type: "bi.textarea_editor",
$value: "dec-label-textarea-editor-item-" + (o.$value ? o.$value : o.text),
cls: "bi-border bi-border-radius",
watermark: o.watermark,
inputType: o.inputType,
width: 300,
height: 200,
value: o.value,
allowBlank: o.allowBlank,
validationChecker: o.validationChecker,
errorText: o.bubbleError ? o.errorText : "",
ref: function (_ref) {
self.editor = _ref;
},
listeners: [{
eventName: BI.TextAreaEditor.EVENT_FOCUS,
action: function () {
self.hideError();
self.fireEvent(BI.TextAreaEditor.EVENT_FOCUS, arguments);
},
}, {
eventName: BI.TextAreaEditor.EVENT_CHANGE,
action: function () {
self.fireEvent(BI.TextAreaEditor.EVENT_CHANGE, arguments);
self.hideError();
},
}, {
eventName: BI.TextAreaEditor.EVENT_CONFIRM,
action: function () {
self.fireEvent(BI.TextAreaEditor.EVENT_CONFIRM, arguments);
},
}, {
eventName: BI.TextAreaEditor.EVENT_BLUR,
action: function () {
self.fireEvent(BI.TextAreaEditor.EVENT_BLUR, arguments);
},
}, {
eventName: BI.TextAreaEditor.EVENT_ERROR,
action: function (v) {
if (!o.bubbleError && BI.isNotNull(o.errorText) && self.editor.isEditing()) {
self.showError(BI.isFunction(o.errorText) ? o.errorText(v) : o.errorText);
}
},
}, {
eventName: BI.TextAreaEditor.EVENT_VALID,
action: function () {
self.hideError();
},
}],
}, o.el),
ref: function (_ref) {
self.editorError = _ref;
},
}],
};
},
getValue: function () {
return this.editor.getValue();
},
setValue: function (v) {
this.editor.setValue(v);
this.hideError();
},
setWaterMark: function (v) {
this.editor.setWaterMark(v);
},
showError: function (text) {
this.editorError.showError(text);
},
focus: function () {
this.editor.focus();
},
hideError: function () {
this.editorError.hideError();
},
});
BI.shortcut("dec.label.textarea.editor.item", Item);*/
var Plugin = BI.inherit(BI.Widget, {
props: {
baseCls: "",
value: {
content: null,
}
},
render: function () {
var t = this,
e = this.options.value[0]==undefined?{content: null}: this.options.value[0];
return {
type: "bi.flex_vertical",
tgap: 15,
items: [{
type: "dec.label.editor.item",
errorTop: 16,
textCls: "dec-font-weight-bold",
text: "正文",
textWidth: 115,
editorWidth: 300,
value: e.content,
ref: function(e) {
t.content = e
}
}]
};
},
/**
*
*
* @returns {boolean}
*/
validation: function () {
var e = !0,
t = this.isVisible();
return BI.isEmpty(this.content.getValue()) && (t && this.content.showError(BI.i18nText("Dec-Error_Null")), e = !1),
e
},
/**
*
* outputActionList
* @returns {{}}
*/
getValue: function() {
var _self= this;
return {OutputSmsAction: BI.extend(_self.value,{
"@class": "com.fr.plugin.ymrt.sms.bean.OutputSmsAction",
actionName: "com.fr.plugin.ymrt.sms.bean.OutputSmsAction",
content: _self.content.getValue(),
})}
},
});
BI.shortcut("dec.schedule.task.file.handling.plugin", Plugin);
BI.config("dec.provider.schedule", function (provider) {
provider.registerHandingWay({
text: "第三方短信通知",
value: "com.fr.plugin.ymrt.sms.bean.OutputSmsAction", // actionName
cardType: "dec.schedule.task.file.handling.plugin",
actions: [] // action
}, [DecCst.Schedule.TaskType.DEFAULT, DecCst.Schedule.TaskType.REPORT, DecCst.Schedule.TaskType.BI]);
});
}());

5
ymrt.properties

@ -0,0 +1,5 @@
appId=xxxx
secretKey=xxxx
host=http://xxxxx
customSmsId=
extendedCode=
Loading…
Cancel
Save