Reader.cs 29 KB
   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;

namespace Dk_Reader
{
public class Reader {
[DllImport("QHD_SmartMC.dll", EntryPoint = "QHD_OpenPort",//读取卡中基本信息
CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int QHD_OpenPort(StringBuilder oErrMsg);
[DllImport("QHD_SmartMC.dll", EntryPoint = "QHD_ClosePort",//读取卡中基本信息
CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int QHD_ClosePort(StringBuilder oErrMsg);
[DllImport("QHD_SmartMC.dll", EntryPoint = "QHD_ReadCard",//读取卡中基本信息
CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int QHD_ReadCard(StringBuilder oInfo, StringBuilder oErrMsg);

[DllImport("QHD_Card.dll", EntryPoint = "getKeyA",//读取卡中基本信息 getKeyStr_ext
CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int getKeyA(IntPtr iReaderPort, int iReaderHandle, int oErrMsg);
[DllImport("QHD_Card.dll", EntryPoint = "getKeyStr_ext",//读取卡中基本信息 getKeyStr_ext
CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int getKeyStr_ext(StringBuilder oErrMsg);
[DllImport("QHD_Card.dll", EntryPoint = "getKeyStr",//读取卡中基本信息 getKeyStr_ext
CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int getKeyStr(IntPtr iReaderPort, int iReaderHandle, StringBuilder oErrMsg);

[DllImport("dkSICARD.dll", EntryPoint = "iDOpenPort",//读取卡中基本信息
CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int iDOpenPort(int iReaderPort, ref IntPtr iReaderHandle, StringBuilder oErrMsg);
[DllImport("dkSICARD.dll", EntryPoint = "iDCloseReader",//读取卡中基本信息
CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int iDCloseReader(IntPtr iReaderHandle, StringBuilder oErrMsg);
[DllImport("dkSICARD.dll", EntryPoint = "getCardNO_Ext",//读取卡中基本信息Ext
CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int getCardNO_Ext(IntPtr iReaderHandle, StringBuilder iCardNo, StringBuilder iIDno, StringBuilder iName, StringBuilder iERRInfo);
[DllImport("dkSICARD.dll", EntryPoint = "getCardNO",//读取卡中基本信息
CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern int getCardNO(IntPtr iReaderHandle, StringBuilder iCardNo, StringBuilder oErrMsg);

//d8健康卡读卡器
[DllImport("dcrf32.dll", EntryPoint = "dc_init",//读取卡中基本信息
CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)]
public static extern Int16 d8Init(short param1, int param2);
[DllImport("dcrf32.dll", EntryPoint = "dc_config_card",//读卡配置
CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)]
public static extern Int16 d8ConfigCard(int param1, int param2);
[DllImport("dcrf32.dll", EntryPoint = "dc_card",//寻卡,找到卡的序号
CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)]
public static extern Int16 d8Card(int param1, int param2, ref ulong param3);
[DllImport("dcrf32.dll", EntryPoint = "dc_load_key")]
public static extern Int16 d8LoadKey(int icdev, int mode,int secnr,[In] byte[] nkey ); //密码装载到读写模块中
[DllImport("dcrf32.dll", EntryPoint = "dc_load_key_hex",//16进制读取
CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)]
public static extern Int16 d8LoadKeyHex(int param1, int param2, int param3, string key);
[DllImport("dcrf32.dll", EntryPoint = "dc_authentication",//扇区权限认证
CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)]
public static extern Int16 d8Authentication(int param1, int param2, int param3);
[DllImport("dcrf32.dll", EntryPoint = "dc_read",//读取卡号
CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)]
public static extern Int16 d8Read(int param1, int param2, byte[] param3);
[DllImport("dcrf32.dll", EntryPoint = "dc_read_hex")]
public static extern int d8ReadHex ( int icdev, int adr, StringBuilder sdata ); //从卡中读数据(转换为16进制)
[DllImport("dcrf32.dll", EntryPoint = "dc_beep",//读卡器蜂鸣
CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl)]
public static extern Int16 d8Beep(int param1, int param2);
[DllImport("RC5.dll", EntryPoint = "crypt",//内存复制
CharSet = CharSet.Ansi, CallingConvention = CallingConvention.StdCall)]
public static extern string crypt(byte[] param1, int param2, byte param3, byte param4);
[DllImport("dcrf32.dll", EntryPoint = "dc_exit",//关闭读卡IO
CharSet = CharSet.Unicode, CallingConvention = CallingConvention.Cdecl)]
public static extern Int16 d8Exit(int param1);
[DllImport("dcrf32.dll")]
public static extern void hex_a (ref string oldValue,ref string newValue,int len); //十六进制字符转换成普通字符
//华视读卡器
[DllImport("termb.dll")]
public static extern int CVR_InitComm (int port);
[DllImport("termb.dll")]
public static extern int CVR_Authenticate ();
[DllImport("termb.dll")]
public static extern int CVR_CloseComm ();
[DllImport("termb.dll")]
public static extern int CVR_Read_Content (int active);
//华大读卡器HD-100
[DllImport("SSSE32.dll")]
public static extern int ICC_Reader_Open ( string name);
//蜂鸣器
[DllImport("SSSE32.dll", EntryPoint = "ICC_PosBeep")]
public static extern System.Int32 ICC_PosBeep(System.Int32 ReaderHandle, Int16 time);
//将字符命令流转为16进制流
[DllImport("SSSE32.dll", EntryPoint = "StrToHex")]
public static extern System.Int32 StrToHex(System.Byte[] strIn, System.Int32 inLen, System.Byte[] strOut);
//密钥认证(模式一),该函数自动调用 存储 于 设备里面的 密钥 进行认证(要先装载密钥)
[DllImport("SSSE32.dll", EntryPoint = "PICC_Reader_Authentication")]
public static extern System.Int32 PICC_Reader_Authentication(System.Int32 ReaderHandle,System.Byte Mode,System.Byte SecNr);
//密钥认证(模式二),使用用户输入传入的 password
//注意:输入的是12位的密钥,例如12个f,但是password必须是6个字节的密钥,需要用StrToHex函数处理。
[DllImport("SSSE32.dll", EntryPoint = "PICC_Reader_Authentication_Pass")]
public static extern System.Int32 PICC_Reader_Authentication_Pass(System.Int32 ReaderHandle,System.Byte Mode,System.Byte SecNr,System.Byte[] PassWord);
//读卡
[DllImport("SSSE32.dll", EntryPoint = "PICC_Reader_Read")]
public static extern System.Int32 PICC_Reader_Read(System.Int32 ReaderHandle, System.Byte Addr,System.Byte[] Data);
[DllImport(@"BY618_108.dll", EntryPoint = "SNBC_InitComm")]
public extern static int SNBC_InitComm(int port);
[DllImport(@"BY618_108.dll", EntryPoint = "SNBC_CloseComm")]
public extern static int SNBC_CloseComm(int port);
[DllImport(@"BY618_108.dll", EntryPoint = "SNBC_Authenticate")]
public extern static int SNBC_Authenticate();
[DllImport(@"BY618_108.dll", EntryPoint = "SNBC_ReadContent")]
public extern static int SNBC_ReadContent();
[DllImport(@"BY618_108.dll", EntryPoint = "SNBC_SavePhoto")]
public extern static int SNBC_SavePhoto(string name);
[DllImport(@"BY618_108.dll", EntryPoint = "SNBC_GetName")]
public extern static int SNBC_GetName(byte[] strName, int len);
[DllImport(@"BY618_108.dll", EntryPoint = "SNBC_GetSex")]
public extern static int SNBC_GetSex(byte[] strSex, int len);
[DllImport(@"BY618_108.dll", EntryPoint = "SNBC_GetBirth")]
public extern static int SNBC_GetBirth(byte[] strBirth, int len);
[DllImport(@"BY618_108.dll", EntryPoint = "SNBC_GetNation")]
public extern static int SNBC_GetNation(byte[] strNation, int len);
[DllImport(@"BY618_108.dll", EntryPoint = "SNBC_GetID")]
public extern static int SNBC_GetID(byte[] strID, int len);
[DllImport(@"BY618_108.dll", EntryPoint = "SNBC_GetAddress")]
public extern static int SNBC_GetAddress(byte[] strAddress, int len);
[DllImport(@"BY618_108.dll", EntryPoint = "SNBC_GetDepartment")]
public extern static int SNBC_GetDepartment(byte[] strDepartment, int len);
[DllImport(@"BY618_108.dll", EntryPoint = "SNBC_GetISSUE")]
public extern static int SNBC_GetISSUE(byte[] strISSUE, int len);
[DllImport(@"BY618_108.dll", EntryPoint = "SNBC_GetEXPIRES")]
public extern static int SNBC_GetEXPIRES(byte[] strEXPIRES, int len);
[DllImport(@"BY618_108.dll", EntryPoint = "SNBC_GetNewAddress")]
public extern static int SNBC_GetNewAddress(byte[] strNewAddress, int len);
//深圳市明泰智能技术有限公司-URF-R330
[DllImport("mwrf32.dll", EntryPoint="rf_init")]
public static extern int rf_init(Int16 port, int baud);
[DllImport("mwrf32.dll", EntryPoint="rf_beep")]
public static extern int rf_beep(int icdev, int _Msec);
[DllImport("mwrf32.dll", EntryPoint="rf_exit")]
public static extern int rf_exit(int icdev);
[DllImport("mwrf32.dll", EntryPoint="rf_load_key")]
public static extern Int16 rf_load_key(int icdev,int mode, int secnr,[MarshalAs(UnmanagedType.LPArray)]byte[] keybuff );
[DllImport("mwrf32.dll", EntryPoint="rf_authentication")]
public static extern Int16 rf_authentication(int icdev, int mode,int secnr);
[DllImport("mwrf32.dll", EntryPoint="rf_reset")]
public static extern Int16 rf_reset(int icdev,int msec);
[DllImport("mwrf32.dll", EntryPoint="rf_request")]
public static extern Int16 rf_request(int icdev, int mode, out UInt16 tagtype);
[DllImport("mwrf32.dll", EntryPoint="rf_anticoll")]
public static extern Int16 rf_anticoll(int icdev, int bcnt,out uint snr);
[DllImport("mwrf32.dll", EntryPoint="rf_select")]
public static extern Int16 rf_select(int icdev, uint snr,out byte size);
[DllImport("mwrf32.dll", EntryPoint="rf_read")]
public static extern Int16 rf_read(int icdev,int blocknr, [MarshalAs(UnmanagedType.LPArray)]byte[] databuff);
[DllImport("mwrf32.dll", EntryPoint="hex_a")]
public static extern Int16 hex_a2([MarshalAs(UnmanagedType.LPArray)]byte[] hex,[MarshalAs(UnmanagedType.LPArray)]byte[] asc, int len );

//湖南长城医疗科技有限公司 GWI-IC30A
[DllImport("GWI_DesktopCardReader.dll", EntryPoint="GWI_M1Card_Open")]
public static extern int GWI_M1Card_Open(StringBuilder msg);
[DllImport("GWI_DesktopCardReader.dll", EntryPoint="GWI_M1Card_Close")]
public static extern int GWI_M1Card_Close(StringBuilder msg);
[DllImport("GWI_DesktopCardReader.dll", EntryPoint="GWI_M1Card_ReadID")]
public static extern int GWI_M1Card_ReadID(StringBuilder CardID, StringBuilder msg);
[DllImport("GWI_DesktopCardReader.dll", EntryPoint="GWI_M1Card_HexReadBlock")]
public static extern int GWI_M1Card_HexReadBlock(int sector, int blockid, int pwdmode,ref char output, char[] PassWord, StringBuilder msg);
[DllImport("GWI_DesktopCardReader.dll", EntryPoint="GWI_M1Card_ReadBlock")]
public static extern int GWI_M1Card_ReadBlock(int sector, int blockid, int pwdmode, StringBuilder Outbuf, char[] PassWord, StringBuilder msg);
// 滦平县妇幼保健院 GWI-IC30A
public string getVcCardGWI_IC30A() {
int status = -1, handle;
string result = "{\"code\":\"-1\"}";
StringBuilder msg = new StringBuilder(100);
StringBuilder temp = new StringBuilder(100);
char[] hexkey = new char[]{'F','F','F','F','F','F','F','F','F','F','F','F'};
handle = GWI_M1Card_Open(msg);
if(0 == handle) {
handle = GWI_M1Card_ReadID( msg, msg);
handle = GWI_M1Card_ReadBlock(1, 1, 0, temp, hexkey, msg);
if(0 == handle) {
result = "{\"code\":\"1\", \"id\":\"" + temp.ToString() + "\"}";
GWI_M1Card_Close( msg);
}
}
return result;
}
// 深圳市明华奥汉科技股份有限公司-URF-35LT-N ---承德市妇幼保健院
public string getVcCardURF_R35LT() {
int status = -1, handle;
string result = "{\"code\":\"-1\"}";

handle = rf_init(0,9600);
if(handle > 0) {
rf_beep(handle, 10);
uint snr=0;
byte size = 0;
byte[] hexkey = new byte[6]{0xff,0xff,0xff,0xff,0xff,0xff};
UInt16 tagtype=0;
status = rf_request(handle, 1, out tagtype);
status = rf_anticoll(handle,0,out snr);
status = rf_select(handle,snr,out size);
status = rf_load_key(handle, 0, 0, hexkey);
if(0 == status) {
status = rf_authentication(handle, 0, 0);
if(0 == status) {
byte[] data=new byte[4];
rf_read(handle, 0, data);
string hex = "";
for(int i=3; i>=0 ; i--) {
hex += data[i].ToString("x2");
}
Int32 cardNo = Int32.Parse(hex, System.Globalization.NumberStyles.HexNumber);
result = "{\"code\":\"1\", \"id\":\"" + cardNo + "\"}";
}
}
rf_exit(handle);
}
return result;
}
// 深圳市明泰智能技术有限公司-URF-R330---邢台市巨鹿医院
public string getVcCardURF_R330() {
int status = -1, handle;
string result = "{\"code\":\"-1\"}";

handle = rf_init(0,9600);
if(handle > 0) {
rf_beep(handle, 10);
uint snr=0;
byte size = 0;
byte[] hexkey = new byte[6]{0xff,0xff,0xff,0xff,0xff,0xff};
UInt16 tagtype=0;
status = rf_request(handle, 1, out tagtype);
status = rf_anticoll(handle,0,out snr);
status = rf_select(handle,snr,out size);
status = rf_load_key(handle, 0, 1, hexkey);
if(0 == status) {
status = rf_authentication(handle, 0, 1);
if(0 == status) {
byte[] data=new byte[16];
byte[] buff=new byte[16];
rf_read(handle, 4, data);
hex_a2(data,buff,16);
string cardno = System.Text.Encoding.ASCII.GetString(buff).Substring(0,12);
result = "{\"code\":\"1\", \"id\":\"" + cardno + "\"}";
}
}
rf_exit(handle);
}
return result;
}
// 威海新北洋数码有限公司 by618-108
public string getIdCard_by618108() {
int ret;
string result = "{\"code\":\"-1\"}";
ret = SNBC_InitComm(1001);//打开USB口1
if (ret == 0) {
ret = SNBC_Authenticate();
if (ret == 0x00) {
ret = SNBC_ReadContent();//关闭USB口1
if (ret == 0x00) {
string tmp = "{\"code\":1,";
byte[] buffer = new byte[70 + 1];
//获取姓名
SNBC_GetName(buffer, 30);
result = Encoding.Default.GetString(buffer).TrimEnd('\0');
tmp += "\"name\":\"" + result + "\",";
//性别
buffer = new byte[70 + 1];
SNBC_GetSex(buffer, 2);
result = Encoding.Default.GetString(buffer).TrimEnd('\0');;
tmp += "\"sex\":\"" + result + "\",";
//民族
buffer = new byte[70 + 1];
SNBC_GetNation(buffer, 20);
result = Encoding.Default.GetString(buffer).TrimEnd('\0');;
tmp += "\"nation\":\"" + result + "\",";
//出生年月
buffer = new byte[70 + 1];
SNBC_GetBirth(buffer, 18);
result = Encoding.Default.GetString(buffer).TrimEnd('\0');;
result = result.Substring(0,4) + "-" + result.Substring(4,2) + "-" + result.Substring(6,2);
tmp += "\"birth\":\"" + result + "\",";
//证件ID
buffer = new byte[70 + 1];
SNBC_GetID(buffer, 18);
result = Encoding.Default.GetString(buffer).TrimEnd('\0');;
tmp += "\"id\":\"" + result + "\",";
//住址
buffer = new byte[70 + 1];
SNBC_GetAddress(buffer, 70);
result = Encoding.Default.GetString(buffer).TrimEnd('\0');;
tmp += "\"address\":\"" + result + "\",";
//签发机构
buffer = new byte[70 + 1];
SNBC_GetDepartment(buffer, 30);
result = Encoding.Default.GetString(buffer).TrimEnd('\0');;
tmp += "\"office\":\"" + result + "\"";
tmp += "}";
result = tmp;
}
}
}
return result;
}
//华大读卡器HD-100 南丘县人民医院
public string Get_HuaDaHd_100_2() {
string result = "{\"code\":\"-1\"}", name = "USB1";
int handle = 0;
handle = ICC_Reader_Open( name);
byte[] Data = new byte[16];//存 读出的数据
if(handle > 0) {
ICC_PosBeep(handle, 1000);
string str = "ffffffffffff";//界面输入的 12位密钥
//密钥需要 从 字符串 类型 转换为 byte数组 类型
byte[] data = Encoding.UTF8.GetBytes(str);//string ---> byte[]
byte[] dataOut = new byte[6];//存 处理后 输出来的 密钥(6个字节的)
int test = StrToHex(data, 12, dataOut);//将字符命令流转为16进制流

int tt = PICC_Reader_Authentication_Pass(handle, 0x61 , 4, dataOut);
//使用参数PassWord传入的Key进行认证;
string result2 = "";
//认证成功
if (tt == 0) {
int tmp = -1;
tmp = PICC_Reader_Read(handle, 17, Data);//读(HEX)
if(tmp == 0) {
for ( int i = 1; i < 11; i++ ) {
result2 += (char)Data[i];
}
result = "{\"code\":\"1\", \"id\":\"" + result2 + "\"}";;
}
}
}
return result ;
}
//华大读卡器HD-100
public string Get_HuaDaHd_100() {
string result = "{\"code\":\"-1\"}", name = "USB1";
int handle = 0;
handle = ICC_Reader_Open( name);
byte[] Data = new byte[16];//存 读出的数据
if(handle > 0) {
ICC_PosBeep(handle, 1000);
string str = "ffffffffffff";//界面输入的 12位密钥
//密钥需要 从 字符串 类型 转换为 byte数组 类型
byte[] data = Encoding.UTF8.GetBytes(str);//string ---> byte[]
byte[] dataOut = new byte[6];//存 处理后 输出来的 密钥(6个字节的)
int test = StrToHex(data, 12, dataOut);//将字符命令流转为16进制流

int tt = PICC_Reader_Authentication_Pass(handle, 0x61 , (byte)(Convert.ToByte("08")/4), dataOut);
//使用参数PassWord传入的Key进行认证;
string result2 = "";
//认证成功
if (tt == 0) {
int tmp = PICC_Reader_Read(handle, Convert.ToByte("08"), Data);//读(HEX)
if(0 == tmp) {
for ( int i = 0; i < Data.Length; i++ ) {
if(Data[i] != 0 && i < 10) {
result2 += (char)Data[i];
}
}
}
result = "{\"code\":\"1\", \"id\":\"" + result2 + "\"}";;
}
}
return result ;
}
//华视身份证读卡器CVR-100UC //北京金诚信齐通科技有限公司 型号号GHC860
public string Get_HuaShiCardNo() {
int status = 0; string result = "{\"code\":\"-1\"}"; string tmp = "{code:99}"; string[] tmp2;
status = CVR_InitComm(1001);
if(status == 1) {
status = CVR_Authenticate();
} else {
CVR_CloseComm();
}
if(status == 1) {
status = CVR_Read_Content(0);
} else {
CVR_CloseComm();
}
if(status == 1)
status = CVR_CloseComm();
string path = System.Environment.CurrentDirectory + Path.DirectorySeparatorChar + "wz.txt";
if(File.Exists(path)) {
tmp = System.IO.File.ReadAllText(path, Encoding.Default);
tmp2 = tmp.Split(new String[]{"\r\n"}, StringSplitOptions.None);
if(tmp2.Length == 9) {
result = "{\"code\":\"1\", \"name\":\"" + tmp2[0] + "\", \"sex\":\"" + tmp2[1] + "\", \"nation\":\"" + tmp2[2] + "\", \"birth\":\""+ tmp2[3] +
"\", \"address\":\"" + tmp2[4] + "\", \"id\":\"" + tmp2[5] + "\", \"office\":\"" + tmp2[6] + "\", \"vailddate\":\"" + tmp2[7] + "\"}";
}
}
return result;
}
//深圳市德卡科技有限公司 D3
//-聊城东昌妇女儿童医院
public string Get_d3CardNo() {
int rCode = -1;
ulong handel = 0;
//初始化读卡
int initCode = d8Init(100, 115200);
byte[] rdata = new byte[64];
string result = null;
StringBuilder temp = new StringBuilder(64);
if(initCode >= 0) {
//配置读卡器
rCode = d8ConfigCard(initCode, 65);
//查询卡的内部卡号
rCode = d8Card(initCode, 0, ref handel);
if(rCode >= 0) {
byte[] hexkey = new byte[6]{0xff,0xff,0xff,0xff,0xff,0xff};
//加载卡扇区密码
rCode = d8LoadKey(initCode, 0 ,8 , hexkey);
if(rCode >= 0) {
//对密码进行认证
rCode = d8Authentication(initCode, 0, 6);
if(rCode >= 0) {
//读卡
rCode = d8ReadHex(initCode, 24, temp);
//蜂鸣
d8Beep(initCode, 10);
//释放IO
d8Exit(initCode);
result = temp.ToString();
if(!String.IsNullOrEmpty(result)) {
return "{\"code\":\"1\", \"id\":\"" + result.Substring(0, 10) + "\"}";
}
}
}
}
}
return "{\"code\":\"-1\"}";
}
//深圳市德卡科技有限公司 D8
public string Get_d8CardNo() {
Int16 rCode = -1;
ulong handel = 0;
//初始化读卡
int initCode = d8Init(100, 115200);
byte[] rdata = new byte[64];
string result = null;
if(initCode >= 0) {
//配置读卡器
rCode = d8ConfigCard(initCode, 65);
//查询卡的内部卡号
rCode = d8Card(initCode, 0, ref handel);
if(rCode >= 0) {
byte[] hexkey = new byte[6]{0xff,0xff,0xff,0xff,0xff,0xff};
//加载卡扇区密码
rCode = d8LoadKey(initCode, 0 ,8 , hexkey);
if(rCode >= 0) {
//对密码进行认证
rCode = d8Authentication(initCode, 0, 8);
if(rCode >= 0) {
//读卡
rCode = d8Read(initCode, 32, rdata);
//蜂鸣
d8Beep(initCode, 10);
//释放IO
d8Exit(initCode);
if(rCode >= 0) {
result = crypt(rdata, 16, 0, 0);
if(!String.IsNullOrEmpty(result)) {
return "{\"code\":\"1\", \"id\":\"" + result + "\"}";
}
}
}
}
}
}
return "{\"code\":\"-1\"}";
}
//天津环球磁卡股份有限公司 GMCC-DC001
public string Get_CMCCDC001CardNo() {
StringBuilder Cardno = new StringBuilder(8000);
StringBuilder RetMsg = new StringBuilder(8000);
int Ret_code = 9;
string Ret_msg = "-1";
try {
Ret_code = __Get_CardNo(ref Cardno, ref RetMsg);
} catch (Exception e) {
Ret_msg = RetMsg.ToString();
}
//读卡成功
if (Ret_code == 0) {
Ret_msg = Cardno.ToString();
return "{\"code\":\"1\", \"id\":\"" + Ret_msg + "\"}";
}

return "{\"code\":\"-1\"}";
}


//获取健康卡或者社保卡,天津环球磁卡股份有限公司 GMCC-DC001
public int __Get_CardNo(ref StringBuilder CardNo, ref StringBuilder Info) {
int type1 = 0;
int type2 = 0;
StringBuilder card = new StringBuilder(8000);
StringBuilder err = new StringBuilder(8000);
type1 = __Get_JKK_CardNo(ref card, ref err);
if (type1 == 0) {
Info.Append("JJK_OK");
CardNo = card;
return 0;
}
type2 = __Get_YB_CardNo(ref card, ref err);
if (type2 == 0) {
Info.Append("SBK_OK");
CardNo = card;
return 0;
} else {
Info = err;
return -1;//读卡失败
}
}

//读取健康卡,天津环球磁卡股份有限公司 GMCC-DC001
public int __Get_JKK_CardNo(ref StringBuilder CardInfo, ref StringBuilder ErrInfo) {
int status = 0;
StringBuilder ErrMSG = new StringBuilder(1000);
StringBuilder Card = new StringBuilder(3000);
status = QHD_OpenPort(ErrMSG);
if (status != 0) {
ErrInfo = ErrMSG;
QHD_ClosePort(ErrMSG);
return -1;//找不到读卡器
} else {
//getKeyA
status = QHD_ReadCard(Card, ErrMSG);
if (status == 0) {
String regular = @" ([0-9]{10}) ";
MatchCollection mc = Regex.Matches(Card.ToString(), regular);


if (0 != mc.Count) {
CardInfo = new StringBuilder(mc[0].ToString().Trim());
}
QHD_ClosePort(ErrMSG);
return 0;//读卡成功
} else {
ErrMSG = ErrInfo;
QHD_ClosePort(ErrMSG);
return -2;//读卡失败
}
}

}

//读取医保卡,天津环球磁卡股份有限公司 GMCC-DC001
public int __Get_YB_CardNo(ref StringBuilder CardNum, ref StringBuilder ErrInfo) {
int status = 0;
IntPtr handel = new IntPtr();
StringBuilder ErrMSG = new StringBuilder(1000);
StringBuilder CardNo = new StringBuilder(3000);
StringBuilder IdNo = new StringBuilder(3000);
StringBuilder Name = new StringBuilder(3000);
status = iDOpenPort(0, ref handel, ErrMSG);
//int str = 0;
if (status == 0) {
//status = getKeyA(handel, 1, str);
status = getCardNO_Ext(handel, CardNo, IdNo, Name, ErrMSG);
if (status == 0) {
CardNum = ErrMSG;
string[] l = CardNo.ToString().Split('|');//用,分组
CardNum = new StringBuilder(l[0]);

status = iDCloseReader(handel, ErrMSG);

ErrInfo = ErrMSG;
return 0;//读卡成功
} else {
status = iDCloseReader(handel, ErrMSG);
ErrInfo = ErrMSG;
return -2;//读卡失败
}
} else {
status = iDCloseReader(handel, ErrMSG);
ErrInfo = ErrMSG;
return -1;//读卡器未找到
}
}
}
}