274 lines
7.6 KiB
C#
274 lines
7.6 KiB
C#
using System;
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using System.Text;
|
||
using UnityEngine;
|
||
using UnityEngine.Networking;
|
||
|
||
public static class InterfaceManager
|
||
{
|
||
#region 接口地址
|
||
|
||
/// <summary>
|
||
/// 是否可用
|
||
/// </summary>
|
||
public static bool isLive = false;
|
||
|
||
/// <summary>
|
||
/// http接口ip地址
|
||
/// </summary>
|
||
public static string http_ip_address { get; set; }
|
||
|
||
/// <summary>
|
||
/// ws服务地址
|
||
/// </summary>
|
||
public static string ws_ip_address { get; set; }
|
||
|
||
/// <summary>
|
||
/// 马允波提供的后台ip,
|
||
/// </summary>
|
||
public static string http_ip_ma_address { get; set; }
|
||
|
||
/// <summary>
|
||
/// 请求头
|
||
/// </summary>
|
||
public static Dictionary<string, string> request_header = new Dictionary<string, string>() { { "Authorization", "none" } };
|
||
|
||
/// <summary>
|
||
/// 机房列表
|
||
/// 参数:
|
||
/// isExport=false¤tPage=1&pageSize=10
|
||
/// </summary>
|
||
public static string get_room_list => "/jk/room/list";
|
||
|
||
/// <summary>
|
||
/// 巡检数据
|
||
/// 参数:
|
||
/// pageSize=1¤tPage=0&isExport=false
|
||
/// </summary>
|
||
public static string get_record_list => "/jk/record/list";
|
||
|
||
/// <summary>
|
||
/// 机器人列表
|
||
/// </summary>
|
||
public static string get_robot_list => "/jk/robot/list";
|
||
|
||
/// <summary>
|
||
/// 设备列表
|
||
/// 参数:
|
||
/// isExport=false
|
||
/// </summary>
|
||
public static string get_device_list => "/jk/device/list";
|
||
|
||
/// <summary>
|
||
/// 机柜列表
|
||
/// 参数:
|
||
/// isExport=false
|
||
/// pageSize=200
|
||
/// </summary>
|
||
public static string get_cabin_list => "/jk/cabin/list";
|
||
|
||
/// <summary>
|
||
/// 机器人摄像头信息
|
||
/// 参数:
|
||
/// robotId=56ce6c39b8144d91ac3767e757933955
|
||
/// </summary>
|
||
public static string get_robot_camera_rtsp => "/jk/robotParam/getCameraRtspParams";
|
||
|
||
/// <summary>
|
||
/// 机器人地图
|
||
/// 注意接口参数:/robot/{robotId}/map
|
||
/// 参数:
|
||
/// robotId=56ce6c39b8144d91ac3767e757933955
|
||
/// </summary>
|
||
public static string get_robot_map => "/jk/robot/";
|
||
|
||
/// <summary>
|
||
/// 任务列表查询
|
||
/// </summary>
|
||
public static string get_task_list => "/jk/task/list";
|
||
|
||
/// <summary>
|
||
/// 任务详情
|
||
/// </summary>
|
||
public static string get_task => "/jk/task/2fc8b609e202404db573946da7e30b57";
|
||
|
||
/// <summary>
|
||
/// 机器人任务队列
|
||
///
|
||
/// </summary>
|
||
public static string get_task_queue => "/jk/task/taskqueue/list/";
|
||
|
||
/// <summary>
|
||
/// 定点任务下发
|
||
/// 参数:
|
||
/// { "robotIp": "192.168.8.198", "pointList": [ { "pointNo": "xj01", "04": "0", "06": "0", "01": "1", "cabinType": "1", "03": "0", "05": "0" } ]}
|
||
/// </summary>
|
||
public static string post_robot_fixed_point => "/jk/robot/dofixedPointins";
|
||
|
||
/// <summary>
|
||
/// 立即执行任务队列中的任务
|
||
/// 参数:
|
||
/// { "robotId": "3e42c3014eb5463a94602c13dfc0921c", "TaskQueue_Id": "1686128400786", "interfaceNo": "goToQueueTask"}
|
||
/// </summary>
|
||
public static string post_robot_send_commond => "/jk/interface/sendCommand";
|
||
|
||
/// <summary>
|
||
/// 定点任务-巡检点列表查询接口
|
||
/// 参数:
|
||
/// roomId=0703de6c8f6111eeb00f0242ac0a0005
|
||
/// </summary>
|
||
public static string get_robot_fixed_pointins => "/jk/robot/fixedPointins";
|
||
|
||
/// <summary>
|
||
/// 巡检任务下发
|
||
/// 参数:
|
||
/// { "taskId": "", "robotId": "56ce6c39b8144d91ac3767e757933955", "robotIp": "192.168.8.198"}
|
||
/// </summary>
|
||
public static string post_robot_doins_task => "/jk/robot/doinsTask";
|
||
|
||
/// <summary>
|
||
/// 巡检任务-任务列表查询接口
|
||
/// 参数:
|
||
/// roomId=0703de6c8f6111eeb00f0242ac0a0005
|
||
/// </summary>
|
||
public static string get_robot_ins_task => "/jk/robot/insTask";
|
||
|
||
/// <summary>
|
||
/// 查询巡检报表数据
|
||
/// 参数:
|
||
/// insId=6978d1982a4449c48f7e4b2064d1b28b
|
||
/// </summary>
|
||
public static string get_record_ins_report => "/jk/record/insReport";
|
||
|
||
/// <summary>
|
||
/// 巡检数据告警详情
|
||
/// 参数:
|
||
/// isExport=false
|
||
/// rocerdId=1f77ddf75f9f490ba84fb2a125962903
|
||
/// </summary>
|
||
public static string get_record_task_list => "/jk/record/tasklist";
|
||
|
||
/// <summary>
|
||
/// 巡检数据停检位置告警列表
|
||
/// 参数:
|
||
/// inspectionPointId=1f77ddf75f9f490ba84fb2a125962903
|
||
/// </summary>
|
||
public static string get_record_dev_list => "/jk/record/devList";
|
||
|
||
/// <summary>
|
||
/// 巡检数据停检位置巡检图片
|
||
/// 参数:
|
||
/// inspectionPointId=1f77ddf75f9f490ba84fb2a125962903
|
||
/// </summary>
|
||
public static string get_record_pic => "/jk/record/getPic";
|
||
|
||
/// <summary>
|
||
/// 获取机器人信息
|
||
/// </summary>
|
||
public static string ws_robot_info => "/jk/api/robotinfo/clkc5gnu5000d3p6p8lu41tnj-clkc5gnu5000e3p6pvux9aid3-socket_index_page_robot_info";
|
||
|
||
/// <summary>
|
||
/// 机器人位置状态信息
|
||
/// 参数:
|
||
/// 机器人id,直接拼接在地址后面
|
||
/// </summary>
|
||
public static string ws_robot_html5 => "/jk/api/html5/";
|
||
|
||
/// <summary>
|
||
/// 巡检结果
|
||
/// </summary>
|
||
public static string get_inspection => "/robot/queryInspection";
|
||
|
||
#endregion
|
||
|
||
#region 调接口
|
||
|
||
/// <summary>
|
||
/// Get请求
|
||
/// </summary>
|
||
/// <param name="_url"></param>
|
||
/// <param name="_header"></param>
|
||
/// <param name="_query"></param>
|
||
/// <param name="_callback"></param>
|
||
/// <returns></returns>
|
||
public static IEnumerator GetRequest(string _url, Dictionary<string, string> _header = null, Dictionary<string, string> _query = null, Action<string, string> _callback = null)
|
||
{
|
||
|
||
StringBuilder builder = new StringBuilder();
|
||
builder.Append(_url);
|
||
|
||
if (_query != null)
|
||
{
|
||
builder.Append("?");
|
||
int i = 0;
|
||
foreach (var item in _query)
|
||
{
|
||
if (i > 0)
|
||
builder.Append("&");
|
||
builder.AppendFormat("{0}={1}", item.Key, item.Value);
|
||
i++;
|
||
}
|
||
}
|
||
|
||
using (UnityWebRequest request = UnityWebRequest.Get(builder.ToString()))
|
||
{
|
||
if (_header != null)
|
||
{
|
||
foreach (var item in _header)
|
||
{
|
||
request.SetRequestHeader(item.Key, item.Value);
|
||
}
|
||
}
|
||
|
||
yield return request.SendWebRequest();
|
||
|
||
if (request.error != null)
|
||
{
|
||
_callback?.Invoke(request.error, null);
|
||
}
|
||
else
|
||
{
|
||
_callback?.Invoke(null, request.downloadHandler.text);
|
||
}
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// Post请求
|
||
/// </summary>
|
||
/// <param name="_url"></param>
|
||
/// <param name="_post_json"></param>
|
||
/// <param name="_callback"></param>
|
||
/// <returns></returns>
|
||
public static IEnumerator PostRequest(string _url, string _post_json, Dictionary<string, string> _header = null, Action<string, string> _callback = null)
|
||
{
|
||
using (UnityWebRequest request = new UnityWebRequest(_url, "POST"))
|
||
{
|
||
var data = Encoding.UTF8.GetBytes(_post_json);
|
||
request.uploadHandler = new UploadHandlerRaw(data);
|
||
request.downloadHandler = new DownloadHandlerBuffer();
|
||
|
||
if (_header != null)
|
||
{
|
||
foreach (var item in _header)
|
||
{
|
||
request.SetRequestHeader(item.Key, item.Value);
|
||
}
|
||
}
|
||
|
||
yield return request.SendWebRequest();
|
||
if (request.error != null)
|
||
{
|
||
_callback?.Invoke(request.error, null);
|
||
}
|
||
else
|
||
{
|
||
_callback?.Invoke(null, request.downloadHandler.text);
|
||
}
|
||
}
|
||
}
|
||
|
||
#endregion
|
||
}
|