using System; using System.Windows; using System.Windows.Media; using System.Windows.Media.Imaging; using System.IO; using System.Text.RegularExpressions; using Platform.Controls.ControlsHelper; using Platform.Library; using TellerSystem.Communication; using TellerSystem.Library.Ext.Function; using Platform.Common.RunningParameters; using TellerSystem.ServiceProxy.Ext.ServiceEntitys; using TellerSystem.Devices.Interface; using TellerSystem.Library.Ext.Variables; using TellerSystem.Controls.Ext.PrintsHelper; using TellerSystem.Library.Ext.TradeExtension; using TellerSystem.PrintTemplate.Extension; using System.Windows.Controls; using System.Printing; using Platform.Print; using TellerSystem.ServiceProxy.Ext.ServiceHelper; using System.Collections.Generic; using System.Drawing; using System.ComponentModel; using TellerSystem.ServiceProxy.Ext; using TellerSystem.Controls.Ext.ControlsHelper; using System.Diagnostics; using System.Text; using TellerSystem.ServiceProxy.Ext.WebAPI.Auth.Entity; using System.Net; using System.Net.Cache; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using TellerSystem.Contract.Function; /******************************平台Dll*****************************/ namespace TellerSystem.Controls.Ext.Controls { /// /// IdCheckViewer.xaml 的交互逻辑 /// public partial class IdCheckViewer { #region Ctor /// /// 核查完毕后是否联动人脸识别 /// public bool Link2RLSB { get; private set; } public IdCheckViewer(IdentityCardEntity info, bool RLSB = true) { InitializeComponent(); Link2RLSB = RLSB; Info = info; Record = new IdCheckerResult(); Record.DeviceInfo = info; Record.IsOnline = SystemSettingsHelper.Instance.IsIdCheck; } string FLAG = TradeManagerHandle.TT_SYSCONFIG_GetConfigValueByConfigID("2ea3a7e6cfa04f89a335bf1e363295de"); private void TradePage_Loaded(object sender, RoutedEventArgs e) { /* 初始化界面逻辑,页面加载后执行*/ if (this.Info != null) { tb_txtID.Text = Info.IdNumber.Trim(); tb_txtID.IsReadOnly = true; if (!string.IsNullOrEmpty(Info.Name)) { tb_txtName.Text = Info.Name.Trim(); tb_txtName.IsReadOnly = true; } if (Info.MyProperty != null) imgPhoto_device.Source = Info.MyProperty; } this.TradeAPIs.SetItems(cb_busType, UserVariable.GetIdCheckReasonType()); cbb_Result.SetItems(new Dictionary { { "公民身份证号码与姓名一致,且存在照片", "00" }, { "公民身份证号码与姓名一致,但不存在照片", "01" }, { "公民身份证号码存在,但与姓名不一致", "02" }, { "公民身份证号码不存在", "03" }, { "其他错误", "04" }, { "输入的参数有误", "05" }, { "认证码错误", "06" } }); if (FLAG == "V0" || FLAG == "V2" || FLAG == "V3" || FLAG == "V4" || FLAG == "V23" || FLAG == "V24") //郑银接入联网核查 { cbb_Result.SetItems(new Dictionary { { "公民身份号码与姓名一致,且存在照片", "00" }, { "公民身份号码与姓名一致,但不存在照片", "01" }, { "公民身份证号码存在,但与姓名不匹配", "02" }, { "公民身份证号码不存在", "03" }, { "其他错误", "04" }, { "输入的参数有误", "05" }, { "上传机构代码错误", "06" }, { "身份证信息一致,照片相符(文字+相片)", "07" }, { "公民姓名与身份证号码一致,相片不一致(文字+相片)", "08" }, { "公民姓名与身份证号码一致(文字)", "09" }, { "非最新证件", "10" } }); } if (AICapacity.GetInstence().IsOpen && string.Compare(this.TradeAPIs.GetTradeMetadata("isRlsb"), "true", true) == 0) { tl_grade.Visibility = grade.Visibility = Visibility.Visible; } if (AICapacity.GetInstence().IsOpen && FLAG != "V5" && string.Compare(this.TradeAPIs.GetTradeMetadata("isRlsb"), "true", true) == 0) { cb_rlbd.Visibility = tbrlbd.Visibility = Visibility.Visible; cb_rlbd.SetItems(new Dictionary { { "是", "1" }, { "否", "0" } }); sfhcxx.Height = 230; grade.Width = 400; } } #endregion #region Property /// /// 核查的主体信息 /// public IdentityCardEntity Info { get; private set; } /// /// 核查结果 /// public IdCheckerResult Record { get; private set; } #endregion #region Internal /// /// 15位身份证转换成18位 /// /// 15位身份证 /// 出生年份 /// private string Convert15to18(string StrCard15, string StrYear) { if (StrCard15 == null || StrCard15.Length != 15) { return StrCard15; } string year = "19"; if (!string.IsNullOrEmpty(StrYear) && StrYear.Length == 2) { year = StrYear; } //生成17位号 String StrCard17 = StrCard15.Substring(0, 6) + year + StrCard15.Substring(6); //计算校验位,返回18位号 return StrCard17 + GetLastNumber(StrCard17); } /// /// 根据17位号生成校验位 /// /// /// private string GetLastNumber(string StrCard17) { //权重值 int[] WI = { 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2, 1 }; string Str18 = "10X98765432"; int num = 0; for (int i = 0; i < 17; i++) { num += int.Parse(StrCard17[i].ToString()) * WI[i]; } num = num % 11; return Str18[num].ToString(); } /// /// 解析图像数据 /// /// private ImageSource CreateImage(String imageStream) { ImageSource ret = null; try { if (!string.IsNullOrEmpty(imageStream)) { //把BASE64转码字符串,转成byte数组 byte[] arr = Convert.FromBase64String(imageStream); //定义流 MemoryStream ms = new MemoryStream(arr); var bitImg = new BitmapImage(); bitImg.BeginInit(); //ms.Seek(0, SeekOrigin.Begin); bitImg.StreamSource = ms; bitImg.EndInit(); ret = bitImg; } } catch (Exception e) { this.ShowWarnMessageBox("加载身份照片数据出错!");//.ShowMessageBox("转换照片出错"); } return ret; } #endregion #region Event private void txtID_LostFocus(object sender, RoutedEventArgs e) { if (tb_txtID.Text.Trim().Length == 15) { tb_txtID.Text = Convert15to18(tb_txtID.Text.Trim(), "19"); } } private void InputName_LostFocus(object sender, RoutedEventArgs e) { Regex rx = new Regex("^.+$"); if (!rx.IsMatch(tb_txtName.Text)) { this.ShowMessageBox("请输入合法的姓名!"); this.SetFocus(); } } /// /// 联网核查 /// private void btnCheck_Click(object sender, RoutedEventArgs e) { #region 注释调以前默认核查成功代码 ///add by likai 20141020 start ///衡水演示隐掉喝茶通讯,默认成功 //cbb_Result.SetSelectedValue("0"); //tb_IssuingAuthority.Text = Info.IssuingAuthority; //tb_NameResult.Text = tb_txtName.Text; //tb_IdNumber.Text = tb_txtID.Text; ////填充返回数据和打印数据 //Record.IsComplated = cbb_Result.GetSelectedValue() == "0" || cbb_Result.GetSelectedValue() == "1"; //Record.Result = cbb_Result.GetSelectedValue(); //_print.Result = cbb_Result.GetSelectedKey(); //Record.Type = cb_busType.GetSelectedValue(); //_print.Type = cb_busType.GetSelectedKey(); //Record.IdNumber = _print.Number = tb_IdNumber.Text.Trim(); //Record.Name = _print.Name = tb_NameResult.Text.Trim(); //Record.IssuingAuthority = _print.Branch = tb_IssuingAuthority.Text.Trim(); //_print.Reason = tb_reason.Text.Trim(); //if (Record.IsComplated) //{ // btnPrint.IsEnabled = true; // this.SetFocus(btnBack); //} ///add by likai 20141020 end /****************** //核查交易 var msg = new Message(Message.BitMap.Agn); this.CommSend(msg); msg.Fd16 = "0001"; msg.Fd60 = "IDC"; msg.Fd89 = cb_busType.SelectedValue.ToString(); msg.Fd27 = LoginUserInfo.TellerNo; msg.Fd62 = tb_txtID.Text; msg.Fd25 = tb_txtName.Text; //渠道无法连接,用于考试系统 if (!ExamSystem.Instance.InExamMode) { this.CallAgnIDC(msg); } else { msg.Fd12 = "0000"; msg.Fd90 = "00"; msg.Fd82 = "河北市承德"; msg.Fd25 = tb_txtName.Text; msg.Fd62 = tb_txtID.Text; msg.FileData = string.Empty; } if (msg.Fd12 != "0000") { this.ShowErrorMessageBox(this.GetError(msg)); this.SetFocus(); return; } //解析结果 注意 核心改成了1位标识 cbb_Result.SetSelectedValue(msg.Fd90.Trim()[1]); tb_IssuingAuthority.Text = msg.Fd82; tb_NameResult.Text = msg.Fd25; tb_IdNumber.Text = msg.Fd62; if (cbb_Result.GetSelectedValue() == "0") { imgPhoto.Source = CreateImage(msg.FileData); _print.Photo = msg.FileData; } //填充返回数据和打印数据 Record.IsComplated = cbb_Result.GetSelectedValue() == "0" || cbb_Result.GetSelectedValue() == "1"; Record.Result = cbb_Result.GetSelectedValue(); _print.Result = cbb_Result.GetSelectedKey(); Record.Type = cb_busType.GetSelectedValue(); _print.Type = cb_busType.GetSelectedKey(); Record.IdNumber = _print.Number = tb_IdNumber.Text.Trim(); Record.Name = _print.Name = tb_NameResult.Text.Trim(); Record.IssuingAuthority = _print.Branch = tb_IssuingAuthority.Text.Trim(); _print.Reason = tb_reason.Text.Trim(); if (Record.IsComplated) { btnPrint.IsEnabled = true; this.SetFocus(btnPrint); } * ******************/ #endregion Message message = new Message(Message.BitMap.Agn); this.InitFd(message); this.CommSend(message); if (FLAG == "V9") {//辰州汇通 message.Fd16 = "1011";//交易代码 message.Fd18 = "IDCK"; message.Fd25 = tb_txtName.Text.Trim();//户名 message.Fd62 = tb_txtID.Text.Trim();//身份证号 message.Fd24 = cb_busType.GetSelectedValue();//业务类型 this.TradeAPIs.CallAgnSHCZ(message); if (message.Fd12 != "0000") { this.TradeAPIs.ShowInfoMessageBox("身份核查不通过!"); this.SetFocus(); return; } tb_NameResult.Text = message.Fd25; tb_IssuingAuthority.Text = message.Fd82; cbb_Result.SetSelectedValue(message.Fd28.Trim()); tb_IdNumber.Text = message.Fd62; } else { //message.Fd16 = "7077"; //message.Fd25 = tb_txtName.Text; //message.Fd62 = tb_txtID.Text; //this.CallAgn(message); #region 调用平台核查 //var msg = new Message(Message.BitMap.Agn); //this.TradeAPIs.InitFd(msg); //this.TradeAPIs.CommSend(msg); //msg.Fd4 = this.CreateSerialNumber(); message.Fd16 = "2001"; message.Fd18 = "C101"; message.Fd24 = string.IsNullOrEmpty(Info.Name) ? "0" : "1";//证件号录入方式 手工 0 、设备 1 message.Fd23 = this.TradeAPIs.GetSelectedValue(cb_busType); message.Fd26 = LoginUserInfo.TellerNo; message.Fd62 = tb_txtID.Text; message.Fd25 = tb_txtName.Text; this.TradeAPIs.CallAgnIDC(message); if (message.Fd12 != "0000") { this.TradeAPIs.ShowInfoMessageBox(string.IsNullOrWhiteSpace(message.Fd13) ? this.TradeAPIs.GetError(message) : message.Fd13); this.TradeAPIs.SetFocus(); return; } cbb_Result.SetSelectedValue(message.Fd89.Trim()); tb_IssuingAuthority.Text = message.Fd83;//签发机关 tb_NameResult.Text = message.Fd25; tb_IdNumber.Text = message.Fd62; //if (message.Fd89.Trim() != "00" || string.IsNullOrWhiteSpace(message.FileData)) return; //try //{ // //把BASE64转码字符串,转成byte数组 // photo = message.FileData; // var arr = Convert.FromBase64String(message.FileData); // //定义流 // var ms = new MemoryStream(arr); // var bitImg = new BitmapImage(); // bitImg.BeginInit(); // ms.Seek(0, SeekOrigin.Begin); // bitImg.StreamSource = ms; // bitImg.EndInit(); // imgPhoto.Source = bitImg; //} //catch //{ // this.TradeAPIs.ShowInfoMessageBox("转换照片出错!"); //} #endregion } btnPrint.IsEnabled = true; this.SetFocus(btnPrint); if (cbb_Result.GetSelectedValue() == "00") { imgPhoto.Source = CreateImage(message.FileData); _print.Photo = message.FileData; } //填充返回数据和打印数据 Record.IsComplated = cbb_Result.GetSelectedValue() == "00" || cbb_Result.GetSelectedValue() == "01"; Record.Result = cbb_Result.GetSelectedValue(); Record.ResultKey = cbb_Result.GetSelectedKey(); _print.Result = cbb_Result.GetSelectedKey(); Record.Type = cb_busType.GetSelectedValue(); _print.Type = cb_busType.GetSelectedKey(); Record.IdNumber = _print.Number = tb_IdNumber.Text.Trim(); Record.Name = _print.Name = tb_NameResult.Text.Trim(); Record.IssuingAuthority = _print.Branch = tb_IssuingAuthority.Text.Trim(); _print.Reason = tb_reason.Text.Trim(); _print.frontPhoto = Info.FrontImg == null ? "" : Info.FrontImg; _print.BackPhoto = Info.BackImg == null ? "" : Info.BackImg; //人脸比对 if (Link2RLSB && AICapacity.GetInstence().IsOpen && string.Compare(this.TradeAPIs.GetTradeMetadata("isRlsb"), "true", true) == 0 && (FLAG == "V5" || (FLAG != "V5" && cb_rlbd.GetSelectedValue() == "1"))) { //身份核查返回的客户照片 img_SFHC = message.FileData; result = ""; ret = false; var ext = new AICapacity.ExtData(this.CreateSerialNumber(), new Dictionary { { "idno", Record.IdNumber }, { "name", Record.Name }, { "trade", this.TradeInfo.TradeCode } }); this.OwnerContainer.ModalInvoke(new Action(() => { ret = AICapacity.GetInstence().GetResultFromRLBD(img_SFHC, out result, ext); }), "正在人脸比对中..."); grade.Text = result; _print.Grade = grade.Text; if (ret != true) { Record.Reject2RLSB = true; if (FLAG == "V8") { if (this.TradeAPIs.ShowQuestionMessageBox("人脸比对不通过是否进行授权操作?") == MessageBoxResult.Yes) { if (AuthAction(new Message() { Fd96_W = "airlsb" })) Record.Reject2RLSB = false; } } else { if (this.TradeAPIs.ShowQuestionMessageBox("人脸比对不通过是否进行授权操作?") == MessageBoxResult.Yes) { if (AuthAction(new Message() { Fd96_W = "fd96w" })) Record.Reject2RLSB = false; } } } } } /// /// 授权方法 /// /// /// private bool AuthAction(Message msg) { // 组织授权检查要素 TellerSystem.ServiceProxy.Ext.ServiceEntitys.PageData[] page = new TellerSystem.ServiceProxy.Ext.ServiceEntitys.PageData[1]; page[0] = new TellerSystem.ServiceProxy.Ext.ServiceEntitys.PageData() { index = 1, datas = this.SaveTradePage((FrameworkElement)this.Content) }; AuthConditionElement element = new AuthConditionElement(); AuthManager c = new AuthManager(); c.AsksuperResultMessage += new AuthManager.AsksuperResultHandle(AsksuperResultMessage); return c.DoAuth(this, element, msg, page, "0", "", "", "", "", "人脸比对", ""); } private void AsksuperResultMessage(AsksuperResultType result, TradeBusData busData) { switch (result) { case AsksuperResultType.Success: this.ShowMessageBox("授权已经通过。"); break; case AsksuperResultType.Failed: this.ShowMessageBox("授权没有通过。"); break; case AsksuperResultType.Undo: this.ShowMessageBox("授权已撤销。"); break; default: break; } } private Print_IdChecker.Print_IdCheckerEntry _print = new Print_IdChecker.Print_IdCheckerEntry(); private string img_SFHC; private string result; private bool? ret; private void btnPrint_Click(object sender, RoutedEventArgs e) { try { var p = new Print_IdChecker(_print); p.PrintData.LoadData(this, new Message()); PrintContainerExt.SetPrintElement(p, this.GetPrintAttributes()); p.LoadPrintData(); var xpsFile = p.PrintToXps(); this.IsHitTestVisible = false; var dialog = new PrintDialog(); var flag = dialog.ShowDialog(); this.IsHitTestVisible = true; if (flag == true) { PrintManager.SendToPrinter(xpsFile, p.ActualWidth, p.ActualHeight, "联网核查打印", dialog.PrintQueue.FullName); //dialog.PrintQueue.AddJob("联网核查打印", xpsFile.FullName, false); //var xpsWriter = PrintQueue.CreateXpsDocumentWriter(dialog.PrintQueue); //xpsWriter.Write(xpsFile.FullName); this.SetFocus(btnBack); } } catch { this.ShowErrorMessageBox("打印发生异常!"); } //this.PrintCertificate(new Platform.Print.PrintContainer[] { p }); } private void btnBack_Click(object sender, RoutedEventArgs e) { this.Close(); } #endregion private void cb_rlbd_LostFocus(object sender, RoutedEventArgs e) { if (cb_rlbd.GetSelectedValue() == "1") grade.Visibility = tl_grade.Visibility = Visibility.Visible; else { grade.Visibility = tl_grade.Visibility = Visibility.Collapsed; grade.Text = string.Empty; } } } /// /// 核查记录 /// public class IdCheckerResult { /// /// 是否联网核查 /// public bool IsOnline { get; internal set; } /// /// 是否完成核查 - 注意当IsOnline为false时,该值必定为true /// public bool IsComplated { get; internal set; } /// /// 人脸比对拒绝标志 /// public bool Reject2RLSB { get; internal set; } /// /// 核查结果 - 结果参考 UserVariable.GetIdCheckResultType() /// public string Result { get; internal set; } /// /// 核查结果值 /// public string ResultKey { get; internal set; } /// /// 核查原因 /// public string Reason { get; internal set; } /// /// 核查种类 - 结果参考 UserVariable.GetIdCheckReasonType() /// public string Type { get; internal set; } /// /// 身份证号码 /// public string IdNumber { get; internal set; } /// /// 姓名 /// public string Name { get; internal set; } /// /// 签发机构 /// public string IssuingAuthority { get; internal set; } /// /// 从身份证读卡器设备上拿取的信息集合 /// public IdentityCardEntity DeviceInfo { get; internal set; } } }