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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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.DownloadFile(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> { { "converted", model.converted }, { "createid", model.createid } };
  218. if (model.directorid != "999999") //章节上传可以不选
  219. {
  220. dic.Add("directorid", model.directorid);
  221. }
  222. dic.Add("duration", model.duration);
  223. dic.Add("subjectid", model.subjectid);
  224. dic.Add("imgUrl", model.imgUrl);
  225. dic.Add("level", model.level);
  226. dic.Add("lsbid", model.lsbid);
  227. dic.Add("mp4code", model.mp4code);
  228. dic.Add("resourcebelong", model.resourcebelong);
  229. dic.Add("resourceclass", model.resourceclass);
  230. dic.Add("resourcecover", model.resourcecover);
  231. dic.Add("resourcename", model.resourcename);
  232. dic.Add("resourcesize", model.resourcesize);
  233. dic.Add("resourcetype", model.resourcetype);
  234. dic.Add("resourceurl", model.resourceurl);
  235. dic.Add("schoolid", model.schoolid);
  236. dic.Add("suffix", model.suffix);
  237. //dic.Add("uid", model.uid);
  238. string body = JsonHelper.ToJson(dic);
  239. string xmlDoc = ZHttpUtil.PostStr(url, body);
  240. JObject obj = JObject.Parse(xmlDoc);
  241. App.ServerMsg = obj["msg"]?.ToString();
  242. return Convert.ToInt32(obj["code"]?.ToString());
  243. }
  244. catch (Exception ex)
  245. {
  246. App.ServerMsg = "网络异常!";
  247. LogHelper.Logerror.Error("【调用接口(RegisterController)】错误日志:" + ex.Message, ex);
  248. return 1;
  249. }
  250. }
  251. /// <summary>
  252. /// 请求服务地址
  253. /// </summary>
  254. /// <param name="schoolcode">
  255. /// </param>
  256. /// <param name="message"></param>
  257. /// <returns>
  258. /// </returns>
  259. public bool GetServiceAddress(string schoolcode, out string message)
  260. {
  261. string url = App.certapiUrl + "/school/find_code"; //地址
  262. Dictionary<string, object> dic = new Dictionary<string, object> { { "schoolcode", schoolcode } };
  263. string body = JsonHelper.ToJson(dic);
  264. ResultVo<ModelServiceAddress> result = ZHttpUtil.PostSignle<ResultVo<ModelServiceAddress>>(url, body, false);
  265. if (result != null)
  266. {
  267. if (result.code == 0)
  268. {
  269. if (result.obj != null)
  270. {
  271. message = result.msg;
  272. App.ServiceAddress = result.obj;
  273. App.SaveServiceAddressData();
  274. return true;
  275. }
  276. message = "服务地址错误,请输入正确的地址!";
  277. return false;
  278. }
  279. else
  280. {
  281. message = result.msg;
  282. return false;
  283. }
  284. }
  285. else
  286. {
  287. message = "无法与服务器建立连接,请检查网络状态。";
  288. return false;
  289. }
  290. }
  291. }
  292. }