|
|
@@ -6,10 +6,16 @@ using System.Data.SqlClient; |
|
|
|
using System.Diagnostics.Eventing.Reader; |
|
|
|
using System.IO; |
|
|
|
using System.Linq; |
|
|
|
using System.Net; |
|
|
|
using System.Net.Http; |
|
|
|
using System.Runtime.InteropServices; |
|
|
|
using System.Text; |
|
|
|
using System.Web; |
|
|
|
using AlarmCSharpDemo; |
|
|
|
using Antlr.Runtime.Misc; |
|
|
|
using Dapper; |
|
|
|
using Org.BouncyCastle.Asn1.X509; |
|
|
|
using Org.BouncyCastle.Ocsp; |
|
|
|
|
|
|
|
namespace DigitalSchoolApi.Controllers |
|
|
|
{ |
|
|
@@ -1114,6 +1120,103 @@ namespace DigitalSchoolApi.Controllers |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public static string OpenDoor(string id) |
|
|
|
{ |
|
|
|
using (IDbConnection connmis = new SqlConnection(_misConnection)) |
|
|
|
{ |
|
|
|
//获取设备 |
|
|
|
var device = connmis.QueryFirstOrDefault<ADR_DeviceEntity>($"select * from ADR_Device where F_EnabledMark=1 and Id='{id}'"); |
|
|
|
if(device!=null) |
|
|
|
{ |
|
|
|
string url = $"http://{device.IpAddress}/ISAPI/AccessControl/RemoteControl/door/1"; |
|
|
|
string username = device.AdminAccount; |
|
|
|
string password = device.AdminPwd; |
|
|
|
string data = $"<?xml version=\"1.0\" encoding=\"UTF-8\"?><RemoteControlDoor xmlns=\"http://www.isapi.org/ver20/XMLSchema\" version=\"2.0\"><cmd>open</cmd> <password>{device.AdminPwd}</password><employeeNo>1</employeeNo><channelNo>1</channelNo><controlType>monitor</controlType><personnelChannelGroupInfoList><personnelChannelGroupInfo><personnelChannelGroupID>1</personnelChannelGroupID><personnelChannelInfoList><personnelChannelInfo><personnelChannelID>1</personnelChannelID></personnelChannelInfo></personnelChannelInfoList></personnelChannelGroupInfo></personnelChannelGroupInfoList><lastOpenDoorFlag>true</lastOpenDoorFlag><callNumber>101</callNumber></RemoteControlDoor>"; |
|
|
|
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); |
|
|
|
request.Method = "PUT"; |
|
|
|
request.ContentType = "application/xml"; |
|
|
|
request.Credentials = new NetworkCredential(username, password); |
|
|
|
byte[] byteArray = Encoding.UTF8.GetBytes(data); |
|
|
|
request.ContentLength = byteArray.Length; |
|
|
|
Stream dataStream = request.GetRequestStream(); |
|
|
|
dataStream.Write(byteArray, 0, byteArray.Length); |
|
|
|
dataStream.Close(); |
|
|
|
HttpWebResponse response; |
|
|
|
|
|
|
|
try |
|
|
|
{ |
|
|
|
response = (HttpWebResponse)request.GetResponse(); |
|
|
|
} |
|
|
|
catch (WebException ex) |
|
|
|
{ |
|
|
|
response = (HttpWebResponse)ex.Response; |
|
|
|
} |
|
|
|
//Console.WriteLine("Response status: {0}", response.StatusDescription); |
|
|
|
dataStream = response.GetResponseStream(); |
|
|
|
StreamReader reader = new StreamReader(dataStream); |
|
|
|
|
|
|
|
string responseFromServer = reader.ReadToEnd(); |
|
|
|
|
|
|
|
//Console.WriteLine(responseFromServer); |
|
|
|
reader.Close(); |
|
|
|
dataStream.Close(); |
|
|
|
|
|
|
|
response.Close(); |
|
|
|
return "开门成功"; |
|
|
|
} |
|
|
|
return "未找到设备"; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static void CloseDoor(string id) |
|
|
|
{ |
|
|
|
using (IDbConnection connmis = new SqlConnection(_misConnection)) |
|
|
|
{ |
|
|
|
//获取设备 |
|
|
|
var device = connmis.QueryFirstOrDefault<ADR_DeviceEntity>($"select * from ADR_Device where F_EnabledMark=1 and Id='{id}'"); |
|
|
|
if (device != null) |
|
|
|
{ |
|
|
|
string url = $"http://{device.IpAddress}/ISAPI/AccessControl/RemoteControl/door/1"; |
|
|
|
string username = device.AdminAccount; |
|
|
|
string password = device.AdminPwd; |
|
|
|
string data = $"<?xml version=\"1.0\" encoding=\"UTF-8\"?><RemoteControlDoor xmlns=\"http://www.isapi.org/ver20/XMLSchema\" version=\"2.0\"><cmd>close</cmd> <password>{device.AdminPwd}</password><employeeNo>1</employeeNo><channelNo>1</channelNo><controlType>monitor</controlType><personnelChannelGroupInfoList><personnelChannelGroupInfo><personnelChannelGroupID>1</personnelChannelGroupID><personnelChannelInfoList><personnelChannelInfo><personnelChannelID>1</personnelChannelID></personnelChannelInfo></personnelChannelInfoList></personnelChannelGroupInfo></personnelChannelGroupInfoList><lastOpenDoorFlag>true</lastOpenDoorFlag><callNumber>101</callNumber></RemoteControlDoor>"; |
|
|
|
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); |
|
|
|
request.Method = "PUT"; |
|
|
|
request.ContentType = "application/xml"; |
|
|
|
request.Credentials = new NetworkCredential(username, password); |
|
|
|
byte[] byteArray = Encoding.UTF8.GetBytes(data); |
|
|
|
request.ContentLength = byteArray.Length; |
|
|
|
Stream dataStream = request.GetRequestStream(); |
|
|
|
dataStream.Write(byteArray, 0, byteArray.Length); |
|
|
|
dataStream.Close(); |
|
|
|
HttpWebResponse response; |
|
|
|
|
|
|
|
try |
|
|
|
{ |
|
|
|
response = (HttpWebResponse)request.GetResponse(); |
|
|
|
} |
|
|
|
catch (WebException ex) |
|
|
|
{ |
|
|
|
response = (HttpWebResponse)ex.Response; |
|
|
|
} |
|
|
|
//Console.WriteLine("Response status: {0}", response.StatusDescription); |
|
|
|
dataStream = response.GetResponseStream(); |
|
|
|
StreamReader reader = new StreamReader(dataStream); |
|
|
|
|
|
|
|
string responseFromServer = reader.ReadToEnd(); |
|
|
|
|
|
|
|
//Console.WriteLine(responseFromServer); |
|
|
|
reader.Close(); |
|
|
|
dataStream.Close(); |
|
|
|
|
|
|
|
response.Close(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
#region 考勤结构体 |
|
|
|
/// <summary> |
|
|
|
/// 考勤设备日志 |
|
|
|