using System; using System.Collections.Generic; using System.Linq; using System.Text; using Newtonsoft.Json; using System.Net; namespace Common { /// /// 与第三方选住云端对接:将相关服务信息推送过去 /// public static class XuanZhuOperation { private static log4net.ILog logger = log4net.LogManager.GetLogger(typeof(XuanZhuOperation)); //private static readonly string _postURL = "http://111.231.106.196:19230/hogood/report"; //### //POST http://111.231.106.196:19230/hogood/report //Content-Type: application/json; charset=UTF-8 //{ // "code": "1094",//酒店编码 // "roomNumber": "8888",//房号 // "address": "001001001",//回路地址 // "name": "廊灯",//回路名称 // "status":"1" //状态:1开,2关 //} //### 返回 //{ // "retCode": 1, //0代表成功 其他代表失败 // "retMsg": "[003]非法访问", // "retData": null //} //### /// /// 上报设备或服务状态信息 /// /// /// /// public static bool ReportService(string url, XuanZhuResponse resp) { string param = Newtonsoft.Json.JsonConvert.SerializeObject(resp); try { var A = (SecurityProtocolType)48; var B = (SecurityProtocolType)192; var C = (SecurityProtocolType)768; var D = (SecurityProtocolType)3072; var E = (SecurityProtocolType)12288; ServicePointManager.SecurityProtocol = A | B | C | D | E; string result = HttpWebRequestHelper.PostWebRequest(url, param); if (resp.code.Equals("1003")) { logger.Error(resp.roomNumber + " Params:" + param + " Result:" + result); } XuanZhuResult returnResult = JsonConvert.DeserializeObject(result); //if (returnResult.retCode == "0")//0代表成功 其他代表失败 //{ // return true; //} //logger.Error(string.Format("酒店({0})客房({1})调用设备状态推送接口({2})结果:{3}", hotelCode, roomNumber, url, returnResult.retMsg)); //return false; return true; } catch (Exception ex) { string Key = "HttpRequest_" + resp.code + "_" + resp.roomNumber; MemoryCacheHelper.Set(Key, 1, DateTimeOffset.Now.AddMinutes(10)); logger.Error(string.Format("酒店({0})客房({1})调用设备状态或异常推送接口({2})失败:{3},数据:{4}", resp.code, resp.roomNumber, url, ex.Message, param)); return false; } } } public class XuanZhuResponse { /// /// 酒店编码 /// public string code { get; set; } /// /// 房号 /// public string roomNumber { get; set; } /// /// 回路地址 /// public string address { get; set; } /// /// 回路名称 /// public string name { get; set; } /// /// 状态 /// public int status { get; set; } /// /// 异常类型 /// public int faultType { get; set; } /// /// 异常值 /// public int faultData { get; set; } /// /// 亮度 /// public int brightness { get; set; } /// /// 当前温度 /// public int currentTemp { get; set; } /// /// 设定温度 /// public int settingTemp { get; set; } /// /// 风速 /// public int fanSpeed { get; set; } /// /// 模式 /// public int mode { get; set; } /// /// 阀门 /// public int valve { get; set; } } internal class XuanZhuResult { /// /// 返回码 /// public string retCode { get; set; } /// /// 返回描述 /// public string retMsg { get; set; } /// /// 返回描述 /// public string retData { get; set; } } }