package com.landtool.lanbase.common.map;
|
|
import com.alibaba.fastjson.JSONObject;
|
import com.landtool.lanbase.common.utils.HttpOperateUtils;
|
import com.landtool.lanbase.config.SysTemPropertyConfig;
|
|
import java.io.IOException;
|
|
import static com.landtool.lanbase.common.utils.HttpOperateUtils.httpGet;
|
|
public class EsbToken {
|
|
/**
|
* 获取资源服务地址
|
* @param Url 服务地址
|
* @param userid 登录用户名
|
* @param RemoteAddr 客户端IP
|
* @param ResourceId 资源ID
|
* @param Espproxy 是否代理
|
* @param sysConfig 配置读取对象
|
* @param subzyids 子图层id
|
* @param isPubzy 是否完全公开
|
* @param tokenValue token值
|
* @param returnToken 是否只返回token
|
* @return
|
*/
|
public static String getEsbUrl(String Url, Integer userid, String identyinfo, Integer ResourceId, Integer Espproxy, SysTemPropertyConfig sysConfig, String subzyids, Boolean isPubzy, String tokenValue, Boolean returnToken) {
|
String ServerUrl = "";
|
String token = "";// token
|
if (Url != null && !Url.equals("")) {
|
ServerUrl = Url;
|
String urlEncode = "";
|
String getTokenUrl = sysConfig.getTokenWebRoot() + "?userid=servdl&password=servdl123" + "&resourceid=" + ResourceId + "&expireSeconds=86400&identyinfo=" + identyinfo;// token获取地址
|
String TokenResponse = null;// 请求token
|
try {
|
TokenResponse = httpGet(getTokenUrl);
|
} catch (IOException e) {
|
return ServerUrl;
|
}
|
JSONObject object = JSONObject.parseObject(TokenResponse);// 转换返回JSON字符串
|
token = object.getString("data");// 获取返回token
|
if (token != null && !token.isEmpty()) {
|
if (ServerUrl.indexOf("?") > -1) {
|
ServerUrl += "&token=" + token;
|
} else {
|
ServerUrl += "?token=" + token;
|
}
|
}
|
}
|
return ServerUrl;
|
}
|
|
/**
|
* 获取资源服务地址
|
* @param userid 登录用户名
|
* @param appId 应用程序ID
|
* @param appUrl 应用程序地址
|
* @param ResourceId 资源ID
|
* @param Espproxy 是否代理
|
* @param sysConfig 配置读取对象
|
* @param subzyids 子图层id
|
* @param tokenValue token值
|
* @return
|
*/
|
public static String getAppEsbToken(Integer userid, Integer appId, String appUrl, Integer ResourceId, Integer Espproxy,
|
SysTemPropertyConfig sysConfig, String subzyids, String tokenValue) {
|
String token = "";// token
|
String urlEncode = "";
|
if (Espproxy == 1) {
|
try {
|
String getTokenUrl = sysConfig.getApptokenWebRoot() + "?userId=" + userid + "&resourceId=" + ResourceId
|
+ "&expireSeconds=86400&appId=" + appId + "&appUrl=" + appUrl + "&subzyids=" + subzyids;// token获取地址
|
String TokenResponse = httpGet(getTokenUrl);// 请求token
|
JSONObject object = JSONObject.parseObject(TokenResponse);// 转换返回JSON字符串
|
token = object.getString("token");// 获取返回token
|
} catch (Exception e) {
|
|
}
|
} else if (Espproxy == 0) {
|
if (tokenValue != "" && tokenValue != null) {
|
token = tokenValue;
|
}
|
}
|
|
return token;
|
}
|
|
|
}
|