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