parent
ae561ea8b8
commit
42b10acc82
|
@ -69,6 +69,26 @@ public class RestUtil {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 附件下载
|
||||||
|
* @param loginName oa登录名
|
||||||
|
* @param apiCode 接口编码
|
||||||
|
* @param fileId 附件id
|
||||||
|
* @param fileName 附件名
|
||||||
|
* @return 附件字节数组
|
||||||
|
*/
|
||||||
|
public byte[] downloadFileBytes(String loginName,String apiCode,String fileId,String fileName){
|
||||||
|
if (StrUtil.isNotEmpty(apiCode)){
|
||||||
|
SysApplicationApiEntity sysApp = getByCode(apiCode);
|
||||||
|
String token = getToken(loginName,sysApp);
|
||||||
|
String appUrl = sysApp.getAppUrl();
|
||||||
|
String url = "/seeyon/rest/attachment/file/@ctp_file_ID@?fileName=@文件名@&token=@token@";
|
||||||
|
url = url.replaceAll("@ctp_file_ID@",fileId).replaceAll("@文件名@",fileName).replaceAll("@token@",token);
|
||||||
|
byte[] bytes = HttpUtil.downloadBytes(appUrl + url);
|
||||||
|
return bytes;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* 获取token
|
* 获取token
|
||||||
* @param login_name
|
* @param login_name
|
||||||
|
@ -78,36 +98,45 @@ public class RestUtil {
|
||||||
public String getToken(String login_name,String api_code){
|
public String getToken(String login_name,String api_code){
|
||||||
if (StrUtil.isNotEmpty(api_code)){
|
if (StrUtil.isNotEmpty(api_code)){
|
||||||
SysApplicationApiEntity sysApp = getByCode(api_code);
|
SysApplicationApiEntity sysApp = getByCode(api_code);
|
||||||
if (null != sysApp){
|
return getToken(login_name,sysApp);
|
||||||
HashMap<String, String> hashMap = new HashMap<>();
|
|
||||||
String app_url = sysApp.getAppUrl();
|
|
||||||
String url = app_url+"/seeyon/rest/token";
|
|
||||||
String headerIn = sysApp.getHeaderIn();
|
|
||||||
JSONArray headers = JSON.parseArray(headerIn);
|
|
||||||
for (int i = 0; i < headers.size(); i++) {
|
|
||||||
JSONObject object1 = headers.getJSONObject(i);
|
|
||||||
String parameterName = object1.getString("parameterName");
|
|
||||||
if ("userName".equals(parameterName) || "password".equals(parameterName) || "loginName".equals(parameterName)){
|
|
||||||
String example = object1.getString("example");
|
|
||||||
hashMap.put(parameterName,example);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (StrUtil.isNotEmpty(login_name)){
|
|
||||||
hashMap.put("loginName",login_name);
|
|
||||||
}
|
|
||||||
String result = HttpRequest.post(url).body(JSON.toJSONString(hashMap)).execute().body();
|
|
||||||
JSONObject jsonObject = JSONObject.parseObject(result);
|
|
||||||
if (null != jsonObject) {
|
|
||||||
logger.info("======token:{}======" ,jsonObject.getString("id"));
|
|
||||||
return jsonObject.getString("id");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}else {
|
}else {
|
||||||
throw new BaseSystemException("api_code不能为空");
|
throw new BaseSystemException("api_code不能为空");
|
||||||
}
|
}
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取token
|
||||||
|
* @param login_name oa登录名
|
||||||
|
* @param sysApp 应用信息
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String getToken(String login_name,SysApplicationApiEntity sysApp){
|
||||||
|
if (null != sysApp){
|
||||||
|
HashMap<String, String> hashMap = new HashMap<>();
|
||||||
|
String app_url = sysApp.getAppUrl();
|
||||||
|
String url = app_url+"/seeyon/rest/token";
|
||||||
|
String headerIn = sysApp.getHeaderIn();
|
||||||
|
JSONArray headers = JSON.parseArray(headerIn);
|
||||||
|
for (int i = 0; i < headers.size(); i++) {
|
||||||
|
JSONObject object1 = headers.getJSONObject(i);
|
||||||
|
String parameterName = object1.getString("parameterName");
|
||||||
|
if ("userName".equals(parameterName) || "password".equals(parameterName) || "loginName".equals(parameterName)){
|
||||||
|
String example = object1.getString("example");
|
||||||
|
hashMap.put(parameterName,example);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (StrUtil.isNotEmpty(login_name)){
|
||||||
|
hashMap.put("loginName",login_name);
|
||||||
|
}
|
||||||
|
String result = HttpRequest.post(url).body(JSON.toJSONString(hashMap)).execute().body();
|
||||||
|
JSONObject jsonObject = JSONObject.parseObject(result);
|
||||||
|
if (null != jsonObject) {
|
||||||
|
logger.info("======token:{}======" ,jsonObject.getString("id"));
|
||||||
|
return jsonObject.getString("id");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
private SysApplicationApiEntity getByCode(String api_code){
|
private SysApplicationApiEntity getByCode(String api_code){
|
||||||
if (StrUtil.isNotEmpty(api_code)){
|
if (StrUtil.isNotEmpty(api_code)){
|
||||||
SysApplicationApiEntity sysApp = new SysApplicationApiEntity();
|
SysApplicationApiEntity sysApp = new SysApplicationApiEntity();
|
||||||
|
|
Loading…
Reference in New Issue