123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589 |
- 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
- {
- /// <summary>
- /// IdCheckViewer.xaml 的交互逻辑
- /// </summary>
- public partial class IdCheckViewer
- {
- #region Ctor
- /// <summary>
- /// 核查完毕后是否联动人脸识别
- /// </summary>
- 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<string, string> { { "公民身份证号码与姓名一致,且存在照片", "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<string, string> {
- { "公民身份号码与姓名一致,且存在照片", "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<string, string> { { "是", "1" }, { "否", "0" } });
- sfhcxx.Height = 230;
- grade.Width = 400;
- }
- }
- #endregion
-
- #region Property
- /// <summary>
- /// 核查的主体信息
- /// </summary>
- public IdentityCardEntity Info { get; private set; }
-
- /// <summary>
- /// 核查结果
- /// </summary>
- public IdCheckerResult Record { get; private set; }
- #endregion
-
- #region Internal
- /// <summary>
- /// 15位身份证转换成18位
- /// </summary>
- /// <param name="StrCard15">15位身份证</param>
- /// <param name="StrYear">出生年份</param>
- /// <returns></returns>
- 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);
- }
-
- /// <summary>
- /// 根据17位号生成校验位
- /// </summary>
- /// <param name="StrCard17"></param>
- /// <returns></returns>
- 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();
- }
-
- /// <summary>
- /// 解析图像数据
- /// </summary>
- /// <param name="imageStream"></param>
- 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();
- }
- }
-
- /// <summary>
- /// 联网核查
- /// </summary>
- 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<string, string> { { "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;
- }
- }
-
- }
-
-
- }
- }
- /// <summary>
- /// 授权方法
- /// </summary>
- /// <param name="msg"></param>
- /// <returns></returns>
- 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;
- }
- }
- }
-
- /// <summary>
- /// 核查记录
- /// </summary>
- public class IdCheckerResult
- {
- /// <summary>
- /// 是否联网核查
- /// </summary>
- public bool IsOnline { get; internal set; }
-
- /// <summary>
- /// 是否完成核查 - 注意当IsOnline为false时,该值必定为true
- /// </summary>
- public bool IsComplated { get; internal set; }
-
- /// <summary>
- /// 人脸比对拒绝标志
- /// </summary>
- public bool Reject2RLSB { get; internal set; }
-
- /// <summary>
- /// 核查结果 - 结果参考 UserVariable.GetIdCheckResultType()
- /// </summary>
- public string Result { get; internal set; }
-
- /// <summary>
- /// 核查结果值
- /// </summary>
- public string ResultKey { get; internal set; }
-
- /// <summary>
- /// 核查原因
- /// </summary>
- public string Reason { get; internal set; }
-
- /// <summary>
- /// 核查种类 - 结果参考 UserVariable.GetIdCheckReasonType()
- /// </summary>
- public string Type { get; internal set; }
-
- /// <summary>
- /// 身份证号码
- /// </summary>
- public string IdNumber { get; internal set; }
-
- /// <summary>
- /// 姓名
- /// </summary>
- public string Name { get; internal set; }
-
- /// <summary>
- /// 签发机构
- /// </summary>
- public string IssuingAuthority { get; internal set; }
-
- /// <summary>
- /// 从身份证读卡器设备上拿取的信息集合
- /// </summary>
- public IdentityCardEntity DeviceInfo { get; internal set; }
- }
- }
-
-
-
-
|