mirror of
https://github.com/yanlongqi/jhinno-openapi-java-sdk.git
synced 2026-03-22 06:15:10 +08:00
Compare commits
3 Commits
release-2.
...
release-2.
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d134b8dc70 | ||
|
|
3686d17f9d | ||
|
|
75c7e02253 |
@@ -5,7 +5,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<artifactId>jhinno-openapi-java-sdk</artifactId>
|
<artifactId>jhinno-openapi-java-sdk</artifactId>
|
||||||
<version>2.0.0</version>
|
<version>2.0.1</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<name>Jhinno OpenAPI SDK for Java</name>
|
<name>Jhinno OpenAPI SDK for Java</name>
|
||||||
<description>The Jhinno OpenAPI SDK for Java used for accessing Jhinno OpenApi Service</description>
|
<description>The Jhinno OpenAPI SDK for Java used for accessing Jhinno OpenApi Service</description>
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.jhinno</groupId>
|
<groupId>com.jhinno</groupId>
|
||||||
<artifactId>jhinno-openapi-java-sdk-parent</artifactId>
|
<artifactId>jhinno-openapi-java-sdk-parent</artifactId>
|
||||||
<version>2.0.0</version>
|
<version>2.0.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|||||||
@@ -57,6 +57,12 @@ public class CommonConstant {
|
|||||||
*/
|
*/
|
||||||
public static final String CURRENT_TIME_MILLIS = "currentTimeMillis";
|
public static final String CURRENT_TIME_MILLIS = "currentTimeMillis";
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* TOKEN
|
||||||
|
*/
|
||||||
|
public static final String TOKEN = "token";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 签名加密格式
|
* 签名加密格式
|
||||||
* <ul>
|
* <ul>
|
||||||
|
|||||||
@@ -43,10 +43,11 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
public class JHApiExecution {
|
public class JHApiExecution {
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* JHApiClient实例
|
* JHApiClient实例
|
||||||
*/
|
*/
|
||||||
public JHApiClient jhApiClient;
|
private JHApiClient jhApiClient;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* token的超时时间
|
* token的超时时间
|
||||||
@@ -157,7 +158,7 @@ public class JHApiExecution {
|
|||||||
/**
|
/**
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
private String getCurrentTimeMillis() {
|
public String getCurrentTimeMillis() {
|
||||||
if (authType == AuthType.ACCESS_SECRET_MODE || !isUsedServerTime) {
|
if (authType == AuthType.ACCESS_SECRET_MODE || !isUsedServerTime) {
|
||||||
return String.valueOf(System.currentTimeMillis());
|
return String.valueOf(System.currentTimeMillis());
|
||||||
}
|
}
|
||||||
@@ -196,7 +197,7 @@ public class JHApiExecution {
|
|||||||
headers.put(CommonConstant.CURRENT_TIME_MILLIS, currentTimeMillis);
|
headers.put(CommonConstant.CURRENT_TIME_MILLIS, currentTimeMillis);
|
||||||
headers.put(CommonConstant.SIGNATURE, getsSignature(username, currentTimeMillis));
|
headers.put(CommonConstant.SIGNATURE, getsSignature(username, currentTimeMillis));
|
||||||
} else if (authType == AuthType.TOKEN_MODE && StringUtils.isNotBlank(username)) {
|
} else if (authType == AuthType.TOKEN_MODE && StringUtils.isNotBlank(username)) {
|
||||||
headers.put("token", getToken(username));
|
headers.put(CommonConstant.TOKEN, getToken(username));
|
||||||
}
|
}
|
||||||
return headers;
|
return headers;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -91,4 +91,10 @@ public class AppPathConstant {
|
|||||||
* 获取应用链接URL
|
* 获取应用链接URL
|
||||||
*/
|
*/
|
||||||
public static final String APPS_GET_URL_PATH = "/ws/api/apps/{appName}/url";
|
public static final String APPS_GET_URL_PATH = "/ws/api/apps/{appName}/url";
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* WEB启动会话URL
|
||||||
|
*/
|
||||||
|
public static final String WEB_SESSION_URL_PATH = "/pageapi/apps/webclient/gui/{desktopId}";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,4 +34,9 @@ public class AppStartedInfo {
|
|||||||
* 作业id(有可能出现,但不是太明白)
|
* 作业id(有可能出现,但不是太明白)
|
||||||
*/
|
*/
|
||||||
private String jobId;
|
private String jobId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* WEB 启动会话URL
|
||||||
|
*/
|
||||||
|
private String webSessionUrl;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.jhinno.sdk.openapi.api.app;
|
|||||||
|
|
||||||
import com.fasterxml.jackson.core.type.TypeReference;
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
import com.jhinno.sdk.openapi.ArgsException;
|
import com.jhinno.sdk.openapi.ArgsException;
|
||||||
|
import com.jhinno.sdk.openapi.AuthType;
|
||||||
import com.jhinno.sdk.openapi.CommonConstant;
|
import com.jhinno.sdk.openapi.CommonConstant;
|
||||||
import com.jhinno.sdk.openapi.ServiceException;
|
import com.jhinno.sdk.openapi.ServiceException;
|
||||||
import com.jhinno.sdk.openapi.api.JHApiExecution;
|
import com.jhinno.sdk.openapi.api.JHApiExecution;
|
||||||
@@ -35,8 +36,10 @@ public class JHAppApiExecution extends JHApiExecution {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 启动一个会话
|
* 启动一个会话
|
||||||
|
*
|
||||||
|
* <h4>一、通过JHClient启动</h4>
|
||||||
* <p>
|
* <p>
|
||||||
* 改方法返回一个重要的参数{@link AppStartedInfo#getJhappUrl()}(拉起景行客户端协议的URL)。
|
* 方法返回一个重要的参数{@link AppStartedInfo#getJhappUrl()}(拉起景行客户端协议的URL)。
|
||||||
* <p>
|
* <p>
|
||||||
* 测试:将该URL复制粘贴到浏览器的地址栏进行访问即可启动会话。
|
* 测试:将该URL复制粘贴到浏览器的地址栏进行访问即可启动会话。
|
||||||
*
|
*
|
||||||
@@ -61,6 +64,16 @@ public class JHAppApiExecution extends JHApiExecution {
|
|||||||
* iframe.src = "{@link AppStartedInfo#getJhappUrl()}";
|
* iframe.src = "{@link AppStartedInfo#getJhappUrl()}";
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
|
* <p>
|
||||||
|
* 注意:如果使用JHAppClient启动应用的,并且没有做浏览器端和服务器没有做时间同步,
|
||||||
|
* 那么 {@link AppStartRequest#setCurrentTimestamp(String)} 参数必传,
|
||||||
|
* 并使用js生产的时间,具体的参数见 {@link AppStartRequest#setCurrentTimestamp(String)}
|
||||||
|
*
|
||||||
|
* <h4>通过浏览器启动</h4>
|
||||||
|
* <pre class="code">
|
||||||
|
* window.open("{@link AppStartedInfo#getWebSessionUrl()}}")
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
* @param username 用户名
|
* @param username 用户名
|
||||||
* @param appId 应用拆
|
* @param appId 应用拆
|
||||||
* @param appStartRequest 启动参数
|
* @param appStartRequest 启动参数
|
||||||
@@ -73,7 +86,26 @@ public class JHAppApiExecution extends JHApiExecution {
|
|||||||
if (CollectionUtil.isEmpty(data)) {
|
if (CollectionUtil.isEmpty(data)) {
|
||||||
throw new ServiceException(path, 500, "获取到的会话信息为空");
|
throw new ServiceException(path, 500, "获取到的会话信息为空");
|
||||||
}
|
}
|
||||||
return data.get(0);
|
AppStartedInfo appStartedInfo = data.get(0);
|
||||||
|
appStartedInfo.setWebSessionUrl(getWebSessionUrl(username, appStartedInfo.getDesktopId()));
|
||||||
|
return appStartedInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getWebSessionUrl(String username, String desktopId) {
|
||||||
|
String webSessionUrlPath = AppPathConstant.WEB_SESSION_URL_PATH.replace("{desktopId}", desktopId);
|
||||||
|
String url = getJhApiClient().getUrl(webSessionUrlPath);
|
||||||
|
Map<String, Object> params = new HashMap<>();
|
||||||
|
AuthType authType = getAuthType();
|
||||||
|
if (authType == AuthType.TOKEN_MODE) {
|
||||||
|
params.put(CommonConstant.TOKEN, getToken(username));
|
||||||
|
} else if (authType == AuthType.ACCESS_SECRET_MODE) {
|
||||||
|
params.put(CommonConstant.USERNAME, username);
|
||||||
|
params.put(CommonConstant.ACCESS_KEY, getAccessKey());
|
||||||
|
String currentTimeMillis = getCurrentTimeMillis();
|
||||||
|
params.put(CommonConstant.CURRENT_TIME_MILLIS, currentTimeMillis);
|
||||||
|
params.put(CommonConstant.SIGNATURE, getsSignature(username, currentTimeMillis));
|
||||||
|
}
|
||||||
|
return JHApiClient.getUrl(url, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -266,7 +298,10 @@ public class JHAppApiExecution extends JHApiExecution {
|
|||||||
if (CollectionUtil.isEmpty(list)) {
|
if (CollectionUtil.isEmpty(list)) {
|
||||||
throw new ServiceException(path, 500, "获取到的会话信息为空");
|
throw new ServiceException(path, 500, "获取到的会话信息为空");
|
||||||
}
|
}
|
||||||
return list.get(0);
|
|
||||||
|
AppStartedInfo appStartedInfo = list.get(0);
|
||||||
|
appStartedInfo.setWebSessionUrl(getWebSessionUrl(username, sessionId));
|
||||||
|
return appStartedInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -196,8 +196,16 @@ public class JHFileApiExecution extends JHApiExecution {
|
|||||||
}
|
}
|
||||||
body.put("uploadPath", uploadPath);
|
body.put("uploadPath", uploadPath);
|
||||||
|
|
||||||
ResponseResult<Object> result = jhApiClient.upload(FilePathConstant.FILE_UPLOAD_PATH, "file", fileName, is, getHeaders(username, false), body, new TypeReference<ResponseResult<Object>>() {
|
ResponseResult<Object> result = getJhApiClient().upload(
|
||||||
});
|
FilePathConstant.FILE_UPLOAD_PATH,
|
||||||
|
"file",
|
||||||
|
fileName,
|
||||||
|
is,
|
||||||
|
getHeaders(username, false),
|
||||||
|
body,
|
||||||
|
new TypeReference<ResponseResult<Object>>() {
|
||||||
|
}
|
||||||
|
);
|
||||||
if (StringUtils.equals(result.getResult(), CommonConstant.FAILED)) {
|
if (StringUtils.equals(result.getResult(), CommonConstant.FAILED)) {
|
||||||
throw new ServiceException(FilePathConstant.FILE_UPLOAD_PATH, result.getCode(), result.getMessage());
|
throw new ServiceException(FilePathConstant.FILE_UPLOAD_PATH, result.getCode(), result.getMessage());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import com.jhinno.sdk.openapi.utils.JsonUtil;
|
|||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import com.jhinno.sdk.openapi.utils.CollectionUtil;
|
import com.jhinno.sdk.openapi.utils.CollectionUtil;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -355,7 +356,7 @@ public class JHJobApiExecution extends JHApiExecution {
|
|||||||
throw new ArgsException("jobId不能为空!");
|
throw new ArgsException("jobId不能为空!");
|
||||||
}
|
}
|
||||||
String path = JobPathConstant.JOB_PEEK_PATH.replace("{jobId}", jobId);
|
String path = JobPathConstant.JOB_PEEK_PATH.replace("{jobId}", jobId);
|
||||||
ResponseResult<String> result = jhApiClient.get(path, getHeaders(username), new TypeReference<ResponseResult<String>>() {
|
ResponseResult<String> result = getJhApiClient().get(path, getHeaders(username), new TypeReference<ResponseResult<String>>() {
|
||||||
});
|
});
|
||||||
if (StringUtils.equals(result.getResult(), CommonConstant.FAILED)) {
|
if (StringUtils.equals(result.getResult(), CommonConstant.FAILED)) {
|
||||||
throw new ServiceException(path, result.getCode(), result.getMessage());
|
throw new ServiceException(path, result.getCode(), result.getMessage());
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ public class JHClientConfig {
|
|||||||
/**
|
/**
|
||||||
* 初始化JHApi客户端
|
* 初始化JHApi客户端
|
||||||
*/
|
*/
|
||||||
public static final JHApiClient client = new JHApiClient("https://172.17.0.5/appform");
|
public static final JHApiClient client = new JHApiClient("https://172.17.0.6/appform");
|
||||||
|
|
||||||
public static final Map<Class<? extends JHApiExecution>, JHApiExecution> jhApiClientMap = new HashMap<>();
|
public static final Map<Class<? extends JHApiExecution>, JHApiExecution> jhApiClientMap = new HashMap<>();
|
||||||
|
|
||||||
@@ -43,7 +43,7 @@ public class JHClientConfig {
|
|||||||
|
|
||||||
jhApiClientMap.forEach((k, v) -> {
|
jhApiClientMap.forEach((k, v) -> {
|
||||||
v.setJhApiClient(client);
|
v.setJhApiClient(client);
|
||||||
v.setAuthType(AuthType.ACCESS_SECRET_MODE);
|
v.setAuthType(AuthType.TOKEN_MODE);
|
||||||
v.setAccessKey(ACCESS_KEY);
|
v.setAccessKey(ACCESS_KEY);
|
||||||
v.setAccessKeySecret(ACCESS_KEY_SECRET);
|
v.setAccessKeySecret(ACCESS_KEY_SECRET);
|
||||||
v.setUsedServerTime(true);
|
v.setUsedServerTime(true);
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
<artifactId>jhinno-openapi-sdk-spring-boot-starter</artifactId>
|
<artifactId>jhinno-openapi-sdk-spring-boot-starter</artifactId>
|
||||||
<version>2.0.0</version>
|
<version>2.0.1</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
<name>Jhinno OpenAPI SDK for Java SpringBoot Starter</name>
|
<name>Jhinno OpenAPI SDK for Java SpringBoot Starter</name>
|
||||||
<description>The Jhinno OpenAPI SDK for Java used for accessing Jhinno OpenApi Service</description>
|
<description>The Jhinno OpenAPI SDK for Java used for accessing Jhinno OpenApi Service</description>
|
||||||
@@ -14,7 +14,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>com.jhinno</groupId>
|
<groupId>com.jhinno</groupId>
|
||||||
<artifactId>jhinno-openapi-java-sdk-parent</artifactId>
|
<artifactId>jhinno-openapi-java-sdk-parent</artifactId>
|
||||||
<version>2.0.0</version>
|
<version>2.0.1</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|
||||||
@@ -22,7 +22,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.jhinno</groupId>
|
<groupId>com.jhinno</groupId>
|
||||||
<artifactId>jhinno-openapi-java-sdk</artifactId>
|
<artifactId>jhinno-openapi-java-sdk</artifactId>
|
||||||
<version>2.0.0</version>
|
<version>2.0.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|||||||
2
pom.xml
2
pom.xml
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>com.jhinno</groupId>
|
<groupId>com.jhinno</groupId>
|
||||||
<artifactId>jhinno-openapi-java-sdk-parent</artifactId>
|
<artifactId>jhinno-openapi-java-sdk-parent</artifactId>
|
||||||
<version>2.0.0</version>
|
<version>2.0.1</version>
|
||||||
<packaging>pom</packaging>
|
<packaging>pom</packaging>
|
||||||
<name>Jhinno OpenAPI SDK for Java parent</name>
|
<name>Jhinno OpenAPI SDK for Java parent</name>
|
||||||
<description>The Jhinno OpenAPI SDK for Java used for accessing Jhinno OpenApi Service</description>
|
<description>The Jhinno OpenAPI SDK for Java used for accessing Jhinno OpenApi Service</description>
|
||||||
|
|||||||
Reference in New Issue
Block a user