官网——C# SDK使用说明 API中心

创建工程

image.png

Apis/目录下的代码拷贝进来

image.png

HelloWorld

  1. using AepSdk.Apis.Core;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Diagnostics;
  5. using Xunit;
  6. namespace CTWingAgent
  7. {
  8. /// <summary>
  9. /// 查询设备列表
  10. /// 官方文档给的示例:https://www.ctwing.cn/yykf/126#see
  11. /// </summary>
  12. public class QueryDeviceList
  13. {
  14. //查询设备列表
  15. public Rootobject DoRequest(string appKey, string appSecret, string MasterKey, string productId, string searchValue = "", string pageNow = "", string pageSize = "")
  16. {
  17. //API地址
  18. string path = "/aep_device_management/devices";
  19. //头
  20. Dictionary<string, string> headers = new Dictionary<string, string>();
  21. headers.Add("MasterKey", MasterKey);
  22. //参数
  23. Dictionary<string, string> param = new Dictionary<string, string>();
  24. param.Add("productId", productId);
  25. param.Add("searchValue", searchValue);
  26. param.Add("pageNow", pageNow);
  27. param.Add("pageSize", pageSize);
  28. string version = "20190507012134";
  29. string application = appKey;
  30. string key = appSecret;
  31. string response = AepHttpRequest.SendAepHttpRequest(path, headers, param, null, version, application, key, "GET");
  32. Debug.WriteLine("[QueryDeviceList] " + response);
  33. Rootobject rootobject = Newtonsoft.Json.JsonConvert.DeserializeObject<Rootobject>(response);
  34. return rootobject;
  35. }
  36. [Fact]
  37. public void Test1()
  38. {
  39. //在 CTWing控制台 > 应用管理 > 打开指定应用
  40. string appKey = "**";
  41. string appSecret = "**";
  42. //在 CTWing控制台 > 产品 > 打开指定产品
  43. string MasterKey = "**";
  44. string productId = "**";
  45. Rootobject result = DoRequest(appKey, appSecret, MasterKey, productId);
  46. }
  47. //////////复制AepHttpRequest.SendAepHttpRequest返回的JSON字符串结果
  48. //////////Visual studio > 编辑 > 选择性粘贴 > 将JSON粘贴为类,即可生成以下数据结构,不需要手动定义
  49. /// <summary>
  50. /// JSON数据结构
  51. /// </summary>
  52. public class Rootobject
  53. {
  54. public int code { get; set; }
  55. public string msg { get; set; }
  56. public Result result { get; set; }
  57. }
  58. public class Result
  59. {
  60. public int pageNum { get; set; }
  61. public int pageSize { get; set; }
  62. public int total { get; set; }
  63. public List[] list { get; set; }
  64. }
  65. public class List
  66. {
  67. public string deviceId { get; set; }
  68. public string deviceName { get; set; }
  69. public string tenantId { get; set; }
  70. public int productId { get; set; }
  71. public string imei { get; set; }
  72. public object imsi { get; set; }
  73. public object firmwareVersion { get; set; }
  74. public int deviceStatus { get; set; }
  75. public int autoObserver { get; set; }
  76. public long createTime { get; set; }
  77. public string createBy { get; set; }
  78. public object updateTime { get; set; }
  79. public object updateBy { get; set; }
  80. public object netStatus { get; set; }
  81. public object onlineAt { get; set; }
  82. public object offlineAt { get; set; }
  83. }
  84. }
  85. }

把demo加入,并修改成单元测试的形式

把demo加入
想运行哪个,并适当修改代码,弄成单元测试的形式即可
image.png