WS人像比对接口的开发:鉴于网上都是的JAVA成熟案例,走了很多弯路,mark一下送给.net开发的小伙伴!
开发前请先阅读如下的pdf文档:
全国人口信息社会应用平台WebService接口调用规范V2.3-4777.pdf
废话不多说,直接上干活。关于NciicServers.dll的生成 请参考我的上一篇博客!
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; using NciicServices; using System.Drawing; using System.Xml; namespace NciicDemo { class Program { static void Main(string[] args) { NciicServices.NciicServices services = new NciicServices.NciicServices(); string inLicense = ""; string inConditions = ""; StreamReader sr = new StreamReader("../../Content/授权文件_上海国际商品拍卖有限公司_gjspgjsp74204_4777.txt", Encoding.Default); String line; while ((line = sr.ReadLine()) != null) { inLicense = line.ToString(); } string base64 = ImgToBase64String("../../Content/yechangzhongtouxiang.jpg"); string userName = "用户名"; string userIDNumber = "用户身份证号"; inConditions= "<?xml version=\"1.0\" encoding=\"utf-8\"?> <ROWS> <INFO> <SBM>上海国际商品拍卖有限公司</SBM> </INFO> <ROW> <GMSFHM>公民身份号码</GMSFHM> <XM>姓名</XM> <XP>相片</XP> </ROW> <ROW FSD=\"200001\" YWLX=\"01\"> <GMSFHM>"+userIDNumber+"</GMSFHM> <XM>"+userName+"</XM> <XP>" + base64 + "</XP> </ROW> </ROWS>"; string returnxml = services.nciicCompare(inLicense, inConditions); XmlDocument XmlLoad = new XmlDocument(); XmlLoad.LoadXml(returnxml); XmlNode M_Root = XmlLoad.SelectSingleNode("ROWS"); XmlNode M_Root1 = M_Root.SelectSingleNode("ROW"); XmlNode M_Root2 = M_Root1.SelectSingleNode("OUTPUT"); XmlNodeList itemList = M_Root2.ChildNodes;//xml所有子节点 if (itemList.Count == 3) { XmlNode item0 = itemList[0]; if (item0.SelectSingleNode("result_gmsfhm").InnerXml.Trim() == "一致") { Console.WriteLine("公民身份号码一致"); } else { Console.WriteLine("公民身份号码不一致"); } XmlNode item1 = itemList[1]; if (item1.SelectSingleNode("result_xm").InnerXml.Trim() == "一致") { Console.WriteLine("姓名一致"); } else { Console.WriteLine("姓名不一致"); } XmlNode item2 = itemList[2]; if (item2.SelectSingleNode("result_fx").InnerXml.Trim() == "系统判断为同一人") { Console.WriteLine("系统通过照片判断为同一人"); } else { Console.WriteLine("系统通过照片不能确定是否为同一人"); } } else if (itemList.Count == 2) { XmlNode item0 = itemList[0]; Console.WriteLine(item0.SelectSingleNode("errormesage").InnerXml.Trim()); } Console.ReadKey(); } //图片转为base64编码的文本 public static string ImgToBase64String(string Imagefilename) { try { Bitmap bmp = new Bitmap(Imagefilename); MemoryStream ms = new MemoryStream(); bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); byte[] arr = new byte[ms.Length]; ms.Position = 0; ms.Read(arr, 0, (int)ms.Length); ms.Close(); String strbaser64 = Convert.ToBase64String(arr); return strbaser64; } catch (Exception ex) { return ex.InnerException.Message.ToString(); } } } }