星火微课系统客户端
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 14KB

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