星火微课系统客户端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

XHApi.cs 13KB

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