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() 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() 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())
|
.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;
|
}
|
|
|
|
public static void main(String[] args) throws IOException {
|
IPass iPass = new IPass();
|
iPass.getIPassZhanquList();
|
}
|
|
|
}
|