星火微课系统客户端
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

Interface.cs 14KB

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 Interface
  11. {
  12. //private string APIRequestAddress = FileToolsCommon.GetConfigValue("APIRequestAddress");
  13. //private string FileRequestAddress = FileToolsCommon.GetConfigValue("FileRequestAddress");
  14. //private string schoolfileRequestAddress = FileToolsCommon.GetConfigValue("schoolfileRequestAddress");
  15. /// <summary>
  16. /// 激活信息--添加
  17. /// </summary>
  18. /// <param name="request"></param>
  19. /// <returns></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(ApplicationData, APP.Signature, Encoding.Default);//存放签名
  52. return 0;
  53. }
  54. else
  55. {
  56. APP.ServerMsg = obj["msg"].ToString();
  57. return Convert.ToInt32(obj["code"].ToString());
  58. }
  59. }
  60. else
  61. {
  62. return 1;
  63. }
  64. }
  65. }
  66. catch (Exception ex)
  67. {
  68. APP.ServerMsg = "网络异常!";
  69. LogHelper.WriteErrLog("【调用接口(RegisterController)】错误日志:" + ex.Message, ex);
  70. return 1;
  71. }
  72. }
  73. /// <summary>
  74. /// 激活信息--添加激活历史
  75. /// </summary>
  76. /// <param name="request"></param>
  77. /// <returns></returns>
  78. public int ActivationAddHistory()
  79. {
  80. try
  81. {
  82. string url = APP.certapiUrl + "/activation/add_history";
  83. Dictionary<string, object> dic = new Dictionary<string, object>
  84. {
  85. { "sign", APP.Signature }
  86. };
  87. string body = JsonHelper.ToJson(dic);
  88. string xmlDoc = HttpHelper.HttpPost(body, url);
  89. if (string.IsNullOrEmpty(xmlDoc))
  90. {
  91. return 1;
  92. //returnObj.message = "账号密码不正确";
  93. }
  94. else
  95. {
  96. JObject obj = JObject.Parse(xmlDoc);
  97. if (obj != null)
  98. {
  99. APP.ServerMsg = obj["msg"].ToString();
  100. return Convert.ToInt32(obj["code"].ToString());
  101. }
  102. else
  103. {
  104. return 1;
  105. }
  106. }
  107. }
  108. catch (Exception ex)
  109. {
  110. LogHelper.WriteErrLog("【调用接口(RegisterController)】错误日志:" + ex.Message, ex);
  111. return 1;
  112. }
  113. }
  114. /// <summary>
  115. /// 登录
  116. /// </summary>
  117. /// <param name="request"></param>
  118. /// <returns></returns>
  119. public int Login(string loginname, string loginpwd)
  120. {
  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.ServiceAddressAPI + "/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. }