id_card_reader.h
3.25 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
#ifndef ETRADECLIENT_HARDWARE_ID_CARD_READER_H_INCLUDED
#define ETRADECLIENT_HARDWARE_ID_CARD_READER_H_INCLUDED
/*
密码机信息:
生产厂商:广州江南科友科技股份有限公司
型号:(未知)
*/
#include <string>
struct IDCardInfo
{
std::wstring name;
std::wstring gender;
std::wstring nation;
std::wstring birth_date;
std::wstring address;
std::wstring id_code;
std::wstring depart;
std::wstring start_date;
std::wstring end_date;
std::wstring portrait_img_path;
void Trim()
{
name = name.substr(name.find_first_not_of(' '), name.find_last_not_of(' ') + 1);
gender = gender.substr(gender.find_first_not_of(' '), gender.find_last_not_of(' ') + 1);
nation = nation.substr(nation.find_first_not_of(' '), nation.find_last_not_of(' ') + 1);
birth_date = birth_date.substr(birth_date.find_first_not_of(' '), birth_date.find_last_not_of(' ') + 1);
address = address.substr(address.find_first_not_of(' '), address.find_last_not_of(' ') + 1);
id_code = id_code.substr(id_code.find_first_not_of(' '), id_code.find_last_not_of(' ') + 1);
depart = depart.substr(depart.find_first_not_of(' '), depart.find_last_not_of(' ') + 1);
start_date = start_date.substr(start_date.find_first_not_of(' '), start_date.find_last_not_of(' ') + 1);
end_date = end_date.substr(end_date.find_first_not_of(' '), end_date.find_last_not_of(' ') + 1);
portrait_img_path = portrait_img_path.substr(portrait_img_path.find_first_not_of(' '), portrait_img_path.find_last_not_of(' ') + 1);
}
};
class IDCardReader
{
typedef int(__stdcall *InitCommFunc)(int port);
typedef int(__stdcall *CloseCommFunc)();
typedef int(__stdcall *AuthenticateFunc)();
typedef int(__stdcall *ReadContentFunc)(int active);
typedef int(__stdcall *ReadContentFieldFunc)(char* name, int* len);
public:
/*This function may throw exception if the card reader library cannot be loaded!*/
IDCardReader();
~IDCardReader();
bool Connect() const;
void Disconnect() const;
bool VerifyCard() const;
IDCardInfo ReadCard() const;
//新中新电子身份证读卡器接口 add by liuye 2017.10.24
bool SynConnect();
bool SynFindCard();
IDCardInfo SynReadCard();
bool SynDisConnect();
//
private:
void Init(); // Load library to initialize all the function object.
bool DoConnect(int port_min, int port_max) const;
void GetCardField(ReadContentFieldFunc fn, std::wstring& field) const;
void GetPortraitPath(std::wstring& portrait_path) const;
InitCommFunc m_init_comm_fn; // Function object to init the communitation with ID card reader.
CloseCommFunc m_close_comm_fn; // Function object to close the communitation with ID card reader.
AuthenticateFunc m_auth_fn; // Function object to authentication of the ID card reader.
ReadContentFunc m_read_content_fn; // Function object to read the content from the ID card reader.
ReadContentFieldFunc m_get_name_fn;
ReadContentFieldFunc m_get_gender_fn;
ReadContentFieldFunc m_get_nation_fn;
ReadContentFieldFunc m_get_birthday_fn;
ReadContentFieldFunc m_get_addr_fn;
ReadContentFieldFunc m_get_id_code_fn;
ReadContentFieldFunc m_get_dept_fn;
ReadContentFieldFunc m_get_start_date_fn;
ReadContentFieldFunc m_get_end_data_fn;
int m_iPort;
static const std::string ID_CARD_READER_HARDWARE_INFO; // Currently this field is not used.
};
#endif // ETRADECLIENT_HARDWARE_ID_CARD_READER_H_INCLUDED