Browse Source

open

master
pioneer 2 years ago
commit
0b97edb9ab
  1. 6
      README.md
  2. BIN
      lib/finekit-10.0.jar
  3. 21
      plugin.xml
  4. 59
      pom.xml
  5. 27
      src/main/java/com/fr/plugin/third/party/jsdbabbe/OutputPluginLifecycleMonitor.java
  6. 342
      src/main/java/com/fr/plugin/third/party/jsdbabbe/Utils.java
  7. 71
      src/main/java/com/fr/plugin/third/party/jsdbabbe/config/CustomDataConfig.java
  8. 117
      src/main/java/com/fr/plugin/third/party/jsdbabbe/http/CustomConfigHttpHandler.java
  9. 16
      src/main/java/com/fr/plugin/third/party/jsdbabbe/http/CustomHttpHandlerProvider.java
  10. 14
      src/main/java/com/fr/plugin/third/party/jsdbabbe/http/CustomURLAliasProvider.java

6
README.md

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

BIN
lib/finekit-10.0.jar

Binary file not shown.

21
plugin.xml

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?><plugin>
<id>com.fr.plugin.third.party.jsdbabbe</id>
<name><![CDATA[消息待办推送_EK]]></name>
<active>yes</active>
<version>1.0.7</version>
<env-version>10.0</env-version>
<jartime>2019-01-01</jartime>
<vendor>FR.OPEN</vendor>
<description><![CDATA[]]></description>
<change-notes><![CDATA[
[2022-07-18]JSD-10114插件初始化<br/>
]]></change-notes>
<lifecycle-monitor class="com.fr.plugin.third.party.jsdbabbe.OutputPluginLifecycleMonitor"/>
<extra-core>
</extra-core>
<extra-decision>
<HttpHandlerProvider class="com.fr.plugin.third.party.jsdbabbe.http.CustomHttpHandlerProvider"/>
<URLAliasProvider class="com.fr.plugin.third.party.jsdbabbe.http.CustomURLAliasProvider"/>
</extra-decision>
<function-recorder class="com.fr.plugin.third.party.jsdbabbe.OutputPluginLifecycleMonitor"/>
</plugin>

59
pom.xml

@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.fr.plugin</groupId>
<artifactId>starter</artifactId>
<version>10.0</version>
</parent>
<packaging>jar</packaging>
<artifactId>plugin-jsd-10114</artifactId>
<dependencies>
<dependency>
<groupId>com.fanruan.api</groupId>
<artifactId>finekit</artifactId>
<version>10.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/finekit-10.0.jar</systemPath>
</dependency>
</dependencies>
<properties>
<!---如果要更改调试插件,改这里的配置就可以了-->
<plugin-path>
${project.basedir}/../webroot/WEB-INF/plugins/plugin-com.fr.plugin.third.party.jsdbabbe-1.0
</plugin-path>
</properties>
<build>
<outputDirectory>${plugin-path}/classes</outputDirectory>
<resources>
<resource>
<targetPath>${plugin-path}</targetPath>
<directory>${project.basedir}</directory>
<includes>
<include>plugin.xml</include>
</includes>
</resource>
<resource>
<targetPath>${plugin-path}</targetPath>
<directory>${project.basedir}/lib</directory>
<includes>
<include>*.jar</include>
<include>*.dll</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>

27
src/main/java/com/fr/plugin/third/party/jsdbabbe/OutputPluginLifecycleMonitor.java

@ -0,0 +1,27 @@
package com.fr.plugin.third.party.jsdbabbe;
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.jsdbabbe.config.CustomDataConfig;
import com.fr.record.analyzer.EnableMetrics;
import com.fr.stable.fun.Authorize;
/**
* 配置信息初始化
*/
@EnableMetrics
@Authorize(callSignKey = "com.fr.plugin.third.party.jsdbabbe")
public class OutputPluginLifecycleMonitor extends AbstractPluginLifecycleMonitor {
@Override
@Focus(id = "com.fr.plugin.third.party.jsdbabbe", text = "plugin-jsdbabbe", source = Original.PLUGIN)
public void afterRun(PluginContext pluginContext) {
CustomDataConfig.getInstance();
}
@Override
public void beforeStop(PluginContext pluginContext) {
}
}

342
src/main/java/com/fr/plugin/third/party/jsdbabbe/Utils.java

@ -0,0 +1,342 @@
package com.fr.plugin.third.party.jsdbabbe;
import com.fanruan.api.log.LogKit;
import com.fanruan.api.util.StringKit;
import com.fr.decision.authority.data.User;
import com.fr.decision.webservice.bean.user.UserBean;
import com.fr.decision.webservice.bean.user.UserUpdateBean;
import com.fr.decision.webservice.impl.user.UserPageQueryAuthorityParam;
import com.fr.decision.webservice.utils.ControllerFactory;
import com.fr.decision.webservice.utils.controller.UserController;
import com.fr.decision.webservice.v10.user.UserService;
import com.fr.plugin.third.party.jsdbabbe.config.CustomDataConfig;
import com.fr.stable.StringUtils;
import com.fr.stable.query.data.DataList;
import com.fr.stable.query.restriction.Restriction;
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.ArrayList;
import java.util.List;
import java.util.Map;
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 createSslHttpClient() {
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 CloseableHttpClient createDefaultHttpClient() {
CloseableHttpClient httpClient = HttpClients.custom()
.build();
return httpClient;
}
public static synchronized CloseableHttpClient createHttpClient(String url) {
CloseableHttpClient httpClient = null;
if (StringKit.isEmpty(url)) {
httpClient = createDefaultHttpClient();
return httpClient;
}
if (url.startsWith("https://")) {
httpClient = createSslHttpClient();
return httpClient;
}
httpClient = createDefaultHttpClient();
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, Map<String, String> headers) 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 ((headers != null) && (headers.size() >= 1)) {
for (Map.Entry<String,String> entry: headers.entrySet()) {
httpPost.addHeader(entry.getKey(), entry.getValue());
}
}
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;
}
/**
* 获取用户信息
*
* @param userCount 用户数,-1为不限制用户数
* @param isAdminContained 是否包含管理员用户
* @return
* @throws Exception
*/
public static List<UserBean> getAllUsers(int userCount, boolean isAdminContained) throws Exception {
List<UserBean> userBeans = new ArrayList<>();
if (userCount == 0) {
return userBeans;
}
int limitCount = userCount;
if (userCount <= -1) {
limitCount = Integer.MAX_VALUE;
}
List<String> adminUserIds = UserService.getInstance().getAdminUserIdList();
if ((adminUserIds == null) || (adminUserIds.size() <= 0)) {
return userBeans;
}
String adminUserId = adminUserIds.get(0);
UserController userController = ControllerFactory.getInstance().getUserController(adminUserId);
DataList dataList = userController.findPageUsersPerfectMatch(adminUserId, new UserPageQueryAuthorityParam(1, limitCount, "", null), new Restriction[0]);
if (dataList == null) {
return userBeans;
}
List users = dataList.getList();
if ((users == null) || (users.size() <= 0)) {
return userBeans;
}
User user;
UserBean userBean;
String userId;
for (int i = 0, max = users.size() - 1; i <= max; i++) {
user = (User) users.get(i);
userId = user.getId();
if ((!isAdminContained) && (adminUserIds.contains(userId))) {
continue;
}
userBean = new UserBean(user.getEmail(), user.isEnable(), user.getMobile(), user.getRealName(), user.getUserName(), user.getId());
userBean.setCreationType(user.getCreationType().toInteger());
userBeans.add(userBean);
}
return userBeans;
}
/**
* 获取不包含管理员的用户信息
*
* @param userCount
* @return
* @throws Exception
*/
public static List<UserBean> getAllUsersWithoutAdmin(int userCount) throws Exception {
return getAllUsers(userCount, false);
}
public static List<String> getAllUserNames(int userCount, boolean isAdminContained) throws Exception {
List<String> userNames = new ArrayList<>();
List<UserBean> userBeans = getAllUsers(userCount, isAdminContained);
UserBean userBean;
for (int i = 0, max = userBeans.size() - 1; i <= max; i++) {
userBean = userBeans.get(i);
userNames.add(userBean.getUsername());
}
return userNames;
}
public static List<String> getAllUserNamesWithoutAdmin(int userCount) throws Exception {
return getAllUserNames(userCount, false);
}
/**
* 通过用户名删除用户,管理员用户无法删除
*
* @param username 用户名
* @return
* @throws Exception
*/
public static int deleteUsersByUsername(String username) throws Exception {
if (StringUtils.isEmpty(username)) {
return 0;
}
User user = UserService.getInstance().getUserByUserName(username);
if (user == null) {
return 0;
}
String userId = user.getId();
List<String> adminUserIds = UserService.getInstance().getAdminUserIdList();
if ((adminUserIds != null) && (adminUserIds.size() >= 1) && (adminUserIds.contains(userId))) {
return 0;
}
UserUpdateBean userUpdateBean = new UserUpdateBean();
userUpdateBean.setRemoveUserIds(new String[]{userId});
return UserService.getInstance().deleteUsers(userUpdateBean);
}
public static int deleteUsersByUsernames(List<String> usernames) throws Exception {
if ((usernames == null) || (usernames.size() <= 0)) {
return 0;
}
String username;
int totalCount = 0, count;
for (int i = 0, max = usernames.size() - 1; i <= max; i++) {
username = usernames.get(i);
count = deleteUsersByUsername(username);
totalCount = totalCount + count;
}
return totalCount;
}
public static void editRealNameByUsername(String username, String realName) throws Exception {
if (StringUtils.isEmpty(username) || StringUtils.isEmpty(realName)) {
return;
}
User user = UserService.getInstance().getUserByUserName(username);
if (user == null) {
return;
}
UserBean userBean = new UserBean(user.getEmail(), user.isEnable(), user.getMobile(), realName, user.getUserName(), user.getId());
UserService.getInstance().editAccount(username, userBean);
}
}

71
src/main/java/com/fr/plugin/third/party/jsdbabbe/config/CustomDataConfig.java

@ -0,0 +1,71 @@
package com.fr.plugin.third.party.jsdbabbe.config;
import com.fr.config.*;
import com.fr.config.holder.Conf;
import com.fr.config.holder.factory.Holders;
import java.util.HashMap;
import java.util.Map;
/**
* 配置数据保存
*/
@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 = "key", name = "key", description = "", status = Status.SHOW)
private Conf<String> key = Holders.simple("");
@Identifier(value = "username", name = "用户名(username)", description = "", status = Status.SHOW)
private Conf<String> username = Holders.simple("");
@Identifier(value = "password", name = "密码(password)", description = "", status = Status.SHOW)
private Conf<String> password = Holders.simple("");
public String getKey() {
return key.get();
}
public void setKey(String key) {
this.key.set(key);
}
public String getUsername() {
return username.get();
}
public void setUsername(String username) {
this.username.set(username);
}
public String getPassword() {
return password.get();
}
public void setPassword(String password) {
this.password.set(password);
}
@Override
public Object clone() throws CloneNotSupportedException {
CustomDataConfig cloned = (CustomDataConfig) super.clone();
cloned.key = (Conf<String>) key.clone();
cloned.username = (Conf<String>) username.clone();
cloned.password = (Conf<String>) password.clone();
return cloned;
}
}

117
src/main/java/com/fr/plugin/third/party/jsdbabbe/http/CustomConfigHttpHandler.java

@ -0,0 +1,117 @@
package com.fr.plugin.third.party.jsdbabbe.http;
import com.fanruan.api.log.LogKit;
import com.fanruan.api.util.StringKit;
import com.fr.decision.fun.impl.BaseHttpHandler;
import com.fr.general.IOUtils;
import com.fr.json.JSONObject;
import com.fr.plugin.third.party.jsdbabbe.Utils;
import com.fr.plugin.third.party.jsdbabbe.config.CustomDataConfig;
import com.fr.third.org.apache.commons.codec.digest.DigestUtils;
import com.fr.third.org.apache.http.impl.client.CloseableHttpClient;
import com.fr.third.springframework.web.bind.annotation.RequestMethod;
import com.fr.web.utils.WebUtils;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
/**
*
*/
public class CustomConfigHttpHandler extends BaseHttpHandler {
@Override
public RequestMethod getMethod() {
return RequestMethod.POST;
}
@Override
public String getPath() {
return "/jsdbabbe/push/message";
}
@Override
public boolean isPublic() {
return true;
}
@Override
public void handle(HttpServletRequest req, HttpServletResponse res) throws Exception {
res.setContentType("application/json; charset=utf-8");
String reqContent = IOUtils.inputStream2String(req.getInputStream());
if (StringKit.isEmpty(reqContent)) {
LogKit.error("消息待办推送流程:请求内容为空");
WebUtils.printAsJSON(res, getFailureJson("请求内容为空"));
return;
}
String url = req.getHeader("Process-Url");
if (StringKit.isEmpty(url)) {
url = WebUtils.getHTTPRequestParameter(req, "process_url");
}
if (StringKit.isEmpty(url)) {
LogKit.error("消息待办推送流程:流程地址为空");
WebUtils.printAsJSON(res, getFailureJson("流程地址为空"));
return;
}
LogKit.info("消息待办推送流程地址:" + url + "\n请求内容:\n" + reqContent);
String resContent = pushMessage(url, reqContent);
if (StringKit.isEmpty(reqContent)) {
WebUtils.printAsJSON(res, getFailureJson("请求内容出错"));
return;
}
WebUtils.printAsJSON(res, getResultJson("success", resContent));
}
private String pushMessage(String url, String reqContent) throws IOException {
//reqContent = handleStr(reqContent);
CloseableHttpClient httpclient = Utils.createHttpClient(url);
Base64.Encoder encoder = Base64.getEncoder();
String auth = CustomDataConfig.getInstance().getUsername() + ":" + CustomDataConfig.getInstance().getPassword();
String basicAuth = "Basic " + (encoder.encodeToString(auth.getBytes(StandardCharsets.UTF_8)));
Map<String, String> headers = new HashMap<>();
headers.put("key", CustomDataConfig.getInstance().getKey());
LogKit.info("消息待办推送发起流程验证内容:\n" + headers);
String result = Utils.createHttpPostContent(httpclient, url, reqContent, basicAuth, "application/json; charset=utf-8", headers);
return result;
}
private JSONObject getSuccessJson() {
JSONObject json = getResultJson("success", "");
return json;
}
private JSONObject getFailureJson(String content) {
JSONObject json = getResultJson("failure", content);
return json;
}
private JSONObject getResultJson(String status, String content) {
JSONObject json = new JSONObject();
json.put("status", status);
json.put("content", new JSONObject(content));
return json;
}
private String handleStr(String value) {
if (StringKit.isEmpty(value)) {
return "";
}
String result = value;
result = result.trim();
result = result.replaceAll("\n", "");
result = result.replaceAll("\r", "");
result = result.trim();
return result;
}
}

16
src/main/java/com/fr/plugin/third/party/jsdbabbe/http/CustomHttpHandlerProvider.java

@ -0,0 +1,16 @@
package com.fr.plugin.third.party.jsdbabbe.http;
import com.fr.decision.fun.impl.AbstractHttpHandlerProvider;
import com.fr.decision.fun.impl.BaseHttpHandler;
public class CustomHttpHandlerProvider extends AbstractHttpHandlerProvider {
@Override
public BaseHttpHandler[] registerHandlers() {
return new BaseHttpHandler[]{
new CustomConfigHttpHandler(),
};
}
}

14
src/main/java/com/fr/plugin/third/party/jsdbabbe/http/CustomURLAliasProvider.java

@ -0,0 +1,14 @@
package com.fr.plugin.third.party.jsdbabbe.http;
import com.fr.decision.fun.impl.AbstractURLAliasProvider;
import com.fr.decision.webservice.url.alias.URLAlias;
import com.fr.decision.webservice.url.alias.URLAliasFactory;
public class CustomURLAliasProvider extends AbstractURLAliasProvider {
@Override
public URLAlias[] registerAlias() {
return new URLAlias[]{
URLAliasFactory.createPluginAlias("/jsdbabbe/push/message", "/jsdbabbe/push/message", true),
};
}
}
Loading…
Cancel
Save