doum
昨天 2f3221b7c90d5663fdb312653a2d188bc4628370
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
90
91
package com.doumee.core.iPass;
 
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.doumee.core.constants.Constants;
import com.doumee.core.constants.ResponseStatus;
import com.doumee.core.exception.BusinessException;
import com.doumee.dao.vo.ZhanQuVO;
import okhttp3.*;
 
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
 
/**
 * Created by IntelliJ IDEA.
 *
 * @Author : Rk
 * @create 2026/2/3 15:15
 */
public class IPass {
 
    private static  String userName = "djpt";
    private static  String password = "CwzOdj3G8Y05NRu9pWjcmmODj56/6iZjSD33couFE3XNrkNjEQUZwnkLEGN6ot1O7b9q/K+PsRNh7iRquL4ZYQdajIM3P+qxn8Q1eW2eICmwMY0L+vWpBK30xU+DX6yzkt5/meitCa5rZERUWUGAfAfimdvhfCazLseXdB3x/ieJ+/C+22LH0gIZoqiC0xqh+xR5NENu0lcC7PLJoCE0rzq+LLY7TNwmv6Ghxjbq5cCuxMd0H6uD3nKM/13+TNLuod5/9RzGBo966CUqLqS2L6XTqZkGCRwJL7pvD0+ZAnM36gXC1aTXT4Z6bYnwsGfpu7MjHODGSrzhrQEXS2Gbfg==";
    private static String tokenUrl = "https://ipaasuat.zhibang.com:4430/open-api/rest/core/auth/login";
    private static String zhanquUrl = "https://ipaasuat.zhibang.com:4430/open-api/mdm/cust-territories-trees/query";
 
    public String getIPassToken(String userName,String password,String tokenUrl) throws IOException {
        OkHttpClient client = new OkHttpClient().newBuilder()
                .build();
        MediaType mediaType = MediaType.parse("application/json; charset=utf-8");
        Map<String,String> requestBody = new HashMap<>();
        requestBody.put("userName",userName);
        requestBody.put("password",password);
        RequestBody body = RequestBody.create(mediaType, JSONObject.toJSON(requestBody).toString());
        Request request = new Request.Builder()
                .url(tokenUrl)
                .method("POST", body)
                .addHeader("User-Agent", "Apifox/1.0.0 (https://apifox.com)")
                .addHeader("Content-Type", "application/json; charset=utf-8")
                .build();
        Response response = client.newCall(request).execute();
        if(Objects.isNull(response)){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"获取IPASS授权权限失败,请联系管理员");
        }
        if(!Constants.equalsInteger(200,response.code())){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"获取IPASS授权权限失败:"+response.message());
        }
        JSONObject jsonObject = JSONObject.parseObject(response.body().string());
        String token = jsonObject.getString("identitytoken");
        return  token;
    }
 
 
 
    public List<ZhanQuVO> getIPassZhanquList(String userName,String password,String tokenUrl,String zhanquUrl) throws IOException {
        OkHttpClient client = new OkHttpClient().newBuilder()
                .build();
        MediaType mediaType = MediaType.parse("application/json");
        Map<String,Object> requestBody = new HashMap<>();
        requestBody.put("nodeLevel","1");
        requestBody.put("pageNo","1");
        requestBody.put("pageSize","1000");
 
        RequestBody body = RequestBody.create(mediaType, JSONObject.toJSON(requestBody).toString());
        Request request = new Request.Builder()
                .url(zhanquUrl)
                .method("POST", body)
                .addHeader("identitytoken", getIPassToken(userName,password,tokenUrl))
                .addHeader("User-Agent", "Apifox/1.0.0 (https://apifox.com)")
                .addHeader("Content-Type", "application/json")
                .build();
        Response response = client.newCall(request).execute();
        if(Objects.isNull(response)){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"获取IPASS战区信息失败,请联系管理员");
        }
        if(!Constants.equalsInteger(200,response.code())){
            throw new BusinessException(ResponseStatus.NOT_ALLOWED.getCode(),"获取IPASS战区信息失败:"+response.message());
        }
        JSONObject json = JSONObject.parseObject(response.body().string());
        JSONArray jsonArray = json.getJSONArray("rows");
        List<ZhanQuVO> zhanQuVOS = jsonArray.toJavaList(ZhanQuVO.class);
        return zhanQuVOS;
    }
 
 
 
 
}