星火微课系统客户端
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

XHApi.cs 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  1. using Common.system;
  2. using Newtonsoft.Json.Linq;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.IO;
  6. using System.Text;
  7. using XHWK.Model;
  8. namespace XHWK.WKTool.DAL
  9. {
  10. using system;
  11. public class XHApi
  12. {
  13. /// <summary>
  14. /// 激活信息--添加
  15. /// </summary>
  16. /// <param name="request">
  17. /// </param>
  18. /// <returns>
  19. /// </returns>
  20. public int ActivationAdd(string mac, string device, string projectcode)
  21. {
  22. try
  23. {
  24. string url = App.certapiUrl + "/activation/add"; //地址
  25. Dictionary<string, object> dic = new Dictionary<string, object>
  26. {
  27. { "mac", mac },
  28. { "device", device },
  29. { "projectcode", projectcode }
  30. };
  31. string body = JsonHelper.ToJson(dic);
  32. string xmlDoc = HttpHelper.HttpPost(body, url);
  33. if (string.IsNullOrEmpty(xmlDoc))
  34. {
  35. App.ServerMsg = "网络异常!";
  36. return 1;
  37. }
  38. else
  39. {
  40. JObject obj = JObject.Parse(xmlDoc);
  41. if (obj != null)
  42. {
  43. if (obj["code"].ToString().Equals("0"))
  44. {
  45. App.Signature = obj["obj"].ToString();
  46. if (!Directory.Exists(App.DataPath))
  47. {
  48. Directory.CreateDirectory(App.DataPath);
  49. }
  50. string ApplicationData = App.DataPath + "signature.txt";
  51. System.IO.File.WriteAllText
  52. (
  53. ApplicationData,
  54. App.Signature,
  55. Encoding.Default
  56. ); //存放签名
  57. return 0;
  58. }
  59. else
  60. {
  61. App.ServerMsg = obj["msg"].ToString();
  62. return Convert.ToInt32(obj["code"].ToString());
  63. }
  64. }
  65. else
  66. {
  67. return 1;
  68. }
  69. }
  70. }
  71. catch (Exception ex)
  72. {
  73. App.ServerMsg = "网络异常!";
  74. LogHelper.WriteErrLog("【调用接口(RegisterController)】错误日志:" + ex.Message, ex);
  75. return 1;
  76. }
  77. }
  78. /// <summary>
  79. /// 激活信息--添加激活历史
  80. /// </summary>
  81. /// <param name="request">
  82. /// </param>
  83. /// <returns>
  84. /// </returns>
  85. public int ActivationAddHistory()
  86. {
  87. try
  88. {
  89. string url = App.certapiUrl + "/activation/add_history";
  90. Dictionary<string, object> dic = new Dictionary<string, object> { { "sign", App.Signature } };
  91. string body = JsonHelper.ToJson(dic);
  92. string xmlDoc = HttpHelper.HttpPost(body, url);
  93. if (string.IsNullOrEmpty(xmlDoc))
  94. {
  95. return 1;
  96. //returnObj.message = "账号密码不正确";
  97. }
  98. else
  99. {
  100. JObject obj = JObject.Parse(xmlDoc);
  101. if (obj != null)
  102. {
  103. App.ServerMsg = obj["msg"].ToString();
  104. return Convert.ToInt32(obj["code"].ToString());
  105. }
  106. else
  107. {
  108. return 1;
  109. }
  110. }
  111. }
  112. catch (Exception ex)
  113. {
  114. LogHelper.WriteErrLog("【调用接口(RegisterController)】错误日志:" + ex.Message, ex);
  115. return 1;
  116. }
  117. }
  118. /// <summary>
  119. /// 登录
  120. /// </summary>
  121. /// <param name="request">
  122. /// </param>
  123. /// <returns>
  124. /// </returns>
  125. public int Login(string loginname, string loginpwd)
  126. {
  127. Console.WriteLine(FileToolsCommon.GetConfigValue("APIRequestAddress"));
  128. string url = App.apiUrl + "/suser/user/login"; //地址
  129. //1.193.37.200
  130. string Address = "";//河南 郑州
  131. HttpHelper.GetAddressIP(out string AddressIP, out AddressIP);
  132. Dictionary<string, object> dic = new Dictionary<string, object>
  133. {
  134. { "loginname", loginname},
  135. { "loginpwd", loginpwd},
  136. {"logip", AddressIP},
  137. {"logaddress", Address},
  138. {"ultype", "microlecture_pc_t"},
  139. {"versionnum", FileToolsCommon.GetConfigValue("VersionName")}
  140. };
  141. string body = JsonHelper.ToJson(dic);
  142. ResultVo<Model_UserInfo> result = HttpHelper.PostAndRespSignle<ResultVo<Model_UserInfo>>(url, postData: body);
  143. if (result != null)
  144. {
  145. App.UserInfo = new Model_UserInfo();
  146. App.ServerMsg = result.msg;
  147. if (result.obj != null)
  148. {
  149. App.UserInfo = result.obj;
  150. }
  151. return result.code;
  152. }
  153. else
  154. {
  155. App.ServerMsg = "网络异常!";
  156. App.UserInfo = new Model_UserInfo();
  157. return 1;
  158. }
  159. }
  160. /// <summary>
  161. /// 下载头像
  162. /// </summary>
  163. /// <param name="headPortrait">
  164. /// </param>
  165. /// <param name="SavePath">
  166. /// </param>
  167. /// <returns>
  168. /// </returns>
  169. public bool DownloadAvatar(string headPortrait, string SavePath)
  170. {
  171. string url = App.showImageUrl + headPortrait;
  172. bool result = HttpHelper.GetDataGetHtml(url, SavePath, "");
  173. return result;
  174. }
  175. /// <summary>
  176. /// 教师教材列表
  177. /// </summary>
  178. /// <param name="request">
  179. /// </param>
  180. /// <returns>
  181. /// </returns>
  182. public int TsubjectbookList()
  183. {
  184. App.TsubjectbookList = new List<Model_TsubjectbookList>();
  185. try
  186. {
  187. string url = App.apiUrl + "/sstudy/tsubjectbook/list"; //地址
  188. Dictionary<string, int> dic = new Dictionary<string, int> { { "teacherid", App.UserInfo.Userid } };
  189. string body = JsonHelper.ToJson(dic);
  190. ResultVo<List<Model_TsubjectbookList>> result = HttpHelper.PostAndRespSignle<ResultVo<List<Model_TsubjectbookList>>>(url, postData: body);
  191. if (result != null)
  192. {
  193. App.ServerMsg = result.msg;
  194. App.TsubjectbookList = result.obj;
  195. return result.code;
  196. }
  197. else
  198. {
  199. App.ServerMsg = "网络异常!";
  200. return 1;
  201. }
  202. }
  203. catch (Exception ex)
  204. {
  205. LogHelper.WriteErrLog("【调用接口(RegisterController)】错误日志:" + ex.Message, ex);
  206. return 1;
  207. }
  208. }
  209. /// <summary>
  210. /// 章节--列表
  211. /// </summary>
  212. /// <param name="request">
  213. /// </param>
  214. /// <returns>
  215. /// </returns>
  216. public int DirectorList(string lsbid, int belong, int createid)
  217. {
  218. App.DirectorList = new List<Model_DirectorList>();
  219. try
  220. {
  221. string url = App.apiUrl + "/sstudy/director/list"; //地址
  222. Dictionary<string, string> dic = new Dictionary<string, string>
  223. {
  224. { "lsbid", lsbid },
  225. { "belong", belong.ToString() },
  226. { "createid", createid.ToString() }
  227. };
  228. string body = JsonHelper.ToJson(dic);
  229. ResultVo<List<Model_DirectorList>> result = HttpHelper.PostAndRespSignle<ResultVo<List<Model_DirectorList>>>(url, postData: body);
  230. if (result != null)
  231. {
  232. App.ServerMsg = result.msg;
  233. App.DirectorList = result.obj;
  234. return result.code;
  235. }
  236. else
  237. {
  238. App.ServerMsg = "网络异常!";
  239. return 1;
  240. }
  241. }
  242. catch (Exception ex)
  243. {
  244. LogHelper.WriteErrLog("【调用接口(RegisterController)】错误日志:" + ex.Message, ex);
  245. return 1;
  246. }
  247. }
  248. /// <summary>
  249. /// 资源--添加
  250. /// </summary>
  251. /// <param name="request">
  252. /// </param>
  253. /// <returns>
  254. /// </returns>
  255. public int ResourceAdd(Model_ResourceAdd model)
  256. {
  257. App.DirectorList = new List<Model_DirectorList>();
  258. try
  259. {
  260. string url = App.apiUrl + "/sstudy/resource/add"; //地址
  261. Dictionary<string, object> dic = new Dictionary<string, object>
  262. {
  263. // converted: 0
  264. //createid: 80
  265. //directorid: 1009
  266. //duration: 39
  267. //imgUrl: ""
  268. //level: 2
  269. //lsbid: 40
  270. //mp4code: "h264"
  271. //resourcebelong: 3
  272. //resourceclass: 2
  273. //resourcecover: "12/resource/20200917/4f297df0-f8c0-11ea-adf5-81f24b97d4ff/weather_pic.jpg"
  274. //resourcename: "weather_pic"
  275. //resourcesize: 6105268
  276. //resourcetype: 0
  277. //resourceurl: "12/resource/20200917/4f297df0-f8c0-11ea-adf5-81f24b97d4ff/weather_pic.mp4"
  278. //schoolid: 12
  279. //suffix: "mp4"
  280. //uid: 80
  281. { "converted", model.converted },
  282. { "createid", model.createid }
  283. };
  284. if (model.directorid != "999999")//章节上传可以不选
  285. {
  286. dic.Add("directorid", model.directorid);
  287. }
  288. dic.Add("duration", model.duration);
  289. dic.Add("subjectid", model.subjectid);
  290. dic.Add("imgUrl", model.imgUrl);
  291. dic.Add("level", model.level);
  292. dic.Add("lsbid", model.lsbid);
  293. dic.Add("mp4code", model.mp4code);
  294. dic.Add("resourcebelong", model.resourcebelong);
  295. dic.Add("resourceclass", model.resourceclass);
  296. dic.Add("resourcecover", model.resourcecover);
  297. dic.Add("resourcename", model.resourcename);
  298. dic.Add("resourcesize", model.resourcesize);
  299. dic.Add("resourcetype", model.resourcetype);
  300. dic.Add("resourceurl", model.resourceurl);
  301. dic.Add("schoolid", model.schoolid);
  302. dic.Add("suffix", model.suffix);
  303. //dic.Add("uid", model.uid);
  304. string body = JsonHelper.ToJson(dic);
  305. string xmlDoc = HttpHelper.HttpPost(body, url);
  306. JObject obj = JObject.Parse(xmlDoc);
  307. if (obj != null)
  308. {
  309. App.ServerMsg = obj["msg"].ToString();
  310. return Convert.ToInt32(obj["code"].ToString());
  311. }
  312. else
  313. {
  314. App.ServerMsg = "网络异常!";
  315. return 1;
  316. }
  317. }
  318. catch (Exception ex)
  319. {
  320. App.ServerMsg = "网络异常!";
  321. LogHelper.WriteErrLog("【调用接口(RegisterController)】错误日志:" + ex.Message, ex);
  322. return 1;
  323. }
  324. }
  325. /// <summary>
  326. /// 请求服务地址
  327. /// </summary>
  328. /// <param name="Schoolcode">
  329. /// </param>
  330. /// <returns>
  331. /// </returns>
  332. public bool GetServiceAddress(string Schoolcode, out string Message)
  333. {
  334. string url = App.certapiUrl + "/school/find_code"; //地址
  335. Dictionary<string, object> dic = new Dictionary<string, object>
  336. {
  337. { "schoolcode", Schoolcode}
  338. };
  339. string body = JsonHelper.ToJson(dic);
  340. ResultVo<Model_ServiceAddress> result = HttpHelper.PostAndRespSignle<ResultVo<Model_ServiceAddress>>(url, postData: body);
  341. if (result != null)
  342. {
  343. if (result.code == 0)
  344. {
  345. if (result.obj != null)
  346. {
  347. Message = result.msg;
  348. App.ServiceAddress = result.obj;
  349. App.SaveServiceAddressData();
  350. return true;
  351. }
  352. else
  353. {
  354. Message = "服务地址错误,请输入正确的地址!";
  355. return false;
  356. }
  357. }
  358. else
  359. {
  360. Message = result.msg;
  361. return false;
  362. }
  363. }
  364. else
  365. {
  366. Message = "无法与服务器建立连接,请检查网络状态。";
  367. return false;
  368. }
  369. }
  370. }
  371. }