2
13693261870
2022-09-16 653761a31dfeb50dd3d007e892d69c90bf0cdafc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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;
        }
      
     
}