commit d06430f1cc5c6dc77f0391ba8431b1819f25ca68 Author: pioneer Date: Wed Nov 9 15:55:40 2022 +0800 open diff --git a/JSD-9942-需求确认书2.0.docx b/JSD-9942-需求确认书2.0.docx new file mode 100644 index 0000000..f059cd3 Binary files /dev/null and b/JSD-9942-需求确认书2.0.docx differ diff --git a/README.md b/README.md new file mode 100644 index 0000000..568b380 --- /dev/null +++ b/README.md @@ -0,0 +1,6 @@ +# open-JSD-9942 + +JSD-9942 集成客户的短信平台,实现可以通过报表内点击时间调取短信平台相关接口发送短信通知\ +免责说明:该源码为第三方爱好者提供,不保证源码和方案的可靠性,也不提供任何形式的源码教学指导和协助!\ +仅作为开发者学习参考使用!禁止用于任何商业用途!\ +为保护开发者隐私,开发者信息已隐去!若原开发者希望公开自己的信息,可联系【pioneer】处理。 \ No newline at end of file diff --git a/plugin.xml b/plugin.xml new file mode 100644 index 0000000..ce2e762 --- /dev/null +++ b/plugin.xml @@ -0,0 +1,23 @@ + + com.eco.plugin.wink.hrzdmsg + + yes + 1.0.10 + 10.0 + 2018-07-31 + wink + + + com.eco.plugin.wink.hrzdmsg + + + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/com/eco/plugin/xx/hrzdmsg/config/InitializeMonitor.java b/src/main/java/com/eco/plugin/xx/hrzdmsg/config/InitializeMonitor.java new file mode 100644 index 0000000..75282a2 --- /dev/null +++ b/src/main/java/com/eco/plugin/xx/hrzdmsg/config/InitializeMonitor.java @@ -0,0 +1,31 @@ +package com.eco.plugin.wink.hrzdmsg.config; + +import com.eco.plugin.wink.hrzdmsg.dsdd.dsdd.DSDDMsgFormula; +import com.eco.plugin.wink.hrzdmsg.dsdd.dsdd.TsBean; +import com.eco.plugin.wink.hrzdmsg.dsdd.dsdd.TsEntity; +import com.eco.plugin.wink.hrzdmsg.dsdd.dsdd.TsHandler; +import com.fr.plugin.context.PluginContext; +import com.fr.plugin.observer.inner.AbstractPluginLifecycleMonitor; +import com.fr.schedule.extension.report.job.output.formula.FormulaBox; +import com.fr.schedule.feature.ScheduleOutputActionEntityRegister; +import com.fr.schedule.feature.output.OutputActionHandler; + +/** + * @author wink + * @version 10.0 + * Created by wink on 2021-12-03 + */ +public class InitializeMonitor extends AbstractPluginLifecycleMonitor { + @Override + public void afterRun(PluginContext pluginContext) { + OutputActionHandler.registerHandler(new TsHandler(), TsBean.class.getName()); + ScheduleOutputActionEntityRegister.getInstance().addClass(TsEntity.class); + FormulaBox.KEY.register(new DSDDMsgFormula()); + PluginSimpleConfig.getInstance(); + } + + @Override + public void beforeStop(PluginContext pluginContext) { + + } +} diff --git a/src/main/java/com/eco/plugin/xx/hrzdmsg/config/PluginSimpleConfig.java b/src/main/java/com/eco/plugin/xx/hrzdmsg/config/PluginSimpleConfig.java new file mode 100644 index 0000000..b072d89 --- /dev/null +++ b/src/main/java/com/eco/plugin/xx/hrzdmsg/config/PluginSimpleConfig.java @@ -0,0 +1,79 @@ +package com.eco.plugin.wink.hrzdmsg.config; + +import com.fr.config.*; +import com.fr.config.holder.Conf; +import com.fr.config.holder.factory.Holders; +import com.fr.intelli.record.Focus; +import com.fr.intelli.record.Original; +import com.fr.record.analyzer.EnableMetrics; + +@Visualization(category = "发送短信信息配置") +@EnableMetrics +public class PluginSimpleConfig extends DefaultConfiguration { + + private static volatile PluginSimpleConfig config = null; + + @Focus(id="com.eco.plugin.wink.hrzdmsg.config", text = "发送短信信息配置", source = Original.PLUGIN) + public static PluginSimpleConfig getInstance() { + if (config == null) { + config = ConfigContext.getConfigInstance(PluginSimpleConfig.class); + } + return config; + } + + @Identifier(value = "loginName", name = "loginName", description = "loginName", status = Status.SHOW) + private Conf loginName = Holders.simple(""); + + @Identifier(value = "password", name = "password", description = "password", status = Status.SHOW) + private Conf password = Holders.simple(""); + + @Identifier(value = "tokenUrl", name = "获取token接口", description = "获取token接口", status = Status.SHOW) + private Conf tokenUrl = Holders.simple(""); + + @Identifier(value = "sendMsgUrl", name = "批量发送短信接口", description = "批量发送短信接口", status = Status.SHOW) + private Conf sendMsgUrl = Holders.simple(""); + + public String getLoginName() { + return loginName.get(); + } + + public void setLoginName(String url) { + this.loginName.set(url); + } + + public String getPassword() { + return password.get(); + } + + public void setPassword(String url) { + this.password.set(url); + } + + public String getTokenUrl() { + return tokenUrl.get(); + } + + public void setTokenUrl(String url) { + this.tokenUrl.set(url); + } + + public String getSendMsgUrl() { + return sendMsgUrl.get(); + } + + public void setSendMsgUrl(String url) { + this.sendMsgUrl.set(url); + } + + @Override + public Object clone() throws CloneNotSupportedException { + PluginSimpleConfig cloned = (PluginSimpleConfig) super.clone(); +// cloned.text = (Conf) text.clone(); +// cloned.count = (Conf) count.clone(); +// cloned.price = (Conf) price.clone(); +// cloned.time = (Conf) time.clone(); +// cloned.student = (Conf) student.clone(); + return cloned; + } + +} diff --git a/src/main/java/com/eco/plugin/xx/hrzdmsg/controller/ControllerRegisterProvider.java b/src/main/java/com/eco/plugin/xx/hrzdmsg/controller/ControllerRegisterProvider.java new file mode 100644 index 0000000..e911f84 --- /dev/null +++ b/src/main/java/com/eco/plugin/xx/hrzdmsg/controller/ControllerRegisterProvider.java @@ -0,0 +1,14 @@ +package com.eco.plugin.wink.hrzdmsg.controller; + +import com.fr.decision.fun.impl.AbstractControllerRegisterProvider; +import com.fr.plugin.transform.FunctionRecorder; + +@FunctionRecorder +public class ControllerRegisterProvider extends AbstractControllerRegisterProvider { + @Override + public Class[] getControllers() { + return new Class[]{ + ControllerSelf.class + }; + } +} diff --git a/src/main/java/com/eco/plugin/xx/hrzdmsg/controller/ControllerSelf.java b/src/main/java/com/eco/plugin/xx/hrzdmsg/controller/ControllerSelf.java new file mode 100644 index 0000000..593e51d --- /dev/null +++ b/src/main/java/com/eco/plugin/xx/hrzdmsg/controller/ControllerSelf.java @@ -0,0 +1,100 @@ +package com.eco.plugin.wink.hrzdmsg.controller; + +import com.eco.plugin.wink.hrzdmsg.config.PluginSimpleConfig; +import com.eco.plugin.wink.hrzdmsg.utils.FRUtils; +import com.eco.plugin.wink.hrzdmsg.utils.HttpUtils; +import com.eco.plugin.wink.hrzdmsg.utils.ResponseUtils; +import com.eco.plugin.wink.hrzdmsg.utils.Utils; +import com.fr.decision.webservice.annotation.LoginStatusChecker; +import com.fr.json.JSONObject; +import com.fr.plugin.context.PluginContexts; +import com.fr.stable.fun.Authorize; +import com.fr.third.springframework.stereotype.Controller; +import com.fr.third.springframework.web.bind.annotation.PostMapping; +import com.fr.third.springframework.web.bind.annotation.ResponseBody; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.util.HashMap; +import java.util.Map; + +@Controller +@LoginStatusChecker(required = false) +@Authorize(callSignKey = "com.fr.plugin.wink.hrzdmsg") +public class ControllerSelf { + + @PostMapping(value = "/sendMsg") + @ResponseBody + public void sendMsg(HttpServletRequest req,HttpServletResponse res){ + if(!PluginContexts.currentContext().isAvailable()){ + ResponseUtils.failedResponse(res,"插件授权过期,请联系管理员!"); + return ; + } + + JSONObject param = Utils.getRequestBody(req); + FRUtils.FRLogInfo("param1:"+param.toString()); + JSONObject content = new JSONObject(param.getString("content")); + param.put("content",content); + FRUtils.FRLogInfo("param2:"+param.toString()); + JSONObject msg = sendMsg(param,PluginSimpleConfig.getInstance()); + ResponseUtils.response(res,msg); + } + + /** + * 发送短信 + * @param param + * @param psc + * @return + */ + public static JSONObject sendMsg(JSONObject param,PluginSimpleConfig psc){ + JSONObject result = new JSONObject(); + result.put("code",200); + String token = getToken(psc); + + if(Utils.isNullStr(token)){ + result.put("code",-1); + result.put("msg","获取token失败!"); + return result; + } + + Map header = new HashMap(); + header.put("Authorization","Bearer "+token); + String url = psc.getSendMsgUrl(); + + String resultStr = HttpUtils.HttpPostJson(url,param.toString(),header); + + if(Utils.isNullStr(resultStr)){ + result.put("code",-1); + result.put("msg","发送短信失败!"); + return result; + } + + result.put("data",resultStr); + + return result; + } + + /** + * 获取token,用于接口鉴权 + * @param psc + * @return + */ + private static String getToken(PluginSimpleConfig psc){ + String url = psc.getTokenUrl(); + String username = psc.getLoginName(); + String psd = psc.getPassword(); + + JSONObject param = new JSONObject(); + param.put("loginName",username); + param.put("password",psd); + + String result = HttpUtils.HttpPostJson(url,param.toString(),null); + + if(Utils.isNullStr(result)){ + return ""; + } + + return new JSONObject(result).getString("accessToken"); + } + +} diff --git a/src/main/java/com/eco/plugin/xx/hrzdmsg/dsdd/db/DBAccessProvider.java b/src/main/java/com/eco/plugin/xx/hrzdmsg/dsdd/db/DBAccessProvider.java new file mode 100644 index 0000000..8c16623 --- /dev/null +++ b/src/main/java/com/eco/plugin/xx/hrzdmsg/dsdd/db/DBAccessProvider.java @@ -0,0 +1,38 @@ +package com.eco.plugin.wink.hrzdmsg.dsdd.db; + +import com.eco.plugin.wink.hrzdmsg.dsdd.dsdd.TsEntity; +import com.fr.decision.plugin.db.AbstractDecisionDBAccessProvider; +import com.fr.stable.db.accessor.DBAccessor; +import com.fr.stable.db.dao.BaseDAO; +import com.fr.stable.db.dao.DAOProvider; + +public class DBAccessProvider extends AbstractDecisionDBAccessProvider { + private static DBAccessor dbAccessor = null; + + public static DBAccessor getDbAccessor(){ + return dbAccessor; + } + + + @Override + public DAOProvider[] registerDAO() { + return new DAOProvider[]{ + new DAOProvider() { + @Override + public Class getEntityClass() { + return TsEntity.class; + } + + @Override + public Class getDAOClass() { + return Dao.class; + } + } + }; + } + + @Override + public void onDBAvailable(DBAccessor dbAccessor) { + this.dbAccessor = dbAccessor; + } +} diff --git a/src/main/java/com/eco/plugin/xx/hrzdmsg/dsdd/db/Dao.java b/src/main/java/com/eco/plugin/xx/hrzdmsg/dsdd/db/Dao.java new file mode 100644 index 0000000..329b672 --- /dev/null +++ b/src/main/java/com/eco/plugin/xx/hrzdmsg/dsdd/db/Dao.java @@ -0,0 +1,14 @@ +package com.eco.plugin.wink.hrzdmsg.dsdd.db; + +import com.eco.plugin.wink.hrzdmsg.dsdd.dsdd.TsEntity; +import com.fr.stable.db.dao.BaseDAO; +import com.fr.stable.db.session.DAOSession; + +/** + * Created by wink on 2021-12-03. + */ +public class Dao extends BaseDAO { + public Dao(DAOSession daoSession) { + super(daoSession); + } +} \ No newline at end of file diff --git a/src/main/java/com/eco/plugin/xx/hrzdmsg/dsdd/dsdd/DSDDMsgFormula.java b/src/main/java/com/eco/plugin/xx/hrzdmsg/dsdd/dsdd/DSDDMsgFormula.java new file mode 100644 index 0000000..e1c4978 --- /dev/null +++ b/src/main/java/com/eco/plugin/xx/hrzdmsg/dsdd/dsdd/DSDDMsgFormula.java @@ -0,0 +1,25 @@ +package com.eco.plugin.wink.hrzdmsg.dsdd.dsdd; + +import com.fr.main.workbook.ResultWorkBook; +import com.fr.schedule.extension.report.provider.impl.AbstractReportOutputFormulaProvider; +import com.fr.schedule.extension.report.util.ScheduleParameterUtils; + +import java.util.List; +import java.util.Map; + +public class DSDDMsgFormula extends AbstractReportOutputFormulaProvider { + public DSDDMsgFormula() { + } + + public void dealWithFormulaParam(TsBean syncBean, ResultWorkBook resultWorkBook, List> param) throws Exception { + syncBean.setBusinessCode(ScheduleParameterUtils.dealWithParameter(syncBean.getBusinessCode(), (Map)param.get(0), resultWorkBook)); + syncBean.setContent(ScheduleParameterUtils.dealWithParameter(syncBean.getContent(), (Map)param.get(0), resultWorkBook)); + syncBean.setSecretKey(ScheduleParameterUtils.dealWithParameter(syncBean.getSecretKey(), (Map)param.get(0), resultWorkBook)); + syncBean.setSource(ScheduleParameterUtils.dealWithParameter(syncBean.getSource(), (Map)param.get(0), resultWorkBook)); + syncBean.setSourceNote(ScheduleParameterUtils.dealWithParameter(syncBean.getSourceNote(), (Map)param.get(0), resultWorkBook)); + } + + public String getActionClassName() { + return TsBean.class.getName(); + } +} diff --git a/src/main/java/com/eco/plugin/xx/hrzdmsg/dsdd/dsdd/TsBean.java b/src/main/java/com/eco/plugin/xx/hrzdmsg/dsdd/dsdd/TsBean.java new file mode 100644 index 0000000..2ead19e --- /dev/null +++ b/src/main/java/com/eco/plugin/xx/hrzdmsg/dsdd/dsdd/TsBean.java @@ -0,0 +1,119 @@ +package com.eco.plugin.wink.hrzdmsg.dsdd.dsdd; + +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; + +@JsonSubTypes.Type(value = TsBean.class, name = "TsBean") +public class TsBean extends BaseOutputAction { + private static final long serialVersionUID = 8245931480823179622L; + private String businessCode = null; + private String content = null; + private String secretKey = null; + private String source = null; + private String sourceNote = null; + public TsBean(){ + super(); + } + + //是否受不同用户生成不同附件影响 + @Override + public boolean willExecuteByUser() { + return true; + } + + @Override + public RunType runType() { + return RunType.SEND_EMAIL; + } + + //这里直接关联第一步的entity类 + @Override + public Class outputActionEntityClass() { + return TsEntity.class; + } + + public TsBean id(String id){ + setId(id); + return this; + } + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } + + public TsBean content(String content){ + setContent(content); + return this; + } + + public String getBusinessCode() { + return businessCode; + } + + public void setBusinessCode(String businessCode) { + this.businessCode = businessCode; + } + + public TsBean businessCode(String content){ + setBusinessCode(content); + return this; + } + + public String getSecretKey() { + return secretKey; + } + + public void setSecretKey(String secretKey) { + this.secretKey = secretKey; + } + + public TsBean secretKey(String content){ + setSecretKey(content); + return this; + } + + public String getSource() { + return source; + } + + public void setSource(String source) { + this.source = source; + } + + public TsBean source(String content){ + setSource(content); + return this; + } + + public String getSourceNote() { + return sourceNote; + } + + public void setSourceNote(String sourceNote) { + this.sourceNote = sourceNote; + } + + public TsBean sourceNote(String content){ + setSourceNote(content); + return this; + } + + //转换成entity对象,用于数据库存储,注意属性不要漏了 + @Override + public TsEntity createOutputActionEntity() { + return new TsEntity() + .id(this.getId()) + .content(this.getContent()) + .businessCode(this.getBusinessCode()) + .secretKey(this.getSecretKey()) + .source(this.getSource()) + .sourceNote(this.getSourceNote()) + ; + } +} diff --git a/src/main/java/com/eco/plugin/xx/hrzdmsg/dsdd/dsdd/TsEntity.java b/src/main/java/com/eco/plugin/xx/hrzdmsg/dsdd/dsdd/TsEntity.java new file mode 100644 index 0000000..89d5fe6 --- /dev/null +++ b/src/main/java/com/eco/plugin/xx/hrzdmsg/dsdd/dsdd/TsEntity.java @@ -0,0 +1,113 @@ +package com.eco.plugin.wink.hrzdmsg.dsdd.dsdd; + +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; + +@Entity +@Table(name = "fine_output_wink_message") //表名 +@TableAssociation(associated = true) +public class TsEntity extends AbstractScheduleEntity{ + public TsEntity(){} + + @Column(name = "businessCode") + private String businessCode = null; + + @Column(name = "content") + private String content = null; + + @Column(name = "secretKey") + private String secretKey = null; + + @Column(name = "source") + private String source = null; + + @Column(name = "sourceNote") + private String sourceNote = null; + + + public TsEntity id(String id) { + setId(id); + return this; + } + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } + + public TsEntity content(String content){ + setContent(content); + return this; + } + + public String getBusinessCode() { + return businessCode; + } + + public void setBusinessCode(String businessCode) { + this.businessCode = businessCode; + } + + public TsEntity businessCode(String content){ + setBusinessCode(content); + return this; + } + + public String getSecretKey() { + return secretKey; + } + + public void setSecretKey(String secretKey) { + this.secretKey = secretKey; + } + + public TsEntity secretKey(String content){ + setSecretKey(content); + return this; + } + + public String getSource() { + return source; + } + + public void setSource(String source) { + this.source = source; + } + + public TsEntity source(String content){ + setSource(content); + return this; + } + + public String getSourceNote() { + return sourceNote; + } + + public void setSourceNote(String sourceNote) { + this.sourceNote = sourceNote; + } + + public TsEntity sourceNote(String content){ + setSourceNote(content); + return this; + } + + //转换成bean对象 + @Override + public TsBean createBean() { + return new TsBean() + .id(this.getId()) + .content(this.getContent()) + .businessCode(this.getBusinessCode()) + .secretKey(this.getSecretKey()) + .source(this.getSource()) + .sourceNote(this.getSourceNote()) + ; + } +} diff --git a/src/main/java/com/eco/plugin/xx/hrzdmsg/dsdd/dsdd/TsHandler.java b/src/main/java/com/eco/plugin/xx/hrzdmsg/dsdd/dsdd/TsHandler.java new file mode 100644 index 0000000..4c0cafa --- /dev/null +++ b/src/main/java/com/eco/plugin/xx/hrzdmsg/dsdd/dsdd/TsHandler.java @@ -0,0 +1,47 @@ +package com.eco.plugin.wink.hrzdmsg.dsdd.dsdd; +import com.eco.plugin.wink.hrzdmsg.config.PluginSimpleConfig; +import com.eco.plugin.wink.hrzdmsg.controller.ControllerSelf; +import com.eco.plugin.wink.hrzdmsg.utils.FRUtils; +import com.fr.decision.authority.data.User; +import com.fr.json.JSONObject; +import com.fr.schedule.feature.output.OutputActionHandler; + +import java.util.Map; + +public class TsHandler extends OutputActionHandler{ + @Override + public void doAction(TsBean tsBean, Map map){ + + //获取参数 + String username = String.valueOf(map.get("username")); + User user = FRUtils.getFRUserByUserName(username); + String mobile = user.getMobile(); + String businessCode = tsBean.getBusinessCode(); + String content = tsBean.getContent(); + String secretKey = tsBean.getSecretKey(); + String source = tsBean.getSource(); + String sourceNote = tsBean.getSourceNote(); + //封装参数 + JSONObject param = new JSONObject(); + param.put("mobile",mobile); + param.put("businessCode",businessCode); + param.put("secretKey",secretKey); + param.put("source",source); + param.put("sourceNote",sourceNote); + JSONObject contentJson = new JSONObject(); + String[] contents = content.split(","); + + for(int i=0;i header){ + FineLoggerFactory.getLogger().info("FRLOG:HttpUtils.get--url:"+url); + + //创建httpClient + CloseableHttpClient httpclient = createHttpClient(cookies); + + HttpGet getMethod = new HttpGet(url); + + if(header != null && header.size() > 0){ + Set keySet = header.keySet(); + + for(String key : keySet){ + getMethod.setHeader(key,header.get(key)); + } + } + + try { + HttpResponse response = httpclient.execute(getMethod); + int status =response.getStatusLine().getStatusCode(); + HttpEntity entity = response.getEntity(); + String returnResult = EntityUtils.toString(entity, "utf-8"); + + FineLoggerFactory.getLogger().info("FRLOG:HttpUtils.get--status:"+status); + FineLoggerFactory.getLogger().info("FRLOG:HttpUtils.get--returnResult:"+returnResult); + + httpclient.close(); + + if (status == HttpStatus.SC_OK) { + return returnResult; + } + } catch (Exception e) { + FineLoggerFactory.getLogger().info("FRLOG:HttpUtils.get--exception:"+e.getMessage()); + } + + try { + httpclient.close(); + } catch (Exception e) { + FineLoggerFactory.getLogger().info("FRLOG:http关闭异常:"+e.getMessage()); + } + + return ""; + } + + /** + * HttpPost请求 + * @param postMethod + * @return + */ + private static String HttpPost(HttpPost postMethod){ + CloseableHttpClient httpclient = createHttpClient(null); + + try { + HttpResponse response = httpclient.execute(postMethod); + int status = response.getStatusLine().getStatusCode(); + HttpEntity entity = response.getEntity(); + String returnResult = EntityUtils.toString(entity, "utf-8"); + FineLoggerFactory.getLogger().info("FRLOG:HttpPost:status:"+status); + FineLoggerFactory.getLogger().info("FRLOG:HttpPost:returnResult:"+returnResult); + httpclient.close(); + + if (status == HttpStatus.SC_OK) { + return returnResult; + } + } catch (Exception e) { + FineLoggerFactory.getLogger().info("FRLOG:HttpPost:exception:"+e.getMessage()); + } + + try { + httpclient.close(); + } catch (Exception e) { + FineLoggerFactory.getLogger().info("FRLOG:http关闭异常:"+e.getMessage()); + } + + return ""; + } + + public static String HttpPostXML(String url, String xmlParam){ + FineLoggerFactory.getLogger().info("FRLOG:HttpPostXML:url:"+url); + + HttpPost postMethod = new HttpPost(url); + + postMethod.setHeader("Content-type", "text/html"); + HttpEntity entity = null; + try { + entity = new StringEntity(xmlParam); + } catch (UnsupportedEncodingException e) { + FineLoggerFactory.getLogger().info("FRLOG:HttpPostXML:参数异常:"+e.getMessage()); + return ""; + } + + postMethod.setEntity(entity); + + return HttpPost(postMethod); + } + + public static String HttpPostText(String url, String xmlParam){ + FineLoggerFactory.getLogger().info("FRLOG:HttpPostText:url:"+url); + + HttpPost postMethod = new HttpPost(url); + + postMethod.setHeader("Content-type", "text/plain"); + HttpEntity entity = null; + try { + entity = new StringEntity(xmlParam); + } catch (UnsupportedEncodingException e) { + FineLoggerFactory.getLogger().info("FRLOG:HttpPostText:参数异常:"+e.getMessage()); + return ""; + } + + postMethod.setEntity(entity); + + return HttpPost(postMethod); + } + + public static String HttpPostJson(String url, String param,Map header){ + FineLoggerFactory.getLogger().info("FRLOG:HttpPostJSON:url:"+url); + + HttpPost postMethod = new HttpPost(url); + + postMethod.setHeader("Content-Type","application/json"); + + if(header != null && header.size() > 0){ + Set keySet = header.keySet(); + + for(String key : keySet){ + postMethod.setHeader(key,header.get(key)); + } + } + + if(!Utils.isNullStr(param)){ + HttpEntity entity = null; + try { + entity = new StringEntity(param); + } catch (UnsupportedEncodingException e) { + FineLoggerFactory.getLogger().info("FRLOG:HttpPostJSON:参数异常:"+e.getMessage()); + return ""; + } + + postMethod.setEntity(entity); + } + + return HttpPost(postMethod); + } + + public static String HttpPostWWWForm(String url, Map header,Map param){ + FineLoggerFactory.getLogger().info("FRLOG:HttpWWWForm:url:"+url); + + HttpPost postMethod = new HttpPost(url); + + if(header != null && header.size() > 0){ + Set keySet = header.keySet(); + + for(String key : keySet){ + postMethod.setHeader(key,header.get(key)); + } + } + + if(param != null && param.size() > 0){ + List params = new ArrayList(param.size()); + + for(Map.Entry map : param.entrySet()){ + params.add(new BasicNameValuePair(map.getKey(), map.getValue())); + } + + try { + postMethod.setEntity(new UrlEncodedFormEntity(params, "UTF-8")); + } catch (UnsupportedEncodingException e) { + FineLoggerFactory.getLogger().info("FRLOG:HttpWWWForm:异常:"+e.getMessage()); + return ""; + } + } + + return HttpPost(postMethod); + } + + private static CloseableHttpClient createHttpClient(Cookie[] cookies){ + + SSLContext sslContext = null; + try { + sslContext = SSLContexts.custom().loadTrustMaterial(null, new TrustStrategy() { + @Override + public boolean isTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException { + return true; + } + }).build(); + } catch (Exception e) { + FRUtils.FRLogInfo("exception:"+e.getMessage()); + } + + CloseableHttpClient httpclient = null; + + if(cookies != null && cookies.length > 0){ + CookieStore cookieStore = cookieToCookieStore(cookies); + + httpclient = HttpClients.custom().setSslcontext(sslContext). + setSSLHostnameVerifier(new NoopHostnameVerifier()).setDefaultCookieStore(cookieStore).build(); + } + else{ + httpclient = HttpClients.custom().setSslcontext(sslContext). + setSSLHostnameVerifier(new NoopHostnameVerifier()).build(); + } + + return httpclient; + } + + /** + * cookies转cookieStore + * @param cookies + * @return + */ + public static CookieStore cookieToCookieStore(Cookie[] cookies){ + CookieStore cookieStore = new BasicCookieStore(); + + if(cookies != null && cookies.length>0){ + for(Cookie cookie : cookies){ + BasicClientCookie cookie1 = new BasicClientCookie(cookie.getName(), cookie.getValue()); + cookieStore.addCookie(cookie1); + } + } + + return cookieStore; + } +} diff --git a/src/main/java/com/eco/plugin/xx/hrzdmsg/utils/ResponseUtils.java b/src/main/java/com/eco/plugin/xx/hrzdmsg/utils/ResponseUtils.java new file mode 100644 index 0000000..fb3170d --- /dev/null +++ b/src/main/java/com/eco/plugin/xx/hrzdmsg/utils/ResponseUtils.java @@ -0,0 +1,108 @@ +package com.eco.plugin.wink.hrzdmsg.utils; + +import com.fr.json.JSONObject; +import com.fr.log.FineLoggerFactory; +import com.fr.web.utils.WebUtils; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.PrintWriter; + +public class ResponseUtils { + private static final int SUCCESS = 200; + private static final int FAILED = -1; + + public static void successResponse(HttpServletResponse res, String body) { + response(res, body, SUCCESS); + } + + public static void failedResponse(HttpServletResponse res, String body) { + response(res, body, FAILED); + } + + private static void response(HttpServletResponse res, String body, int code) { + JSONObject object = new JSONObject(); + PrintWriter pw; + try { + object.put("code", code); + object.put("data", body); + pw = WebUtils.createPrintWriter(res); + } catch (Exception e) { + FineLoggerFactory.getLogger().info(e.getMessage()); + return; + } + res.setContentType("application/json;charset=utf-8"); + String result = object.toString(); + pw.println(result); + pw.flush(); + pw.close(); + } + + public static void response(HttpServletResponse res,JSONObject json){ + PrintWriter pw; + try { + pw = WebUtils.createPrintWriter(res); + } catch (Exception e) { + FineLoggerFactory.getLogger().info(e.getMessage()); + return; + } + res.setContentType("application/json;charset=utf-8"); + String result = json.toString(); + pw.println(result); + pw.flush(); + pw.close(); + } + + public static void responseText(HttpServletResponse res,String text){ + PrintWriter pw; + try { + pw = WebUtils.createPrintWriter(res); + } catch (Exception e) { + FineLoggerFactory.getLogger().info(e.getMessage()); + return; + } + res.setContentType("text/html;charset=utf-8"); + pw.println(text); + pw.flush(); + pw.close(); + } + + public static void responseXml(HttpServletResponse res,String xml){ + PrintWriter pw; + try { + pw = WebUtils.createPrintWriter(res); + } catch (Exception e) { + FineLoggerFactory.getLogger().info(e.getMessage()); + return; + } + res.setContentType("text/xml;charset=utf-8"); + pw.println(xml); + pw.flush(); + pw.close(); + } + + public static void setCSRFHeader(HttpServletResponse httpServletResponse){ + httpServletResponse.setHeader("Access-Control-Allow-Origin", "*"); + httpServletResponse.setHeader("Access-Control-Allow-Methods", "POST,GET,OPTIONS,DELETE,HEAD,PUT,PATCH"); + httpServletResponse.setHeader("Access-Control-Max-Age", "36000"); + httpServletResponse.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept,Authorization,authorization"); + } + + public static void responseJsonp(HttpServletRequest req, HttpServletResponse res, JSONObject json){ + PrintWriter pw; + try { + pw = WebUtils.createPrintWriter(res); + } catch (Exception e) { + FineLoggerFactory.getLogger().info(e.getMessage()); + return; + } + res.setContentType("text/javascript;charset=utf-8;charset=utf-8"); + String result = json.toString(); + + String jsonp=req.getParameter("callback"); + + pw.println(jsonp+"("+result+")"); + pw.flush(); + pw.close(); + } +} diff --git a/src/main/java/com/eco/plugin/xx/hrzdmsg/utils/Utils.java b/src/main/java/com/eco/plugin/xx/hrzdmsg/utils/Utils.java new file mode 100644 index 0000000..133a2ee --- /dev/null +++ b/src/main/java/com/eco/plugin/xx/hrzdmsg/utils/Utils.java @@ -0,0 +1,329 @@ +package com.eco.plugin.wink.hrzdmsg.utils; + +import com.fr.base.TemplateUtils; +import com.fr.data.NetworkHelper; +import com.fr.decision.webservice.v10.user.UserService; +import com.fr.io.utils.ResourceIOUtils; +import com.fr.json.JSONObject; +import com.fr.stable.CodeUtils; +import com.fr.stable.StringUtils; +import com.fr.third.org.apache.commons.codec.digest.DigestUtils; +import com.fr.web.utils.WebUtils; + +import javax.servlet.http.Cookie; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.BufferedReader; +import java.io.InputStream; +import java.net.URLEncoder; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class Utils { + + /** + * 判断字符串是否为空 + * @param str + * @return true 空字符串 false 非空字符串 + */ + public static boolean isNullStr(String str){ + return !(str != null && !str.isEmpty() && !"null".equals(str)); + } + + /** + * 判断字符串是否非空 + * @param str + * @return + */ + public static boolean isNotNullStr(String str){ + return !isNullStr(str); + } + + /** + * MD5加密 + * @param str + * @return + */ + public static String getMd5Str(String str) + { + return DigestUtils.md5Hex(str); + } + + /** + * 帆软shaEncode加密 + */ + + public static String shaEncode(String str){ + return CodeUtils.sha256Encode(str); + } + + /** + * 获取uuid + */ + public static String uuid(){ + return UUID.randomUUID().toString(); + } + + /** + * 替换空字符串 + * @param str + * @param replace + * @return + */ + public static String replaceNullStr(String str,String replace){ + if(isNullStr(str)){ + return replace; + } + + return str; + } + + /** + * 获取请求体 + * @param req + * @return + */ + public static JSONObject getRequestBody(HttpServletRequest req){ + StringBuffer sb = new StringBuffer(); + String line = null; + try { + BufferedReader reader = req.getReader(); + while ((line = reader.readLine()) != null) + sb.append(line); + } catch (Exception e) { + FRUtils.FRLogInfo("getRequestBody:exception:"+e.getMessage()); + } + //将空格和换行符替换掉避免使用反序列化工具解析对象时失败 + String jsonString = sb.toString().replaceAll("\\s","").replaceAll("\n",""); + + JSONObject json = new JSONObject(jsonString); + + return json; + } + + /** + * 获取ip + * @return + */ + public static String getIp(HttpServletRequest req){ + String realIp = req.getHeader("X-Real-IP"); + String fw = req.getHeader("X-Forwarded-For"); + if (StringUtils.isNotEmpty(fw) && !"unKnown".equalsIgnoreCase(fw)) { + int para3 = fw.indexOf(","); + return para3 != -1 ? fw.substring(0, para3) : fw; + } else { + fw = realIp; + if (StringUtils.isNotEmpty(realIp) && !"unKnown".equalsIgnoreCase(realIp)) { + return realIp; + } else { + if (StringUtils.isBlank(realIp) || "unknown".equalsIgnoreCase(realIp)) { + fw = req.getHeader("Proxy-Client-IP"); + } + + if (StringUtils.isBlank(fw) || "unknown".equalsIgnoreCase(fw)) { + fw = req.getHeader("WL-Proxy-Client-IP"); + } + + if (StringUtils.isBlank(fw) || "unknown".equalsIgnoreCase(fw)) { + fw = req.getHeader("HTTP_CLIENT_IP"); + } + + if (StringUtils.isBlank(fw) || "unknown".equalsIgnoreCase(fw)) { + fw = req.getHeader("HTTP_X_FORWARDED_FOR"); + } + + if (StringUtils.isBlank(fw) || "unknown".equalsIgnoreCase(fw)) { + fw = req.getRemoteAddr(); + } + + return fw; + } + } + } + + /** + * 根据key获取cookie + * @param req + * @return + */ + public static String getCookieByKey(HttpServletRequest req,String key){ + Cookie[] cookies = req.getCookies(); + String cookie = ""; + + if(cookies == null || cookies.length <=0){ + return ""; + } + + for(int i = 0; i < cookies.length; i++) { + Cookie item = cookies[i]; + if (item.getName().equalsIgnoreCase(key)) { + cookie = item.getValue(); + } + } + + FRUtils.FRLogInfo("cookie:"+cookie); + + return cookie; + } + + /** + * 判断是否是手机端的链接 + * @param req + * @return + */ + public static boolean isMobile(HttpServletRequest req) { + String[] mobileArray = {"iPhone", "iPad", "android", "windows phone", "xiaomi"}; + String userAgent = req.getHeader("user-agent"); + if (userAgent != null && userAgent.toUpperCase().contains("MOBILE")) { + for(String mobile : mobileArray) { + if(userAgent.toUpperCase().contains(mobile.toUpperCase())) { + return true; + } + } + } + return NetworkHelper.getDevice(req).isMobile(); + } + + /** + * 只编码中文 + * @param url + * @return + */ + public static String encodeCH(String url ){ + Matcher matcher = Pattern.compile("[\\u4e00-\\u9fa5]").matcher(url); + + while(matcher.find()){ + String chn = matcher.group(); + url = url.replaceAll(chn, URLEncoder.encode(chn)); + } + + return url; + } + + /** + * 获取web-inf文件夹下的文件 + * filename /resources/ip4enc.properties + */ + public static InputStream getResourcesFile(String filename){ + return ResourceIOUtils.read(filename); + } + + /** + * + * @param res + * @param path /com/fr/plugin/loginAuth/html/getMac.html + * @param parameterMap + */ + public static void toErrorPage(HttpServletResponse res,String path,Map parameterMap){ + if(parameterMap == null){ + parameterMap = new HashMap(); + } + + try { + String macPage = TemplateUtils.renderTemplate(path, parameterMap); + WebUtils.printAsString(res, macPage); + }catch (Exception e){ + FRUtils.FRLogError("跳转页面异常"); + } + + } + + /** + * 判断是否是管理员 + * @param username + * @return + */ + public static boolean isAdmin(String username) throws Exception{ + return UserService.getInstance().isAdmin(UserService.getInstance().getUserByUserName(username).getId()); + } + + /** + * 去掉浏览器中的参数 + * @param url + * @param param + * @return + */ + public static String removeParam(String url,String param){ + if(!url.contains("?"+param) && !url.contains("&"+param)){ + return url; + } + + return url.substring(0,url.indexOf(url.contains("?"+param) ? "?"+param : "&"+param)); + } + + /** + * 获取跳转链接 + * @param req + * @param param + * @return + */ + public static String getRedirectUrl(HttpServletRequest req,String param){ + String url = FRUtils.getAllUrl(req); + + if(isNotNullStr(param)){ + url = removeParam(url,param); + } + + url = encodeCH(url); + + return url; + } + + /** + * 去除空格换行 + * @param str + * @return + */ + public static String trim(String str){ + return str.trim().replaceAll("\n","").replaceAll("\r",""); + } + + /** + * list 转化为指定字符分割的字符串 + * @param list + * @param list + * @return + */ + public static String listToStr(List list, String split){ + String result = ""; + + if(list == null || list.size() <= 0){ + return result; + } + + for(String str : list){ + result+=","+str; + } + + result = result.substring(1); + + return result; + } + + /** + * array 转化为指定字符分割的字符串 + * @param list + * @param list + * @return + */ + public static String arrayToStr(String[] list, String split){ + String result = ""; + + if(list == null ||list.length <= 0){ + return result; + } + + for(int i=0;i 0) ? (r.push(t), BI.each(i, function (e, t) { + var i = t.actionName; + r.push(i), + o[i] = t + }), s = BI.concat(s, BI.difference(l[t].actions, r))) : (r.push(t), o[t] = i), a.push(l[t].runType)) + }); + var t = BI.filter(i, function (e, t) { + return c.store.isDefaultByRunType(t, a) || c.store.isDefaultValueItem(t, r, s) + }); + return { + scheduleOutput: BI.extend({}, this.model.currTask.scheduleOutput, { + outputActionList: BI.map(o, function (e, t) { + return delete t.runType, + BI.extend({ + resultURL: window.location.protocol + "//" + window.location.host + Dec.fineServletURL + }, t) + }).concat(t) + }) + } + }, + _cardCreator: function (i) { + var t = this, + e = BI.find(this.model.handlingItems, function (e, t) { + return t.value === i + }); + return e && BI.isKey(e.cardType) ? { + type: e.cardType, + value: this.store.findActionValue(e, BI.deepClone(this.model.outputActionList)), + ref: function (e) { + t[i + "Pane"] = e + } + } + : { + type: "bi.label", + text: i + } + }, + _createLeftItems: function (e) { + var n = this; + return BI.map(e, function (e, t) { + var i = n.model.handlingItems[t].text; + return { + type: "dec.schedule.task.file.handling.item", + text: i, + value: t, + listeners: [{ + eventName: "EVENT_DELETE", + action: function () { + n.store.deleteAction(t, i) + } + } + ] + } + }) + } +}); + +BI.shortcut("dec.schedule.task.handling", e) \ No newline at end of file diff --git a/src/main/resources/com/eco/plugin/xx/hrzdmsg/js/ui.js b/src/main/resources/com/eco/plugin/xx/hrzdmsg/js/ui.js new file mode 100644 index 0000000..de4b7da --- /dev/null +++ b/src/main/resources/com/eco/plugin/xx/hrzdmsg/js/ui.js @@ -0,0 +1,18 @@ +FR.sendMsg = function(param){ + var result = ""; + var paramstr = JSON.stringify(param); + $.ajax({ + async:false, + url : "/webroot/decision/sendMsg", + method:"post", + contentType:"application/json", + data:paramstr, + success:function(data){ + result = data; + }, + error:function(data){ + result = data; + } + }) + return result; +} \ No newline at end of file