123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305 |
- using Common.system;
-
- using Newtonsoft.Json.Linq;
-
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Text;
-
- using XHWK.Model;
-
- namespace XHWK.WKTool.DAL
- {
- using system;
-
- public class XhApi
- {
- /// <summary>
- /// 激活信息--添加
- /// </summary>
- /// <returns>
- /// </returns>
- public int ActivationAdd(string mac, string device, string projectcode)
- {
- try
- {
- string url = App.certapiUrl + "/activation/add"; //地址
- Dictionary<string, object> dic = new Dictionary<string, object> { { "mac", mac }, { "device", device }, { "projectcode", projectcode } };
- string body = JsonHelper.ToJson(dic);
- string xmlDoc = ZHttpUtil.PostStr(url, body, false);
- if (string.IsNullOrEmpty(xmlDoc))
- {
- App.ServerMsg = "网络异常!";
- return 1;
- }
- JObject obj = JObject.Parse(xmlDoc);
- if (obj["code"] != null)
- {
- if (obj["code"].ToString().Equals("0"))
- {
- App.Signature = obj["obj"]?.ToString();
- if (!Directory.Exists(App.DataPath))
- {
- Directory.CreateDirectory(App.DataPath);
- }
- string applicationData = App.DataPath + "signature.txt";
- System.IO.File.WriteAllText(applicationData, App.Signature, Encoding.Default); //存放签名
- return 0;
- }
- App.ServerMsg = obj["msg"]?.ToString();
- return Convert.ToInt32(obj["code"].ToString());
- }
- return 1;
- }
- catch (Exception ex)
- {
- App.ServerMsg = "网络异常!";
- LogHelper.Logerror.Error("【调用接口(RegisterController)】错误日志:" + ex.Message, ex);
- return 1;
- }
- }
-
- /// <summary>
- /// 激活信息--添加激活历史
- /// </summary>
- /// <returns>
- /// </returns>
- public int ActivationAddHistory()
- {
- try
- {
- string url = App.certapiUrl + "/activation/add_history";
- Dictionary<string, object> dic = new Dictionary<string, object> { { "sign", App.Signature } };
- string body = JsonHelper.ToJson(dic);
- string xmlDoc = ZHttpUtil.PostStr(url, body, false);
- if (string.IsNullOrEmpty(xmlDoc))
- {
- return 1;
- //returnObj.message = "账号密码不正确";
- }
- else
- {
- JObject obj = JObject.Parse(xmlDoc);
- App.ServerMsg = obj["msg"]?.ToString();
- return Convert.ToInt32(obj["code"]?.ToString());
- }
- }
- catch (Exception ex)
- {
- LogHelper.Logerror.Error("【调用接口(RegisterController)】错误日志:" + ex.Message, ex);
- return 1;
- }
- }
-
- /// <summary>
- /// 登录
- /// </summary>
- /// <returns>
- /// </returns>
- public int Login(string loginname, string loginpwd)
- {
- string url = App.apiUrl + "/suser/user/login"; //地址
-
- //1.193.37.200
- const string address = ""; //河南 郑州
- ZHttpUtil.GetAddressIp(out string addressIp, out addressIp);
- Dictionary<string, object> dic = new Dictionary<string, object>
- {
- { "loginname", loginname },
- { "loginpwd", loginpwd },
- { "logip", addressIp },
- { "logaddress", address },
- { "ultype", "microlecture_pc_t" },
- { "versionnum", FileToolsCommon.GetConfigValue("VersionName") }
- };
- string body = JsonHelper.ToJson(dic);
- ResultVo<ModelUserInfo> result = ZHttpUtil.PostSignle<ResultVo<ModelUserInfo>>(url, postData: body);
- if (result != null)
- {
- App.UserInfo = new ModelUserInfo();
- App.ServerMsg = result.msg;
- if (result.obj != null)
- {
- App.UserInfo = result.obj;
- ZHttpUtil.tokenKey = result.obj.token_key;
- ZHttpUtil.tokenValue = result.obj.token_value;
- ZHttpUtil.userId = result.obj.Userid + "";
- }
- return result.code;
- }
- App.ServerMsg = "网络异常!";
- App.UserInfo = new ModelUserInfo();
- return 1;
- }
-
- /// <summary>
- /// 下载头像
- /// </summary>
- /// <param name="headPortrait">
- /// </param>
- /// <param name="savePath">
- /// </param>
- /// <returns>
- /// </returns>
- public bool DownloadAvatar(string headPortrait, string savePath)
- {
- string url = App.showImageUrl + headPortrait;
- bool result = ZHttpUtil.DownloadFile(url, savePath, "");
- return result;
- }
-
- /// <summary>
- /// 教师教材列表
- /// </summary>
- /// <returns>
- /// </returns>
- public int TsubjectbookList()
- {
- App.TsubjectbookList = new List<ModelTsubjectbookList>();
- try
- {
- string url = App.apiUrl + "/sstudy/tsubjectbook/list"; //地址
- Dictionary<string, int> dic = new Dictionary<string, int> { { "teacherid", App.UserInfo.Userid } };
- string body = JsonHelper.ToJson(dic);
- ResultVo<List<ModelTsubjectbookList>> result = ZHttpUtil.PostSignle<ResultVo<List<ModelTsubjectbookList>>>(url, postData: body);
- if (result != null)
- {
- App.ServerMsg = result.msg;
- App.TsubjectbookList = result.obj;
- return result.code;
- }
- else
- {
- App.ServerMsg = "网络异常!";
- return 1;
- }
- }
- catch (Exception ex)
- {
- LogHelper.Logerror.Error("【调用接口(RegisterController)】错误日志:" + ex.Message, ex);
- return 1;
- }
- }
-
- /// <summary>
- /// 章节--列表
- /// </summary>
- /// <returns>
- /// </returns>
- public int DirectorList(string lsbid, int belong, int createid)
- {
- App.DirectorList = new List<ModelDirectorList>();
- try
- {
- string url = App.apiUrl + "/sstudy/director/list"; //地址
- Dictionary<string, string> dic = new Dictionary<string, string> { { "lsbid", lsbid }, { "belong", belong.ToString() }, { "createid", createid.ToString() } };
- string body = JsonHelper.ToJson(dic);
- ResultVo<List<ModelDirectorList>> result = ZHttpUtil.PostSignle<ResultVo<List<ModelDirectorList>>>(url, postData: body);
- if (result != null)
- {
- App.ServerMsg = result.msg;
- App.DirectorList = result.obj;
- return result.code;
- }
- else
- {
- App.ServerMsg = "网络异常!";
- return 1;
- }
- }
- catch (Exception ex)
- {
- LogHelper.Logerror.Error("【调用接口(RegisterController)】错误日志:" + ex.Message, ex);
- return 1;
- }
- }
-
- /// <summary>
- /// 资源--添加
- /// </summary>
- /// <returns>
- /// </returns>
- public int ResourceAdd(ModelResourceAdd model)
- {
- App.DirectorList = new List<ModelDirectorList>();
- try
- {
- string url = App.apiUrl + "/sstudy/resource/add"; //地址
- Dictionary<string, object> dic = new Dictionary<string, object> { { "converted", model.converted }, { "createid", model.createid } };
- if (model.directorid != "999999") //章节上传可以不选
- {
- dic.Add("directorid", model.directorid);
- }
- dic.Add("duration", model.duration);
- dic.Add("subjectid", model.subjectid);
- dic.Add("imgUrl", model.imgUrl);
- dic.Add("level", model.level);
- dic.Add("lsbid", model.lsbid);
- dic.Add("mp4code", model.mp4code);
- dic.Add("resourcebelong", model.resourcebelong);
- dic.Add("resourceclass", model.resourceclass);
- dic.Add("resourcecover", model.resourcecover);
- dic.Add("resourcename", model.resourcename);
- dic.Add("resourcesize", model.resourcesize);
- dic.Add("resourcetype", model.resourcetype);
- dic.Add("resourceurl", model.resourceurl);
- dic.Add("schoolid", model.schoolid);
- dic.Add("suffix", model.suffix);
- //dic.Add("uid", model.uid);
- string body = JsonHelper.ToJson(dic);
- string xmlDoc = ZHttpUtil.PostStr(url, body);
- JObject obj = JObject.Parse(xmlDoc);
- App.ServerMsg = obj["msg"]?.ToString();
- return Convert.ToInt32(obj["code"]?.ToString());
- }
- catch (Exception ex)
- {
- App.ServerMsg = "网络异常!";
- LogHelper.Logerror.Error("【调用接口(RegisterController)】错误日志:" + ex.Message, ex);
- return 1;
- }
- }
-
- /// <summary>
- /// 请求服务地址
- /// </summary>
- /// <param name="schoolcode">
- /// </param>
- /// <param name="message"></param>
- /// <returns>
- /// </returns>
- public bool GetServiceAddress(string schoolcode, out string message)
- {
- string url = App.certapiUrl + "/school/find_code"; //地址
- Dictionary<string, object> dic = new Dictionary<string, object> { { "schoolcode", schoolcode } };
- string body = JsonHelper.ToJson(dic);
- ResultVo<ModelServiceAddress> result = ZHttpUtil.PostSignle<ResultVo<ModelServiceAddress>>(url, body, false);
- if (result != null)
- {
- if (result.code == 0)
- {
- if (result.obj != null)
- {
- message = result.msg;
- App.ServiceAddress = result.obj;
- App.SaveServiceAddressData();
- return true;
- }
- message = "服务地址错误,请输入正确的地址!";
- return false;
- }
- else
- {
- message = result.msg;
- return false;
- }
- }
- else
- {
- message = "无法与服务器建立连接,请检查网络状态。";
- return false;
- }
- }
- }
- }
|