Browse Source

开门接口

master
dao 1 month ago
parent
commit
7459217670
2 changed files with 126 additions and 2 deletions
  1. +103
    -0
      DigitalSchoolApi/Controllers/HKAttendanceController.cs
  2. +23
    -2
      DigitalSchoolApi/Controllers/YKTController.cs

+ 103
- 0
DigitalSchoolApi/Controllers/HKAttendanceController.cs View File

@@ -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>
/// 考勤设备日志


+ 23
- 2
DigitalSchoolApi/Controllers/YKTController.cs View File

@@ -6,6 +6,8 @@ using System.Data.SqlClient;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using System.Web.Http;
using Dapper;
using DigitalSchoolApi.Models;
@@ -14,7 +16,7 @@ using Learun.Application.Organization;

namespace DigitalSchoolApi.Controllers
{
public class YKTController : BaseController
public class YKTController : BaseController
{
private readonly static string _admsConnection = ConfigurationManager.ConnectionStrings["CoreDBString"].ConnectionString;
private readonly static string _misConnection = ConfigurationManager.ConnectionStrings["ConnectionPfcMisDBString"].ConnectionString;
@@ -273,6 +275,25 @@ namespace DigitalSchoolApi.Controllers
RecurringJob.RemoveIfExists("LeaderAttendance");
return Ok();
}
/// <summary>
/// 开门(延迟5秒后调用关门)
/// </summary>
/// <returns></returns>
public IHttpActionResult OpenCloseDoor(string id,bool c)
{
var r = HKAttendanceController.OpenDoor(id);

if (c)
{
Task.Factory.StartNew(() =>
{

Thread.Sleep(5000);
HKAttendanceController.CloseDoor(id);
});
}
return Ok(r);
}

#region 长阳报名\晚归预警
/// <summary>
@@ -590,7 +611,7 @@ namespace DigitalSchoolApi.Controllers
() => TLMSchoolController.AssignSendEmail(entityList),
Cron.Daily(entityList[0].F_Hour.Value), TimeZoneInfo.Local);
}
}
}
}


Loading…
Cancel
Save