添加 ETV语音电视的支持。另外修改一些BUG

This commit is contained in:
2026-01-08 08:38:29 +08:00
parent 599251d91b
commit 69baadd312
14 changed files with 497 additions and 13 deletions

View File

@@ -6751,7 +6751,7 @@ namespace WebSite.Controllers
else
{
hostModal = HostModalManager.GetByModalAddress(host.ID, modalAddress);//设备控制
HttpContext.Cache.Insert(MKey,hostModal,null,DateTime.Now.AddMinutes(30),Cache.NoSlidingExpiration);
HttpContext.Cache.Insert(MKey, hostModal, null, DateTime.Now.AddMinutes(30), Cache.NoSlidingExpiration);
}
if (hostModal == null)
{
@@ -7177,6 +7177,444 @@ namespace WebSite.Controllers
// return Json(ex.Message, JsonRequestBehavior.AllowGet);
// }
//}
/// <summary>
/// ETV-艺龙酒店(绥化北林店)728893
/// 授权接口
/// </summary>
/// <returns></returns>
[HttpPost()]
public ActionResult ETV_Auth()
{
Request.InputStream.Position = 0;
byte[] reqBody = new byte[Request.InputStream.Length];
Request.InputStream.Read(reqBody, 0, reqBody.Length);
string reqData = System.Text.Encoding.UTF8.GetString(reqBody);
var ttt = JsonConvert.DeserializeObject<TV_AuthData>(reqData);
//clientId a6f3270f77b545a087daa1caed816b3b
//clientSecret8854e0b8261b49d6989b5b2f39bd157a
if (ttt.clientId.Equals("a6f3270f77b545a087daa1caed816b3b") && ttt.clientSecret.Equals("8854e0b8261b49d6989b5b2f39bd157a"))
{
var token = Guid.NewGuid().ToString("N");
string kkk = "ETVKey";
CSRedisCacheHelper.Set_PartitionWithTime(kkk, token, 7 * 24 * 60, 5);
TV_ResponseData c = new TV_ResponseData();
c.code = 200;
c.msg = null;
c.data = new TTT_Data()
{
token = token,
expiresIn = 7 * 24 * 60 * 60
};
//{
// "code": 200,
// "msg": null,
// "data": {
// "token": "74b87337454200d4d33f80c4663dc5e5",
// "expiresIn": 154589
// }
//}
return Json(c, JsonRequestBehavior.AllowGet);
}
else
{
TV_ResponseData c = new TV_ResponseData();
c.code = 500;
c.msg = "鉴权数据错误";
c.data = null;
return Json(c, JsonRequestBehavior.AllowGet);
}
}
/// <summary>
/// 两天时间要对接完,时间紧迫,数据先写死
/// </summary>
public static Dictionary<string, string> ETVDic = new Dictionary<string, string>()
{
//艺龙酒店(绥化北林万达广场店)
{"1668326697184","1213"}
};
[HttpPost()]
public ActionResult ETV_Controller()
{
try
{
string IP = "";
string PPP = Request.UserHostAddress;
string III = Request.ServerVariables["REMOTE_ADDR"];
if (string.IsNullOrEmpty(III))
{
IP = PPP;
}
else
{
IP = III;
}
var token = Request.Headers["Authorization"];
string kkk = "ETVKey";
var t_take = CSRedisCacheHelper.Get_Partition<string>(kkk, 5);
//t_take = "abc";
if (t_take == null || !t_take.Equals(token))
{
return Json(new { code = 500, msg = "token已经过期" }, JsonRequestBehavior.AllowGet);
}
Request.InputStream.Position = 0;
byte[] reqBody = new byte[Request.InputStream.Length];
Request.InputStream.Read(reqBody, 0, reqBody.Length);
string reqData = System.Text.Encoding.UTF8.GetString(reqBody);
var ttt = JsonConvert.DeserializeObject<ETV_ControllerData>(reqData);
string hotelid_WANBU = ttt.hotelId;
//var hotelid = ETVDic[hotelid_WANBU];
string hotelid = "";
int hotelid_int = 0;
//int.TryParse(hotelid, out hotelid_int);
SysHotel hotel_sys = null;
string KKKHotel = "HotelInfoETV_" + hotelid_WANBU;
var hotel_ooo = HttpContext.Cache.Get(KKKHotel);
if (hotel_ooo != null)
{
hotel_sys = hotel_ooo as SysHotel;
}
else
{
hotel_sys = SysHotelManager.GetByETV_HotelId(hotelid_WANBU);
HttpContext.Cache.Insert(KKKHotel, hotel_sys, null, Cache.NoAbsoluteExpiration, new TimeSpan(0, 20, 0));
}
if (hotel_sys != null)
{
hotelid_int = hotel_sys.ID;
hotelid = hotel_sys.ID.ToString();
}
else
{
return Json(new { code = 500, msg = "找不到此酒店" }, JsonRequestBehavior.AllowGet);//"小度音箱(" + request.payload.cuid + ")尚未绑定客房主机"
}
string msgid = Guid.NewGuid().ToString("N");
string roomNo = ttt.roomNo;
string traceId = ttt.traceId;
string domain = ttt.domain;
string intent = ttt.intent;
List<ETV_CanShu> slots = ttt.slots;
bool is_monitor = true;
if (is_monitor)
{
IOTMonitorData i = new IOTMonitorData();
i.RemoteIP = IP;
i.Step = 0;
string ti =DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffffff");
i.CreateTime = DateTime.Now;
i.TriggerTime = ti;
i.HotelId = hotelid;
i.HotelCode = int.Parse(hotel_sys.Code);
i.RoomNumber = roomNo;
i.RequestId = msgid;
i.Platform = "ETV";
i.CommandDescription = reqData;
SendMQTTData.Send(i);
}
Host host = null;
string ETVKongZhiKey = CacheKey.ETV_YuYin + "_" + hotelid + "_" + roomNo;
var UXV = HttpContext.Cache.Get(ETVKongZhiKey);
if (UXV != null)
{
host = UXV as Host;
}
else
{
// host = HostManager.GetByXiaoDuCUID(XiaoDuCUID);//根据小度音箱序列号获取对应RCU主机
host = HostManager.GetByRoomNumber(roomNo, hotelid_int);
if (host != null)
{
string code = host.SysHotel.Code;
string roomno = host.RoomNumber;
HttpContext.Cache.Insert(ETVKongZhiKey, host, null, DateTime.Now.AddMinutes(20), Cache.NoSlidingExpiration);
}
}
if (host == null)
{
return Json(new { code = 500, msg = "找不到此房间" }, JsonRequestBehavior.AllowGet);//"小度音箱(" + request.payload.cuid + ")尚未绑定客房主机"
}
int hotelcode = 0;
int.TryParse(host.SysHotel.Code, out hotelcode);
bool is_online = Common.CSRedisCacheHelper.Contains(host.HostNumber, host.MAC);
if (true)
{
string sss = "酒店(" + host.SysHotel.Name + host.SysHotel.Code + ")房间号:(" + host.RoomNumber + ") is_online: " + is_online.ToString();
IOTMonitorData i = new IOTMonitorData();
i.ControlClass = ControlClass_KongZhiSheBei;
i.Step = 1;
i.CreateTime = DateTime.Now;
string ti = CPUData.GetNowPrecise().ToString("yyyy-MM-dd HH:mm:ss.ffffff");
i.TriggerTime = ti;
i.HotelId = hotelid;
i.HotelCode = int.Parse(host.SysHotel.Code);
i.RoomNumber = roomNo;
i.RequestId = msgid;
i.Platform = "ETV";
i.CommandDescription = sss;
SendMQTTData.Send(i);
}
if (!is_online)
{
logger.Error("ETV当前访问酒店(" + host.SysHotel.Name + host.SysHotel.Code + ")客房rcu(" + host.RoomNumber + ")不在线");
return Json(new { code = 500, msg = "当前客户已经离线" }, JsonRequestBehavior.AllowGet);
}
bool is_take_card = CheckGetPower(host);
if (true)
{
string sss = "酒店(" + host.SysHotel.Name + host.SysHotel.Code + ")房间号:(" + host.RoomNumber + ") 取电: " + is_take_card.ToString();
IOTMonitorData i = new IOTMonitorData();
i.Step = 2;
i.CreateTime = DateTime.Now;
string ti = CPUData.GetNowPrecise().ToString("yyyy-MM-dd HH:mm:ss.ffffff");
i.TriggerTime = ti;
i.HotelId = hotelid;
i.HotelCode = hotelcode;
i.RoomNumber = roomNo;
i.RequestId = msgid;
i.Platform = "ETV";
i.CommandDescription = sss;
SendMQTTData.Send(i);
}
if (!is_take_card)
{
logger.Error("ETV当前访问酒店(" + host.SysHotel.Name + host.SysHotel.Code + ")客房rcu(" + host.RoomNumber + ")尚未取电");
return Json(new { code = 500, msg = "只有取电后才能控制" }, JsonRequestBehavior.AllowGet);
}
IList<HostModal> hostModals = null;
string Hkey = "ETVIOT_" + host.ID;
var dataH = HttpContext.Cache.Get(Hkey);
if (dataH != null)
{
hostModals = dataH as IList<HostModal>;
}
else
{
hostModals = HostModalManager.LoadByHostID(host.ID).Where(r => r.Modal.WXActiveIndicator).ToList();
if (hostModals != null && hostModals.Count > 0)
{
HttpContext.Cache.Insert(Hkey, hostModals, null, DateTime.Now.AddMinutes(30), Cache.NoSlidingExpiration);
}
}
// hostmodal只需要 address 和type
// device.Address = hostModal.Modal.ModalAddress;
// device.Type = hostModal.Modal.Type
if (intent.Equals("IOT.Light") || intent.Equals("IOT.Switch") || intent.Equals("IOT.Curtain"))
{
foreach (var item in slots)
{
var action = item.action;
var name = item.applianceName;
List<HostModal> q1 = new List<HostModal>();
if (name.Equals("灯"))
{
q1 = hostModals.Where(A => A.Modal.Name.Contains("灯")).ToList();
}
else
{
q1 = hostModals.Where(A => A.Modal.Name.Equals(name)||A.Modal.AliasName.Equals(name)).ToList();
}
if (q1 != null && q1.Count > 0)
{
foreach (var item_inter in q1)
{
int status = 0;
int brightness = 0;
if (action.Equals("TurnOnRequest"))
{
status = 1;
brightness = 100;
}
else if (action.Equals("TurnOffRequest"))
{
status = 2;
brightness = 0;
}
Thread.Sleep(50);
HostModalManager.SetDevice(host, item_inter, status, brightness);
}
}
}
}
if (intent.Equals("IOT.AirCondition"))
{
foreach (var item in slots)
{
var action = item.action;
var name = item.applianceName;
var value = item.value;
var q1 = hostModals.Where(A => A.Modal.Type == DeviceType.AirConditioner && A.Modal.Name.Equals(name));
foreach (var item_inter in q1)
{
int status = 0;
int temperature = 25;
int fanSpeed = 0;
int mode = 0;
int dianci_famen = 0;
int brightness = 0;
if (action.Equals("TurnOnRequest"))
{
status = 1;
}
if (action.Equals("TurnOffRequest"))
{
status = 2;
}
if (action.Equals("setTemperature"))
{
int v = 25;
int.TryParse(value, out v);
temperature = v;
}
if (action.Equals("setFanSpeed"))
{
//value=highmiddlelowauto自动
//空调风速自动0,低1,中2,高3
if (value.Equals("high"))
{
fanSpeed = 3;
}
else if (value.Equals("middle"))
{
fanSpeed = 2;
}
else if (value.Equals("low"))
{
fanSpeed = 1;
}
else if (value.Equals("auto"))
{
fanSpeed = 0;
}
}
if (action.Equals("setMode"))
{
//value=cool制冷heat制热fan=通风auto自动
//自动0制冷1制热2送风3
if (value.Equals("cool"))
{
mode = 1;
}
else if (value.Equals("heat"))
{
mode = 2;
}
else if (value.Equals("fan"))
{
mode = 3;
}
else if (value.Equals("auto"))
{
mode = 0;
}
}
HostModalManager.SetDevice(host, item_inter, status, brightness, temperature, fanSpeed, mode);
}
if (q1 != null)
{
}
}
}
if (intent.Equals("IOT.SceneTrigger"))
{
foreach (var item in slots)
{
var action = item.action;
var name = item.applianceName;
int hid = int.Parse(hotelid);
var scene = RoomTypeSceneManager.LoadAll().Where(A => A.HotelID == hid && A.Name.Equals(name)).FirstOrDefault();
if (scene != null)
{
if (action.Equals("TurnOnRequest"))
{
LightControlManager.ApplyScene(host, scene);
}
if (action.Equals("TurnOffRequest"))
{
LightControlManager.ApplyScene(host, scene);
}
}
}
}
if (is_monitor)
{
IOTMonitorData i = new IOTMonitorData();
i.Step = 4;
string ti = CPUData.GetNowPrecise().ToString("yyyy-MM-dd HH:mm:ss.ffffff");
i.CreateTime = DateTime.Now;
i.TriggerTime = ti;
i.HotelId = hotelid;
i.HotelCode = hotelcode;
i.RoomNumber = roomNo;
i.RequestId = msgid;
i.Platform = "ETV";
i.CommandDescription = "success";
SendMQTTData.Send(i);
}
return Json(new { code = 200, msg = "控制成功" }, JsonRequestBehavior.AllowGet);
}
catch (Exception ex)
{
return Json(new { code = 500, msg = ex.Message }, JsonRequestBehavior.AllowGet);
}
}
}
public class ETV_ControllerData
{
public string hotelId { get; set; }
public string roomNo { get; set; }
public string traceId { get; set; }
public string domain { get; set; }
public string intent { get; set; }
public List<ETV_CanShu> slots { get; set; }
}
public class ETV_CanShu
{
public string applianceType { get; set; }
public string action { get; set; }
public string applianceName { get; set; }
public string value { get; set; }
}
public class TV_ResponseData
{
public int code { get; set; }
public object msg { get; set; }
public TTT_Data data { get; set; }
}
public class TTT_Data
{
public string token { get; set; }
/// <summary>
/// 时间为秒
/// </summary>
public long expiresIn { get; set; }
}
public class TV_AuthData
{
public string clientId { get; set; }
public string clientSecret { get; set; }
}
public class HiWeiToken
{