You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
261 lines
11 KiB
C#
261 lines
11 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Text;
|
|
using System.Web.Script.Serialization;
|
|
|
|
namespace HuizhongLibrary.UFace
|
|
{
|
|
public class UfaceService
|
|
{
|
|
public static string appId="";
|
|
public static string appKey = "";
|
|
public static string appSecret = "";
|
|
public static string token = "";
|
|
|
|
#region 获取AccessToken
|
|
public static string GetAccessToken(out string ErrorMessage)
|
|
{
|
|
ErrorMessage="";
|
|
string url = "http://gs-api.uface.uni-ubi.com/v1/{"+ UfaceService.appId + "}/auth";
|
|
var model = new UFace_Auth();
|
|
model.appId = UfaceService.appId;
|
|
model.appKey = UfaceService.appKey;
|
|
model.CreateSign(UfaceService.appSecret);
|
|
String postmessage = model.ToJsonString();
|
|
JavaScriptSerializer JsonConvert = new JavaScriptSerializer();
|
|
UTF8Encoding encoding = new UTF8Encoding();
|
|
byte[] data = encoding.GetBytes(postmessage);
|
|
string XmlContent = CustomIO.HttpRequest(url, "POST", "", null, HttpVersion.Version10, null, out ErrorMessage);
|
|
if (string.IsNullOrEmpty(ErrorMessage) == false) return "";
|
|
var model2 = JsonConvert.Deserialize<UFace_Auth_Result>(XmlContent);
|
|
if (model2.result == 1)
|
|
{
|
|
return model2.data;
|
|
}
|
|
else
|
|
{
|
|
ErrorMessage = model2.msg;
|
|
}
|
|
return "";
|
|
}
|
|
#endregion
|
|
#region 创建设备
|
|
public static string CreateDevice(string deviceKey,string name,string tag,out string ErrorMessage)
|
|
{
|
|
ErrorMessage = "";
|
|
string url = "http://gs-api.uface.uni-ubi.com/v1/" + UfaceService.appId + "/device";
|
|
var model = new UFace_Device();
|
|
model.appId = UfaceService.appId;
|
|
model.token = UfaceService.token;
|
|
model.deviceKey= deviceKey;
|
|
model.name = name;
|
|
model.tag = tag;
|
|
String postmessage = model.ToJsonString();
|
|
JavaScriptSerializer JsonConvert = new JavaScriptSerializer();
|
|
UTF8Encoding encoding = new UTF8Encoding();
|
|
byte[] data = encoding.GetBytes(postmessage);
|
|
string XmlContent = CustomIO.HttpRequest(url, "POST", "", null, HttpVersion.Version10, null, out ErrorMessage);
|
|
if (string.IsNullOrEmpty(ErrorMessage) == false) return "";
|
|
var model2 = JsonConvert.Deserialize<UFace_Device_Result>(XmlContent);
|
|
if (model2.result == 1)
|
|
{
|
|
return model2.data;
|
|
}
|
|
else
|
|
{
|
|
ErrorMessage = model2.msg;
|
|
}
|
|
return "";
|
|
}
|
|
#endregion
|
|
#region 设备列表查询
|
|
public static List<UFace_Device_Search_Result_DeviceInfo> GetListDevice(string deviceKey, string name, string tag, out string ErrorMessage)
|
|
{
|
|
ErrorMessage = "";
|
|
var ListModel = new List<UFace_Device_Search_Result_DeviceInfo>();
|
|
string url = "http://gs-api.uface.uni-ubi.com/v1/" + UfaceService.appId + "/device/search";
|
|
var model = new UFace_Device_Search();
|
|
model.appId = UfaceService.appId;
|
|
model.token = UfaceService.token;
|
|
String postmessage = model.ToJsonString();
|
|
JavaScriptSerializer JsonConvert = new JavaScriptSerializer();
|
|
UTF8Encoding encoding = new UTF8Encoding();
|
|
byte[] data = encoding.GetBytes(postmessage);
|
|
string XmlContent = CustomIO.HttpRequest(url, "POST", "", null, HttpVersion.Version10, null, out ErrorMessage);
|
|
if (string.IsNullOrEmpty(ErrorMessage) == false) return ListModel;
|
|
var model2 = JsonConvert.Deserialize<UFace_Device_Search_Result>(XmlContent);
|
|
if (model2.result == 1)
|
|
{
|
|
foreach (var item in model2.data.content)
|
|
{
|
|
var mm = item.Copy();
|
|
ListModel.Add(mm);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
ErrorMessage = model2.msg;
|
|
}
|
|
return ListModel;
|
|
}
|
|
#endregion
|
|
#region 人员新增
|
|
public static UFace_Person_Info AddPerson(string deviceKey, string name, string tag, out string ErrorMessage)
|
|
{
|
|
ErrorMessage = "";
|
|
string url = "http://gs-api.uface.uni-ubi.com/v1/" + UfaceService.appId + "/device/search";
|
|
var model = new UFace_Person();
|
|
model.appId = UfaceService.appId;
|
|
model.token = UfaceService.token;
|
|
String postmessage = model.ToJsonString();
|
|
JavaScriptSerializer JsonConvert = new JavaScriptSerializer();
|
|
UTF8Encoding encoding = new UTF8Encoding();
|
|
byte[] data = encoding.GetBytes(postmessage);
|
|
string XmlContent = CustomIO.HttpRequest(url, "POST", "", null, HttpVersion.Version10, null, out ErrorMessage);
|
|
if (string.IsNullOrEmpty(ErrorMessage) == false) return null;
|
|
var model2 = JsonConvert.Deserialize<UFace_Person_Result>(XmlContent);
|
|
if (model2.result == 1)
|
|
{
|
|
return model2.data;
|
|
}
|
|
else
|
|
{
|
|
ErrorMessage = model2.msg;
|
|
}
|
|
return null;
|
|
}
|
|
#endregion
|
|
#region 人员删除
|
|
public static void DeletePerson(string guid, out string ErrorMessage)
|
|
{
|
|
ErrorMessage = "";
|
|
string url = "http://gs-api.uface.uni-ubi.com/v1/"+ UfaceService.appId + "/person/"+ guid;
|
|
var model = new UFace_Person_Delete();
|
|
model.appId = UfaceService.appId;
|
|
model.token = UfaceService.token;
|
|
model.guid = guid;
|
|
String postmessage = model.ToJsonString();
|
|
JavaScriptSerializer JsonConvert = new JavaScriptSerializer();
|
|
UTF8Encoding encoding = new UTF8Encoding();
|
|
byte[] data = encoding.GetBytes(postmessage);
|
|
string XmlContent = CustomIO.HttpRequest(url, "DELETE", "", null, HttpVersion.Version10, null, out ErrorMessage);
|
|
if (string.IsNullOrEmpty(ErrorMessage) == false) return;
|
|
var model2 = JsonConvert.Deserialize<UFace_Auth_Result>(XmlContent);
|
|
if (model2.result == 1)
|
|
{
|
|
|
|
}
|
|
else
|
|
{
|
|
ErrorMessage = model2.msg;
|
|
}
|
|
}
|
|
#endregion
|
|
#region 人员修改
|
|
public static void UpdatePerson(string guid, out string ErrorMessage)
|
|
{
|
|
ErrorMessage = "";
|
|
string url = "http://gs-api.uface.uni-ubi.com/v1/" + UfaceService.appId + "/person/" + guid;
|
|
var model = new UFace_Person_Delete();
|
|
model.appId = UfaceService.appId;
|
|
model.token = UfaceService.token;
|
|
model.guid = guid;
|
|
String postmessage = model.ToJsonString();
|
|
JavaScriptSerializer JsonConvert = new JavaScriptSerializer();
|
|
UTF8Encoding encoding = new UTF8Encoding();
|
|
byte[] data = encoding.GetBytes(postmessage);
|
|
string XmlContent = CustomIO.HttpRequest(url, "POST", "", null, HttpVersion.Version10, null, out ErrorMessage);
|
|
if (string.IsNullOrEmpty(ErrorMessage) == false) return;
|
|
var model2 = JsonConvert.Deserialize<UFace_Auth_Result>(XmlContent);
|
|
if (model2.result == 1)
|
|
{
|
|
|
|
}
|
|
else
|
|
{
|
|
ErrorMessage = model2.msg;
|
|
}
|
|
}
|
|
#endregion
|
|
#region 人员授权
|
|
public static void AddPersonPermission(UFace_PersonPermission model, out string ErrorMessage)
|
|
{
|
|
ErrorMessage = "";
|
|
string url = "http://gs-api.uface.uni-ubi.com/v1/" + UfaceService.appId + "/person/" + model.guid + "/devices";
|
|
model.appId = UfaceService.appId;
|
|
model.token = UfaceService.token;
|
|
String postmessage = model.ToJsonString();
|
|
JavaScriptSerializer JsonConvert = new JavaScriptSerializer();
|
|
UTF8Encoding encoding = new UTF8Encoding();
|
|
byte[] data = encoding.GetBytes(postmessage);
|
|
string XmlContent = CustomIO.HttpRequest(url, "POST", "", null, HttpVersion.Version10, null, out ErrorMessage);
|
|
if (string.IsNullOrEmpty(ErrorMessage) == false) return;
|
|
var model2 = JsonConvert.Deserialize<UFace_Auth_Result>(XmlContent);
|
|
if (model2.result == 1)
|
|
{
|
|
|
|
}
|
|
else
|
|
{
|
|
ErrorMessage = model2.msg;
|
|
}
|
|
}
|
|
#endregion
|
|
#region 人员消权
|
|
public static void DeletePersonPermission(string guid,string deviceKey, out string ErrorMessage)
|
|
{
|
|
ErrorMessage = "";
|
|
string url = "http://gs-api.uface.uni-ubi.com/v1/" + UfaceService.appId + "/person/" + guid + "/devices";
|
|
var model = new UFace_PersonPermission_Delete();
|
|
model.appId = UfaceService.appId;
|
|
model.token = UfaceService.token;
|
|
model.guid = guid;
|
|
model.deviceKey = deviceKey;
|
|
String postmessage = model.ToJsonString();
|
|
JavaScriptSerializer JsonConvert = new JavaScriptSerializer();
|
|
UTF8Encoding encoding = new UTF8Encoding();
|
|
byte[] data = encoding.GetBytes(postmessage);
|
|
string XmlContent = CustomIO.HttpRequest(url, "POST", "", null, HttpVersion.Version10, null, out ErrorMessage);
|
|
if (string.IsNullOrEmpty(ErrorMessage) == false) return;
|
|
var model2 = JsonConvert.Deserialize<UFace_Auth_Result>(XmlContent);
|
|
if (model2.result == 1)
|
|
{
|
|
|
|
}
|
|
else
|
|
{
|
|
ErrorMessage = model2.msg;
|
|
}
|
|
}
|
|
#endregion
|
|
#region 照片上传
|
|
public static UFace_Photo_Result_data AddPhoto(UFace_Photo model, out string ErrorMessage)
|
|
{
|
|
ErrorMessage = "";
|
|
string url = "http://gs-api.uface.uni-ubi.com/v1/" + UfaceService.appId + "/person/" + model.guid + "/face/valid";
|
|
model.appId = UfaceService.appId;
|
|
model.token = UfaceService.token;
|
|
String postmessage = model.ToJsonString();
|
|
JavaScriptSerializer JsonConvert = new JavaScriptSerializer();
|
|
UTF8Encoding encoding = new UTF8Encoding();
|
|
byte[] data = encoding.GetBytes(postmessage);
|
|
string XmlContent = CustomIO.HttpRequest(url, "POST", "", null, HttpVersion.Version10, null, out ErrorMessage);
|
|
if (string.IsNullOrEmpty(ErrorMessage) == false) return null;
|
|
var model2 = JsonConvert.Deserialize<UFace_Photo_Result>(XmlContent);
|
|
if (model2.result == 1)
|
|
{
|
|
return model2.data;
|
|
}
|
|
else
|
|
{
|
|
ErrorMessage = model2.msg;
|
|
}
|
|
return null;
|
|
}
|
|
#endregion
|
|
|
|
}
|
|
}
|