Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

72 строки
2.3 KiB

  1. using Newtonsoft.Json;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace DataVAPI.Model
  8. {
  9. /// <summary>
  10. /// 返回消息
  11. /// </summary>
  12. public class JsonMsg<T> where T : class
  13. {
  14. /// <summary>
  15. /// 状态码
  16. /// </summary>
  17. public int code { get; set; }
  18. /// <summary>
  19. /// 消息
  20. /// </summary>
  21. public string msg { get; set; }
  22. /// <summary>
  23. /// 描述
  24. /// </summary>
  25. public string ms { get; set; }
  26. /// <summary>
  27. /// 内容
  28. /// </summary>
  29. public IOTData<T> obj { get; set; }
  30. ///// <summary>
  31. ///// 返回数据
  32. ///// </summary>
  33. //public IOTData<T> oTData { get; set; }
  34. /// <summary>
  35. /// 图标
  36. /// </summary>
  37. public int icon { get; set; }
  38. public static JsonMsg<T> OK(T obj, string msg = "接口名称", string mso = "调用接口成功")
  39. {
  40. string str = $"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")} 接口名称为“ {msg + "”调用成功,描述:" + mso + JsonConvert.SerializeObject(obj)}";
  41. ConsoleColor currentForeColor = Console.ForegroundColor;
  42. Console.ForegroundColor = ConsoleColor.Green;
  43. Console.WriteLine(str);
  44. Console.ForegroundColor = currentForeColor;
  45. return new JsonMsg<T>() { code = 1, ms = mso, msg = "成功", obj = new IOTData<T> { data = obj }, icon = 1};
  46. }
  47. public static JsonMsg<T> Error(T obj, string msg = "接口名称", string mso = "调用接口成功失败")
  48. {
  49. string str = $"{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")} 接口名称为“ {msg + "”调用失败,描述:" + mso + JsonConvert.SerializeObject(obj)}";
  50. ConsoleColor currentForeColor = Console.ForegroundColor;
  51. Console.ForegroundColor = ConsoleColor.Red;
  52. Console.WriteLine(str);
  53. Console.ForegroundColor = currentForeColor;
  54. return new JsonMsg<T>() { code = 0, ms = mso, msg = "失败",icon = 1, obj = new IOTData<T> { data = obj } };
  55. }
  56. }
  57. public class IOTData<T> where T : class
  58. {
  59. public T data { get; set; }
  60. }
  61. }