|
|
|
|
|
|
|
|
|
# 开放平台子插件demo
|
|
|
|
|
|
|
|
|
|
``` txt
|
|
|
|
|
api接口,分三级结构(类似httpHandlerProvider)
|
|
|
|
|
分组类(CallerProvider)———API描述类(Loader)——API执行逻辑(Caller)
|
|
|
|
|
└——额外Caller(指不希望默认添加到面板但添加菜单里可以看到)
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#### PluginAPICallerProvider 提供方法registerCallers注册具体API
|
|
|
|
|
|
|
|
|
|
``` java
|
|
|
|
|
package com.tptj.plugin.hg.client.open.fun;
|
|
|
|
|
|
|
|
|
|
import com.fr.stable.fun.mark.Mutable;
|
|
|
|
|
|
|
|
|
|
public interface APICallerProvider extends Mutable {
|
|
|
|
|
String XML_TAG = "OpenClientAPIProvider";
|
|
|
|
|
int CURRENT_LEVEL = 1;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* API列表
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
PluginAPICaller[] registerCallers();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 希望读取到可添加项但不希望直接导入到面板的Caller
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
APICaller[] extraCaller();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 分组显示名 要求唯一
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
String groupName();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 分组描述
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
String groupDescription();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
#### PluginAPICaller提供具体api参数
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
``` java
|
|
|
|
|
package com.tptj.plugin.hg.client.open.fun;
|
|
|
|
|
|
|
|
|
|
import com.tptj.plugin.hg.client.center.core.store.api.APIEntity;
|
|
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
public interface APILoader {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return 显示名 唯一
|
|
|
|
|
*/
|
|
|
|
|
String APIName();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 插件逻辑类
|
|
|
|
|
* @return APICallerProvider
|
|
|
|
|
*/
|
|
|
|
|
APICaller APICaller();
|
|
|
|
|
/**
|
|
|
|
|
* @return 默认参数
|
|
|
|
|
*/
|
|
|
|
|
Map<String,Object> defaultParameters();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @return 请求路径 不含/webroot/decision/sp/client/api/
|
|
|
|
|
*/
|
|
|
|
|
String path();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 插件ID 统一分配
|
|
|
|
|
* @return ID
|
|
|
|
|
*/
|
|
|
|
|
String getApiId();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return 配置
|
|
|
|
|
*/
|
|
|
|
|
Map<String, Object> config();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return 是否公开
|
|
|
|
|
*/
|
|
|
|
|
boolean isPublic();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return 描述
|
|
|
|
|
*/
|
|
|
|
|
String Description();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return 请求类型 GET/POST/DELETE/PUT
|
|
|
|
|
*/
|
|
|
|
|
String RequestType();
|
|
|
|
|
APIEntity toAPIEntity();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
``` java
|
|
|
|
|
|
|
|
|
|
package com.tptj.plugin.hg.client.open.fun;
|
|
|
|
|
|
|
|
|
|
import com.fr.decision.webservice.Response;
|
|
|
|
|
import com.tptj.plugin.hg.client.open.exception.CodeException;
|
|
|
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @author 秃破天际
|
|
|
|
|
* @version 10.0
|
|
|
|
|
* Created by 秃破天际 on 2020-04-30
|
|
|
|
|
**/
|
|
|
|
|
public interface APICaller {
|
|
|
|
|
/**
|
|
|
|
|
* 传入请求和配置的默认参数,执行API,并给出响应
|
|
|
|
|
* @param req
|
|
|
|
|
* @param defaultParameters
|
|
|
|
|
* @param config
|
|
|
|
|
* @return
|
|
|
|
|
* @throws CodeException
|
|
|
|
|
*/
|
|
|
|
|
Response call(HttpServletRequest req, Map<String,Object> defaultParameters,Map<String,Object> config)throws CodeException;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Response call(HttpServletRequest req, HttpServletResponse res, Map<String,Object> defaultParameters, Map<String,Object> config)throws CodeException;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return 描述 尽量简短
|
|
|
|
|
*/
|
|
|
|
|
String Description();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
#### 认证器,类似 但是只有一级
|
|
|
|
|
|
|
|
|
|
``` java
|
|
|
|
|
package com.tptj.plugin.hg.client.open.fun;
|
|
|
|
|
|
|
|
|
|
import com.fr.stable.fun.mark.Mutable;
|
|
|
|
|
import com.tptj.plugin.hg.client.center.core.store.authentication.AuthEntity;
|
|
|
|
|
|
|
|
|
|
import java.util.Map;
|
|
|
|
|
|
|
|
|
|
public interface PluginAuthProvider extends AuthenticationProvider , Mutable {
|
|
|
|
|
String XML_TAG = "PluginAuthProvider";
|
|
|
|
|
int CURRENT_LEVEL = 1;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return ID 唯一
|
|
|
|
|
*/
|
|
|
|
|
String AuthId();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return 显示名 唯一
|
|
|
|
|
*/
|
|
|
|
|
String AuthName();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return 描述
|
|
|
|
|
*/
|
|
|
|
|
String Description();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return 默认参数
|
|
|
|
|
*/
|
|
|
|
|
Map<String,Object> defaultParameters();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return 配置
|
|
|
|
|
*/
|
|
|
|
|
Map<String, Object> config();
|
|
|
|
|
|
|
|
|
|
AuthEntity toAuthEntity();
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据请求和配置进行自定义的权限验证
|
|
|
|
|
* @param req
|
|
|
|
|
* @param defaultParameters
|
|
|
|
|
* @param config
|
|
|
|
|
* @return 是否通过
|
|
|
|
|
* @throws CodeException
|
|
|
|
|
*/
|
|
|
|
|
boolean auth(HttpServletRequest req, Map<String,Object> defaultParameters,Map<String,Object> config)throws CodeException;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
注入点
|
|
|
|
|
|
|
|
|
|
``` xml
|
|
|
|
|
|
|
|
|
|
<dependence>
|
|
|
|
|
<Item key="com.tptj.plugin.hg.client.center.v10" type="plugin"/> <!-- 依赖于主框架 -->
|
|
|
|
|
</dependence>
|
|
|
|
|
<extra-core>
|
|
|
|
|
<OpenClientAPIProviderclass="com.fr.plugin.jee.port.DemoCallerProvider"/>
|
|
|
|
|
<OpenClientAuthProviderclass="com.fr.plugin.jee.port.DemoAuth"/>
|
|
|
|
|
</extra-core>
|
|
|
|
|
```
|