Browse Source

提交热敏打印

master
胡超1 1 year ago
parent
commit
01ecaecb13
  1. 12
      CPF_Cef/Common/ChunkedUpload.cs
  2. 181
      CPF_Cef/Devices/Fingerprint.cs
  3. 33
      CPF_Cef/Devices/PrintPJ.cs
  4. 81
      CPF_Cef/MainModel.cs
  5. 3
      CPF_Cef/Parame.cs

12
CPF_Cef/Common/ChunkedUpload.cs

@ -17,7 +17,7 @@ namespace AksWebBrowser.Common
public class ChunkedUpload public class ChunkedUpload
{ {
private readonly HttpClient _httpClient; private readonly HttpClient _httpClient;
public static string callback = string.Empty;
public ChunkedUpload(HttpClient httpClient) public ChunkedUpload(HttpClient httpClient)
{ {
_httpClient = httpClient; _httpClient = httpClient;
@ -93,13 +93,14 @@ namespace AksWebBrowser.Common
/// 获取签字版数据 /// 获取签字版数据
/// </summary> /// </summary>
/// <returns></returns> /// <returns></returns>
public async Task<string> PostSign() { public async Task PostSign(string type, string _callback)
string ret = string.Empty; {
try try
{ {
callback = _callback;
var client = new HttpClient(); var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, Parame.signUrl); var request = new HttpRequestMessage(HttpMethod.Post, Parame.signUrl);
var content = new StringContent("{\r\n command: \"sign\",\r\n command_num: 111,\r\n data: {\r\n operation: \"open\",\r\n operation_code: 1,\r\n parameters: {\r\n data_type: 1,\r\n title_name: \"\",\r\n }\r\n }\r\n }", null, "text/plain"); var content = new StringContent("{\r\n command: \"sign\",\r\n command_num: 111,\r\n data: {\r\n operation: \"" + type + "\",\r\n operation_code: 1,\r\n parameters: {\r\n data_type: 1,\r\n title_name: \"\",\r\n }\r\n }\r\n }", null, "text/plain");
request.Content = content; request.Content = content;
var response = await client.SendAsync(request); var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode(); response.EnsureSuccessStatusCode();
@ -107,14 +108,13 @@ namespace AksWebBrowser.Common
{ {
// 读取响应内容 // 读取响应内容
string body = await response.Content.ReadAsStringAsync(); string body = await response.Content.ReadAsStringAsync();
ret = body; Log.Info(body);
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
Log.Error("签字版post请求: " + ex.Message); Log.Error("签字版post请求: " + ex.Message);
} }
return ret;
} }
} }
} }

181
CPF_Cef/Devices/Fingerprint.cs

@ -1,21 +1,194 @@
using System; using AKSWebBrowser.Commen;
using CPF.Controls;
using CPF.Linux;
using CPF.Windows;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization;
using System.Linq; using System.Linq;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Timers;
namespace AksWebBrowser.Devices namespace AksWebBrowser.Devices
{ {
//apt-get install gcc-c++ libstdc++-devel //apt-get install gcc-c++ libstdc++-devel
public class Fingerprint public class Fingerprint
{ {
public Fingerprint(){} public static int td = -1, pnWidth = 0, pnHeight = 0, init = -1;
public static string callback = string.Empty, FileName = string.Empty;
//开启定时
public static System.Timers.Timer timer = new System.Timers.Timer(500);
public Fingerprint() { }
//读取指纹
public static string LIVESCANFinger(string _callback)
{
try
{
callback = _callback;
init = LibFingerprint.LIVESCAN_Init();
if (init == 1)
{
Log.Info("初始化指纹成功");
td = LibFingerprint.LIVESCAN_GetChannelCount();
if (td > 0)
{
Log.Info("获得采集器通道数量成功");
int pnBright = 254;
int status = LibFingerprint.LIVESCAN_GetBright(td, ref pnBright);
Log.Info(" 获得采集器当前的亮度:" + status);
Log.Info(" 获得采集器当前的亮度:" + pnBright);
int pnContrast = 254;
status = LibFingerprint.LIVESCAN_GetContrast(td, ref pnContrast);
Log.Info(" 获得采集器当前对比度:" + status);
Log.Info(" 获得采集器当前对比度:" + pnBright);
int pnWidth = 0, pnHeight = 0;
status = LibFingerprint.LIVESCAN_GetMaxImageSize(td, ref pnWidth, ref pnHeight);
Log.Info(" 获得采集器采集图像的宽度、高度的最大值:" + status);
Log.Info(" 获得采集器采集图像的宽度、高度的最大值:" + pnWidth + "*" + pnHeight);
byte[] pszDesc = new byte[1024];
status = LibFingerprint.LIVESCAN_GetDesc(pszDesc);
Log.Info("获得接口规范的说明:" + status);
Log.Info("获得接口规范的说明返回数据:" + Encoding.UTF8.GetString(pszDesc));
MessageBox.Show("转变采集");
string time = DateTime.Now.ToString("yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo);
FileName = "/tmp/" + time + ".bmp";
timer.Stop();
timer.Elapsed += OnTimedEvent;
timer.AutoReset = true;//重复执行
timer.Enabled = true;//启动定时器
}
else
{
Log.Info("获得采集器通道数量失败");
}
Task.Run(() =>
{
LibFingerprint.LIVESCAN_Close();
});
}
else
{
Log.Info("初始化指纹失败,错误代码:" + init);
}
}
catch (Exception ex)
{
if (init == 1)
{
Task.Run(() =>
{
LibFingerprint.LIVESCAN_Close();
});
}
Log.Error("读取指纹异常:" + ex.Message);
}
return "";
}
//定时任务
private static void OnTimedEvent(object sender, ElapsedEventArgs e)
{
try
{
int status = LibFingerprint.LIVESCAN_BeginCapture(td);
byte[] pRawData = new byte[pnWidth * pnHeight];
status = LibFingerprint.LIVESCAN_GetFPRawData(td, pRawData);
//status = LibFingerprint.LIVESCAN_GetFPBmpData(td, Encoding.UTF8.GetBytes(FileName));
if (status == 1)
{
Log.Info("采集一帧图像:" + Encoding.UTF8.GetString(pRawData));
Log.Info("获取指纹成功");
timer.Stop();
Log.Info("停止采集");
}
LibFingerprint.LIVESCAN_EndCapture(td);
}
catch (Exception ex)
{
Log.Error("定时读取指纹异常:" + ex.Message);
timer.Stop();
}
}
} }
class LibFingerprint class LibFingerprint
{ {
[DllImport("libmsprintsdk", EntryPoint = "SetInit", CharSet = CharSet.Ansi)] //初始化指纹
public static extern int SetInit(); [DllImport("libID_FprCap", EntryPoint = "LIVESCAN_Init", SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
public static extern int LIVESCAN_Init();
//关闭
[DllImport("libID_FprCap", EntryPoint = " LIVESCAN_Close", SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
public static extern int LIVESCAN_Close();
//获得采集器通道数量
[DllImport("libID_FprCap", EntryPoint = "LIVESCAN_GetChannelCount", SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
public static extern int LIVESCAN_GetChannelCount();
//设置采集器当前的亮度
[DllImport("libID_FprCap", EntryPoint = "LIVESCAN_SetBright", SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
public static extern int LIVESCAN_SetBright(int nChannel, int nBright);
//设置采集器当前对比度
[DllImport("libID_FprCap", EntryPoint = "LIVESCAN_SetContrast", SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
public static extern int LIVESCAN_SetContrast(int nChannel, int nContrast);
//获得采集器当前的亮度
[DllImport("libID_FprCap", EntryPoint = "LIVESCAN_GetBright", SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
public static extern int LIVESCAN_GetBright(int nChannel, ref int pnBright);
//获得采集器当前对比度
[DllImport("libID_FprCap", EntryPoint = "LIVESCAN_GetContrast", SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
public static extern int LIVESCAN_GetContrast(int nChannel, ref int pnContrast);
// 获得采集器采集图像的宽度、高度的最大值
[DllImport("libID_FprCap", EntryPoint = "LIVESCAN_GetMaxImageSize", SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
public static extern int LIVESCAN_GetMaxImageSize(int nChannel, ref int pnWidth, ref int pnHeight);
//获得当前图像的采集位置、宽度和高度
[DllImport("libID_FprCap", EntryPoint = "LIVESCAN_GetCaptWindow", SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
public static extern int LIVESCAN_GetCaptWindow(int nChannel, ref int pnOriginX, ref int pnOriginY, ref int pnWidth, ref int pnHeight);
//设置当前图像的采集位置、宽度和高度
[DllImport("libID_FprCap", EntryPoint = " LIVESCAN_SetCaptWindow", SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
public static extern int LIVESCAN_SetCaptWindow(int nChannel, int nOriginX, int nOriginY, int nWidth, int nHeight);
//调用采集器的属性设置对话框
[DllImport("libID_FprCap", EntryPoint = "LIVESCAN_Setup", SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
public static extern int LIVESCAN_Setup();
//采集器是否支持设置对话框
[DllImport("libID_FprCap", EntryPoint = "LIVESCAN_IsSupportSetup", SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
public static extern int LIVESCAN_IsSupportSetup();
//准备采集一帧图像
[DllImport("libID_FprCap", EntryPoint = "LIVESCAN_BeginCapture", SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
public static extern int LIVESCAN_BeginCapture(int nChannel);
//采集一帧图像
[DllImport("libID_FprCap", EntryPoint = " LIVESCAN_GetFPRawData", SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
public static extern int LIVESCAN_GetFPRawData(int nChannel, byte[] pRawData);
//采集一帧 BMP 格式图像数据
[DllImport("libID_FprCap", EntryPoint = " LIVESCAN_GetFPBmpData", SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
public static extern int LIVESCAN_GetFPBmpData(int nChannel, byte[] pBmpData);
//结束采集一帧图像
[DllImport("libID_FprCap", EntryPoint = " LIVESCAN_EndCapture", SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
public static extern int LIVESCAN_EndCapture(int nChannel);
//获得接口规范的说明
[DllImport("libID_FprCap", EntryPoint = " LIVESCAN_GetDesc", SetLastError = true, CharSet = CharSet.Auto, ExactSpelling = false, CallingConvention = CallingConvention.Cdecl)]
public static extern int LIVESCAN_GetDesc(byte[] pszDesc);
} }
} }

33
CPF_Cef/Devices/PrintPJ.cs

@ -69,23 +69,24 @@ namespace AksWebBrowser.Devices
/// <returns></returns> /// <returns></returns>
public int Print(string ph, string ddrs, string qrcode, string ywmc) public int Print(string ph, string ddrs, string qrcode, string ywmc)
{ {
StringBuilder sbData = new StringBuilder("");
try try
{ {
sbData = new StringBuilder(string.Format(" 您预约办理的{0}业务-,排号为:", ywmc)); //注册gb2312
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
string txt = string.Format(" 您预约办理的{0}业务-,排号为:", ywmc);
LibPrint.SetClean(); LibPrint.SetClean();
LibPrint.SetReadZKmode(0); LibPrint.SetReadZKmode(0);
LibPrint.SetAlignment(0); LibPrint.SetAlignment(0);
LibPrint.SetSizetext(2, 1); LibPrint.SetSizetext(2, 1);
LibPrint.SetLinespace(20); LibPrint.SetLinespace(20);
LibPrint.PrintString(sbData, 0); LibPrint.PrintString(Encoding.GetEncoding("gb2312").GetBytes(txt), 0);
LibPrint.PrintFeedDot(0);
//排号 //排号
LibPrint.SetAlignment(1); LibPrint.SetAlignment(1);
LibPrint.SetBold(1); LibPrint.SetBold(1);
LibPrint.SetSizetext(2, 2); LibPrint.SetSizetext(2, 2);
sbData = new StringBuilder(ph); LibPrint.PrintString(Encoding.GetEncoding("gb2312").GetBytes(ph), 0);
LibPrint.PrintString(sbData, 0);
LibPrint.SetAlignment(0); LibPrint.SetAlignment(0);
LibPrint.SetBold(0); LibPrint.SetBold(0);
@ -93,32 +94,30 @@ namespace AksWebBrowser.Devices
LibPrint.PrintFeedDot(10); LibPrint.PrintFeedDot(10);
//等候 //等候
sbData = new StringBuilder(string.Format("您前面有 {0} 人等候,注意业务窗口的呼叫号码信息。过号请重新取号。", ddrs)); txt = string.Format("您前面有 {0} 人等候,注意业务窗口的呼叫号码信息。过号请重新取号。", ddrs);
LibPrint.PrintString(sbData, 1); LibPrint.PrintString(Encoding.GetEncoding("gb2312").GetBytes(txt), 1);
LibPrint.PrintFeedDot(60); LibPrint.PrintFeedDot(60);
//二维码 //二维码
LibPrint.SetClean(); LibPrint.SetClean();
LibPrint.SetCommandmode(10); LibPrint.SetCommandmode(10);
LibPrint.SetAlignment(1); LibPrint.SetAlignment(1);
LibPrint.SetLeftmargin(-60); LibPrint.SetLeftmargin(-40);
sbData = new StringBuilder(qrcode); LibPrint.PrintQrcode(Encoding.GetEncoding("gb2312").GetBytes(qrcode), 0, 8, 1);
LibPrint.PrintQrcode(sbData, 2, 6, 1);
LibPrint.PrintRemainQR(); LibPrint.PrintRemainQR();
LibPrint.PrintFeedDot(100); LibPrint.PrintFeedDot(80);
//时间 //时间
LibPrint.SetClean(); LibPrint.SetClean();
LibPrint.SetSizetext(0, 0); LibPrint.SetSizetext(0, 0);
LibPrint.SetAlignment(2); LibPrint.SetAlignment(2);
sbData = new StringBuilder(DateTime.Now.ToLocalTime().ToString()); LibPrint.PrintString(Encoding.GetEncoding("gb2312").GetBytes(DateTime.Now.ToLocalTime().ToString()), 1);
LibPrint.PrintString(sbData, 1); LibPrint.PrintFeedDot(140);
LibPrint.PrintFeedDot(190);
LibPrint.PrintFeedDot(200);
LibPrint.PrintCutpaper(0); LibPrint.PrintCutpaper(0);
} }
catch (Exception ex) catch (Exception ex)
{ {
Log.Error("票据打印失败:"+ex.Message);
return 1; return 1;
} }
return 0; return 0;
@ -188,7 +187,7 @@ namespace AksWebBrowser.Devices
public static extern int SetDevname(int iDevtype, byte[] cDevname, int iBaudrate); public static extern int SetDevname(int iDevtype, byte[] cDevname, int iBaudrate);
[DllImport("libmsprintsdk", EntryPoint = "PrintString", CharSet = CharSet.Ansi)] [DllImport("libmsprintsdk", EntryPoint = "PrintString", CharSet = CharSet.Ansi)]
public static extern int PrintString(StringBuilder strData, int iImme); public static extern int PrintString(byte[] strData, int iImme);
[DllImport("libmsprintsdk", EntryPoint = "PrintFeedline", CharSet = CharSet.Ansi)] [DllImport("libmsprintsdk", EntryPoint = "PrintFeedline", CharSet = CharSet.Ansi)]
public static extern int PrintFeedline(int iLine); public static extern int PrintFeedline(int iLine);
@ -221,7 +220,7 @@ namespace AksWebBrowser.Devices
public static extern int PrintDiskimgfile(StringBuilder strData); public static extern int PrintDiskimgfile(StringBuilder strData);
[DllImport("libmsprintsdk", EntryPoint = "PrintQrcode", CharSet = CharSet.Ansi)] [DllImport("libmsprintsdk", EntryPoint = "PrintQrcode", CharSet = CharSet.Ansi)]
public static extern int PrintQrcode(StringBuilder strData, int iLmargin, int iMside, int iRound); public static extern int PrintQrcode(byte[] strData, int iLmargin, int iMside, int iRound);
[DllImport("libmsprintsdk", EntryPoint = "PrintRemainQR", CharSet = CharSet.Ansi)] [DllImport("libmsprintsdk", EntryPoint = "PrintRemainQR", CharSet = CharSet.Ansi)]
public static extern int PrintRemainQR(); public static extern int PrintRemainQR();

81
CPF_Cef/MainModel.cs

@ -27,6 +27,7 @@ using System.Web;
using System.Xml.Linq; using System.Xml.Linq;
using static System.Net.Mime.MediaTypeNames; using static System.Net.Mime.MediaTypeNames;
using AksWebBrowser.Devices; using AksWebBrowser.Devices;
using System.Reflection;
namespace AKS.EnterpriseLibrary.WebBrowser namespace AKS.EnterpriseLibrary.WebBrowser
{ {
@ -50,9 +51,9 @@ namespace AKS.EnterpriseLibrary.WebBrowser
{ {
try try
{ {
//Finger("","");
IDCard iDCard = new IDCard(); IDCard iDCard = new IDCard();
string result = iDCard.getIdCard(); string result = iDCard.getIdCard();
Log.Info(result);
SubmitLogs(result, "IDCardRead"); SubmitLogs(result, "IDCardRead");
return result; return result;
} }
@ -355,10 +356,9 @@ namespace AKS.EnterpriseLibrary.WebBrowser
} }
else else
{ {
Task.Run(() => HttpPostResponseBySign("open", callback));
sign.OpenComDevice(callback); string result = "{\"callback\":\"" + callback + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"suffix\":\"jpg\",\"data\":\"" + "签字版已打开" + "\"}";
string result = "{\"callback\":\"" + callback + "\",\"message\":\"success\",\"code\":\"200\",\"status\":true,\"suffix\":\"png\",\"data\":\"" + "成功" + "\"}"; SubmitLogs(result, "openCamera");
SubmitLogs(result, "OpenSign");
return result; return result;
} }
} }
@ -371,6 +371,38 @@ namespace AKS.EnterpriseLibrary.WebBrowser
} }
} }
/// <summary>
/// 指纹
/// </summary>
/// <param name="paramsString"></param>
/// <returns></returns>
[JSFunction]
public string Finger(string paramsString, string callback)
{
try
{
if (false)//!isFuncisFuncObject("Finger")
{
Utils.MessagesBox("指纹设备未授权使用");
return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "指纹设备未授权使用" + "\"}";
}
else
{
string result = Fingerprint.LIVESCANFinger(callback);
SubmitLogs(result, "Finger");
return result;
}
}
catch (Exception ex)
{
Log.Error("指纹异常: " + ex.Message + "");
string result = "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + ex.Message + "\"}";
SubmitLogs(result, "Finger");
return result;
}
}
/// <summary> /// <summary>
/// 关闭签字版 /// 关闭签字版
/// </summary> /// </summary>
@ -386,10 +418,6 @@ namespace AKS.EnterpriseLibrary.WebBrowser
Utils.MessagesBox("签字版设备未授权使用"); Utils.MessagesBox("签字版设备未授权使用");
return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "签字版设备未授权使用" + "\"}"; return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "签字版设备未授权使用" + "\"}";
} }
else if (Parame.tcpClient == null)
{
return "{\"message\":\"fali\",\"code\":\"400\",\"status\":false,\"data\":\"" + "硬件服务未启动" + "\"}";
}
else else
{ {
//paramsString = "{\"callback\":\"" + callback + "\",\"type\":\"7\",\"param\":{\"data\":\"" + "" + "\"}}"; //paramsString = "{\"callback\":\"" + callback + "\",\"type\":\"7\",\"param\":{\"data\":\"" + "" + "\"}}";
@ -1052,46 +1080,15 @@ namespace AKS.EnterpriseLibrary.WebBrowser
@event6.Set(); @event6.Set();
} }
/// <summary>
/// 获取签字版base64
/// </summary>
/// <returns></returns>
public string GetSignBase64()
{
//获取设备信息
Task.Run(() => HttpPostResponseBySign());
@event6.WaitOne();
if (string.IsNullOrEmpty(qzbStr))
{
return "";
}
else
{
JObject jo = (JObject)JsonConvert.DeserializeObject(qzbStr);
if (jo["code"].ToString() == "0")
{
return jo["data"].ToString();
}
else
{
Log.Info(jo["returnMsg"].ToString());
return "";
}
}
}
/// <summary> /// <summary>
/// 签字版 /// 签字版
/// </summary> /// </summary>
private string qzbStr = string.Empty; private async void HttpPostResponseBySign(string type,string callback)
private AutoResetEvent @event7 = new AutoResetEvent(false);
private async void HttpPostResponseBySign()
{ {
var httpClient = new HttpClient(); var httpClient = new HttpClient();
var uploader = new ChunkedUpload(httpClient); var uploader = new ChunkedUpload(httpClient);
qzbStr = await uploader.PostSign(); await uploader.PostSign(type, callback);
@event7.Set();
} }
/// <summary> /// <summary>

3
CPF_Cef/Parame.cs

@ -24,7 +24,8 @@ namespace AksWebBrowser
//签字版 //签字版
public static string signUrl = "http://127.0.0.1:9399/device"; public static string signUrl = "http://127.0.0.1:9399/device";
//票据打印机 //票据打印机
public static string pritPj = "/dev/ttyUSB7"; public static string pritPj = "/dev/ttyS7";
//波特率
public static int pritPjPort = 38400; public static int pritPjPort = 38400;
} }
public struct Func public struct Func

Loading…
Cancel
Save