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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
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;
    }
 
 
}