using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace DataVAPI.Model { /// /// 返回消息 /// public class JsonMsg where T : class { /// /// 状态码 /// public int code { get; set; } /// /// 消息 /// public string msg { get; set; } /// /// 描述 /// public string ms { get; set; } /// /// 内容 /// public IOTData obj { get; set; } ///// ///// 返回数据 ///// //public IOTData oTData { get; set; } /// /// 图标 /// public int icon { get; set; } public static JsonMsg OK(T obj, string msg = "接口名称", string mso = "调用接口成功") { string str = $"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")} 接口名称为“ {msg + "”调用成功,描述:" + mso + obj}"; ConsoleColor currentForeColor = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine(str); Console.ForegroundColor = currentForeColor; ; return new JsonMsg() { code = 1, ms = mso, msg = "成功", obj = new IOTData { data = obj }, icon = 1}; } public static JsonMsg Error(T obj, string msg = "接口名称", string mso = "调用接口成功失败") { string str = $"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")} 接口名称为“ {msg + "”调用失败,描述:" + mso + obj}"; ConsoleColor currentForeColor = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(str); Console.ForegroundColor = currentForeColor; return new JsonMsg() { code = 0, ms = mso, msg = "失败",icon = 1, obj = new IOTData { data = obj } }; } } public class IOTData where T : class { public T data { get; set; } } }