package com.landtool.lanbase.common.map;
|
|
import javax.annotation.PostConstruct;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Component;
|
|
import com.landtool.lanbase.common.utils.HttpOperateUtils;
|
import com.landtool.lanbase.config.SysTemPropertyConfig;
|
import com.landtool.lanbase.modules.res.entity.Res_MainInfo;
|
import com.landtool.lanbase.modules.res.service.ResMainInfoService;
|
|
@Component
|
public class TerraToken {
|
@Autowired
|
private ResMainInfoService resMainInfoService;
|
|
private static TerraToken ter;
|
|
|
@PostConstruct
|
public void init(){
|
ter=this;
|
ter.resMainInfoService=this.resMainInfoService;
|
}
|
public static String getToken(String Url, Integer userid, String RemoteAddr, Integer ResourceId, Integer Espproxy, SysTemPropertyConfig sysConfig, String subzyids, Boolean isPubzy, String tokenValue, Boolean returnToken) {
|
String ServerUrl = "";
|
Res_MainInfo resMainInfo = ter.resMainInfoService.selectByPrimaryKey(ResourceId);
|
// long expiration=resMainInfo.getExpiration()!=null?resMainInfo.getExpiration():null;
|
String token = "";// token
|
if (Url != null && !Url.equals("")) {
|
ServerUrl = Url;
|
String urlEncode = "";
|
if (Espproxy == 1) {
|
try {
|
String getTokenUrl = sysConfig.getTerraTokenWebRoot() + "?userid=" + userid + "&resourceId=" + ResourceId +"&clientIp=" + RemoteAddr + "&subzyids=" + subzyids + "&isPubzy=" + isPubzy;// token获取地址;// token获取地址
|
String TokenResponse = HttpOperateUtils.httpGet(getTokenUrl);// 请求token
|
// JSONObject object = JSONObject.parseObject(TokenResponse);// 转换返回JSON字符串
|
token = TokenResponse;// 获取返回token
|
if(token != null && !token.isEmpty()) {
|
if (ServerUrl.indexOf("?") > -1) {
|
ServerUrl += "&token=" + token;
|
} else {
|
ServerUrl += "?token=" + token;
|
}
|
}
|
} catch (Exception e) {
|
//if (ServerUrl.indexOf("?") > -1) {
|
// ServerUrl += "&token=";
|
//} else {
|
// ServerUrl += "?token=";
|
//}
|
}
|
} else if (Espproxy == 0 && tokenValue != null && !tokenValue.isEmpty()) {
|
if (ServerUrl.indexOf("?") > -1) {
|
ServerUrl += "&token=" + tokenValue;
|
} else {
|
ServerUrl += "?token=" + tokenValue;
|
}
|
token = tokenValue;
|
}
|
}
|
if(returnToken) return token;
|
return ServerUrl;
|
}
|
|
|
}
|