星火微课系统客户端
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

XHApi.cs 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  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(ApplicationData, APP.Signature, Encoding.Default);//存放签名
  51. return 0;
  52. }
  53. else
  54. {
  55. APP.ServerMsg = obj["msg"].ToString();
  56. return Convert.ToInt32(obj["code"].ToString());
  57. }
  58. }
  59. else
  60. {
  61. return 1;
  62. }
  63. }
  64. }
  65. catch (Exception ex)
  66. {
  67. APP.ServerMsg = "网络异常!";
  68. LogHelper.WriteErrLog("【调用接口(RegisterController)】错误日志:" + ex.Message, ex);
  69. return 1;
  70. }
  71. }
  72. /// <summary>
  73. /// 激活信息--添加激活历史
  74. /// </summary>
  75. /// <param name="request">
  76. /// </param>
  77. /// <returns>
  78. /// </returns>
  79. public int ActivationAddHistory()
  80. {
  81. try
  82. {
  83. string url = APP.certapiUrl + "/activation/add_history";
  84. Dictionary<string, object> dic = new Dictionary<string, object>
  85. {
  86. { "sign", APP.Signature }
  87. };
  88. string body = JsonHelper.ToJson(dic);
  89. string xmlDoc = HttpHelper.HttpPost(body, url);
  90. if (string.IsNullOrEmpty(xmlDoc))
  91. {
  92. return 1;
  93. //returnObj.message = "账号密码不正确";
  94. }
  95. else
  96. {
  97. JObject obj = JObject.Parse(xmlDoc);
  98. if (obj != null)
  99. {
  100. APP.ServerMsg = obj["msg"].ToString();
  101. return Convert.ToInt32(obj["code"].ToString());
  102. }
  103. else
  104. {
  105. return 1;
  106. }
  107. }
  108. }
  109. catch (Exception ex)
  110. {
  111. LogHelper.WriteErrLog("【调用接口(RegisterController)】错误日志:" + ex.Message, ex);
  112. return 1;
  113. }
  114. }
  115. /// <summary>
  116. /// 登录
  117. /// </summary>
  118. /// <param name="request">
  119. /// </param>
  120. /// <returns>
  121. /// </returns>
  122. public int Login(string loginname, string loginpwd)
  123. {
  124. Console.WriteLine(FileToolsCommon.GetConfigValue("APIRequestAddress"));
  125. string url = APP.apiUrl + "/suser/user/login";//地址
  126. //1.193.37.200
  127. string Address = "";//河南 郑州
  128. HttpHelper.GetAddressIP(out string AddressIP, out AddressIP);
  129. Dictionary<string, object> dic = new Dictionary<string, object>
  130. {
  131. { "loginname", loginname},
  132. { "loginpwd", loginpwd},
  133. {"logip", AddressIP},
  134. {"logaddress", Address},
  135. {"ultype", "microlecture_pc_t"},
  136. {"versionnum", FileToolsCommon.GetConfigValue("VersionName")}
  137. };
  138. string body = JsonHelper.ToJson(dic);
  139. ResultVo<Model_UserInfo> result = HttpHelper.PostAndRespSignle<ResultVo<Model_UserInfo>>(url, postData: body);
  140. if (result != null)
  141. {
  142. APP.UserInfo = new Model_UserInfo();
  143. APP.ServerMsg = result.msg;
  144. if (result.obj != null)
  145. {
  146. APP.UserInfo = result.obj;
  147. }
  148. return result.code;
  149. }
  150. else
  151. {
  152. APP.ServerMsg = "网络异常!";
  153. APP.UserInfo = new Model_UserInfo();
  154. return 1;
  155. }
  156. }
  157. /// <summary>
  158. /// 下载头像
  159. /// </summary>
  160. /// <param name="headPortrait">
  161. /// </param>
  162. /// <param name="SavePath">
  163. /// </param>
  164. /// <returns>
  165. /// </returns>
  166. public bool DownloadAvatar(string headPortrait, string SavePath)
  167. {
  168. string url = APP.showImageUrl + headPortrait;
  169. bool result = HttpHelper.GetDataGetHtml(url, SavePath, "");
  170. return result;
  171. }
  172. /// <summary>
  173. /// 教师教材列表
  174. /// </summary>
  175. /// <param name="request">
  176. /// </param>
  177. /// <returns>
  178. /// </returns>
  179. public int TsubjectbookList()
  180. {
  181. APP.TsubjectbookList = new List<Model_TsubjectbookList>();
  182. try
  183. {
  184. string url = APP.apiUrl + "/sstudy/tsubjectbook/list";//地址
  185. Dictionary<string, int> dic = new Dictionary<string, int>
  186. {
  187. { "teacherid",APP.UserInfo.Userid}
  188. };
  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. }