Browse Source

提交开源任务材料

master
LAPTOP-SB56SG4Q\86185 3 years ago
commit
0606303903
  1. BIN
      JSD-9204需求确认书.docx
  2. 6
      README.md
  3. BIN
      facaiyuApiDocV2.0.pdf
  4. BIN
      lib/finekit-10.0.jar
  5. BIN
      lib/gson-2.8.6.jar
  6. 24
      plugin.xml
  7. 41
      src/main/java/com/fr/plugin/third/party/jsdjcae/sms/OutputPluginLifecycleMonitor.java
  8. 33
      src/main/java/com/fr/plugin/third/party/jsdjcae/sms/ResultModel.java
  9. 43
      src/main/java/com/fr/plugin/third/party/jsdjcae/sms/SmsDBAccess.java
  10. 26
      src/main/java/com/fr/plugin/third/party/jsdjcae/sms/SmsFormulaProvider.java
  11. 27
      src/main/java/com/fr/plugin/third/party/jsdjcae/sms/SmsOutputFormulaExtractor.java
  12. 188
      src/main/java/com/fr/plugin/third/party/jsdjcae/sms/Utils.java
  13. 92
      src/main/java/com/fr/plugin/third/party/jsdjcae/sms/bean/OutputSmsAction.java
  14. 78
      src/main/java/com/fr/plugin/third/party/jsdjcae/sms/config/CustomDataConfig.java
  15. 21
      src/main/java/com/fr/plugin/third/party/jsdjcae/sms/dao/SmsDao.java
  16. 82
      src/main/java/com/fr/plugin/third/party/jsdjcae/sms/entity/SmsEntity.java
  17. 140
      src/main/java/com/fr/plugin/third/party/jsdjcae/sms/handle/AESUtil.java
  18. 59
      src/main/java/com/fr/plugin/third/party/jsdjcae/sms/handle/SMSUtils.java
  19. 136
      src/main/java/com/fr/plugin/third/party/jsdjcae/sms/handle/SmsOutputActionHandler.java
  20. 43
      src/main/java/com/fr/plugin/third/party/jsdjcae/sms/inter/framework/dto/CustomSmsIdAndMobile.java
  21. 54
      src/main/java/com/fr/plugin/third/party/jsdjcae/sms/inter/framework/dto/CustomSmsIdAndMobileAndContent.java
  22. 76
      src/main/java/com/fr/plugin/third/party/jsdjcae/sms/inter/framework/dto/PersonalityParams.java
  23. 60
      src/main/java/com/fr/plugin/third/party/jsdjcae/sms/inter/framework/dto/TemplateSmsIdAndMobile.java
  24. 12
      src/main/java/com/fr/plugin/third/party/jsdjcae/sms/inter/http/v1/dto/request/BalanceRequest.java
  25. 43
      src/main/java/com/fr/plugin/third/party/jsdjcae/sms/inter/http/v1/dto/request/BaseRequest.java
  26. 32
      src/main/java/com/fr/plugin/third/party/jsdjcae/sms/inter/http/v1/dto/request/MoRequest.java
  27. 32
      src/main/java/com/fr/plugin/third/party/jsdjcae/sms/inter/http/v1/dto/request/ReportRequest.java
  28. 32
      src/main/java/com/fr/plugin/third/party/jsdjcae/sms/inter/http/v1/dto/request/ShortLinkRequest.java
  29. 39
      src/main/java/com/fr/plugin/third/party/jsdjcae/sms/inter/http/v1/dto/request/SmsBaseRequest.java
  30. 39
      src/main/java/com/fr/plugin/third/party/jsdjcae/sms/inter/http/v1/dto/request/SmsBatchOnlyRequest.java
  31. 41
      src/main/java/com/fr/plugin/third/party/jsdjcae/sms/inter/http/v1/dto/request/SmsBatchRequest.java
  32. 26
      src/main/java/com/fr/plugin/third/party/jsdjcae/sms/inter/http/v1/dto/request/SmsPersonalityAllRequest.java
  33. 26
      src/main/java/com/fr/plugin/third/party/jsdjcae/sms/inter/http/v1/dto/request/SmsPersonalityRequest.java
  34. 60
      src/main/java/com/fr/plugin/third/party/jsdjcae/sms/inter/http/v1/dto/request/SmsShortLinkBatchRequest.java
  35. 53
      src/main/java/com/fr/plugin/third/party/jsdjcae/sms/inter/http/v1/dto/request/SmsSingleRequest.java
  36. 35
      src/main/java/com/fr/plugin/third/party/jsdjcae/sms/inter/http/v1/dto/request/TemplateSmsSendRequest.java
  37. 34
      src/main/java/com/fr/plugin/third/party/jsdjcae/sms/inter/http/v1/dto/response/BalanceResponse.java
  38. 65
      src/main/java/com/fr/plugin/third/party/jsdjcae/sms/inter/http/v1/dto/response/MoResponse.java
  39. 94
      src/main/java/com/fr/plugin/third/party/jsdjcae/sms/inter/http/v1/dto/response/ReportResponse.java
  40. 45
      src/main/java/com/fr/plugin/third/party/jsdjcae/sms/inter/http/v1/dto/response/ResponseData.java
  41. 90
      src/main/java/com/fr/plugin/third/party/jsdjcae/sms/inter/http/v1/dto/response/ShortLinkReportResponse.java
  42. 57
      src/main/java/com/fr/plugin/third/party/jsdjcae/sms/inter/http/v1/dto/response/SmsResponse.java
  43. 57
      src/main/java/com/fr/plugin/third/party/jsdjcae/sms/inter/http/v1/dto/response/SmsTemplateResponse.java
  44. 55
      src/main/java/com/fr/plugin/third/party/jsdjcae/sms/js/FileDef.java
  45. 28
      src/main/java/com/fr/plugin/third/party/jsdjcae/sms/js/JSCSSBridge.java
  46. 140
      src/main/java/com/fr/plugin/third/party/jsdjcae/sms/util/AES.java
  47. 134
      src/main/java/com/fr/plugin/third/party/jsdjcae/sms/util/DateUtil.java
  48. 105
      src/main/java/com/fr/plugin/third/party/jsdjcae/sms/util/GZIPUtils.java
  49. 129
      src/main/java/com/fr/plugin/third/party/jsdjcae/sms/util/JsonHelper.java
  50. 51
      src/main/java/com/fr/plugin/third/party/jsdjcae/sms/util/Md5.java
  51. 451
      src/main/java/com/fr/plugin/third/party/jsdjcae/sms/util/http/HttpClient.java
  52. 94
      src/main/java/com/fr/plugin/third/party/jsdjcae/sms/util/http/HttpRequest.java
  53. 19
      src/main/java/com/fr/plugin/third/party/jsdjcae/sms/util/http/HttpRequestBytes.java
  54. 22
      src/main/java/com/fr/plugin/third/party/jsdjcae/sms/util/http/HttpRequestKV.java
  55. 67
      src/main/java/com/fr/plugin/third/party/jsdjcae/sms/util/http/HttpRequestParams.java
  56. 40
      src/main/java/com/fr/plugin/third/party/jsdjcae/sms/util/http/HttpRequestPraser.java
  57. 44
      src/main/java/com/fr/plugin/third/party/jsdjcae/sms/util/http/HttpRequestPraserBytes.java
  58. 71
      src/main/java/com/fr/plugin/third/party/jsdjcae/sms/util/http/HttpRequestPraserKV.java
  59. 46
      src/main/java/com/fr/plugin/third/party/jsdjcae/sms/util/http/HttpRequestPraserString.java
  60. 19
      src/main/java/com/fr/plugin/third/party/jsdjcae/sms/util/http/HttpRequestString.java
  61. 113
      src/main/java/com/fr/plugin/third/party/jsdjcae/sms/util/http/HttpResponse.java
  62. 32
      src/main/java/com/fr/plugin/third/party/jsdjcae/sms/util/http/HttpResponseBytes.java
  63. 19
      src/main/java/com/fr/plugin/third/party/jsdjcae/sms/util/http/HttpResponseBytesPraser.java
  64. 32
      src/main/java/com/fr/plugin/third/party/jsdjcae/sms/util/http/HttpResponsePraser.java
  65. 33
      src/main/java/com/fr/plugin/third/party/jsdjcae/sms/util/http/HttpResponseString.java
  66. 30
      src/main/java/com/fr/plugin/third/party/jsdjcae/sms/util/http/HttpResponseStringPraser.java
  67. 69
      src/main/java/com/fr/plugin/third/party/jsdjcae/sms/util/http/HttpResultCode.java
  68. 47
      src/main/java/com/fr/plugin/third/party/jsdjcae/sms/util/http/HttpsParams.java
  69. 21
      src/main/java/com/fr/plugin/third/party/jsdjcae/sms/util/http/HttpsRequestBytes.java
  70. 23
      src/main/java/com/fr/plugin/third/party/jsdjcae/sms/util/http/HttpsRequestKV.java
  71. 21
      src/main/java/com/fr/plugin/third/party/jsdjcae/sms/util/http/HttpsRequestString.java
  72. 219
      src/main/resources/com/fr/plugin/third/party/jsdjcae/sms/theme.js

BIN
JSD-9204需求确认书.docx

Binary file not shown.

6
README.md

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

BIN
facaiyuApiDocV2.0.pdf

Binary file not shown.

BIN
lib/finekit-10.0.jar

Binary file not shown.

BIN
lib/gson-2.8.6.jar

Binary file not shown.

24
plugin.xml

@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?><plugin>
<id>com.fr.plugin.third.party.jsdjcae</id>
<name><![CDATA[第三方定制短信]]></name>
<active>yes</active>
<version>0.3</version>
<env-version>10.0</env-version>
<jartime>2018-07-31</jartime>
<vendor>fr.open</vendor>
<description><![CDATA[]]></description>
<change-notes><![CDATA[
]]></change-notes>
<lifecycle-monitor class="com.fr.plugin.third.party.jsdjcae.sms.OutputPluginLifecycleMonitor"/>
<extra-core>
</extra-core>
<extra-decision>
<!--插件注入处理公式的类-->
<OutputFormulaProvider class="com.fr.plugin.third.party.jsdjcae.sms.SmsFormulaProvider"/>
<!--插件注入提取公式的类-->
<OutputFormulaExtractorProvider class="com.fr.plugin.third.party.jsdjcae.sms.SmsOutputFormulaExtractor"/>
<WebResourceProvider class="com.fr.plugin.third.party.jsdjcae.sms.js.JSCSSBridge"/>
<DecisionDBAccessProvider class="com.fr.plugin.third.party.jsdjcae.sms.SmsDBAccess"/>
</extra-decision>
<function-recorder class="com.fr.plugin.third.party.jsdjcae.sms.OutputPluginLifecycleMonitor"/>
</plugin>

41
src/main/java/com/fr/plugin/third/party/jsdjcae/sms/OutputPluginLifecycleMonitor.java

@ -0,0 +1,41 @@
package com.fr.plugin.third.party.jsdjcae.sms;
import com.fr.intelli.record.Focus;
import com.fr.intelli.record.Original;
import com.fr.plugin.context.PluginContext;
import com.fr.plugin.observer.inner.AbstractPluginLifecycleMonitor;
import com.fr.plugin.third.party.jsdjcae.sms.bean.OutputSmsAction;
import com.fr.plugin.third.party.jsdjcae.sms.config.CustomDataConfig;
import com.fr.plugin.third.party.jsdjcae.sms.entity.SmsEntity;
import com.fr.plugin.third.party.jsdjcae.sms.handle.SmsOutputActionHandler;
import com.fr.record.analyzer.EnableMetrics;
import com.fr.schedule.feature.ScheduleOutputActionEntityRegister;
import com.fr.schedule.feature.output.OutputActionHandler;
import com.fr.stable.fun.Authorize;
/**
* @Author fr.open
* @Date 2020/9/15
* @Description
**/
/**
* 配置信息初始化
*/
@EnableMetrics
@Authorize(callSignKey = "com.fr.plugin.third.party.jsdjcae")
public class OutputPluginLifecycleMonitor extends AbstractPluginLifecycleMonitor {
@Override
@Focus(id = "com.fr.plugin.third.party.jsdjcae", text = "plugin-jsdjcae", source = Original.PLUGIN)
public void afterRun(PluginContext pluginContext) {
OutputActionHandler.registerHandler(new SmsOutputActionHandler(), OutputSmsAction.class.getName());
ScheduleOutputActionEntityRegister.getInstance().addClass(SmsEntity.class);
CustomDataConfig.getInstance();
}
@Override
public void beforeStop(PluginContext pluginContext) {
OutputActionHandler.removeOutputHandler(OutputSmsAction.class.getName());
ScheduleOutputActionEntityRegister.getInstance().removeClass(SmsEntity.class);
}
}

33
src/main/java/com/fr/plugin/third/party/jsdjcae/sms/ResultModel.java

@ -0,0 +1,33 @@
package com.fr.plugin.third.party.jsdjcae.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;
}
}

43
src/main/java/com/fr/plugin/third/party/jsdjcae/sms/SmsDBAccess.java

@ -0,0 +1,43 @@
package com.fr.plugin.third.party.jsdjcae.sms;
import com.fr.decision.plugin.db.AbstractDecisionDBAccessProvider;
import com.fr.plugin.third.party.jsdjcae.sms.dao.SmsDao;
import com.fr.plugin.third.party.jsdjcae.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/third/party/jsdjcae/sms/SmsFormulaProvider.java

@ -0,0 +1,26 @@
package com.fr.plugin.third.party.jsdjcae.sms;
import com.fr.main.workbook.ResultWorkBook;
import com.fr.plugin.third.party.jsdjcae.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();
}
}

27
src/main/java/com/fr/plugin/third/party/jsdjcae/sms/SmsOutputFormulaExtractor.java

@ -0,0 +1,27 @@
package com.fr.plugin.third.party.jsdjcae.sms;
import com.fr.plugin.third.party.jsdjcae.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);
}
}

188
src/main/java/com/fr/plugin/third/party/jsdjcae/sms/Utils.java

@ -0,0 +1,188 @@
package com.fr.plugin.third.party.jsdjcae.sms;
import com.fanruan.api.log.LogKit;
import com.fanruan.api.util.StringKit;
import com.fr.third.org.apache.http.HttpEntity;
import com.fr.third.org.apache.http.HttpStatus;
import com.fr.third.org.apache.http.client.config.RequestConfig;
import com.fr.third.org.apache.http.client.methods.CloseableHttpResponse;
import com.fr.third.org.apache.http.client.methods.HttpGet;
import com.fr.third.org.apache.http.client.methods.HttpPost;
import com.fr.third.org.apache.http.conn.ssl.NoopHostnameVerifier;
import com.fr.third.org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import com.fr.third.org.apache.http.entity.StringEntity;
import com.fr.third.org.apache.http.impl.client.CloseableHttpClient;
import com.fr.third.org.apache.http.impl.client.HttpClients;
import com.fr.third.org.apache.http.ssl.SSLContextBuilder;
import com.fr.third.org.apache.http.ssl.TrustStrategy;
import com.fr.third.org.apache.http.util.EntityUtils;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.UUID;
public class Utils {
public static String DEFAULT_USER_AGENT = "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36";
public static RequestConfig REQUEST_CONFIG = RequestConfig.custom()
.setConnectionRequestTimeout(30000)
.setSocketTimeout(30000) // 服务端相应超时
.setConnectTimeout(30000) // 建立socket链接超时时间
.build();
public static CloseableHttpClient createSSLClientDefault() {
try {
SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustStrategy() {
@Override
public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {
return true;
}
}).build();
HostnameVerifier hostnameVerifier = NoopHostnameVerifier.INSTANCE;
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, hostnameVerifier);
return HttpClients.custom().setSSLSocketFactory(sslsf).build();
} catch (Exception e) {
LogKit.error(e.getMessage(), e);
}
return HttpClients.createDefault();
}
public static synchronized CloseableHttpClient createHttpClient(String url) {
CloseableHttpClient httpClient = null;
if (StringKit.isEmpty(url)) {
httpClient = HttpClients.createDefault();
return httpClient;
}
if (url.startsWith("https://")) {
httpClient = createSSLClientDefault();
return httpClient;
}
httpClient = HttpClients.createDefault();
return httpClient;
}
public static synchronized String createHttpGetContent(CloseableHttpClient httpClient, String url, String basicAuth) throws IOException {
if ((httpClient == null) || (StringKit.isEmpty(url))) {
return "";
}
HttpGet httpGet = new HttpGet(url);
httpGet.addHeader("User-Agent", Utils.DEFAULT_USER_AGENT);
if (StringKit.isNotEmpty(basicAuth)) {
httpGet.addHeader("Authorization", basicAuth);
}
httpGet.setConfig(Utils.REQUEST_CONFIG);
CloseableHttpResponse response = httpClient.execute(httpGet);
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode != HttpStatus.SC_OK) {
response.close();
LogKit.info("http请求出错,http status:" + statusCode);
return "";
}
HttpEntity httpEntity = response.getEntity();
if (httpEntity == null) {
response.close();
LogKit.info("http请求出错,http响应内容为空");
return "";
}
String responseContent = EntityUtils.toString(httpEntity, "UTF-8");
response.close();
if (StringKit.isEmpty(responseContent)) {
LogKit.info("http请求出错,http响应内容为空1");
return "";
}
return responseContent;
}
public static synchronized String createHttpPostContent(CloseableHttpClient httpClient, String url, String bodyContent, String basicAuth,String contentType) throws IOException {
if ((httpClient == null) || (StringKit.isEmpty(url))) {
return "";
}
HttpPost httpPost = new HttpPost(url);
httpPost.addHeader("User-Agent", Utils.DEFAULT_USER_AGENT);
httpPost.setConfig(Utils.REQUEST_CONFIG);
if (StringKit.isNotEmpty(basicAuth)) {
httpPost.addHeader("Authorization", basicAuth);
}
if (StringKit.isNotEmpty(contentType)) {
httpPost.addHeader("Content-Type", contentType);
}
StringEntity bodyEntity = new StringEntity(bodyContent, "UTF-8");
httpPost.setEntity(bodyEntity);
CloseableHttpResponse response = httpClient.execute(httpPost);
int statusCode = response.getStatusLine().getStatusCode();
if (statusCode != HttpStatus.SC_OK) {
response.close();
LogKit.info("http请求出错,http status:" + statusCode);
return "";
}
HttpEntity httpEntity = response.getEntity();
if (httpEntity == null) {
response.close();
LogKit.info("http请求出错,http响应内容为空");
return "";
}
String responseContent = EntityUtils.toString(httpEntity, "UTF-8");
response.close();
if (StringKit.isEmpty(responseContent)) {
LogKit.info("http请求出错,http响应内容为空1");
return "";
}
return responseContent;
}
/**
* 获取完整请求链接
*
* @param req 请求
* @return
*/
public static String getFullRequestUrl(HttpServletRequest req) {
if (req == null) {
return "";
}
String url = req.getRequestURL().toString();
String queryUrl = req.getQueryString();
if ((queryUrl == null) || "null".equalsIgnoreCase(queryUrl)) {
queryUrl = "";
} else {
queryUrl = "?" + queryUrl;
}
String fullUrl = url + queryUrl;
return fullUrl;
}
/**
* 重定向
*
* @param res
* @param url
*/
public static void sendRedirect(HttpServletResponse res, String url) {
if ((res == null) || (StringKit.isEmpty(url))) {
return;
}
res.setStatus(HttpServletResponse.SC_MOVED_TEMPORARILY);
res.setHeader("Location", url);
}
public static synchronized String getUuid() {
String uuid = UUID.randomUUID().toString().replace("-", "");
return uuid;
}
}

92
src/main/java/com/fr/plugin/third/party/jsdjcae/sms/bean/OutputSmsAction.java

@ -0,0 +1,92 @@
package com.fr.plugin.third.party.jsdjcae.sms.bean;
import com.fr.plugin.third.party.jsdjcae.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 = "";
private String phone = "";
private String datasetName= "";
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).phone(this.phone).datasetName(this.datasetName);
}
@Override
public OutputSmsAction id(String id) {
setId(id);
return this;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getDatasetName() {
return datasetName;
}
public void setDatasetName(String datasetName) {
this.datasetName = datasetName;
}
public OutputSmsAction content(String value) {
setContent(value);
return this;
}
public OutputSmsAction phone(String value) {
setPhone(value);
return this;
}
public OutputSmsAction datasetName(String value) {
setDatasetName(value);
return this;
}
}

78
src/main/java/com/fr/plugin/third/party/jsdjcae/sms/config/CustomDataConfig.java

@ -0,0 +1,78 @@
package com.fr.plugin.third.party.jsdjcae.sms.config;
import com.fr.config.*;
import com.fr.config.holder.Conf;
import com.fr.config.holder.factory.Holders;
/**
* 配置数据保存
*/
@Visualization(category = "第三方定制短信配置")
public class CustomDataConfig extends DefaultConfiguration {
public String getNameSpace() {
return this.getClass().getName();
}
private static volatile CustomDataConfig config = null;
public static CustomDataConfig getInstance() {
if (config == null) {
config = ConfigContext.getConfigInstance(CustomDataConfig.class);
}
return config;
}
@Identifier(value = "dataSyncUrl", name = "短信发送地址", description = "", status = Status.SHOW)
private Conf<String> dataSyncUrl = Holders.simple("xxxx");
@Identifier(value = "dataUsername", name = "短信用户名", description = "", status = Status.SHOW)
private Conf<String> dataUsername = Holders.simple("xxxx");
@Identifier(value = "dataPassword", name = "短信密码", description = "", status = Status.SHOW)
private Conf<String> dataPassword = Holders.simple("xxxx");
@Identifier(value = "smskey", name = "短信数字签名Key", description = "", status = Status.SHOW)
private Conf<String> smskey = Holders.simple("xxxxx");
public String getDataSyncUrl() {
return dataSyncUrl.get();
}
public void setDataSyncUrl(String dataSyncUrl) {
this.dataSyncUrl.set(dataSyncUrl);
}
public String getDataUsername() {
return dataUsername.get();
}
public void setDataUsername(String dataUsername) {
this.dataUsername.set(dataUsername);
}
public String getDataPassword() {
return dataPassword.get();
}
public void setDataPassword(String dataPassword) {
this.dataPassword.set(dataPassword);
}
public String getSmskey() {
return smskey.get();
}
public void setSmskey(String smskey) {
this.smskey.set(smskey);
}
@Override
public Object clone() throws CloneNotSupportedException {
CustomDataConfig cloned = (CustomDataConfig) super.clone();
cloned.dataSyncUrl = (Conf<String>) dataSyncUrl.clone();
cloned.dataUsername = (Conf<String>) dataUsername.clone();
cloned.dataPassword = (Conf<String>) dataPassword.clone();
cloned.smskey = (Conf<String>) smskey.clone();
return cloned;
}
}

21
src/main/java/com/fr/plugin/third/party/jsdjcae/sms/dao/SmsDao.java

@ -0,0 +1,21 @@
package com.fr.plugin.third.party.jsdjcae.sms.dao;
import com.fr.plugin.third.party.jsdjcae.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;
}
}

82
src/main/java/com/fr/plugin/third/party/jsdjcae/sms/entity/SmsEntity.java

@ -0,0 +1,82 @@
package com.fr.plugin.third.party.jsdjcae.sms.entity;
import com.fr.plugin.third.party.jsdjcae.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;
@Column(name = "phone",length = 1000)
private String phone;
@Column(name = "datasetName",length = 1000)
private String datasetName;
public SmsEntity() {
}
@Override
public BaseBean createBean() {
return new OutputSmsAction().id(this.getId()).content(this.content).phone(this.phone).datasetName(this.datasetName);
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getDatasetName() {
return datasetName;
}
public void setDatasetName(String datasetName) {
this.datasetName = datasetName;
}
public SmsEntity content(String value) {
setContent(value);
return this;
}
public SmsEntity phone(String value) {
setPhone(value);
return this;
}
public SmsEntity datasetName(String value) {
setDatasetName(value);
return this;
}
public SmsEntity id(String id) {
setId(id);
return this;
}
}

140
src/main/java/com/fr/plugin/third/party/jsdjcae/sms/handle/AESUtil.java

@ -0,0 +1,140 @@
package com.fr.plugin.third.party.jsdjcae.sms.handle;
import java.security.MessageDigest;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
public class AESUtil {
/**
* 将16进制转换为二进制   
*
* @param hexStr
*   
* @return   
*/
public static byte[] parseHexStr2Byte(String hexStr) {
if (hexStr.length() < 1)
return null;
byte[] result = new byte[hexStr.length() / 2];
for (int i = 0; i < hexStr.length() / 2; i++) {
int high = Integer.parseInt(hexStr.substring(i * 2, i * 2 + 1), 16);
int low = Integer.parseInt(hexStr.substring(i * 2 + 1, i * 2 + 2),
16);
result[i] = (byte) (high * 16 + low);
}
return result;
}
/**
* 将二进制转换成16进制   
*
* @param buf
*   
* @return   
*/
public static String parseByte2HexStr(byte buf[]) {
StringBuffer sb = new StringBuffer();
for (int i = 0; i < buf.length; i++) {
String hex = Integer.toHexString(buf[i] & 0xFF);
if (hex.length() == 1) {
hex = '0' + hex;
}
sb.append(hex.toUpperCase());
}
return sb.toString();
}
/**
* 加密   
*
* @param content
* 需要加密的内容   
* @param password
* 加密密码   
* @return   
*/
public static String encrypt(String content, String password) {
try {
Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding");
int blockSize = cipher.getBlockSize();
byte[] dataBytes = content.getBytes();
int plaintextLength = dataBytes.length;
if (plaintextLength % blockSize != 0) {
plaintextLength = plaintextLength
+ (blockSize - (plaintextLength % blockSize));
}
byte[] plaintext = new byte[plaintextLength];
System.arraycopy(dataBytes, 0, plaintext, 0, dataBytes.length);
SecretKeySpec keyspec = new SecretKeySpec(password.getBytes(), "AES");
IvParameterSpec ivspec = new IvParameterSpec(password.getBytes());
cipher.init(Cipher.ENCRYPT_MODE, keyspec, ivspec);
byte[] encrypted = cipher.doFinal(plaintext);
return parseByte2HexStr(encrypted);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
/**
* @Title随机生成16为大小写字母+数字
* @return String
* */
public static String getCharAndNumr() {
String val = "";
Random random = new Random();
for (int i = 0; i < 16; i++) {
String charOrNum = random.nextInt(2) % 2 == 0 ? "char" : "num"; // 输出字母还是数字
if ("char".equalsIgnoreCase(charOrNum)) // 字符串
{
int choice = random.nextInt(2) % 2 == 0 ? 65 : 97; // 取得大写字母还是小写字母
val += (char) (choice + random.nextInt(26));
} else if ("num".equalsIgnoreCase(charOrNum)) // 数字
{
val += String.valueOf(random.nextInt(10));
}
}
return val;
}
public static String MD5(String sourceStr) {
String result = "";
try {
MessageDigest md = MessageDigest.getInstance("MD5");
md.update(sourceStr.getBytes());
byte b[] = md.digest();
int i;
StringBuffer buf = new StringBuffer("");
for (int offset = 0; offset < b.length; offset++) {
i = b[offset];
if (i < 0)
i += 256;
if (i < 16)
buf.append("0");
buf.append(Integer.toHexString(i));
}
result = buf.toString();
} catch (Exception e) {
System.out.println(e);
}
return result;
}
public static String getTradeNo(){
return new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date())+(int) (Math.random() * (1000 - 100) + 100);
}
}

59
src/main/java/com/fr/plugin/third/party/jsdjcae/sms/handle/SMSUtils.java

@ -0,0 +1,59 @@
package com.fr.plugin.third.party.jsdjcae.sms.handle;
import com.fanruan.api.log.LogKit;
import com.fanruan.api.util.StringKit;
import com.fr.json.JSONObject;
import com.fr.plugin.context.PluginContexts;
import com.fr.plugin.third.party.jsdjcae.sms.Utils;
import com.fr.plugin.third.party.jsdjcae.sms.config.CustomDataConfig;
import com.fr.third.org.apache.http.impl.client.CloseableHttpClient;
import java.io.IOException;
public class SMSUtils {
/**
* 发送短信
*
* @param phoneContent
* @param smsContent
*/
public static synchronized void sendSms(String phoneContent, String smsContent) throws IOException {
//添加认证
if (!PluginContexts.currentContext().isAvailable()) {
LogKit.error("第三方定制短信插件试用过期, 请购买许可证");
return;
}
if (StringKit.isEmpty(phoneContent) || StringKit.isEmpty(smsContent)) {
return;
}
String userSyncUrl = CustomDataConfig.getInstance().getDataSyncUrl();
String userSyncUsername = CustomDataConfig.getInstance().getDataUsername();
String userSyncPassword = CustomDataConfig.getInstance().getDataPassword();
String smsKey = CustomDataConfig.getInstance().getSmskey();
if (StringKit.isEmpty(userSyncUrl) || StringKit.isEmpty(userSyncUsername) || StringKit.isEmpty(userSyncPassword) || StringKit.isEmpty(smsKey)) {
return;
}
sendSms(phoneContent, smsContent, userSyncUsername, userSyncPassword, userSyncUrl, smsKey);
}
public static void sendSms(String phoneContent, String smsContent, String username, String password, String smsUrl, String smsKey) throws IOException {
String tradeNo = AESUtil.getTradeNo();
JSONObject bodyJson = new JSONObject();
bodyJson.put("tradeNo", tradeNo);
bodyJson.put("userName", username);
bodyJson.put("userPassword", password);
bodyJson.put("phones", phoneContent);
bodyJson.put("content", smsContent);
bodyJson.put("etnumber", "");
String sign = AESUtil.encrypt(bodyJson.toString(), smsKey);
bodyJson.put("sign", sign);
bodyJson.put("userPassword", AESUtil.MD5(password));
LogKit.info("第三方定制短信,接口地址:" + smsUrl);
LogKit.info("第三方定制短信,接口内容:\n" + bodyJson.toString());
CloseableHttpClient httpClient = Utils.createHttpClient(smsUrl);
String content = Utils.createHttpPostContent(httpClient, smsUrl, bodyJson.toString(), "", "application/json;charset=UTF-8");
httpClient.close();
LogKit.info("第三方定制短信,接口响应内容:\n" + content);
}
}

136
src/main/java/com/fr/plugin/third/party/jsdjcae/sms/handle/SmsOutputActionHandler.java

@ -0,0 +1,136 @@
package com.fr.plugin.third.party.jsdjcae.sms.handle;
import com.fanruan.api.data.TableDataKit;
import com.fanruan.api.log.LogKit;
import com.fanruan.api.util.StringKit;
import com.fr.base.TableData;
import com.fr.decision.authority.AuthorityContext;
import com.fr.decision.authority.data.User;
import com.fr.general.PropertiesUtils;
import com.fr.general.data.DataModel;
import com.fr.log.FineLoggerFactory;
import com.fr.plugin.third.party.jsdjcae.sms.ResultModel;
import com.fr.plugin.third.party.jsdjcae.sms.bean.OutputSmsAction;
import com.fr.plugin.third.party.jsdjcae.sms.inter.http.v1.dto.request.SmsSingleRequest;
import com.fr.plugin.third.party.jsdjcae.sms.inter.http.v1.dto.response.SmsResponse;
import com.fr.plugin.third.party.jsdjcae.sms.util.AES;
import com.fr.plugin.third.party.jsdjcae.sms.util.GZIPUtils;
import com.fr.plugin.third.party.jsdjcae.sms.util.JsonHelper;
import com.fr.plugin.third.party.jsdjcae.sms.util.http.*;
import com.fr.schedule.base.constant.ScheduleConstants;
import com.fr.schedule.feature.output.OutputActionHandler;
import com.fr.script.Calculator;
import com.fr.stable.StringUtils;
import com.fr.stable.query.QueryFactory;
import com.fr.stable.query.restriction.RestrictionFactory;
import java.io.IOException;
import java.util.*;
import java.util.stream.Collectors;
/**
* @Author fr.open
* @Date 2020/9/15
* @Description
**/
public class SmsOutputActionHandler extends OutputActionHandler<OutputSmsAction> {
public SmsOutputActionHandler() {
}
@Override
public void doAction(OutputSmsAction action, Map<String, Object> map) throws Exception {
sendSms(action, map);
sendSmsByDataset(action, map);
}
private void sendSms(OutputSmsAction action, Map<String, Object> map) throws Exception {
LogKit.info("第三方定制短信,按手机号码和短信内容发送...");
String smsContent = StringKit.trim(action.getContent());
if (StringKit.isEmpty(smsContent)) {
LogKit.info("第三方定制短信,短信内容为空");
return;
}
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());
mobiles = createMobiles(mobiles, action.getPhone());
if (mobiles.isEmpty()) {
LogKit.info("第三方定制短信,号码为空");
return;
}
String mobileContent = com.fr.third.org.apache.commons.lang3.StringUtils.join(mobiles, ",");
LogKit.info("第三方定制短信,内容为 {}", smsContent);
LogKit.info("第三方定制短信,号码为 {}", mobileContent);
SMSUtils.sendSms(mobileContent, smsContent);
}
private List<String> createMobiles(List<String> userMobiles, String phoneContent) {
if (userMobiles == null) {
userMobiles = new ArrayList<>();
}
if (StringKit.isEmpty(phoneContent)) {
return userMobiles;
}
String[] phones = phoneContent.split(",");
if ((phones == null) || (phones.length <= 0)) {
return userMobiles;
}
String phone;
for (int i = 0, max = phones.length - 1; i <= max; i++) {
phone = StringKit.trim(phones[i]);
if (StringKit.isNotEmpty(phone) && (phone.length() >= 3)) {
userMobiles.add(phone);
}
}
return userMobiles;
}
private void sendSmsByDataset(OutputSmsAction action, Map<String, Object> map) throws Exception {
LogKit.info("第三方定制短信,按数据集发送...");
String datasetName = StringKit.trim(action.getDatasetName());
if (StringKit.isEmpty(datasetName)) {
LogKit.info("第三方定制短信,数据集名称为空");
return;
}
TableData tableData = TableDataKit.findTableData(datasetName);
if (tableData == null) {
return;
}
DataModel dataModel = tableData.createDataModel(Calculator.createCalculator());
if (dataModel == null) {
return;
}
if ((dataModel.getColumnCount() <= 1) || (dataModel.getRowCount() <= 0)) {
return;
}
String mobileContent, smsContent;
Object mobileObj, smsObj;
for (int i = 0, max = dataModel.getRowCount() - 1; i <= max; i++) {
mobileObj = dataModel.getValueAt(i, 0);
smsObj = dataModel.getValueAt(i, 1);
if ((mobileObj == null) || (smsObj == null)) {
continue;
}
mobileContent = StringKit.trim(String.valueOf(mobileObj));
smsContent = StringKit.trim(String.valueOf(smsObj));
if (StringKit.isEmpty(mobileContent) || StringKit.isEmpty(smsContent)) {
continue;
}
SMSUtils.sendSms(mobileContent, smsContent);
}
}
}

43
src/main/java/com/fr/plugin/third/party/jsdjcae/sms/inter/framework/dto/CustomSmsIdAndMobile.java

@ -0,0 +1,43 @@
package com.fr.plugin.third.party.jsdjcae.sms.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/third/party/jsdjcae/sms/inter/framework/dto/CustomSmsIdAndMobileAndContent.java

@ -0,0 +1,54 @@
package com.fr.plugin.third.party.jsdjcae.sms.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/third/party/jsdjcae/sms/inter/framework/dto/PersonalityParams.java

@ -0,0 +1,76 @@
package com.fr.plugin.third.party.jsdjcae.sms.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;
}
}

60
src/main/java/com/fr/plugin/third/party/jsdjcae/sms/inter/framework/dto/TemplateSmsIdAndMobile.java

@ -0,0 +1,60 @@
package com.fr.plugin.third.party.jsdjcae.sms.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/third/party/jsdjcae/sms/inter/http/v1/dto/request/BalanceRequest.java

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

43
src/main/java/com/fr/plugin/third/party/jsdjcae/sms/inter/http/v1/dto/request/BaseRequest.java

@ -0,0 +1,43 @@
package com.fr.plugin.third.party.jsdjcae.sms.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/third/party/jsdjcae/sms/inter/http/v1/dto/request/MoRequest.java

@ -0,0 +1,32 @@
package com.fr.plugin.third.party.jsdjcae.sms.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/third/party/jsdjcae/sms/inter/http/v1/dto/request/ReportRequest.java

@ -0,0 +1,32 @@
package com.fr.plugin.third.party.jsdjcae.sms.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/third/party/jsdjcae/sms/inter/http/v1/dto/request/ShortLinkRequest.java

@ -0,0 +1,32 @@
package com.fr.plugin.third.party.jsdjcae.sms.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/third/party/jsdjcae/sms/inter/http/v1/dto/request/SmsBaseRequest.java

@ -0,0 +1,39 @@
package com.fr.plugin.third.party.jsdjcae.sms.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;
}
}

39
src/main/java/com/fr/plugin/third/party/jsdjcae/sms/inter/http/v1/dto/request/SmsBatchOnlyRequest.java

@ -0,0 +1,39 @@
package com.fr.plugin.third.party.jsdjcae.sms.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/third/party/jsdjcae/sms/inter/http/v1/dto/request/SmsBatchRequest.java

@ -0,0 +1,41 @@
package com.fr.plugin.third.party.jsdjcae.sms.inter.http.v1.dto.request;
import com.fr.plugin.third.party.jsdjcae.sms.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/third/party/jsdjcae/sms/inter/http/v1/dto/request/SmsPersonalityAllRequest.java

@ -0,0 +1,26 @@
package com.fr.plugin.third.party.jsdjcae.sms.inter.http.v1.dto.request;
import com.fr.plugin.third.party.jsdjcae.sms.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/third/party/jsdjcae/sms/inter/http/v1/dto/request/SmsPersonalityRequest.java

@ -0,0 +1,26 @@
package com.fr.plugin.third.party.jsdjcae.sms.inter.http.v1.dto.request;
import com.fr.plugin.third.party.jsdjcae.sms.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/third/party/jsdjcae/sms/inter/http/v1/dto/request/SmsShortLinkBatchRequest.java

@ -0,0 +1,60 @@
package com.fr.plugin.third.party.jsdjcae.sms.inter.http.v1.dto.request;
import com.fr.plugin.third.party.jsdjcae.sms.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/third/party/jsdjcae/sms/inter/http/v1/dto/request/SmsSingleRequest.java

@ -0,0 +1,53 @@
package com.fr.plugin.third.party.jsdjcae.sms.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;
}
}

35
src/main/java/com/fr/plugin/third/party/jsdjcae/sms/inter/http/v1/dto/request/TemplateSmsSendRequest.java

@ -0,0 +1,35 @@
package com.fr.plugin.third.party.jsdjcae.sms.inter.http.v1.dto.request;
import com.fr.plugin.third.party.jsdjcae.sms.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/third/party/jsdjcae/sms/inter/http/v1/dto/response/BalanceResponse.java

@ -0,0 +1,34 @@
package com.fr.plugin.third.party.jsdjcae.sms.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/third/party/jsdjcae/sms/inter/http/v1/dto/response/MoResponse.java

@ -0,0 +1,65 @@
package com.fr.plugin.third.party.jsdjcae.sms.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/third/party/jsdjcae/sms/inter/http/v1/dto/response/ReportResponse.java

@ -0,0 +1,94 @@
package com.fr.plugin.third.party.jsdjcae.sms.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;
}
}

45
src/main/java/com/fr/plugin/third/party/jsdjcae/sms/inter/http/v1/dto/response/ResponseData.java

@ -0,0 +1,45 @@
package com.fr.plugin.third.party.jsdjcae.sms.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;
}
}

90
src/main/java/com/fr/plugin/third/party/jsdjcae/sms/inter/http/v1/dto/response/ShortLinkReportResponse.java

@ -0,0 +1,90 @@
package com.fr.plugin.third.party.jsdjcae.sms.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/third/party/jsdjcae/sms/inter/http/v1/dto/response/SmsResponse.java

@ -0,0 +1,57 @@
package com.fr.plugin.third.party.jsdjcae.sms.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/third/party/jsdjcae/sms/inter/http/v1/dto/response/SmsTemplateResponse.java

@ -0,0 +1,57 @@
package com.fr.plugin.third.party.jsdjcae.sms.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;
}
}

55
src/main/java/com/fr/plugin/third/party/jsdjcae/sms/js/FileDef.java

@ -0,0 +1,55 @@
package com.fr.plugin.third.party.jsdjcae.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/third/party/jsdjcae/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/third/party/jsdjcae/sms/js/JSCSSBridge.java

@ -0,0 +1,28 @@
package com.fr.plugin.third.party.jsdjcae.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/third/party/jsdjcae/sms/util/AES.java

@ -0,0 +1,140 @@
package com.fr.plugin.third.party.jsdjcae.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;
}
}
}

134
src/main/java/com/fr/plugin/third/party/jsdjcae/sms/util/DateUtil.java

@ -0,0 +1,134 @@
package com.fr.plugin.third.party.jsdjcae.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/third/party/jsdjcae/sms/util/GZIPUtils.java

@ -0,0 +1,105 @@
package com.fr.plugin.third.party.jsdjcae.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/third/party/jsdjcae/sms/util/JsonHelper.java

@ -0,0 +1,129 @@
package com.fr.plugin.third.party.jsdjcae.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/third/party/jsdjcae/sms/util/Md5.java

@ -0,0 +1,51 @@
package com.fr.plugin.third.party.jsdjcae.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/third/party/jsdjcae/sms/util/http/HttpClient.java

@ -0,0 +1,451 @@
package com.fr.plugin.third.party.jsdjcae.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 SecureRandom());
} else {
ctx.init(null, new TrustManager[] { myX509TrustManager }, new 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/third/party/jsdjcae/sms/util/http/HttpRequest.java

@ -0,0 +1,94 @@
package com.fr.plugin.third.party.jsdjcae.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;
}
}

19
src/main/java/com/fr/plugin/third/party/jsdjcae/sms/util/http/HttpRequestBytes.java

@ -0,0 +1,19 @@
package com.fr.plugin.third.party.jsdjcae.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/third/party/jsdjcae/sms/util/http/HttpRequestKV.java

@ -0,0 +1,22 @@
package com.fr.plugin.third.party.jsdjcae.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/third/party/jsdjcae/sms/util/http/HttpRequestParams.java

@ -0,0 +1,67 @@
package com.fr.plugin.third.party.jsdjcae.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/third/party/jsdjcae/sms/util/http/HttpRequestPraser.java

@ -0,0 +1,40 @@
package com.fr.plugin.third.party.jsdjcae.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/third/party/jsdjcae/sms/util/http/HttpRequestPraserBytes.java

@ -0,0 +1,44 @@
package com.fr.plugin.third.party.jsdjcae.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/third/party/jsdjcae/sms/util/http/HttpRequestPraserKV.java

@ -0,0 +1,71 @@
package com.fr.plugin.third.party.jsdjcae.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/third/party/jsdjcae/sms/util/http/HttpRequestPraserString.java

@ -0,0 +1,46 @@
package com.fr.plugin.third.party.jsdjcae.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/third/party/jsdjcae/sms/util/http/HttpRequestString.java

@ -0,0 +1,19 @@
package com.fr.plugin.third.party.jsdjcae.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/third/party/jsdjcae/sms/util/http/HttpResponse.java

@ -0,0 +1,113 @@
package com.fr.plugin.third.party.jsdjcae.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/third/party/jsdjcae/sms/util/http/HttpResponseBytes.java

@ -0,0 +1,32 @@
package com.fr.plugin.third.party.jsdjcae.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/third/party/jsdjcae/sms/util/http/HttpResponseBytesPraser.java

@ -0,0 +1,19 @@
package com.fr.plugin.third.party.jsdjcae.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/third/party/jsdjcae/sms/util/http/HttpResponsePraser.java

@ -0,0 +1,32 @@
package com.fr.plugin.third.party.jsdjcae.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/third/party/jsdjcae/sms/util/http/HttpResponseString.java

@ -0,0 +1,33 @@
package com.fr.plugin.third.party.jsdjcae.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/third/party/jsdjcae/sms/util/http/HttpResponseStringPraser.java

@ -0,0 +1,30 @@
package com.fr.plugin.third.party.jsdjcae.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/third/party/jsdjcae/sms/util/http/HttpResultCode.java

@ -0,0 +1,69 @@
package com.fr.plugin.third.party.jsdjcae.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/third/party/jsdjcae/sms/util/http/HttpsParams.java

@ -0,0 +1,47 @@
package com.fr.plugin.third.party.jsdjcae.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/third/party/jsdjcae/sms/util/http/HttpsRequestBytes.java

@ -0,0 +1,21 @@
package com.fr.plugin.third.party.jsdjcae.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());
}
}

23
src/main/java/com/fr/plugin/third/party/jsdjcae/sms/util/http/HttpsRequestKV.java

@ -0,0 +1,23 @@
package com.fr.plugin.third.party.jsdjcae.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/third/party/jsdjcae/sms/util/http/HttpsRequestString.java

@ -0,0 +1,21 @@
package com.fr.plugin.third.party.jsdjcae.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());
}
}

219
src/main/resources/com/fr/plugin/third/party/jsdjcae/sms/theme.js

@ -0,0 +1,219 @@
!(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: "",
phone: "",
datasetName: ""
}
},
render: function () {
debugger;
var t = this,
e = this.options.value[0] == undefined ? {
content: "",
phone: "",
datasetName: ""
} : 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.phone,
ref: function (e) {
t.phone = e
}
},
{
type: "dec.label.textarea.item",
errorTop: 16,
textCls: "dec-font-weight-bold",
text: "内容",
textWidth: 115,
editorWidth: 300,
value: e.content,
ref: function (e) {
t.content = e
}
}, {
type: "dec.label.editor.item",
errorTop: 16,
textCls: "dec-font-weight-bold",
text: "数据集名称",
textWidth: 115,
editorWidth: 300,
value: e.datasetName,
ref: function (e) {
t.datasetName = e
}
}
]
};
},
/**
*
*
* @returns {boolean}
*/
validation: function () {
return true;
},
/**
*
* outputActionList
* @returns {{}}
*/
getValue: function () {
var _self = this;
return {
OutputSmsAction: BI.extend(_self.value, {
"@class": "com.fr.plugin.third.party.jsdjcae.sms.bean.OutputSmsAction",
actionName: "com.fr.plugin.third.party.jsdjcae.sms.bean.OutputSmsAction",
content: _self.content.getValue(),
phone: _self.phone.getValue(),
datasetName: _self.datasetName.getValue(),
})
}
},
});
BI.shortcut("dec.schedule.task.file.handling.plugin", Plugin);
BI.config("dec.provider.schedule", function (provider) {
provider.registerHandingWay({
text: "第三方短信通知",
value: "com.fr.plugin.third.party.jsdjcae.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]);
});
}());
Loading…
Cancel
Save