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
{
public class XHApi
{
///
/// 激活信息--添加
///
///
///
public int ActivationAdd(string mac, string device, string projectcode)
{
try
{
string url = APP.certapiUrl + "/activation/add";//地址
Dictionary dic = new Dictionary
{
{ "mac", mac },
{ "device", device },
{ "projectcode", projectcode }
};
string body = JsonHelper.ToJson(dic);
string xmlDoc = HttpHelper.HttpPost(body, url);
if (string.IsNullOrEmpty(xmlDoc))
{
APP.ServerMsg = "网络异常!";
return 1;
}
else
{
JObject obj = JObject.Parse(xmlDoc);
if (obj != 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;
}
else
{
APP.ServerMsg = obj["msg"].ToString();
return Convert.ToInt32(obj["code"].ToString());
}
}
else
{
return 1;
}
}
}
catch (Exception ex)
{
APP.ServerMsg = "网络异常!";
LogHelper.WriteErrLog("【调用接口(RegisterController)】错误日志:" + ex.Message, ex);
return 1;
}
}
///
/// 激活信息--添加激活历史
///
///
///
public int ActivationAddHistory()
{
try
{
string url = APP.certapiUrl + "/activation/add_history";
Dictionary dic = new Dictionary
{
{ "sign", APP.Signature }
};
string body = JsonHelper.ToJson(dic);
string xmlDoc = HttpHelper.HttpPost(body, url);
if (string.IsNullOrEmpty(xmlDoc))
{
return 1;
//returnObj.message = "账号密码不正确";
}
else
{
JObject obj = JObject.Parse(xmlDoc);
if (obj != null)
{
APP.ServerMsg = obj["msg"].ToString();
return Convert.ToInt32(obj["code"].ToString());
}
else
{
return 1;
}
}
}
catch (Exception ex)
{
LogHelper.WriteErrLog("【调用接口(RegisterController)】错误日志:" + ex.Message, ex);
return 1;
}
}
///
/// 登录
///
///
///
public int Login(string loginname, string loginpwd)
{
Console.WriteLine(APP.isDebug);
Console.WriteLine(APP.apiUrl);
Console.WriteLine(FileToolsCommon.GetConfigValue("APIRequestAddress"));
string url = APP.apiUrl + "/user/login";//地址
//1.193.37.200
string Address = "";//河南 郑州
HttpHelper.GetAddressIP(out string AddressIP, out AddressIP);
Dictionary dic = new Dictionary
{
{ "loginname", loginname},
{ "loginpwd", loginpwd},
{"logip", AddressIP},
{"logaddress", Address},
{"ultype", "microlecture_pc_t"},
{"versionnum", FileToolsCommon.GetConfigValue("VersionName")}
};
string body = JsonHelper.ToJson(dic);
ResultVo result = HttpHelper.PostAndRespSignle>(url, postData: body);
if (result != null)
{
APP.UserInfo = new Model_UserInfo();
APP.ServerMsg = result.msg;
if (result.obj != null)
{
APP.UserInfo = result.obj;
}
return result.code;
}
else
{
APP.ServerMsg = "网络异常!";
APP.UserInfo = new Model_UserInfo();
return 1;
}
}
///
/// 下载头像
///
///
///
///
public bool DownloadAvatar(string headPortrait, string SavePath)
{
string url = APP.showImageUrl + headPortrait;
bool result = HttpHelper.GetDataGetHtml(url, SavePath, "");
return result;
}
///
/// 教师教材列表
///
///
///
public int TsubjectbookList()
{
APP.TsubjectbookList = new List();
try
{
string url = APP.apiUrl + "/tsubjectbook/list";//地址
Dictionary dic = new Dictionary
{
{ "teacherid",APP.UserInfo.Userid}
};
string body = JsonHelper.ToJson(dic);
ResultVo> result = HttpHelper.PostAndRespSignle>>(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.WriteErrLog("【调用接口(RegisterController)】错误日志:" + ex.Message, ex);
return 1;
}
}
///
/// 章节--列表
///
///
///
public int DirectorList(string lsbid, int belong, int createid)
{
APP.DirectorList = new List();
try
{
string url = APP.apiUrl + "/director/list";//地址
Dictionary dic = new Dictionary
{
{ "lsbid", lsbid },
{ "belong", belong.ToString() },
{ "createid", createid.ToString() }
};
string body = JsonHelper.ToJson(dic);
ResultVo> result = HttpHelper.PostAndRespSignle>>(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.WriteErrLog("【调用接口(RegisterController)】错误日志:" + ex.Message, ex);
return 1;
}
}
///
/// 资源--添加
///
///
///
public int ResourceAdd(Model_ResourceAdd model)
{
APP.DirectorList = new List();
try
{
string url = APP.apiUrl + "/resource/add";//地址
Dictionary dic = new Dictionary
{
// converted: 0
//createid: 80
//directorid: 1009
//duration: 39
//imgUrl: ""
//level: 2
//lsbid: 40
//mp4code: "h264"
//resourcebelong: 3
//resourceclass: 2
//resourcecover: "12/resource/20200917/4f297df0-f8c0-11ea-adf5-81f24b97d4ff/weather_pic.jpg"
//resourcename: "weather_pic"
//resourcesize: 6105268
//resourcetype: 0
//resourceurl: "12/resource/20200917/4f297df0-f8c0-11ea-adf5-81f24b97d4ff/weather_pic.mp4"
//schoolid: 12
//suffix: "mp4"
//uid: 80
{ "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 = HttpHelper.HttpPost(body, url);
JObject obj = JObject.Parse(xmlDoc);
if (obj != null)
{
APP.ServerMsg = obj["msg"].ToString();
return Convert.ToInt32(obj["code"].ToString());
}
else
{
APP.ServerMsg = "网络异常!";
return 1;
}
}
catch (Exception ex)
{
APP.ServerMsg = "网络异常!";
LogHelper.WriteErrLog("【调用接口(RegisterController)】错误日志:" + ex.Message, ex);
return 1;
}
}
///
/// 请求服务地址
///
///
///
public bool GetServiceAddress(string Schoolcode, out string Message)
{
string url = APP.certapiUrl + "/school/find_code";//地址
Dictionary dic = new Dictionary
{
{ "schoolcode", Schoolcode}
};
string body = JsonHelper.ToJson(dic);
ResultVo result = HttpHelper.PostAndRespSignle>(url, postData: body);
if (result != null)
{
if (result.code == 0)
{
if (result.obj != null)
{
Message = result.msg;
APP.ServiceAddress = result.obj;
APP.SaveServiceAddressData();
return true;
}
else
{
Message = "服务地址错误,请输入正确的地址!";
return false;
}
}
else
{
Message = result.msg;
return false;
}
}
else
{
Message = "无法与服务器建立连接,请检查网络状态。";
return false;
}
}
}
}