• 大小: 0.18M
    文件类型: .rar
    金币: 2
    下载: 1 次
    发布日期: 2020-12-26
  • 语言: C#
  • 标签: C#  组件  身份证  activex  

资源简介


一般来说winform应用程序解决这个问题起来时很容易的,web应用程序就麻烦一点了。

这里我说说我的解决思路:

一、你必要有联机型居民身份证阅读器一个(带驱动光盘),这里我用的是精伦电子公司的iDR200,并有这个阅读器的开发接口说明。

二、新建一个winform控件项目ReadCardControl,添加一个主类ReadCard

1、  声明dll入口

        [DllImport("Sdtapi.dll")]

        private static extern int InitComm(int iPort);//初始化

        [DllImport("Sdtapi.dll")]

        private static extern int Authenticate();//卡认证

        [DllImport("Sdtapi.dll")]

        private static extern int ReadBaseInfos(StringBuilder NameStringBuilder GenderStringBuilder FolkStringBuilder BirthDay,StringBuilder CodeStringBuilder AddressStringBuilder AgencyStringBuilder ExpireStartStringBuilder ExpireEnd);//读取数据,推荐使用

        [DllImport("Sdtapi.dll")]

        private static extern int CloseComm();//关闭端口

        [DllImport("Sdtapi.dll")]

        private static extern int ReadBaseMsg(byte[] pMsgref int len);//读取数据,这里不用

        [DllImport("Sdtapi.dll")]

        private static extern int ReadBaseMsgW(byte[] pMsgref int len);//读取数据,这里不用

        [DllImport("kernel32.dll")]

        private static extern int Beep(int dwFreqint dwDuration);//用来大吼一声

       2、读卡方法

        private string[] arrys = null;//声明用来保存身份证信息的数组

        public void OnTimer()

        {

            StringBuilder Name = new StringBuilder(31);

            StringBuilder Gender = new StringBuilder(3);

            StringBuilder Folk = new StringBuilder(10);

            StringBuilder BirthDay = new StringBuilder(9);

            StringBuilder Code = new StringBuilder(19);

            StringBuilder Address = new StringBuilder(71);

            StringBuilder Agency = new StringBuilder(31);

            StringBuilder ExpireStart = new StringBuilder(9);

            StringBuilder ExpireEnd = new StringBuilder(9);

            //int len = 0;

            //string[] temp;

            char[] param = { '\0' };

            byte[] pMsg = new byte[256];

            string[] baseinfo = new string[9];

 

            //打开端口

            int intOpenRet = InitComm(1001);

            if (intOpenRet != 1)

            {

                //SetText("阅读机具未连接", lblMsg);

                return;

            }

            //卡认证

            int intReadRet = Authenticate();

            if (intReadRet != 1)

            {

                //SetText("卡认证失败", lblMsg);

                CloseComm();

                return;

            }

            //ReadBaseInfos(推荐使用)

            int intReadBaseInfosRet = ReadBaseInfos(NameGenderFolkBirthDayCodeAddressAgencyExpireStartExpireEnd);

            if (intReadBaseInfosRet != 1)

            {

                //SetText("读卡失败", lblMsg);

                CloseComm();

                return;

            }

            Beep(2047, 200);

            arrys = new string[10];

            arrys[0] = Code.ToString().Trim();

            arrys[1] = Name.ToString().Trim();

            arrys[2] = Gender.ToString().Trim();

            arrys[3] = Folk.ToString().Trim();

            arrys[4] = BirthDay.ToString().Trim();

            arrys[5] = Address.ToString().Trim();

            arrys[6] = Agency.ToString().Trim();

            arrys[7] = ExpireStart.ToString().Trim();

            arrys[8] = ExpireEnd.ToString().Trim();

            arrys[9] = System.IO.Directory.GetCurrentDirectory()  "\\photo.bmp";

            //SetText("读卡成功", lblMsg);

            //SetText("证件号码:" Code.ToString(), label1);

            //SetText("姓名:" Name.ToString(), label2);

            //SetText("性别:" Gender.ToString(), label3);

            //SetText("民族:" Folk.ToString(), label4);

            //SetText("出生日期:" BirthDay.ToString(), label5);

            //SetText("地址:" Address.ToString(), label6);

            //SetText("签发机关:" Agency.ToString(), label7);

            //SetText("签发时间:" ExpireStart.ToString(), label8);

            //SetText("有效截止时间:" ExpireEnd.ToString(), label9);

            SetImage("photo.bmp", pictureBox1);

            CloseComm();

        }

2、  声明一个客户端调用的方法Test(这里没有直接用数组)

        public string Test()

        {

            string str = "";

            foreach (string s in arrys)

            {

                str  = s   ",";

            }

            str = str.TrimEnd(',');

            return str;

}

三、将这个控件封装成activex组件

ReadCard类的头部添加

[Guid("B9BB196C-5008-4156-840F-9FE37BA81502")]

若要实现客户端访问服务器端数据,则必须实现IObjectSafe接口

接口声明如下:

    [ComImportGuidAttribute("CB5BDC81-93C1-11CF-8F20-00805F2CD064")]

    [InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]

    public interface IObjectSafe

    {

        [PreserveSig]

        void GetInterfaceSafeOptions(ref Guid id, [MarshalAs(UnmanagedType.U4)] ref int pdwSupportedOptions, [MarshalAs(UnmanagedType.U4)] ref int pdwEnabledOptions);

 

        [PreserveSig()]

        void SetInterfaceSafeOptions(ref Guid id, [MarshalAs(UnmanagedType.U4)] int dwOptionSetMask, [MarshalAs(UnmanagedType.U4)]int dwEnabledOptions);

}

 四、新建一个web应用程序项目

1、界面:

                <table style="width:100%;" border="1" width="100%" bordercolordark="#FFFFFF" cellspacing="0" cellpadding="2"bordercolor="#000000">

            <tr>

                <td style="width:33.3%text-alignright;">证件号码:</td>

                <td style="width:33.3%" id="td1">&nbsp;</td>

                <td style="width:33.3%text-alignleft;" rowspan="6">

                         <object id="csharpActiveX" name="csharpActiveX" classid="clsid:B9BB196C-5008-4156-840F-9FE37BA81502"></object></td>

            </tr>

            

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace ReadCardControl
{
    [ComImport GuidAttribute(“CB5BDC81-93C1-11CF-8F20-00805F2CD064“)]
    [InterfaceTypeAttribute(ComInterfaceType.InterfaceIsIUnknown)]
    public interface IobjectSafe
    {
        [PreserveSig]
        void GetInterfaceSafeOptions(ref Guid id [MarshalAs(UnmanagedType.U4)] ref int pdwSupportedOptions [MarshalAs(UnmanagedType.U4)] ref int pdwEnabledOptions);

        [PreserveSig()]
        void SetInterfaceSafeOptions(ref Guid id [MarshalAs(UnmanagedType.U4)] int dwOptionSetMask [MarshalAs(UnmanagedType.U4)] int dwEnabledOptions);
    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       1434  2010-03-02 16:56  ReadCardControl.sln

     文件       4096  2010-03-03 13:20  WebApplication1\bin\WebApplication1.dll

     文件      11776  2010-03-03 13:20  WebApplication1\bin\WebApplication1.pdb

     文件       3674  2010-03-04 09:07  WebApplication1\Default.aspx

     文件        339  2010-03-03 13:18  WebApplication1\Default.aspx.cs

     文件        853  2010-03-02 16:55  WebApplication1\Default.aspx.designer.cs

     文件        540  2010-03-03 08:36  WebApplication1\obj\Release\WebApplication1.csproj.FileListAbsolute.txt

     文件       4096  2010-03-03 13:20  WebApplication1\obj\Release\WebApplication1.dll

     文件      11776  2010-03-03 13:20  WebApplication1\obj\Release\WebApplication1.pdb

     文件       1317  2010-03-02 16:55  WebApplication1\Properties\AssemblyInfo.cs

     文件       7305  2010-03-02 16:56  WebApplication1\Web.config

     文件       4223  2010-03-02 16:56  WebApplication1\WebApplication1.csproj

     文件       1298  2010-03-02 16:56  WebApplication1\WebApplication1.csproj.user

     文件       6144  2010-03-02 16:31  ReadCardControl\bin\Debug\ReadCardControl.dll

     文件        120  2010-03-02 16:15  ReadCardControl\bin\Debug\ReadCardControl.dll.config

     文件      13824  2010-03-02 16:31  ReadCardControl\bin\Debug\ReadCardControl.pdb

     文件       2032  2010-03-02 16:31  ReadCardControl\bin\Debug\ReadCardControl.tlb

     文件      57344  2007-01-09 14:33  ReadCardControl\bin\Debug\Sdtapi.dll

     文件      90112  2005-01-12 16:53  ReadCardControl\bin\Debug\WltRS.dll

     文件      38862  2010-03-03 11:20  ReadCardControl\bin\Release\photo.bmp

     文件       8192  2010-03-03 13:24  ReadCardControl\bin\Release\ReadCardControl.dll

     文件      17920  2010-03-03 13:24  ReadCardControl\bin\Release\ReadCardControl.pdb

     文件       3060  2010-03-03 13:24  ReadCardControl\bin\Release\ReadCardControl.tlb

     文件      57344  2007-01-09 14:33  ReadCardControl\bin\Release\Sdtapi.dll

     文件      90112  2005-01-12 16:53  ReadCardControl\bin\Release\WltRS.dll

     文件        708  2010-03-03 08:39  ReadCardControl\IobjectSafe.cs

     文件       1026  2010-03-02 16:31  ReadCardControl\obj\Debug\ReadCardControl.csproj.FileListAbsolute.txt

     文件        781  2010-03-02 16:31  ReadCardControl\obj\Debug\ReadCardControl.csproj.GenerateResource.Cache

     文件       6144  2010-03-02 16:31  ReadCardControl\obj\Debug\ReadCardControl.dll

     文件      13824  2010-03-02 16:31  ReadCardControl\obj\Debug\ReadCardControl.pdb

............此处省略37个文件信息

评论

共有 条评论