package com.stylefeng.guns.modular.system.util.videoGateway;
|
|
import cn.hutool.core.util.CharsetUtil;
|
import cn.hutool.crypto.SmUtil;
|
import cn.hutool.crypto.symmetric.SM4;
|
import cn.hutool.http.HttpRequest;
|
import cn.hutool.http.HttpResponse;
|
import cn.hutool.http.HttpUtil;
|
import com.alibaba.fastjson.JSON;
|
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONObject;
|
import com.stylefeng.guns.modular.system.util.videoGateway.model.*;
|
import lombok.extern.slf4j.Slf4j;
|
import org.apache.commons.lang.StringUtils;
|
|
import java.util.ArrayList;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
/**
|
* 视频网关工具类型
|
* @author zhibing.pu
|
* @Date 2024/12/18 19:32
|
*/
|
@Slf4j
|
public class VideoGateway {
|
|
private static AccountLogin accountLogin;
|
|
|
/**
|
* 获取 SessionId
|
* @return
|
*/
|
public static SessionId getSessionId(){
|
HttpRequest get = HttpUtil.createGet("https://zhyn.cg.gz.gov.cn/api/cws-auth/v1/session-id/third-platform");
|
get.header("operate-terminal", "4");
|
log.info("【获取 SessionId】请求参数:" + get);
|
HttpResponse execute = get.execute();
|
String body = execute.body();
|
log.info("【获取 SessionId】返回结果:" + body);
|
JSONObject result = JSON.parseObject(body);
|
Integer code = result.getInteger("code");
|
if(-1 == code){
|
log.error(result.getString("msg"));
|
return null;
|
}
|
SessionId sessionId = result.getObject("data", SessionId.class);
|
SM4 sm4 = SmUtil.sm4("EP77VsBj9yeOKpcO".getBytes());
|
String decryptStr = sm4.decryptStr(sessionId.getPublicKey(), CharsetUtil.CHARSET_UTF_8);
|
sessionId.setKey(decryptStr);
|
return sessionId;
|
}
|
|
|
/**
|
* 登录
|
*/
|
public static void accountLogin(){
|
SessionId sessionId = getSessionId();
|
if(null == sessionId){
|
throw new RuntimeException("获取sessionId失败");
|
}
|
HttpRequest post = HttpUtil.createPost("https://zhyn.cg.gz.gov.cn/api/cws-auth/v1/account-login/applet/third-platform");
|
post.header("operate-terminal", "4");
|
Map<String, Object> body = new HashMap<>();
|
body.put("account", "UgRn8RGM1Z9k");
|
SM4 sm4 = SmUtil.sm4(sessionId.getKey().getBytes());
|
String encryptHex = sm4.encryptHex("Lti52D@#&J6q");
|
body.put("pwd", encryptHex);
|
body.put("sessionId", sessionId.getSessionId());
|
log.info("【登录】请求参数:" + JSON.toJSONString(body) + "\npublicKey:" + sessionId.getPublicKey() + "\n加密key:" + sessionId.getKey());
|
post.body(JSON.toJSONString(body));
|
HttpResponse execute = post.execute();
|
log.info("【登录】返回结果:" + execute.body());
|
JSONObject result = JSON.parseObject(execute.body());
|
Integer code = result.getInteger("code");
|
if(0 != code){
|
log.error(result.getString("msg"));
|
return;
|
}
|
accountLogin = result.getObject("data", AccountLogin.class);
|
}
|
|
|
/**
|
* 获取车辆列表数据
|
* @param vehicleNum 车牌号
|
* @param companyId 公司id
|
* @param companyName 公司名称
|
* @return
|
*/
|
public static List<Vehicle> getVehicleList(String vehicleNum, String companyId, String companyName, int num){
|
if(null == accountLogin){
|
accountLogin();
|
}
|
HttpRequest post = HttpUtil.createPost("https://zhyn.cg.gz.gov.cn/api/cws-user/biz-vehicle-infos/v1/smallDataList");
|
post.header("operate-terminal", "4");
|
post.header("token", accountLogin.getToken());
|
Map<String, Object> body = new HashMap<>();
|
if(StringUtils.isNotEmpty(vehicleNum)){
|
body.put("vehicleNum", vehicleNum);
|
}
|
if(StringUtils.isNotEmpty(companyId)){
|
body.put("companyId", companyId);
|
}
|
if(StringUtils.isNotEmpty(companyName)){
|
body.put("companyName", companyName);
|
}
|
log.info("【获取车辆列表】请求参数:" + JSON.toJSONString(body));
|
post.body(JSON.toJSONString(body));
|
HttpResponse execute = post.execute();
|
if(401 == execute.getStatus()){
|
log.error("token失效,重新登录");
|
accountLogin = null;
|
if(num == 3){
|
log.error("token失效,请联系管理员");
|
return null;
|
}
|
num++;
|
return getVehicleList(vehicleNum, companyId, companyName, num);
|
}
|
log.info("【获取车辆列表】返回结果:" + execute.body());
|
JSONObject result = JSON.parseObject(execute.body());
|
Integer code = result.getInteger("code");
|
if(0 != code){
|
log.error(result.getString("msg"));
|
return null;
|
}
|
List<Vehicle> list = new ArrayList();
|
JSONArray data = result.getJSONArray("data");
|
for (int i = 0; i < data.size(); i++) {
|
Vehicle object = data.getObject(i, Vehicle.class);
|
list.add(object);
|
}
|
return list;
|
}
|
|
|
/**
|
* 获取船舶列表
|
* @param shipNum 船舶号
|
* @param companyId 公司id
|
* @param companyName 公司名称
|
* @return
|
*/
|
public static List<Ship> getShipList(String shipNum, String companyId, String companyName, int num){
|
if(null == accountLogin){
|
accountLogin();
|
}
|
HttpRequest post = HttpUtil.createPost("https://zhyn.cg.gz.gov.cn/api/cws-user/biz-ship-infos/v1/smallDataList");
|
post.header("operate-terminal", "4");
|
post.header("token", accountLogin.getToken());
|
Map<String, Object> body = new HashMap<>();
|
if(StringUtils.isNotEmpty(shipNum)){
|
body.put("shipNum", shipNum);
|
}
|
if(StringUtils.isNotEmpty(companyId)){
|
body.put("companyId", companyId);
|
}
|
if(StringUtils.isNotEmpty(companyName)){
|
body.put("companyName", companyName);
|
}
|
log.info("【获取船舶列表】请求参数:" + JSON.toJSONString(body));
|
post.body(JSON.toJSONString(body));
|
HttpResponse execute = post.execute();
|
if(401 == execute.getStatus()){
|
log.error("token失效,重新登录");
|
if(num == 3){
|
log.error("token失效,请联系管理员");
|
return null;
|
}
|
num++;
|
accountLogin = null;
|
return getShipList(shipNum, companyId, companyName, num);
|
}
|
log.info("【获取船舶列表】返回结果:" + execute.body());
|
JSONObject result = JSON.parseObject(execute.body());
|
Integer code = result.getInteger("code");
|
if(0 != code){
|
log.error(result.getString("msg"));
|
return null;
|
}
|
List<Ship> list = new ArrayList();
|
JSONArray data = result.getJSONArray("data");
|
for (int i = 0; i < data.size(); i++) {
|
Ship object = data.getObject(i, Ship.class);
|
list.add(object);
|
}
|
return list;
|
}
|
|
|
/**
|
* 2018年协议车辆在线状态接口
|
* @return
|
*/
|
public static List<VehicleOnline> queryRuntimeInfoByCache(int num){
|
if(null == accountLogin){
|
accountLogin();
|
}
|
HttpRequest post = HttpUtil.createPost("https://zhyn.cg.gz.gov.cn/map/web/map/queryRuntimeInfoByCache");
|
post.header("operate-terminal", "4");
|
post.header("token", accountLogin.getToken());
|
post.body("{}");
|
log.info("【2018年协议车辆在线】请求参数:" + post.getUrl());
|
HttpResponse execute = post.execute();
|
if(401 == execute.getStatus()){
|
log.error("token失效,重新登录");
|
if(num == 3){
|
log.error("token失效,请联系管理员");
|
return null;
|
}
|
num++;
|
accountLogin = null;
|
return queryRuntimeInfoByCache(num);
|
}
|
log.info("【2018年协议车辆在线】返回结果:" + execute.body());
|
JSONObject result = JSON.parseObject(execute.body());
|
Integer code = result.getInteger("code");
|
if(0 != code){
|
log.error(result.getString("msg"));
|
return null;
|
}
|
List<VehicleOnline> list = new ArrayList();
|
JSONArray data = result.getJSONArray("data");
|
for (int i = 0; i < data.size(); i++) {
|
VehicleOnline object = data.getObject(i, VehicleOnline.class);
|
list.add(object);
|
}
|
return list;
|
}
|
|
|
/**
|
* 2023年协议车辆在线状态接口
|
* @return
|
*/
|
public static List<VehicleOnline> locationRealTimeInfoCache(int num){
|
if(null == accountLogin){
|
accountLogin();
|
}
|
HttpRequest get = HttpUtil.createGet("https://zhyn.cg.gz.gov.cn/jttweb/api/v1/location/locationRealTimeInfoCache");
|
get.header("operate-terminal", "4");
|
get.header("token", accountLogin.getToken());
|
log.info("【2023年协议车辆在线】请求参数:" + get.getUrl());
|
HttpResponse execute = get.execute();
|
if(401 == execute.getStatus()){
|
log.error("token失效,重新登录");
|
if(num == 3){
|
log.error("token失效,请联系管理员");
|
return null;
|
}
|
num++;
|
accountLogin = null;
|
return locationRealTimeInfoCache(num);
|
}
|
log.info("【2023年协议车辆在线】返回结果:" + execute.body());
|
JSONObject result = JSON.parseObject(execute.body());
|
Integer code = result.getInteger("code");
|
if(0 != code){
|
log.error(result.getString("msg"));
|
return null;
|
}
|
List<VehicleOnline> list = new ArrayList();
|
JSONArray data = result.getJSONArray("data");
|
for (int i = 0; i < data.size(); i++) {
|
VehicleOnline object = data.getObject(i, VehicleOnline.class);
|
list.add(object);
|
}
|
return list;
|
}
|
|
|
/**
|
* 2018年协议发送拍摄指令接口
|
* @param terminalId 终点卡号
|
* @param channelId 通道ID
|
* @return
|
*/
|
public static String cameraShot2018(String terminalId, Integer channelId, int num){
|
if(null == accountLogin){
|
accountLogin();
|
}
|
HttpRequest post = HttpUtil.createPost("https://zhyn.cg.gz.gov.cn/map/web/vehicleCtrl/" + terminalId + "/cameraShot");
|
post.header("operate-terminal", "4");
|
post.header("token", accountLogin.getToken());
|
Map<String, Object> body = new HashMap<>();
|
body.put("channelId", channelId);
|
log.info("【2018年协议发送拍摄指令接口】请求参数:" + JSON.toJSONString(body));
|
post.body(JSON.toJSONString(body));
|
HttpResponse execute = post.execute();
|
if(401 == execute.getStatus()){
|
log.error("token失效,重新登录");
|
if(num == 3){
|
log.error("token失效,请联系管理员");
|
return null;
|
}
|
num++;
|
accountLogin = null;
|
return cameraShot2018(terminalId, channelId, num);
|
}
|
log.info("【2018年协议发送拍摄指令接口】返回结果:" + execute.body());
|
JSONObject result = JSON.parseObject(execute.body());
|
Integer code = result.getInteger("code");
|
if(0 != code){
|
log.error(result.getString("msg"));
|
return null;
|
}
|
//返回文件ID
|
return result.getString("data");
|
}
|
|
|
/**
|
* 2023年协议发送拍摄指令接口
|
* @param vehicleId 车船 ID
|
* @param vehicleType 车船类型:1 车辆 2 船舶
|
* @param terminalId 终点卡号
|
* @param channelId 通道ID
|
* @return
|
*/
|
public static String cameraShot2023(Integer vehicleId, Integer vehicleType, String terminalId, Integer channelId, int num){
|
if(null == accountLogin){
|
accountLogin();
|
}
|
HttpRequest get = HttpUtil.createGet("https://zhyn.cg.gz.gov.cn/api/cws-business/biz-device-send-records/v1/cameraShot?vehicleId=" + vehicleId + "&vehicleType=" + vehicleType + "&terminalId=" + terminalId + "&channelId=" + channelId);
|
get.header("operate-terminal", "4");
|
get.header("token", accountLogin.getToken());
|
Map<String, Object> body = new HashMap<>();
|
log.info("【2023年协议发送拍摄指令接口】请求参数:" + get.getUrl());
|
HttpResponse execute = get.execute();
|
if(401 == execute.getStatus()){
|
log.error("token失效,重新登录");
|
if(num == 3){
|
log.error("token失效,请联系管理员");
|
return null;
|
}
|
num++;
|
accountLogin = null;
|
return cameraShot2023(vehicleId, vehicleType, terminalId, channelId, num);
|
}
|
log.info("【2023年协议发送拍摄指令接口】返回结果:" + execute.body());
|
JSONObject result = JSON.parseObject(execute.body());
|
Integer code = result.getInteger("code");
|
if(0 != code){
|
log.error(result.getString("msg"));
|
return null;
|
}
|
//返回文件ID
|
return result.getString("data");
|
}
|
|
|
/**
|
* 2018年协议车辆获取拍摄图片接口
|
* @param terminalId 终端卡号
|
* @param fileId 文件ID
|
* @return
|
*/
|
public static String getCameraShotByFileId2018(String terminalId, String fileId, int num){
|
if(null == accountLogin){
|
accountLogin();
|
}
|
HttpRequest get = HttpUtil.createGet("https://zhyn.cg.gz.gov.cn/map/web/vehicleCtrl/getCameraShotById?terminalId=" + terminalId + "&id=" + fileId);
|
get.header("operate-terminal", "4");
|
get.header("token", accountLogin.getToken());
|
log.info("【2018年协议车辆获取拍摄图片】请求参数:" + get.getUrl());
|
HttpResponse execute = get.execute();
|
if(401 == execute.getStatus()){
|
log.error("token失效,重新登录");
|
if(num == 3){
|
log.error("token失效,请联系管理员");
|
return null;
|
}
|
num++;
|
accountLogin = null;
|
return getCameraShotByFileId2018(terminalId, fileId, num);
|
}
|
log.info("【2018年协议车辆获取拍摄图片】返回结果:" + execute.body());
|
JSONObject result = JSON.parseObject(execute.body());
|
Integer code = result.getInteger("code");
|
if(0 != code){
|
log.error(result.getString("msg"));
|
return null;
|
}
|
//图片地址
|
String data = result.getString("data");
|
if(null == data){
|
return null;
|
}
|
return "https://zhyn-pic.cg.gz.gov.cn" + data;
|
}
|
|
|
/**
|
* 2023年协议车辆获取拍摄图片接口
|
* @param fileId 文件ID
|
* @return
|
*/
|
public static String getCameraShotByFileId2023(String fileId, int num){
|
if(null == accountLogin){
|
accountLogin();
|
}
|
HttpRequest get = HttpUtil.createGet("https://zhyn.cg.gz.gov.cn/api/cws-business/biz-device-send-records/v1/getCameraShotById?id=" + fileId);
|
get.header("operate-terminal", "4");
|
get.header("token", accountLogin.getToken());
|
log.info("【2023年协议车辆获取拍摄图片】请求参数:" + get.getUrl());
|
HttpResponse execute = get.execute();
|
if(401 == execute.getStatus()){
|
log.error("token失效,重新登录");
|
if(num == 3){
|
log.error("token失效,请联系管理员");
|
return null;
|
}
|
num++;
|
accountLogin = null;
|
return getCameraShotByFileId2023(fileId, num);
|
}
|
log.info("【2023年协议车辆获取拍摄图片】返回结果:" + execute.body());
|
JSONObject result = JSON.parseObject(execute.body());
|
Integer code = result.getInteger("code");
|
if(0 != code){
|
log.error(result.getString("msg"));
|
return null;
|
}
|
//图片地址
|
String data = result.getString("data");
|
if(null == data){
|
return null;
|
}
|
return "https://zhyn-pic.cg.gz.gov.cn" + data;
|
}
|
|
|
/**
|
* 获取车辆轨迹接口
|
* @param vehicleNum 车牌号
|
* @param vehicleType 车船类型(1=车辆,2=船舶)
|
* @param startTime 开始时间(yyyy-MM-dd HH:mm:ss)
|
* @param endTime 结束时间(yyyy-MM-dd HH:mm:ss)
|
* @return
|
*/
|
public static List<TrackInfo> getTrackInfoByVehicleNum(String vehicleNum, String vehicleType, String startTime, String endTime, int num){
|
if(null == accountLogin){
|
accountLogin();
|
}
|
HttpRequest post = HttpUtil.createPost("https://zhyn.cg.gz.gov.cn/map/web/map/getTrackInfoByVehicleNum");
|
post.header("operate-terminal", "4");
|
post.header("token", accountLogin.getToken());
|
Map<String, Object> body = new HashMap<>();
|
body.put("vehicleNum", vehicleNum);
|
body.put("vehicleType", vehicleType);
|
body.put("startTime", startTime);
|
body.put("endTime", endTime);
|
log.info("请求参数:" + JSON.toJSONString(body));
|
post.body(JSON.toJSONString(body));
|
HttpResponse execute = post.execute();
|
if(401 == execute.getStatus()){
|
log.error("token失效,重新登录");
|
if(num == 3){
|
log.error("token失效,请联系管理员");
|
return null;
|
}
|
num++;
|
accountLogin = null;
|
return getTrackInfoByVehicleNum(vehicleNum, vehicleType, startTime, endTime, num);
|
}
|
log.info("返回结果:" + execute.body());
|
JSONObject result = JSON.parseObject(execute.body());
|
Integer code = result.getInteger("code");
|
if(0 != code){
|
log.error(result.getString("msg"));
|
return null;
|
}
|
List<TrackInfo> list = new ArrayList();
|
JSONArray data = result.getJSONArray("data");
|
for (int i = 0; i < data.size(); i++) {
|
TrackInfo object = data.getObject(i, TrackInfo.class);
|
list.add(object);
|
}
|
return list;
|
}
|
|
|
|
public static void main(String[] args) {
|
// SM4 sm4 = SmUtil.sm4("EP77VsBj9yeOKpcO".getBytes());
|
// String encryptHex = sm4.encryptHex(content);
|
// String decryptStr = sm4.decryptStr("357b94ca60ce8140f3d22eceaaa5d71b0d25d6cd20c8218d9a3ddcd30881126d", CharsetUtil.CHARSET_UTF_8);
|
// System.err.println(decryptStr);
|
|
// accountLogin();
|
// System.err.println(accountLogin);
|
// getVehicleList(null, null, null);
|
// getShipList(null, null, null);
|
// queryRuntimeInfoByCache();
|
// locationRealTimeInfoCache(0);
|
|
|
List<Vehicle> 粤AFX998 = VideoGateway.getVehicleList("粤AFX998", null, null, 0);
|
System.err.println(粤AFX998);
|
}
|
|
// public static void main(String[] args) {
|
//// SM4 sm4 = SmUtil.sm4("EP77VsBj9yeOKpcO".getBytes());
|
//// String encryptHex = sm4.encryptHex(content);
|
//// String decryptStr = sm4.decryptStr("357b94ca60ce8140f3d22eceaaa5d71b0d25d6cd20c8218d9a3ddcd30881126d", CharsetUtil.CHARSET_UTF_8);
|
//// System.err.println(decryptStr);
|
//
|
// accountLogin();
|
// System.err.println(accountLogin);
|
//// Integer integer2018 = cameraShot2018("041023412161", 5);
|
//// System.err.println(integer2018);
|
//// String cameraShotByFileId2018 = getCameraShotByFileId2018("041023412161", integer2018.toString());
|
//// System.err.println(cameraShotByFileId2018);
|
// Integer integer2023 = cameraShot2023(918, 1, "00000000041033990843", 6);
|
// System.err.println(integer2023);
|
// String cameraShotByFileId2023 = getCameraShotByFileId2023("00000000041033990843", integer2023.toString());
|
// System.err.println(cameraShotByFileId2023);
|
//
|
// }
|
}
|