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

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