星火微课系统客户端
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  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. /// <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. string url = APP.apiUrl + "/user/login";//地址
  119. //1.193.37.200
  120. string Address = "";//河南 郑州
  121. HttpHelper.GetAddressIP(out string AddressIP, out AddressIP);
  122. Dictionary<string, object> dic = new Dictionary<string, object>
  123. {
  124. { "loginname", loginname},
  125. { "loginpwd", loginpwd},
  126. {"logip", AddressIP},
  127. {"logaddress", Address},
  128. {"ultype", "microlecture_pc_t"},
  129. {"versionnum", FileToolsCommon.GetConfigValue("VersionName")}
  130. };
  131. string body = JsonHelper.ToJson(dic);
  132. ResultVo<Model_UserInfo> result = HttpHelper.PostAndRespSignle<ResultVo<Model_UserInfo>>(url, postData: body);
  133. if (result != null)
  134. {
  135. APP.UserInfo = new Model_UserInfo();
  136. APP.ServerMsg = result.msg;
  137. if (result.obj != null)
  138. {
  139. APP.UserInfo = result.obj;
  140. }
  141. return result.code;
  142. }
  143. else
  144. {
  145. APP.ServerMsg = "网络异常!";
  146. APP.UserInfo = new Model_UserInfo();
  147. return 1;
  148. }
  149. }
  150. /// <summary>
  151. /// 下载头像
  152. /// </summary>
  153. /// <param name="headPortrait"></param>
  154. /// <param name="SavePath"></param>
  155. /// <returns></returns>
  156. public bool DownloadAvatar(string headPortrait, string SavePath)
  157. {
  158. string url = APP.showImageUrl + headPortrait;
  159. bool result = HttpHelper.GetDataGetHtml(url, SavePath, "");
  160. return result;
  161. }
  162. /// <summary>
  163. /// 教师教材列表
  164. /// </summary>
  165. /// <param name="request"></param>
  166. /// <returns></returns>
  167. public int TsubjectbookList()
  168. {
  169. APP.TsubjectbookList = new List<Model_TsubjectbookList>();
  170. try
  171. {
  172. string url = APP.apiUrl + "/tsubjectbook/list";//地址
  173. Dictionary<string, int> dic = new Dictionary<string, int>
  174. {
  175. { "teacherid",APP.UserInfo.Userid}
  176. };
  177. string body = JsonHelper.ToJson(dic);
  178. ResultVo<List<Model_TsubjectbookList>> result = HttpHelper.PostAndRespSignle<ResultVo<List<Model_TsubjectbookList>>>(url, postData: body);
  179. if (result != null)
  180. {
  181. APP.ServerMsg = result.msg;
  182. APP.TsubjectbookList = result.obj;
  183. return result.code;
  184. }
  185. else
  186. {
  187. APP.ServerMsg = "网络异常!";
  188. return 1;
  189. }
  190. }
  191. catch (Exception ex)
  192. {
  193. LogHelper.WriteErrLog("【调用接口(RegisterController)】错误日志:" + ex.Message, ex);
  194. return 1;
  195. }
  196. }
  197. /// <summary>
  198. /// 章节--列表
  199. /// </summary>
  200. /// <param name="request"></param>
  201. /// <returns></returns>
  202. public int DirectorList(string lsbid, int belong, int createid)
  203. {
  204. APP.DirectorList = new List<Model_DirectorList>();
  205. try
  206. {
  207. string url = APP.apiUrl + "/director/list";//地址
  208. Dictionary<string, string> dic = new Dictionary<string, string>
  209. {
  210. { "lsbid", lsbid },
  211. { "belong", belong.ToString() },
  212. { "createid", createid.ToString() }
  213. };
  214. string body = JsonHelper.ToJson(dic);
  215. ResultVo<List<Model_DirectorList>> result = HttpHelper.PostAndRespSignle<ResultVo<List<Model_DirectorList>>>(url, postData: body);
  216. if (result != null)
  217. {
  218. APP.ServerMsg = result.msg;
  219. APP.DirectorList = result.obj;
  220. return result.code;
  221. }
  222. else
  223. {
  224. APP.ServerMsg = "网络异常!";
  225. return 1;
  226. }
  227. }
  228. catch (Exception ex)
  229. {
  230. LogHelper.WriteErrLog("【调用接口(RegisterController)】错误日志:" + ex.Message, ex);
  231. return 1;
  232. }
  233. }
  234. /// <summary>
  235. /// 资源--添加
  236. /// </summary>
  237. /// <param name="request"></param>
  238. /// <returns></returns>
  239. public int ResourceAdd(Model_ResourceAdd model)
  240. {
  241. APP.DirectorList = new List<Model_DirectorList>();
  242. try
  243. {
  244. string url = APP.apiUrl + "/resource/add";//地址
  245. Dictionary<string, object> dic = new Dictionary<string, object>
  246. {
  247. // converted: 0
  248. //createid: 80
  249. //directorid: 1009
  250. //duration: 39
  251. //imgUrl: ""
  252. //level: 2
  253. //lsbid: 40
  254. //mp4code: "h264"
  255. //resourcebelong: 3
  256. //resourceclass: 2
  257. //resourcecover: "12/resource/20200917/4f297df0-f8c0-11ea-adf5-81f24b97d4ff/weather_pic.jpg"
  258. //resourcename: "weather_pic"
  259. //resourcesize: 6105268
  260. //resourcetype: 0
  261. //resourceurl: "12/resource/20200917/4f297df0-f8c0-11ea-adf5-81f24b97d4ff/weather_pic.mp4"
  262. //schoolid: 12
  263. //suffix: "mp4"
  264. //uid: 80
  265. { "converted", model.converted },
  266. { "createid", model.createid }
  267. };
  268. if (model.directorid != "999999")//章节上传可以不选
  269. {
  270. dic.Add("directorid", model.directorid);
  271. }
  272. dic.Add("duration", model.duration);
  273. dic.Add("subjectid", model.subjectid);
  274. dic.Add("imgUrl", model.imgUrl);
  275. dic.Add("level", model.level);
  276. dic.Add("lsbid", model.lsbid);
  277. dic.Add("mp4code", model.mp4code);
  278. dic.Add("resourcebelong", model.resourcebelong);
  279. dic.Add("resourceclass", model.resourceclass);
  280. dic.Add("resourcecover", model.resourcecover);
  281. dic.Add("resourcename", model.resourcename);
  282. dic.Add("resourcesize", model.resourcesize);
  283. dic.Add("resourcetype", model.resourcetype);
  284. dic.Add("resourceurl", model.resourceurl);
  285. dic.Add("schoolid", model.schoolid);
  286. dic.Add("suffix", model.suffix);
  287. //dic.Add("uid", model.uid);
  288. string body = JsonHelper.ToJson(dic);
  289. string xmlDoc = HttpHelper.HttpPost(body, url);
  290. JObject obj = JObject.Parse(xmlDoc);
  291. if (obj != null)
  292. {
  293. APP.ServerMsg = obj["msg"].ToString();
  294. return Convert.ToInt32(obj["code"].ToString());
  295. }
  296. else
  297. {
  298. APP.ServerMsg = "网络异常!";
  299. return 1;
  300. }
  301. }
  302. catch (Exception ex)
  303. {
  304. APP.ServerMsg = "网络异常!";
  305. LogHelper.WriteErrLog("【调用接口(RegisterController)】错误日志:" + ex.Message, ex);
  306. return 1;
  307. }
  308. }
  309. /// <summary>
  310. /// 请求服务地址
  311. /// </summary>
  312. /// <param name="Schoolcode"></param>
  313. /// <returns></returns>
  314. public bool GetServiceAddress(string Schoolcode, out string Message)
  315. {
  316. string url = APP.certapiUrl + "/school/find_code";//地址
  317. Dictionary<string, object> dic = new Dictionary<string, object>
  318. {
  319. { "schoolcode", Schoolcode}
  320. };
  321. string body = JsonHelper.ToJson(dic);
  322. ResultVo<Model_ServiceAddress> result = HttpHelper.PostAndRespSignle<ResultVo<Model_ServiceAddress>>(url, postData: body);
  323. if (result != null)
  324. {
  325. if (result.code == 0)
  326. {
  327. if (result.obj != null)
  328. {
  329. Message = result.msg;
  330. APP.ServiceAddress = result.obj;
  331. APP.SaveServiceAddressData();
  332. return true;
  333. }
  334. else
  335. {
  336. Message = "服务地址错误,请输入正确的地址!";
  337. return false;
  338. }
  339. }
  340. else
  341. {
  342. Message = result.msg;
  343. return false;
  344. }
  345. }
  346. else
  347. {
  348. Message = "无法与服务器建立连接,请检查网络状态。";
  349. return false;
  350. }
  351. }
  352. }
  353. }