1663 lines
63 KiB
C#
1663 lines
63 KiB
C#
using Models;
|
||
using Models.ModelItems;
|
||
using Models.View;
|
||
using Newtonsoft.Json;
|
||
using Org.BouncyCastle.Utilities.Encoders;
|
||
using Services.Api;
|
||
using Services.Cache;
|
||
using Services.Extensions;
|
||
using Services.Manager;
|
||
using Services.Tool;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Collections.Specialized;
|
||
using System.Data.SqlClient;
|
||
using System.Drawing;
|
||
using System.Drawing.Imaging;
|
||
using System.IO;
|
||
using System.Linq;
|
||
using System.Net;
|
||
using System.Net.Http;
|
||
using System.Net.Security;
|
||
using System.Security.Cryptography.X509Certificates;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
using System.Web;
|
||
using System.Web.Caching;
|
||
using System.Web.Hosting;
|
||
using System.Web.Mvc;
|
||
using System.Xml.Linq;
|
||
using static Services.Tool.HttpRequestHelp;
|
||
|
||
namespace UI.Controllers
|
||
{
|
||
/// <summary>
|
||
/// 微信小程序专用api
|
||
/// 创建时间:2021年11月25日14:26:22
|
||
/// 更新记录
|
||
/// 更新时间:2021年11月30日15:31:28
|
||
/// 更新内容:获取指定酒店房间信息
|
||
/// 涉及函数:HostsInfo HostsServer.GetHostsInfo
|
||
/// </summary>
|
||
public class WxController : Controller
|
||
{
|
||
// GET
|
||
public JsonResult Update()
|
||
{
|
||
try
|
||
{
|
||
string TimePath = HostingEnvironment.MapPath("~/Upload/Image/");//保存路径
|
||
TimePath += DateTime.Now.ToString("yyyy-MM-dd");
|
||
TimePath += "\\";
|
||
var oFile = Request.Files[0];//获得上传的文件
|
||
//获取后缀名
|
||
string ext = Path.GetExtension(Request.Files[0].FileName);
|
||
//string fullPath = Guid.NewGuid().ToString() + ext;
|
||
string fullPath = DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss fff") + ext;
|
||
if (!Directory.Exists(TimePath))//判断文件夹是否存在
|
||
{
|
||
Directory.CreateDirectory(TimePath);//不存在则创建文件夹
|
||
}
|
||
oFile.SaveAs(TimePath + fullPath);
|
||
//int c = oFile.ContentLength;//字节长度
|
||
FileInfo file = new FileInfo(TimePath + fullPath);
|
||
string imgUrl = TimePath + fullPath;
|
||
string UPUrl = HostingEnvironment.MapPath("~/Upload/Imgs/");//压缩后保存路径
|
||
string littleUrl = HostingEnvironment.MapPath("~/Upload/Img/");//压缩后保存路径
|
||
if (!Directory.Exists(UPUrl))//判断文件夹是否存在
|
||
{
|
||
Directory.CreateDirectory(UPUrl);//不存在则创建文件夹
|
||
}
|
||
string ur;//传递URL给前端
|
||
//long size;
|
||
//缩略图
|
||
Task<string> taskOne = MakeThumbnail(imgUrl, littleUrl, 85, 85, "Cut");
|
||
|
||
//using (FileStream fs = new FileStream(file.ToString(), FileMode.OpenOrCreate, FileAccess.Read))
|
||
//{
|
||
|
||
// Image objImage = Image.FromStream(fs);
|
||
// ImageFormat imFormat = objImage.RawFormat;
|
||
// MemoryStream memoryStream = Zip(objImage, imFormat, 250, fs.Length);
|
||
// Image img = Image.FromStream(memoryStream);
|
||
// img.Save(UPUrl + file.Name);
|
||
// size = memoryStream.Length;
|
||
// //异步压缩图
|
||
// string ftpURL = "auth.blv-oa.com:50/uts_Manager/oyl_FTP/Image";
|
||
// Task<string> task = FtpUpload(UPUrl + fullPath, ftpURL);
|
||
// task.Start();
|
||
// ur = task.Result;
|
||
//}
|
||
Task<string> tasktwo = MakeThumbnail(imgUrl, UPUrl, 500, 500, "");
|
||
tasktwo.Start();
|
||
// //异步压缩图
|
||
string ftpURL = "auth.blv-oa.com:50/uts_Manager/oyl_FTP/Image";
|
||
Task<string> task = FtpUpload(tasktwo.Result, ftpURL);
|
||
task.Start();
|
||
ur = task.Result;
|
||
taskOne.Start();
|
||
string urltwo = taskOne.Result;
|
||
string ftpURLTwo = "auth.blv-oa.com:50/uts_Manager/oyl_FTP/Img";
|
||
Task<string> taskTwo = FtpUpload(urltwo, ftpURLTwo);
|
||
taskTwo.Start();
|
||
ur = taskTwo.Result;
|
||
var data1 = new
|
||
{
|
||
src = ur
|
||
//,sizes = size
|
||
|
||
};
|
||
var Person = new
|
||
{
|
||
code = 0,//0表示成功
|
||
msg = "",//
|
||
data = data1
|
||
};
|
||
return Json(Person);//
|
||
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
LogHelp.WriteExceptionLog(e, this.GetType().Name);
|
||
return null;
|
||
}
|
||
|
||
}
|
||
[HttpPost]
|
||
[Route("ApiWx/Login")]
|
||
//Wx账号密码登录的接口
|
||
public ActionResult Wxlog(string Uid = "", int appid = 0, string Pwd = "", bool islong = false)
|
||
{
|
||
Logs.WriteTimingPlanLog("用户名:" + Uid + "密码:" + Pwd);
|
||
var result = new ReturnResult<dynamic>();
|
||
try
|
||
{
|
||
result = OTApi.Wxlog(Uid, Pwd, appid, null, islong);
|
||
var Ip = IPHelper.GetIP();
|
||
DbLog log = new DbLog() { Uid = Uid, Ip = Ip, Client = HttpContext.Request.UserAgent };
|
||
var Message = result.Message;
|
||
Task.Run(() =>
|
||
{
|
||
Data loc = HttpRequestHelp.GetIp($@"https://sp0.baidu.com/8aQDcjqpAAV3otqbppnN2DJv/api.php?query={log.Ip}&co=&resource_id=6006&oe=utf8");
|
||
if (loc != null && loc.status == 0)
|
||
{
|
||
if (loc.data.Count > 0)
|
||
{
|
||
log.location = loc.data[0].location;
|
||
}
|
||
}
|
||
DbLogServer.WriteDbLog($"{Uid}请求应用 {Message[3]}({appid}) 授权" + (result.Status == 200 ? "请求成功~" : "请求失败~"), 0, log);
|
||
if (result.Status == 200)
|
||
DBlog.WirtDB(Message[2], Message[0], appid);
|
||
});
|
||
if (result.Status == 200)
|
||
{
|
||
result.Message = "请求成功~";
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelp.WriteExceptionLog(ex);
|
||
result.Status = 500;
|
||
result.Message = "服务器错误";
|
||
result.Data = null;
|
||
}
|
||
return Json(result);
|
||
}
|
||
[HttpPost]
|
||
//token登录的接口
|
||
[Route("ApiWx/LoginToken")]
|
||
public ActionResult Wxlog(string token, int appid = 5)
|
||
{
|
||
var info = new ReturnResult<dynamic>();
|
||
try
|
||
{
|
||
info = OTApi.WxlogToken(token, appid, HttpContext.Request.UserAgent);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelp.WriteExceptionLog(ex);
|
||
info.Status = 500;
|
||
info.Message = "服务器错误";
|
||
info.Data = null;
|
||
}
|
||
return Json(info);
|
||
|
||
}
|
||
/// <summary>
|
||
/// 获取指定酒店房间信息
|
||
/// </summary>
|
||
/// <param name="HotelID">酒店id</param>
|
||
/// <returns></returns>
|
||
[HttpPost]
|
||
[Route("ApiWx/HostsInfo")]
|
||
public ActionResult HostsInfo(int HotelID = 0, string token = "")
|
||
{
|
||
var res = new ReturnResult<List<HostsAdd>>();
|
||
try
|
||
{
|
||
if (false)//TokenHelper.CheckToken(token) == null)
|
||
{
|
||
res.Status = 1024;
|
||
res.Message = "token过期~";
|
||
}
|
||
else
|
||
{
|
||
res.Data = HostsServer.GetHostsInfo(HotelID);
|
||
var rstime = "";
|
||
using (var client = new HttpClient())
|
||
{
|
||
FormDataValue bb = new FormDataValue() { key = "blw_ws@2015", id = HotelID.ToString() };
|
||
// 创建参数字典
|
||
var parameters = new FormUrlEncodedContent(new[]
|
||
{
|
||
new KeyValuePair<string, string>("jsonData", JsonConvert.SerializeObject(bb))
|
||
});
|
||
var response = client.PostAsync("https://www.boonlive-rcu.com/api/GetHotelListByCode?jsonData=" , parameters).Result;
|
||
var aa = response.Content.ReadAsStringAsync().Result;
|
||
rstime = JsonConvert.DeserializeObject<Rsit>(aa).Result;
|
||
|
||
}
|
||
res.Data[0].CreateTime = DateTime.Parse(rstime);
|
||
res.Status = 200;
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelp.WriteExceptionLog(ex);
|
||
res.Status = 500;
|
||
res.Message = "服务器错误";
|
||
res.Data = null;
|
||
}
|
||
return Json(res);
|
||
|
||
}
|
||
|
||
public class Rsit
|
||
{
|
||
public bool IsSuccess { get; set; }
|
||
public string Result { get; set; }
|
||
}
|
||
public class FormDataValue
|
||
{
|
||
public string key { get; set; }
|
||
public string id { get; set; }
|
||
}
|
||
|
||
/// <summary>
|
||
/// 绑定MAC地址 解绑传入 NoCheck false
|
||
/// </summary>
|
||
/// <param name="MAC">MAC地址</param>
|
||
/// <param name="token">token</param>
|
||
///已经绑定 100 异常 500 成功 200
|
||
/// <returns></returns>
|
||
[HttpPost]
|
||
[Route("ApiWx/GetMAC")]
|
||
public ActionResult GetMAC(string MAC = "", string token = "", string roomID = "", string roomNumber = "", int HotelID = 0, bool NoCheck = true, string loc = null)
|
||
{
|
||
var res = new ReturnResult<dynamic>();
|
||
try
|
||
{
|
||
string isok = TokenHelper.CheckToken(token);
|
||
if (isok == null)
|
||
{
|
||
res.Status = 1024;
|
||
res.Message = "token过期~";
|
||
}
|
||
else
|
||
{
|
||
var userinfo = JsonConvert.DeserializeObject<UserInfo>(isok);
|
||
//实际环境 16 测试环境 15
|
||
if (CacheHelp.cacheSysUserAutho.First(x => x.UserId == userinfo.Id && x.AuthorityId == 16 && x.AuthotypeId == 3 && x.HotelId == HotelID) == null)
|
||
{
|
||
res.Status = 1000;
|
||
res.Message = "无权限~";
|
||
}
|
||
else
|
||
{
|
||
if (NoCheck)
|
||
{
|
||
var isMAC = HostsServer.CheckMAC(MAC);
|
||
if (isMAC != null)
|
||
{
|
||
//已经绑定 100
|
||
res.Status = 100;
|
||
res.Data = new
|
||
{
|
||
Hosts = isMAC,
|
||
};
|
||
return Json(res);
|
||
}
|
||
}
|
||
var MACOK = HostsServer.GetMAC(MAC, HotelID, roomID, roomNumber, userinfo, loc);
|
||
if (MACOK)
|
||
res.Status = 200;//绑定成功
|
||
else
|
||
res.Status = 150;//绑定失败
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelp.WriteExceptionLog(ex);
|
||
res.Status = 500;
|
||
res.Data = null;
|
||
res.Message = "服务器错误";
|
||
}
|
||
finally
|
||
{
|
||
if (res.Status == 200)
|
||
{
|
||
CacheHelp.Removesys(CacheHelp.syskey.sysMACLogs);
|
||
}
|
||
}
|
||
return Json(res);
|
||
}
|
||
[HttpPost]
|
||
[Route("ApiWx/Logsinfo")]
|
||
//Wx 日志
|
||
public ActionResult GetLogs(string token, int page = 1, int length = 10, int AppType = -1, Dictionary<string, string> search = null)
|
||
{
|
||
var res = new ReturnResult<dynamic>();
|
||
try
|
||
{
|
||
//2021注定又是充满期望和挑战的一年,有什么理由不尽情try一下呢,纵使遭遇异常,catch住,调整参数再次retry,finally还是要抵达远方。
|
||
string isok = TokenHelper.CheckToken(token);
|
||
if (isok == null)
|
||
{
|
||
res.Status = 1024;
|
||
res.Message = "token过期~";
|
||
}
|
||
else
|
||
{
|
||
var userinfo = JsonConvert.DeserializeObject<UserInfo>(isok);
|
||
|
||
|
||
//有权限的酒店
|
||
var hotels = CacheHelp.cacheSysUserAutho.Where(x => x.UserId == userinfo.Id && x.AuthotypeId != 1).Select(x => x.HotelId).Distinct().ToList();
|
||
|
||
int begin = (page - 1) * length;
|
||
var resdata = SqlSugarBase.Db.Queryable<View_MAClog>().Where(x => hotels.Contains(x.Hotelsid)).Count();
|
||
//.AddDays(1) 添加一天是因为 传入的 参数为 20012-10-1 转型后为 2012-10-1 00:00:00 对 2012-10-1 1:00:00的数据不能赛选
|
||
string sql = $@" where ( '{AppType}' = '-1' or AppType = '{AppType}' )";
|
||
if (hotels.Count != 0)
|
||
{
|
||
sql += "and ( ";
|
||
for (int i = 0; i < hotels.Count; i++)
|
||
{
|
||
sql += " HotelID=" + hotels[i] + " or";
|
||
}
|
||
sql = sql.Substring(0, sql.Length - 2);
|
||
sql += ")";
|
||
}
|
||
if (search != null)
|
||
{
|
||
string createtime = string.Empty;
|
||
string endtime = string.Empty;
|
||
string name = string.Empty;
|
||
string hotelsid = string.Empty;
|
||
if (!string.IsNullOrEmpty(search["starttime"]))
|
||
{
|
||
sql += "and ( '@createtime' = '' or createtime > '@createtime' )";
|
||
createtime = DateTime.Parse(search["starttime"]).ToString("yyyy-MM-dd HH:mm:ss");
|
||
}
|
||
if (!string.IsNullOrEmpty(search["endtime"]))
|
||
{
|
||
sql += " AND ( '@endtime' = '' or createtime < '@endtime')";
|
||
endtime = DateTime.Parse(search["endtime"]).AddDays(1).ToString("yyyy-MM-dd HH:mm:ss");
|
||
}
|
||
if (!string.IsNullOrEmpty(search["name"]))
|
||
{
|
||
sql += " and uid like '@name' ";
|
||
name = search["name"];
|
||
}
|
||
if (!string.IsNullOrEmpty(search["hotelsid"]))
|
||
{
|
||
sql += "and ('@hotelsid'='' or Hotelsid = '@hotelsid')";
|
||
hotelsid = search["hotelsid"];
|
||
}
|
||
sql = sql.Replace("@name", "%" + (string.IsNullOrEmpty(name) ? "" : name) + "%").Replace("@endtime", string.IsNullOrEmpty(endtime) ? "" : endtime).Replace("@createtime", createtime).Replace("@hotelsid", (string.IsNullOrEmpty(hotelsid) ? "" : hotelsid));
|
||
}
|
||
else
|
||
sql = string.Empty;
|
||
sql += $" order by CreateTime desc LIMIT 1,{length}";
|
||
//var data = SqlSugarBase.Db.a.View_MAClogs.SqlQuery($"select TOP {length} * from View_MAClog " + sql).ToList();
|
||
var data = SqlSugarBase.Db.Ado.SqlQuery<View_MAClog>($"select * from View_MAClog " + sql).ToList();
|
||
Logs.WriteLog("sql" + sql);
|
||
|
||
//var filtcount = db.View_MAClogs.SqlQuery("select * from View_MAClog " + sql).Count();
|
||
var filtcount = SqlSugarBase.Db.Ado.SqlQuery<View_MAClog>("select * from View_MAClog " + sql).Count();
|
||
|
||
res.Data = new
|
||
{
|
||
filtcount = filtcount,
|
||
sum = resdata,
|
||
data = data
|
||
};
|
||
res.Status = 200;
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelp.WriteExceptionLog(ex);
|
||
res.Status = 500;
|
||
res.Data = null;
|
||
res.Message = "服务器错误";
|
||
}
|
||
return Json(res);
|
||
}
|
||
[HttpPost]
|
||
[Route("ApiWx/ErrorInfo")]
|
||
//Wx rcu 反馈错误
|
||
public ActionResult ErrorInfo(string token, string MAC, int HotelID, int type, string roomNumber)
|
||
{
|
||
var res = new ReturnResult<dynamic>();
|
||
try
|
||
{
|
||
//2021注定又是充满期望和挑战的一年,有什么理由不尽情try一下呢,纵使遭遇异常,catch住,调整参数再次retry,finally还是要抵达远方。
|
||
string isok = TokenHelper.CheckToken(token);
|
||
if (isok == null)
|
||
{
|
||
res.Status = 1024;
|
||
res.Message = "token过期~";
|
||
}
|
||
else
|
||
{
|
||
var userinfo = JsonConvert.DeserializeObject<UserInfo>(isok);
|
||
if (HostsServer.AddErrorInfo(userinfo.Id, MAC, HotelID, type, roomNumber))
|
||
{
|
||
res.Status = 200;
|
||
}
|
||
else
|
||
{
|
||
res.Status = 100;
|
||
}
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelp.WriteExceptionLog(ex);
|
||
res.Status = 500;
|
||
res.Data = null;
|
||
res.Message = "服务器错误";
|
||
}
|
||
finally
|
||
{
|
||
CacheHelp.Removesys(CacheHelp.syskey.sysErrorInfoListKey);
|
||
}
|
||
return Json(res);
|
||
}
|
||
/// <summary>
|
||
/// 获取酒店房间类型
|
||
/// </summary>
|
||
/// <param name="token"></param>
|
||
/// <param name="HotelID">酒店编号</param>
|
||
/// <returns></returns>
|
||
[HttpPost]
|
||
[Route("ApiWx/GetRoomTypeAndModalsList")]
|
||
public ActionResult GetRoomTypeAndModalsList(string token, int HotelID)
|
||
{
|
||
var res = new ReturnResult<dynamic>();
|
||
try
|
||
{
|
||
string isok = TokenHelper.CheckToken(token);
|
||
if (isok == null)
|
||
{
|
||
res.Status = 1024;
|
||
res.Message = "token过期~";
|
||
}
|
||
else
|
||
{
|
||
List<TBL_ROOM_TYPE_LIST> roomList = SqlSugarBase.RcuDb.Queryable<TBL_ROOM_TYPE_LIST>().Where(it => it.HOTEL_OLD_ID == HotelID && it.IsDel != 1).ToList();
|
||
res.Status = 200;
|
||
res.Data = roomList;
|
||
res.Message = "查询成功";
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelp.WriteExceptionLog(ex);
|
||
res.Status = 500;
|
||
res.Data = null;
|
||
res.Message = "服务器错误";
|
||
}
|
||
|
||
return Json(res);
|
||
}
|
||
|
||
[HttpPost]
|
||
[Route("ApiWx/CheckFaceSN")]
|
||
// 人脸机 检查是否绑定
|
||
public ActionResult CheckFaceSN(string token, string faceSN)
|
||
{
|
||
var res = new ReturnResult<List<Hosts>>();
|
||
try
|
||
{
|
||
string isok = TokenHelper.CheckToken(token);
|
||
if (isok == null)
|
||
{
|
||
res.Status = 1024;
|
||
res.Message = "token过期~";
|
||
}
|
||
else
|
||
{
|
||
res.Data = FaceServer.CheckfaceSNHosts(faceSN);
|
||
res.Status = 200;
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelp.WriteExceptionLog(ex);
|
||
res.Status = 500;
|
||
res.Data = null;
|
||
res.Message = "服务器错误";
|
||
}
|
||
return Json(res);
|
||
}
|
||
[HttpPost]
|
||
[Route("ApiWx/GetFaceSN")]
|
||
public ActionResult GetFaceSN(string faceSN = "", string token = "", string roomNumber = "", int HotelID = 0, string faceAddress = "", string roomID = "", bool isjb = false)
|
||
{
|
||
var res = new ReturnResult<int>();
|
||
try
|
||
{
|
||
string isok = TokenHelper.CheckToken(token);
|
||
var userinfo = JsonConvert.DeserializeObject<UserInfo>(isok);
|
||
if (isok == null)
|
||
{
|
||
res.Status = 1024;
|
||
res.Message = "token过期~";
|
||
}
|
||
else
|
||
{
|
||
if (HotelID != 0 && CacheHelp.cacheSysUserAutho.First(x => x.HotelId == HotelID && x.AuthorityId == 21 && x.AuthotypeId == 3) == null)
|
||
{
|
||
res.Data = -1;
|
||
res.Message = "权限不足~";
|
||
res.Status = 1000;
|
||
|
||
}
|
||
else
|
||
{
|
||
res.Data = FaceServer.GetfaceSN(userinfo, faceSN, roomNumber, HotelID, faceAddress, roomID, isjb);
|
||
res.Status = 200;
|
||
}
|
||
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelp.WriteExceptionLog(ex);
|
||
res.Status = 500;
|
||
res.Data = -1;
|
||
res.Message = "服务器错误";
|
||
}
|
||
finally
|
||
{
|
||
if (res.Status == 200 && res.Data == 0)
|
||
{
|
||
CacheHelp.Removesys(CacheHelp.syskey.sysMACLogs);
|
||
}
|
||
}
|
||
return Json(res);
|
||
}
|
||
[HttpPost]
|
||
[Route("ApiWx/OpenDoorTest")]
|
||
public ActionResult OpenDoorTest(string faceSN = "", string token = "")
|
||
{
|
||
var res = new ReturnResult<int>();
|
||
try
|
||
{
|
||
string isok = TokenHelper.CheckToken(token);
|
||
if (isok == null)
|
||
{
|
||
res.Status = 1024;
|
||
res.Message = "token过期~";
|
||
}
|
||
else
|
||
{
|
||
//访问人脸机管理后台方法本地路径http://localhost:55151/App/WxTest/ActionOpenDoorToDevice
|
||
if (string.IsNullOrEmpty(faceSN))
|
||
{
|
||
res.Status = 500;
|
||
|
||
res.Message = "人脸编号不能为空";
|
||
}
|
||
else
|
||
{
|
||
returnInfo info = FacemachineTest.opendoor(faceSN);
|
||
if (info.Status == 200)
|
||
{
|
||
res.Status = 200;
|
||
res.Message = "开门信息下发成功";
|
||
}
|
||
else
|
||
{
|
||
res.Status = 500;
|
||
res.Message = "开门信息下发失败";
|
||
}
|
||
}
|
||
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
|
||
LogHelp.WriteExceptionLog(ex);
|
||
res.Status = 500;
|
||
res.Data = -1;
|
||
res.Message = "服务器错误";
|
||
}
|
||
return Json(res);
|
||
}
|
||
[HttpPost]
|
||
[Route("ApiWx/RestartTheDevice")]
|
||
public ActionResult RestartTheDevice(string faceSN = "", string token = "")
|
||
{
|
||
var res = new ReturnResult<int>();
|
||
try
|
||
{
|
||
string isok = TokenHelper.CheckToken(token);
|
||
if (isok == null)
|
||
{
|
||
res.Status = 1024;
|
||
res.Message = "token过期~";
|
||
}
|
||
else
|
||
{
|
||
//访问人脸机管理后台方法本地路径http://localhost:55151/App/WxTest/ActionOpenDoorToDevice
|
||
if (string.IsNullOrEmpty(faceSN))
|
||
{
|
||
res.Status = 500;
|
||
|
||
res.Message = "人脸编号不能为空";
|
||
}
|
||
else
|
||
{
|
||
returnInfo info = FacemachineTest.RestartDevice(faceSN);
|
||
if (info.Status == 200)
|
||
{
|
||
res.Status = 200;
|
||
res.Message = "重启信息下发成功";
|
||
}
|
||
else
|
||
{
|
||
res.Status = 500;
|
||
res.Message = "重启信息下发失败";
|
||
}
|
||
}
|
||
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
|
||
LogHelp.WriteExceptionLog(ex);
|
||
res.Status = 500;
|
||
res.Data = -1;
|
||
res.Message = "服务器错误";
|
||
}
|
||
return Json(res);
|
||
}
|
||
[HttpPost]
|
||
[Route("ApiWx/GeteDeviceInfomation")]
|
||
public ActionResult GeteDeviceInfomation(string faceSN = "", string hotelCode = "", string token = "")
|
||
{
|
||
var res = new ReturnResult<int>();
|
||
try
|
||
{
|
||
string isok = TokenHelper.CheckToken(token);
|
||
if (isok == null)
|
||
{
|
||
res.Status = 1024;
|
||
res.Message = "token过期~";
|
||
}
|
||
else
|
||
{
|
||
//访问人脸机管理后台方法本地路径http://localhost:55151/App/WxTest/ActionOpenDoorToDevice
|
||
if (string.IsNullOrEmpty(faceSN))
|
||
{
|
||
res.Status = 500;
|
||
|
||
res.Message = "人脸编号不能为空";
|
||
}
|
||
else
|
||
{
|
||
returnInfo info = FacemachineTest.GeteDeviceInfo(faceSN, hotelCode);
|
||
if (info.Status == 200)
|
||
{
|
||
res.Status = 200;
|
||
|
||
res.Message = "获取设备信息下发成功,版本号码是:" + info.APKVersion;
|
||
}
|
||
else
|
||
{
|
||
res.Status = 500;
|
||
res.Message = "获取设备信息下发失败";
|
||
}
|
||
}
|
||
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
|
||
LogHelp.WriteExceptionLog(ex);
|
||
res.Status = 500;
|
||
res.Data = -1;
|
||
res.Message = "服务器错误";
|
||
}
|
||
return Json(res);
|
||
}
|
||
[HttpPost]
|
||
[Route("ApiWx/DeletePeopleFromDeviceByGroup")]
|
||
public ActionResult DeletePeopleFromDeviceByGroup(string faceSN = "", string hotelCode = "", string token = "")
|
||
{
|
||
var res = new ReturnResult<int>();
|
||
try
|
||
{
|
||
string isok = TokenHelper.CheckToken(token);
|
||
if (isok == null)
|
||
{
|
||
res.Status = 1024;
|
||
res.Message = "token过期~";
|
||
}
|
||
else
|
||
{
|
||
//访问人脸机管理后台方法本地路径http://localhost:55151/App/WxTest/ActionOpenDoorToDevice
|
||
if (string.IsNullOrEmpty(faceSN))
|
||
{
|
||
res.Status = 500;
|
||
|
||
res.Message = "人脸编号不能为空";
|
||
}
|
||
else
|
||
{
|
||
returnInfo info = FacemachineTest.delPeopleFromDeviceByGroup(faceSN, hotelCode);
|
||
if (info.Status == 200)
|
||
{
|
||
res.Status = 200;
|
||
res.Message = "删除所有住户人员下发成功";
|
||
}
|
||
else
|
||
{
|
||
res.Status = 500;
|
||
res.Message = "删除所有住户人员下发失败";
|
||
}
|
||
}
|
||
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
|
||
LogHelp.WriteExceptionLog(ex);
|
||
res.Status = 500;
|
||
res.Data = -1;
|
||
res.Message = "服务器错误";
|
||
}
|
||
return Json(res);
|
||
}
|
||
[HttpPost]
|
||
[Route("ApiWx/GetThePeopleListOfDevice")]
|
||
public ActionResult GetThePeopleListOfDevice(string faceSN = "", string hotelCode = "", string token = "")
|
||
{
|
||
var res = new ReturnResult<int>();
|
||
try
|
||
{
|
||
string isok = TokenHelper.CheckToken(token);
|
||
if (isok == null)
|
||
{
|
||
res.Status = 1024;
|
||
res.Message = "token过期~";
|
||
}
|
||
else
|
||
{
|
||
//访问人脸机管理后台方法本地路径http://localhost:55151/App/WxTest/ActionOpenDoorToDevice
|
||
if (string.IsNullOrEmpty(faceSN))
|
||
{
|
||
res.Status = 500;
|
||
|
||
res.Message = "人脸编号不能为空";
|
||
}
|
||
else
|
||
{
|
||
returnInfo info = FacemachineTest.GetsThePeopleListOfDevice(faceSN, hotelCode);
|
||
if (info.Status == 200)
|
||
{
|
||
res.Status = 200;
|
||
res.Message = "获取入住人员数量下发成功,人数是:" + info.puinfo;
|
||
}
|
||
else
|
||
{
|
||
res.Status = 500;
|
||
res.Message = "获取入住人员数量下发失败";
|
||
}
|
||
}
|
||
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
|
||
LogHelp.WriteExceptionLog(ex);
|
||
res.Status = 500;
|
||
res.Data = -1;
|
||
res.Message = "服务器错误";
|
||
}
|
||
return Json(res);
|
||
}
|
||
/// <summary>
|
||
/// pms开房测试
|
||
/// </summary>
|
||
/// <param name="idNumber">证件号码</param>
|
||
/// <param name="name">入住人员姓名</param>
|
||
/// <param name="sex">入住人员姓别</param>
|
||
/// <param name="picture">入住人员照片路径</param>
|
||
/// <param name="phone">入住人员电话号码</param>
|
||
/// <param name="faceSN"></param>
|
||
/// <param name="hotelCode">酒店编号</param>
|
||
/// <param name="token"></param>
|
||
/// <returns></returns>
|
||
[HttpPost]
|
||
[Route("ApiWx/openRommCheckin")]
|
||
public ActionResult openRommCheckin(string idNumber, string name, int sex, string picture, string phone, string faceSN = "", string hotelCode = "", string room = "", string token = "")
|
||
{
|
||
var res = new ReturnResult<int>();
|
||
try
|
||
{
|
||
string isok = TokenHelper.CheckToken(token);
|
||
if (isok == null)
|
||
{
|
||
res.Status = 1024;
|
||
res.Message = "token过期~";
|
||
}
|
||
else
|
||
{
|
||
//访问人脸机管理后台方法本地路径http://localhost:55151/App/WxTest/ActionOpenDoorToDevice
|
||
if (string.IsNullOrEmpty(faceSN))
|
||
{
|
||
res.Status = 500;
|
||
|
||
res.Message = "人脸编号不能为空";
|
||
}
|
||
else
|
||
{
|
||
returnInfo info = FacemachineTest.openRoomCheckin(idNumber, name, sex, picture, phone, faceSN, hotelCode, room);
|
||
if (info.Status == 200)
|
||
{
|
||
res.Status = 200;
|
||
res.Message = "下发人脸成功";
|
||
}
|
||
else
|
||
{
|
||
res.Status = 500;
|
||
res.Message = "下发人脸失败";
|
||
}
|
||
}
|
||
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
|
||
LogHelp.WriteExceptionLog(ex);
|
||
res.Status = 500;
|
||
res.Data = -1;
|
||
res.Message = "服务器错误";
|
||
}
|
||
return Json(res);
|
||
}
|
||
[HttpPost]
|
||
[Route("ApiWx/roomCheckOut")]
|
||
public ActionResult roomCheckOut(string faceSN = "", string hotelCode = "", string room = "", string token = "")
|
||
{
|
||
var res = new ReturnResult<int>();
|
||
try
|
||
{
|
||
string isok = TokenHelper.CheckToken(token);
|
||
if (isok == null)
|
||
{
|
||
res.Status = 1024;
|
||
res.Message = "token过期~";
|
||
}
|
||
else
|
||
{
|
||
//访问人脸机管理后台方法本地路径http://localhost:55151/App/WxTest/ActionOpenDoorToDevice
|
||
if (string.IsNullOrEmpty(faceSN))
|
||
{
|
||
res.Status = 500;
|
||
|
||
res.Message = "人脸编号不能为空";
|
||
}
|
||
else
|
||
{
|
||
returnInfo info = FacemachineTest.roomtoCheckOut(faceSN, hotelCode, room);
|
||
if (info.Status == 200)
|
||
{
|
||
res.Status = 200;
|
||
res.Message = "退房成功";
|
||
}
|
||
else
|
||
{
|
||
res.Status = 500;
|
||
res.Message = "退房失败";
|
||
}
|
||
}
|
||
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
|
||
LogHelp.WriteExceptionLog(ex);
|
||
res.Status = 500;
|
||
res.Data = -1;
|
||
res.Message = "服务器错误";
|
||
}
|
||
return Json(res);
|
||
}
|
||
|
||
|
||
|
||
#region 缩略图
|
||
/// <summary>
|
||
/// 生成缩略图
|
||
/// </summary>
|
||
/// <param name="originalImagePath">源图路径(物理路径)</param>
|
||
/// <param name="thumbnailPath">缩略图路径(物理路径)</param>
|
||
/// <param name="width">缩略图宽度</param>
|
||
/// <param name="height">缩略图高度</param>
|
||
/// <param name="mode">生成缩略图的方式</param>
|
||
public Task<string> MakeThumbnail(string originalImagePath, string thumbnailPath, int width, int height, string mode)
|
||
{
|
||
ReturnResult result = new ReturnResult();
|
||
FileInfo info = new FileInfo(originalImagePath);
|
||
Image originalImage = Image.FromFile(originalImagePath);
|
||
int towidth = width;
|
||
int toheight = height;
|
||
int x = 0;
|
||
int y = 0;
|
||
int ow = originalImage.Width;
|
||
int oh = originalImage.Height;
|
||
if (mode == "")
|
||
{
|
||
if (ow > oh)
|
||
{
|
||
mode = "W";
|
||
}
|
||
else
|
||
{
|
||
mode = "H";
|
||
}
|
||
}
|
||
switch (mode)
|
||
{
|
||
case "HW"://指定高宽缩放(可能变形)
|
||
break;
|
||
case "W"://指定宽,高按比例
|
||
toheight = originalImage.Height * width / originalImage.Width;
|
||
break;
|
||
case "H"://指定高,宽按比例
|
||
towidth = originalImage.Width * height / originalImage.Height;
|
||
break;
|
||
case "Cut"://指定高宽裁减(不变形)
|
||
if ((double)originalImage.Width / (double)originalImage.Height > (double)towidth / (double)toheight)
|
||
{
|
||
oh = originalImage.Height;
|
||
ow = originalImage.Height * towidth / toheight;
|
||
y = 0;
|
||
x = (originalImage.Width - ow) / 2;
|
||
}
|
||
else
|
||
{
|
||
ow = originalImage.Width;
|
||
oh = originalImage.Width * height / towidth;
|
||
x = 0;
|
||
y = (originalImage.Height - oh) / 2;
|
||
}
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
//新建一个bmp图片
|
||
Image bitmap = new System.Drawing.Bitmap(towidth, toheight);
|
||
//新建一个画板
|
||
Graphics g = System.Drawing.Graphics.FromImage(bitmap);
|
||
//设置高质量插值法
|
||
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
|
||
//设置高质量,低速度呈现平滑程度
|
||
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
|
||
//清空画布并以透明背景色填充
|
||
g.Clear(Color.Transparent);
|
||
//在指定位置并且按指定大小绘制原图片的指定部分
|
||
g.DrawImage(originalImage, new Rectangle(0, 0, towidth, toheight),
|
||
new Rectangle(x, y, ow, oh),
|
||
GraphicsUnit.Pixel);
|
||
try
|
||
{
|
||
|
||
if (!Directory.Exists(thumbnailPath))
|
||
{
|
||
Directory.CreateDirectory(thumbnailPath);
|
||
}
|
||
//以jpg格式保存缩略图
|
||
bitmap.Save(thumbnailPath + "1" + info.Name);
|
||
CompressImage(thumbnailPath + "1" + info.Name, thumbnailPath + info.Name);
|
||
return new Task<string>(() => thumbnailPath + info.Name);
|
||
//return thumbnailPath + info.Name;
|
||
}
|
||
catch (System.Exception e)
|
||
{
|
||
LogHelp.WriteExceptionLog(e, this.GetType().Name);
|
||
return null;
|
||
}
|
||
finally
|
||
{
|
||
originalImage.Dispose();
|
||
bitmap.Dispose();
|
||
g.Dispose();
|
||
}
|
||
|
||
}
|
||
#endregion
|
||
|
||
/// <summary>
|
||
/// 图片上传到ftp(异步)
|
||
/// </summary>
|
||
/// <param name="filename">源文件路径</param>
|
||
public Task<string> FtpUpload(string filename, string ftpServerIP)
|
||
{
|
||
string ftpUserID = "uts_manager";//ftp账号
|
||
string ftpPassword = "uts_Inhaos@all";//ftp密码
|
||
FileInfo fileInf = new FileInfo(filename);
|
||
FtpWebRequest reqFTP;
|
||
ServicePointManager.ServerCertificateValidationCallback =
|
||
new RemoteCertificateValidationCallback(ValidateServerCertificate);
|
||
try
|
||
{
|
||
// 根据uri创建FtpWebRequest对象
|
||
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + ftpServerIP + "/" + fileInf.Name));
|
||
// ftp用户名和密码
|
||
reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
|
||
// 默认为true,连接不会被关闭
|
||
// 在一个命令之后被执行
|
||
reqFTP.KeepAlive = true;
|
||
//如果要连接的 FTP 服务器要求凭据并支持安全套接字层 (SSL),则应将 EnableSsl 设置为 true。如果不写会报出421错误(服务不可用)
|
||
reqFTP.EnableSsl = false;
|
||
// 指定执行什么命令
|
||
reqFTP.Method = WebRequestMethods.Ftp.UploadFile;
|
||
// 指定数据传输类型
|
||
reqFTP.UseBinary = true;
|
||
// 上传文件时通知服务器文件的大小
|
||
reqFTP.ContentLength = fileInf.Length;
|
||
// 缓冲大小设置为 10kb
|
||
int buffLength = 10480;
|
||
byte[] buff = new byte[buffLength];
|
||
int contentLen;
|
||
// 打开一个文件流 (System.IO.FileStream) 去读上传的文件
|
||
FileStream fs = fileInf.OpenRead();
|
||
try
|
||
{
|
||
// 把上传的文件写入流
|
||
Stream strm = reqFTP.GetRequestStream();
|
||
// 每次读文件流的buffLength kb
|
||
contentLen = fs.Read(buff, 0, buffLength);
|
||
// 流内容没有结束
|
||
while (contentLen != 0)
|
||
{
|
||
// 把内容从file stream 写入 upload stream
|
||
strm.Write(buff, 0, contentLen);
|
||
contentLen = fs.Read(buff, 0, buffLength);
|
||
}
|
||
// 关闭两个流
|
||
strm.Close();
|
||
fs.Close();
|
||
return new Task<string>(() => fileInf.Name);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
Response.Write("Upload Error:" + ex.Message);
|
||
}
|
||
}
|
||
catch (Exception e)
|
||
{
|
||
Response.Write("Upload Error:" + e.Message);
|
||
}
|
||
return null;
|
||
}
|
||
|
||
|
||
/// <summary>
|
||
/// 无损压缩图片
|
||
/// </summary>
|
||
/// <param name="originalFileFullName">原图片地址</param>
|
||
/// <param name="afterConversionFileFullName">压缩后保存图片地址</param>
|
||
/// <param name="flag">压缩质量(数字越小压缩率越高)1-100</param>
|
||
/// <param name="size">压缩后图片的最大大小</param>
|
||
/// <param name="isFirst">是否是第一次调用</param>
|
||
/// <returns></returns>
|
||
public static bool CompressImage(string originalFileFullName, string afterConversionFileFullName, int flag = 90, int size = 100, bool isFirst = true)
|
||
{
|
||
Image iSource = Image.FromFile(originalFileFullName);
|
||
ImageFormat tFormat = iSource.RawFormat;
|
||
//如果是第一次调用,原始图像的大小小于要压缩的大小,则直接复制文件,并且返回true
|
||
FileInfo firstFileInfo = new FileInfo(originalFileFullName);
|
||
if (firstFileInfo.Length < size * 1024)
|
||
{
|
||
firstFileInfo.CopyTo(afterConversionFileFullName);
|
||
return true;
|
||
}
|
||
|
||
int dHeight = iSource.Height;// / 2;
|
||
int dWidth = iSource.Width;/// 2;
|
||
int sW = dWidth, sH = dHeight;
|
||
//按比例缩放
|
||
Size tem_size = new Size(iSource.Width, iSource.Height);
|
||
//if (tem_size.Width > dHeight || tem_size.Width > dWidth)
|
||
//{
|
||
// if ((tem_size.Width * dHeight) > (tem_size.Width * dWidth))
|
||
// {
|
||
// sW = dWidth;
|
||
// sH = (dWidth * tem_size.Height) / tem_size.Width;
|
||
// }
|
||
// else
|
||
// {
|
||
// sH = dHeight;
|
||
// sW = (tem_size.Width * dHeight) / tem_size.Height;
|
||
// }
|
||
//}
|
||
//else
|
||
//{
|
||
// sW = tem_size.Width;
|
||
// sH = tem_size.Height;
|
||
//}
|
||
|
||
Bitmap ob = new Bitmap(dWidth, dHeight);
|
||
Graphics g = Graphics.FromImage(ob);
|
||
|
||
g.Clear(Color.WhiteSmoke);
|
||
g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
|
||
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
|
||
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
|
||
|
||
g.DrawImage(iSource, new Rectangle(0, 0, sW, sH), 0, 0, iSource.Width, iSource.Height, GraphicsUnit.Pixel);
|
||
|
||
g.Dispose();
|
||
|
||
//以下代码为保存图片时,设置压缩质量
|
||
EncoderParameters ep = new EncoderParameters();
|
||
long[] qy = new long[1];
|
||
qy[0] = flag;//设置压缩的比例1-100
|
||
EncoderParameter eParam = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, qy);
|
||
ep.Param[0] = eParam;
|
||
|
||
try
|
||
{
|
||
ImageCodecInfo[] arrayICI = ImageCodecInfo.GetImageEncoders();
|
||
ImageCodecInfo jpegICIinfo = null;
|
||
for (int x = 0; x < arrayICI.Length; x++)
|
||
{
|
||
if (arrayICI[x].FormatDescription.Equals("JPEG"))
|
||
{
|
||
jpegICIinfo = arrayICI[x];
|
||
break;
|
||
}
|
||
}
|
||
if (jpegICIinfo != null)
|
||
{
|
||
ob.Save(afterConversionFileFullName, jpegICIinfo, ep);
|
||
FileInfo fi = new FileInfo(afterConversionFileFullName);
|
||
if (fi.Length > 1024 * size)
|
||
{
|
||
var str = afterConversionFileFullName.Split('.').ToList();
|
||
var path = str.LastOrDefault();
|
||
path = HostingEnvironment.MapPath($"~/Upload/Image/{new Random().Next()}{DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss")}.{path}");
|
||
ob.Save(path, jpegICIinfo, ep);
|
||
//flag = flag - 10;
|
||
return CompressImage(path, afterConversionFileFullName, flag, size, false);
|
||
}
|
||
//else
|
||
//{
|
||
// ob.Save(afterConversionFileFullName, jpegICIinfo, ep);
|
||
//}
|
||
}
|
||
else
|
||
{
|
||
ob.Save(afterConversionFileFullName, tFormat);
|
||
}
|
||
return true;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelp.WriteExceptionLog(ex);
|
||
return false;
|
||
}
|
||
finally
|
||
{
|
||
iSource.Dispose();
|
||
ob.Dispose();
|
||
//不是第一次就删除源文件
|
||
if (!isFirst)
|
||
{
|
||
System.IO.File.Delete(originalFileFullName);
|
||
}
|
||
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 无证书时跳过不报错
|
||
/// </summary>
|
||
/// <param name="sender"></param>
|
||
/// <param name="certificate"></param>
|
||
/// <param name="chain"></param>
|
||
/// <param name="sslPolicyErrors"></param>
|
||
/// <returns></returns>
|
||
public static bool ValidateServerCertificate
|
||
(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
|
||
{
|
||
return true;
|
||
}
|
||
}
|
||
|
||
public static class FacemachineTest
|
||
{
|
||
//开门命令
|
||
public static returnInfo opendoor(string sn)
|
||
{
|
||
returnInfo ri = new returnInfo();
|
||
|
||
//请求路径
|
||
//string url = "http://localhost:55151/App/WxTest/ActionOpenDoorToDevice";
|
||
string url = "http://face.blv-oa.com/App/WxTest/ActionOpenDoorToDevice";
|
||
//定义request并设置request的路径
|
||
WebRequest request = WebRequest.Create(url);
|
||
request.Method = "post";
|
||
Face past = new Face();
|
||
past.Serial = sn;
|
||
|
||
//初始化request参数
|
||
//string postData = "{Pwd:\"\",OutBoxCode:\"OutBoxCode\",ShippingCode:\"ShippingCode\",MO:\"zzz\",istest:1}";
|
||
//"{ ID: \"1\", NAME: \"Jim\", CREATETIME: \"1988-09-11\" }";
|
||
//设置参数的编码格式,解决中文乱码
|
||
string postData = Newtonsoft.Json.JsonConvert.SerializeObject(past);
|
||
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
|
||
|
||
//设置request的MIME类型及内容长度
|
||
request.ContentType = "application/json";
|
||
request.ContentLength = byteArray.Length;
|
||
|
||
//打开request字符流
|
||
Stream dataStream = request.GetRequestStream();
|
||
dataStream.Write(byteArray, 0, byteArray.Length);
|
||
dataStream.Close();
|
||
|
||
//定义response为前面的request响应
|
||
WebResponse response = request.GetResponse();
|
||
|
||
//获取相应的状态代码
|
||
Console.WriteLine(((HttpWebResponse)response).StatusDescription);
|
||
|
||
//定义response字符流
|
||
dataStream = response.GetResponseStream();
|
||
StreamReader reader = new StreamReader(dataStream);
|
||
string responseFromServer = reader.ReadToEnd();//读取所有
|
||
|
||
ri = JsonConvert.DeserializeObject<returnInfo>(responseFromServer);
|
||
|
||
|
||
Console.WriteLine(responseFromServer);
|
||
|
||
return ri;
|
||
}
|
||
//重启命令
|
||
public static returnInfo RestartDevice(string sn)
|
||
{
|
||
returnInfo ri = new returnInfo();
|
||
|
||
//请求路径
|
||
//string url = "http://localhost:55151/App/WxTest/ActionResetToDevice";
|
||
string url = "http://face.blv-oa.com/App/WxTest/ActionResetToDevice";
|
||
//定义request并设置request的路径
|
||
WebRequest request = WebRequest.Create(url);
|
||
request.Method = "post";
|
||
Face past = new Face();
|
||
past.Serial = sn;
|
||
|
||
//初始化request参数
|
||
//string postData = "{Pwd:\"\",OutBoxCode:\"OutBoxCode\",ShippingCode:\"ShippingCode\",MO:\"zzz\",istest:1}";
|
||
//"{ ID: \"1\", NAME: \"Jim\", CREATETIME: \"1988-09-11\" }";
|
||
//设置参数的编码格式,解决中文乱码
|
||
string postData = Newtonsoft.Json.JsonConvert.SerializeObject(past);
|
||
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
|
||
|
||
//设置request的MIME类型及内容长度
|
||
request.ContentType = "application/json";
|
||
request.ContentLength = byteArray.Length;
|
||
|
||
//打开request字符流
|
||
Stream dataStream = request.GetRequestStream();
|
||
dataStream.Write(byteArray, 0, byteArray.Length);
|
||
dataStream.Close();
|
||
|
||
//定义response为前面的request响应
|
||
WebResponse response = request.GetResponse();
|
||
|
||
//获取相应的状态代码
|
||
Console.WriteLine(((HttpWebResponse)response).StatusDescription);
|
||
|
||
//定义response字符流
|
||
dataStream = response.GetResponseStream();
|
||
StreamReader reader = new StreamReader(dataStream);
|
||
string responseFromServer = reader.ReadToEnd();//读取所有
|
||
|
||
ri = JsonConvert.DeserializeObject<returnInfo>(responseFromServer);
|
||
|
||
|
||
Console.WriteLine(responseFromServer);
|
||
|
||
return ri;
|
||
}
|
||
|
||
// 获取设备信息
|
||
public static returnInfo GeteDeviceInfo(string sn, string hotelCode)
|
||
{
|
||
returnInfo ri = new returnInfo();
|
||
|
||
//请求路径
|
||
//string url = "http://localhost:55151/App/WxTest/GetDeviceInfo";
|
||
string url = "http://face.blv-oa.com/App/WxTest/GetDeviceInfo";
|
||
//定义request并设置request的路径
|
||
WebRequest request = WebRequest.Create(url);
|
||
request.Method = "post";
|
||
Faceinfo past = new Faceinfo();
|
||
past.Serial = sn;
|
||
past.hotelCode = hotelCode;
|
||
//初始化request参数
|
||
//string postData = "{Pwd:\"\",OutBoxCode:\"OutBoxCode\",ShippingCode:\"ShippingCode\",MO:\"zzz\",istest:1}";
|
||
//"{ ID: \"1\", NAME: \"Jim\", CREATETIME: \"1988-09-11\" }";
|
||
//设置参数的编码格式,解决中文乱码
|
||
string postData = Newtonsoft.Json.JsonConvert.SerializeObject(past);
|
||
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
|
||
|
||
//设置request的MIME类型及内容长度
|
||
request.ContentType = "application/json";
|
||
request.ContentLength = byteArray.Length;
|
||
|
||
//打开request字符流
|
||
Stream dataStream = request.GetRequestStream();
|
||
dataStream.Write(byteArray, 0, byteArray.Length);
|
||
dataStream.Close();
|
||
|
||
//定义response为前面的request响应
|
||
WebResponse response = request.GetResponse();
|
||
|
||
//获取相应的状态代码
|
||
Console.WriteLine(((HttpWebResponse)response).StatusDescription);
|
||
|
||
//定义response字符流
|
||
dataStream = response.GetResponseStream();
|
||
StreamReader reader = new StreamReader(dataStream);
|
||
string responseFromServer = reader.ReadToEnd();//读取所有
|
||
|
||
ri = JsonConvert.DeserializeObject<returnInfo>(responseFromServer);
|
||
|
||
|
||
Console.WriteLine(responseFromServer);
|
||
|
||
return ri;
|
||
}
|
||
//删除用户组信息
|
||
public static returnInfo delPeopleFromDeviceByGroup(string sn, string hotelCode)
|
||
{
|
||
returnInfo ri = new returnInfo();
|
||
|
||
//请求路径
|
||
//string url = "http://localhost:55151/App/WxTest/DeletePeopleFromDeviceByGroup";
|
||
string url = "http://face.blv-oa.com/App/WxTest/DeletePeopleFromDeviceByGroup";
|
||
//定义request并设置request的路径
|
||
WebRequest request = WebRequest.Create(url);
|
||
request.Method = "post";
|
||
Faceinfo past = new Faceinfo();
|
||
past.Serial = sn;
|
||
past.hotelCode = hotelCode;
|
||
//初始化request参数
|
||
//string postData = "{Pwd:\"\",OutBoxCode:\"OutBoxCode\",ShippingCode:\"ShippingCode\",MO:\"zzz\",istest:1}";
|
||
//"{ ID: \"1\", NAME: \"Jim\", CREATETIME: \"1988-09-11\" }";
|
||
//设置参数的编码格式,解决中文乱码
|
||
string postData = Newtonsoft.Json.JsonConvert.SerializeObject(past);
|
||
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
|
||
|
||
//设置request的MIME类型及内容长度
|
||
request.ContentType = "application/json";
|
||
request.ContentLength = byteArray.Length;
|
||
|
||
//打开request字符流
|
||
Stream dataStream = request.GetRequestStream();
|
||
dataStream.Write(byteArray, 0, byteArray.Length);
|
||
dataStream.Close();
|
||
|
||
//定义response为前面的request响应
|
||
WebResponse response = request.GetResponse();
|
||
|
||
//获取相应的状态代码
|
||
Console.WriteLine(((HttpWebResponse)response).StatusDescription);
|
||
|
||
//定义response字符流
|
||
dataStream = response.GetResponseStream();
|
||
StreamReader reader = new StreamReader(dataStream);
|
||
string responseFromServer = reader.ReadToEnd();//读取所有
|
||
|
||
ri = JsonConvert.DeserializeObject<returnInfo>(responseFromServer);
|
||
|
||
|
||
Console.WriteLine(responseFromServer);
|
||
|
||
return ri;
|
||
}
|
||
|
||
//获取入住人员数量
|
||
public static returnInfo GetsThePeopleListOfDevice(string sn, string hotelCode)
|
||
{
|
||
returnInfo ri = new returnInfo();
|
||
|
||
//请求路径
|
||
//string url = "http://localhost:55151/App/WxTest/GetThePeopleListOfDevice";
|
||
string url = "http://face.blv-oa.com/App/WxTest/GetThePeopleListOfDevice";
|
||
//定义request并设置request的路径
|
||
WebRequest request = WebRequest.Create(url);
|
||
request.Method = "post";
|
||
Faceinfo past = new Faceinfo();
|
||
past.Serial = sn;
|
||
past.hotelCode = hotelCode;
|
||
//初始化request参数
|
||
//string postData = "{Pwd:\"\",OutBoxCode:\"OutBoxCode\",ShippingCode:\"ShippingCode\",MO:\"zzz\",istest:1}";
|
||
//"{ ID: \"1\", NAME: \"Jim\", CREATETIME: \"1988-09-11\" }";
|
||
//设置参数的编码格式,解决中文乱码
|
||
string postData = Newtonsoft.Json.JsonConvert.SerializeObject(past);
|
||
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
|
||
|
||
//设置request的MIME类型及内容长度
|
||
request.ContentType = "application/json";
|
||
request.ContentLength = byteArray.Length;
|
||
|
||
//打开request字符流
|
||
Stream dataStream = request.GetRequestStream();
|
||
dataStream.Write(byteArray, 0, byteArray.Length);
|
||
dataStream.Close();
|
||
|
||
//定义response为前面的request响应
|
||
WebResponse response = request.GetResponse();
|
||
|
||
//获取相应的状态代码
|
||
Console.WriteLine(((HttpWebResponse)response).StatusDescription);
|
||
|
||
//定义response字符流
|
||
dataStream = response.GetResponseStream();
|
||
StreamReader reader = new StreamReader(dataStream);
|
||
string responseFromServer = reader.ReadToEnd();//读取所有
|
||
|
||
ri = JsonConvert.DeserializeObject<returnInfo>(responseFromServer);
|
||
|
||
|
||
Console.WriteLine(responseFromServer);
|
||
|
||
return ri;
|
||
}
|
||
|
||
//下发人脸
|
||
public static returnInfo openRoomCheckin(string idNumber, string name, int sex, string picture, string phone, string faceSN, string hotelCode, string room)
|
||
{
|
||
returnInfo ri = new returnInfo();
|
||
|
||
//请求路径
|
||
//string url = "http://localhost:55151/App/WxTest/visitinfo";
|
||
string url = "http://face.blv-oa.com/App/WxTest/visitinfo";
|
||
//定义request并设置request的路径
|
||
WebRequest request = WebRequest.Create(url);
|
||
request.Method = "post";
|
||
openroomchin past = new openroomchin();
|
||
past.idNumber = idNumber;
|
||
past.name = name;
|
||
past.sex = sex;
|
||
past.picture = picture;
|
||
past.phone = phone;
|
||
past.hotel = hotelCode;
|
||
past.room = room;
|
||
past.faceSN = faceSN;
|
||
|
||
|
||
//初始化request参数
|
||
//string postData = "{Pwd:\"\",OutBoxCode:\"OutBoxCode\",ShippingCode:\"ShippingCode\",MO:\"zzz\",istest:1}";
|
||
//"{ ID: \"1\", NAME: \"Jim\", CREATETIME: \"1988-09-11\" }";
|
||
//设置参数的编码格式,解决中文乱码
|
||
string postData = Newtonsoft.Json.JsonConvert.SerializeObject(past);
|
||
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
|
||
|
||
//设置request的MIME类型及内容长度
|
||
request.ContentType = "application/json";
|
||
request.ContentLength = byteArray.Length;
|
||
|
||
//打开request字符流
|
||
Stream dataStream = request.GetRequestStream();
|
||
dataStream.Write(byteArray, 0, byteArray.Length);
|
||
dataStream.Close();
|
||
|
||
//定义response为前面的request响应
|
||
WebResponse response = request.GetResponse();
|
||
|
||
//获取相应的状态代码
|
||
Console.WriteLine(((HttpWebResponse)response).StatusDescription);
|
||
|
||
//定义response字符流
|
||
dataStream = response.GetResponseStream();
|
||
StreamReader reader = new StreamReader(dataStream);
|
||
string responseFromServer = reader.ReadToEnd();//读取所有
|
||
if (responseFromServer == "true")
|
||
{
|
||
ri.Status = 200;
|
||
}
|
||
else
|
||
{
|
||
ri.Status = 500;
|
||
}
|
||
//ri = JsonConvert.DeserializeObject<returnInfo>(responseFromServer);
|
||
Console.WriteLine(responseFromServer);
|
||
|
||
return ri;
|
||
}
|
||
|
||
//删除人脸
|
||
public static returnInfo roomtoCheckOut(string faceSN, string hotelCode, string room)
|
||
{
|
||
returnInfo ri = new returnInfo();
|
||
|
||
//请求路径
|
||
//string url = "http://localhost:55151/App/WxTest/CheckOut";
|
||
string url = " http://face.blv-oa.com/App/WxTest/CheckOut";
|
||
//定义request并设置request的路径
|
||
WebRequest request = WebRequest.Create(url);
|
||
request.Method = "post";
|
||
roomCheckOut past = new roomCheckOut();
|
||
past.key = "abc";
|
||
past.data.HotelCode = hotelCode;
|
||
past.data.roomid = room;
|
||
past.data.checkOutTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
||
|
||
|
||
//初始化request参数
|
||
//string postData = "{\"data\":{\"HotelCode\":\"hotelCode,\"roomid\":\"102\",\"CheckTime\":\"2024-04-08T17:55:37.801093+08:00\"}}";
|
||
//"{ ID: \"1\", NAME: \"Jim\", CREATETIME: \"1988-09-11\" }";
|
||
//设置参数的编码格式,解决中文乱码
|
||
string postData = Newtonsoft.Json.JsonConvert.SerializeObject(past);
|
||
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
|
||
|
||
//设置request的MIME类型及内容长度
|
||
request.ContentType = "application/json";
|
||
request.ContentLength = byteArray.Length;
|
||
|
||
//打开request字符流
|
||
Stream dataStream = request.GetRequestStream();
|
||
dataStream.Write(byteArray, 0, byteArray.Length);
|
||
dataStream.Close();
|
||
|
||
//定义response为前面的request响应
|
||
WebResponse response = request.GetResponse();
|
||
|
||
//获取相应的状态代码
|
||
Console.WriteLine(((HttpWebResponse)response).StatusDescription);
|
||
|
||
//定义response字符流
|
||
dataStream = response.GetResponseStream();
|
||
StreamReader reader = new StreamReader(dataStream);
|
||
string responseFromServer = reader.ReadToEnd();//读取所有
|
||
if (responseFromServer == "true")
|
||
{
|
||
ri.Status = 200;
|
||
|
||
}
|
||
else
|
||
{
|
||
ri.Status = 500;
|
||
}
|
||
//ri = JsonConvert.DeserializeObject<returnInfo>(responseFromServer);
|
||
|
||
|
||
Console.WriteLine(responseFromServer);
|
||
|
||
return ri;
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
}
|
||
|
||
public class roomCheckOut
|
||
{
|
||
public string key { get; set; }
|
||
public data data { get; set; }
|
||
public roomCheckOut()
|
||
{
|
||
data = new data();
|
||
}
|
||
}
|
||
// {
|
||
// "": "1287",
|
||
// "": "102",
|
||
// "CheckTime": "2012-12-1",
|
||
//}
|
||
public class data
|
||
{
|
||
//public string faceSN { get; set; }
|
||
public string HotelCode { get; set; }
|
||
public string roomid { get; set; }
|
||
public string checkOutTime { get; set; }
|
||
}
|
||
|
||
|
||
public class openroomchin
|
||
{
|
||
|
||
|
||
public int sex { get; set; }
|
||
public string name { get; set; }
|
||
public string idNumber { get; set; }
|
||
public string picture { get; set; }
|
||
|
||
public string phone { get; set; }
|
||
public string faceSN { get; set; }
|
||
public string hotel { get; set; }
|
||
public string room { get; set; }
|
||
|
||
}
|
||
|
||
|
||
|
||
|
||
|
||
public class Face
|
||
{
|
||
public string Serial { get; set; }
|
||
}
|
||
public class Faceinfo
|
||
{
|
||
public string Serial { get; set; }
|
||
public string hotelCode { get; set; }
|
||
}
|
||
|
||
public class returnInfo
|
||
{
|
||
public int Status { get; set; }
|
||
public string Message { get; set; }
|
||
public string APKVersion { get; set; }
|
||
public string puinfo { get; set; }
|
||
}
|
||
|
||
|
||
|
||
|
||
}
|