Commit 630fe9d470bf599ffab16ee157d943297907ec23
1 parent
20dbffcd
feat(card_client&dlcm):支持m1卡操作
支持m1卡,卡片入库时写入卡片基本信息,读卡时先调用cpu接口,然后调用m1卡接口。
Showing
8 changed files
with
286 additions
and
55 deletions
dlcm/dlcm/DLCDevice.cc
@@ -123,12 +123,12 @@ int DLCDevice::M1LoadKeyHex(const unsigned char mode, const unsigned char* key, | @@ -123,12 +123,12 @@ int DLCDevice::M1LoadKeyHex(const unsigned char mode, const unsigned char* key, | ||
123 | 123 | ||
124 | int DLCDevice::M1Read(const unsigned char adr, const unsigned char* data) | 124 | int DLCDevice::M1Read(const unsigned char adr, const unsigned char* data) |
125 | { | 125 | { |
126 | - return dc_read(dev_, adr, (unsigned char*)data); | 126 | + return dc_read_hex(dev_, adr, (char*)data); |
127 | } | 127 | } |
128 | 128 | ||
129 | int DLCDevice::M1Write(const unsigned char adr, const unsigned char* data) | 129 | int DLCDevice::M1Write(const unsigned char adr, const unsigned char* data) |
130 | { | 130 | { |
131 | - return dc_write(dev_, adr, (unsigned char*)data); | 131 | + return dc_write_hex(dev_, adr, (char*)data); |
132 | } | 132 | } |
133 | 133 | ||
134 | int DLCDevice::M1FindCard() | 134 | int DLCDevice::M1FindCard() |
dlcm/dlcm/main.cpp
@@ -8,16 +8,26 @@ int main() | @@ -8,16 +8,26 @@ int main() | ||
8 | { | 8 | { |
9 | std::cout << "Test start " << std::endl; | 9 | std::cout << "Test start " << std::endl; |
10 | DLCConnectDevice(); | 10 | DLCConnectDevice(); |
11 | - int result = DLCFindCard(); | ||
12 | - | ||
13 | - result = DLCM1FindCard(); | ||
14 | 11 | ||
15 | - result = DLCM1AuthenticationKey(0, (unsigned char*)"ffffffffffff"); | 12 | + //int result = DLCFindCard(); |
13 | + | ||
14 | + int result = DLCM1FindCard(); | ||
15 | + | ||
16 | + result = DLCM1AuthenticationKey(1, (unsigned char*)"ffffffffffff"); | ||
17 | + | ||
18 | + unsigned char read_text[32] = {0}; | ||
19 | + | ||
20 | + //result = DLCM1ReadCard(4, read_text); | ||
21 | + | ||
22 | + result = DLCM1WriteCard(4, read_text); | ||
23 | + | ||
24 | + char card_num[8] = { 0 }; | ||
25 | + memcpy(card_num, read_text, 8); | ||
26 | + | ||
27 | + /*int result = DLCFindCard(); | ||
16 | 28 | ||
17 | - unsigned char read_text[32] = { 0 }; | ||
18 | - result = DLCM1ReadCard(1, read_text); | ||
19 | - const char *write_text = "222222222222"; | ||
20 | - result = DLCM1WriteCard(1, (const unsigned char*)write_text); | 29 | + unsigned char card_num[12] = { 0 }; |
30 | + result = DLCReadCardData((const unsigned char*)"3f00", 5, 0, 12, 0, card_num);*/ | ||
21 | 31 | ||
22 | DLCDisconnectDevice(); | 32 | DLCDisconnectDevice(); |
23 | 33 |
etrade_card_client/Config/application_config.json
@@ -9,7 +9,7 @@ | @@ -9,7 +9,7 @@ | ||
9 | "client_cert_subject": "*.diligrp.com", | 9 | "client_cert_subject": "*.diligrp.com", |
10 | "client_cert_filename": "", | 10 | "client_cert_filename": "", |
11 | "client_cert_password": "", | 11 | "client_cert_password": "", |
12 | - "security_level": 2, | 12 | + "security_level": 0, |
13 | "encrypt_type": 1, | 13 | "encrypt_type": 1, |
14 | "id_reader": 1 | 14 | "id_reader": 1 |
15 | } | 15 | } |
16 | \ No newline at end of file | 16 | \ No newline at end of file |
etrade_card_client/ETradeClient/browser/async_js_callback_handler.cpp
@@ -46,6 +46,7 @@ namespace HW | @@ -46,6 +46,7 @@ namespace HW | ||
46 | static const std::string JSON_VAL_FILEID_ID_CARD = "10"; | 46 | static const std::string JSON_VAL_FILEID_ID_CARD = "10"; |
47 | static const std::string JSON_VAL_FILEID_PIN_PAD = "11"; | 47 | static const std::string JSON_VAL_FILEID_PIN_PAD = "11"; |
48 | static const std::string JSON_VAL_FILEID_BANK_CARD_NUM = "20"; | 48 | static const std::string JSON_VAL_FILEID_BANK_CARD_NUM = "20"; |
49 | + static const std::string JSON_VAL_FILEID_M1_CARD = "30"; | ||
49 | 50 | ||
50 | struct HWRequest | 51 | struct HWRequest |
51 | { | 52 | { |
@@ -63,7 +64,20 @@ namespace HW | @@ -63,7 +64,20 @@ namespace HW | ||
63 | PT::read_json(ss, ptree); | 64 | PT::read_json(ss, ptree); |
64 | std::string cmd = ptree.get<std::string>(JSON_TAG_CMD); | 65 | std::string cmd = ptree.get<std::string>(JSON_TAG_CMD); |
65 | std::string file_id = ptree.get<std::string>(JSON_TAG_FILEID); | 66 | std::string file_id = ptree.get<std::string>(JSON_TAG_FILEID); |
66 | - std::string data = ptree.get<std::string>(JSON_TAG_DATA); | 67 | + std::string data; |
68 | + | ||
69 | + if (file_id.compare(JSON_VAL_FILEID_M1_CARD) == 0 && | ||
70 | + cmd.compare(JSON_VAL_CMD_ACTIVATE) == 0) | ||
71 | + { | ||
72 | + PT::ptree data_tree = ptree.get_child(JSON_TAG_DATA); | ||
73 | + std::stringstream os; | ||
74 | + PT::write_json(os, data_tree); | ||
75 | + data = os.str(); | ||
76 | + } | ||
77 | + else | ||
78 | + { | ||
79 | + data = ptree.get<std::string>(JSON_TAG_DATA); | ||
80 | + } | ||
67 | std::string seq = ptree.get<std::string>(JSON_TAG_SEQ); | 81 | std::string seq = ptree.get<std::string>(JSON_TAG_SEQ); |
68 | return { cmd, file_id, data, seq }; | 82 | return { cmd, file_id, data, seq }; |
69 | } | 83 | } |
@@ -99,6 +113,7 @@ namespace HW | @@ -99,6 +113,7 @@ namespace HW | ||
99 | m_hw_cmd_map.insert(JSON_VAL_CMD_READ + JSON_VAL_FILEID_DILI_CARD_SERVICE_INFO, new ReadDILICardServiceInfoCmd()); | 113 | m_hw_cmd_map.insert(JSON_VAL_CMD_READ + JSON_VAL_FILEID_DILI_CARD_SERVICE_INFO, new ReadDILICardServiceInfoCmd()); |
100 | m_hw_cmd_map.insert(JSON_VAL_CMD_WRITE + JSON_VAL_FILEID_DILI_CARD_SERVICE_INFO, new WriteDILICardServiceInfoCmd()); | 114 | m_hw_cmd_map.insert(JSON_VAL_CMD_WRITE + JSON_VAL_FILEID_DILI_CARD_SERVICE_INFO, new WriteDILICardServiceInfoCmd()); |
101 | m_hw_cmd_map.insert(JSON_VAL_CMD_READ + JSON_VAL_FILEID_BANK_CARD_NUM, new ReadBankCardNumCmd()); | 115 | m_hw_cmd_map.insert(JSON_VAL_CMD_READ + JSON_VAL_FILEID_BANK_CARD_NUM, new ReadBankCardNumCmd()); |
116 | + m_hw_cmd_map.insert(JSON_VAL_CMD_ACTIVATE + JSON_VAL_FILEID_M1_CARD, new ActivateDILIM1CardCmd()); | ||
102 | } | 117 | } |
103 | std::string HandleRequest(const std::string& request_json) | 118 | std::string HandleRequest(const std::string& request_json) |
104 | { | 119 | { |
etrade_card_client/ETradeClient/hardware/dili_card_device.cpp
@@ -353,7 +353,7 @@ namespace DILICard | @@ -353,7 +353,7 @@ namespace DILICard | ||
353 | WriteCardFile(DF01_DIR, SERVICE_INFO_FILE_ID, 0/*offset*/, ACTIVATE_KEY_ID, K_F0015_DAMK1_DV, DecToHex(0)); // Default length is 0. | 353 | WriteCardFile(DF01_DIR, SERVICE_INFO_FILE_ID, 0/*offset*/, ACTIVATE_KEY_ID, K_F0015_DAMK1_DV, DecToHex(0)); // Default length is 0. |
354 | } | 354 | } |
355 | 355 | ||
356 | - BasicInfo RWDevice::ReadCardBasicInfo() const | 356 | + DILICard::BasicInfo RWDevice::ReadCardBasicInfo() const |
357 | { | 357 | { |
358 | const uint32_t kOffset = 0; | 358 | const uint32_t kOffset = 0; |
359 | const uint32_t kLength = CARD_CHIP_NUM_LEN + CARD_SN_LEN + CARD_TYPE_CODE_LEN + CARD_ISSUER_CODE_LEN + CARD_VERIFY_CODE_LEN; | 359 | const uint32_t kLength = CARD_CHIP_NUM_LEN + CARD_SN_LEN + CARD_TYPE_CODE_LEN + CARD_ISSUER_CODE_LEN + CARD_VERIFY_CODE_LEN; |
@@ -361,7 +361,7 @@ namespace DILICard | @@ -361,7 +361,7 @@ namespace DILICard | ||
361 | const std::string kKey = ""; | 361 | const std::string kKey = ""; |
362 | std::string basic_info_str = ReadCardFile(MF_FILE_DIR, BASIC_INFO_FILE_ID, kOffset, kLength, kKeyID, kKey); | 362 | std::string basic_info_str = ReadCardFile(MF_FILE_DIR, BASIC_INFO_FILE_ID, kOffset, kLength, kKeyID, kKey); |
363 | 363 | ||
364 | - BasicInfo basic_info; | 364 | + DILICard::BasicInfo basic_info; |
365 | 365 | ||
366 | uint32_t offset = 0; | 366 | uint32_t offset = 0; |
367 | basic_info.chip_num = basic_info_str.substr(offset, CARD_CHIP_NUM_LEN); | 367 | basic_info.chip_num = basic_info_str.substr(offset, CARD_CHIP_NUM_LEN); |
@@ -425,7 +425,7 @@ namespace DILICard | @@ -425,7 +425,7 @@ namespace DILICard | ||
425 | if (NULL != key_id) | 425 | if (NULL != key_id) |
426 | { | 426 | { |
427 | memcpy(aucKey, key.c_str(), 32); | 427 | memcpy(aucKey, key.c_str(), 32); |
428 | - iResult = DLCReadCardData(aucDir, file_id, offset, length, aucData, aucKey); | 428 | + iResult = DLCReadCardData(aucDir, file_id, offset, length, aucKey, aucData); |
429 | } | 429 | } |
430 | else | 430 | else |
431 | { | 431 | { |
@@ -529,4 +529,92 @@ namespace DILICard | @@ -529,4 +529,92 @@ namespace DILICard | ||
529 | 529 | ||
530 | return bResult; | 530 | return bResult; |
531 | } | 531 | } |
532 | + | ||
533 | + int RWDevice::M1FindCard() const | ||
534 | + { | ||
535 | + return DLCM1FindCard(); | ||
536 | + } | ||
537 | + | ||
538 | + BasicInfo RWDevice::M1ReadBasicInfo() const | ||
539 | + { | ||
540 | + BasicInfo basic_info; | ||
541 | + unsigned char data[33] = { 0 }; | ||
542 | + | ||
543 | + const char* key = "ffffffffffff"; | ||
544 | + int error_code = DLCM1AuthenticationKey(1, (unsigned char*)key); | ||
545 | + if (error_code) | ||
546 | + { | ||
547 | + throw std::exception(std::to_string(error_code).c_str()); | ||
548 | + } | ||
549 | + | ||
550 | + error_code = DLCM1ReadCard(4, data); | ||
551 | + if (error_code) | ||
552 | + { | ||
553 | + throw std::exception(std::to_string(error_code).c_str()); | ||
554 | + } | ||
555 | + basic_info.chip_num.insert(0, (char*)data, 8); | ||
556 | + basic_info.type_code.insert(0, (char*)&data[16], 6); | ||
557 | + | ||
558 | + error_code = DLCM1ReadCard(5, data); | ||
559 | + if (error_code) | ||
560 | + { | ||
561 | + throw std::exception(std::to_string(error_code).c_str()); | ||
562 | + } | ||
563 | + basic_info.issuer_code.insert(0, (char*)data, 4); | ||
564 | + basic_info.verify_code.insert(0, (char*)&data[16], 3); | ||
565 | + | ||
566 | + error_code = DLCM1ReadCard(6, data); | ||
567 | + if (error_code) | ||
568 | + { | ||
569 | + throw std::exception(std::to_string(error_code).c_str()); | ||
570 | + } | ||
571 | + basic_info.sub_type.insert(0, (char*)data, 2); | ||
572 | + basic_info.maker_version.insert(0, (char*)&data[16], 2); | ||
573 | + | ||
574 | + basic_info.device_id = basic_info.chip_num; | ||
575 | + | ||
576 | + return basic_info; | ||
577 | + } | ||
578 | + | ||
579 | + int RWDevice::M1WriteBasicInfo(std::string card_num, std::string card_type_num, std::string market_id, std::string safe_code, std::string m1_type, std::string card_version) const | ||
580 | + { | ||
581 | + int result = 0; | ||
582 | + | ||
583 | + do | ||
584 | + { | ||
585 | + const char* key = "ffffffffffff"; | ||
586 | + | ||
587 | + if (DLCM1AuthenticationKey(1, (unsigned char*)key)) | ||
588 | + { | ||
589 | + break; | ||
590 | + } | ||
591 | + | ||
592 | + unsigned char data[32] = { 0 }; | ||
593 | + memset(data, '0', 32); | ||
594 | + memcpy(data, card_num.c_str(), 8); | ||
595 | + memcpy(&data[16], card_type_num.c_str(), 6); | ||
596 | + if (DLCM1WriteCard(4, (unsigned char*)data)) | ||
597 | + { | ||
598 | + break; | ||
599 | + } | ||
600 | + | ||
601 | + memset(data, '0', 32); | ||
602 | + memcpy(data, market_id.c_str(), 4); | ||
603 | + memcpy(&data[16], safe_code.c_str(), 3); | ||
604 | + if (DLCM1WriteCard(5, (unsigned char*)data)) | ||
605 | + { | ||
606 | + break; | ||
607 | + } | ||
608 | + | ||
609 | + memset(data, '0', 32); | ||
610 | + memcpy(data, m1_type.c_str(), 2); | ||
611 | + memcpy(&data[16], card_version.c_str(), 2); | ||
612 | + if (DLCM1WriteCard(6, (unsigned char*)data)) | ||
613 | + { | ||
614 | + break; | ||
615 | + } | ||
616 | + } while (0); | ||
617 | + | ||
618 | + return result; | ||
619 | + } | ||
532 | } // DILICard | 620 | } // DILICard |
533 | \ No newline at end of file | 621 | \ No newline at end of file |
etrade_card_client/ETradeClient/hardware/dili_card_device.h
@@ -13,6 +13,8 @@ CPU卡读写器产品信息: | @@ -13,6 +13,8 @@ CPU卡读写器产品信息: | ||
13 | #include <string> | 13 | #include <string> |
14 | #include <cstdint> | 14 | #include <cstdint> |
15 | 15 | ||
16 | +#include <boost/property_tree/ptree.hpp> | ||
17 | + | ||
16 | namespace DILICard | 18 | namespace DILICard |
17 | { | 19 | { |
18 | struct BasicInfo | 20 | struct BasicInfo |
@@ -22,6 +24,9 @@ namespace DILICard | @@ -22,6 +24,9 @@ namespace DILICard | ||
22 | std::string type_code; // 卡片类型码(卡类型编码) | 24 | std::string type_code; // 卡片类型码(卡类型编码) |
23 | std::string issuer_code; // 发卡机构编码 | 25 | std::string issuer_code; // 发卡机构编码 |
24 | std::string verify_code; // 校验码(安全码编码(3位数)) | 26 | std::string verify_code; // 校验码(安全码编码(3位数)) |
27 | + std::string sub_type; //m1卡卡类型 | ||
28 | + std::string maker_version; //卡片硬件版本 | ||
29 | + std::string chip_type; //芯片类型(2-m1卡|1-cpu卡) | ||
25 | }; | 30 | }; |
26 | 31 | ||
27 | // 卡密钥代码 | 32 | // 卡密钥代码 |
@@ -54,14 +59,14 @@ namespace DILICard | @@ -54,14 +59,14 @@ namespace DILICard | ||
54 | const std::string& key_F0015_DEAK, | 59 | const std::string& key_F0015_DEAK, |
55 | const std::string& key_F0015_DAMK1) const; | 60 | const std::string& key_F0015_DAMK1) const; |
56 | void ResetCard(const std::string& key_DCCK, const std::string& key_F0015_DACK) const; | 61 | void ResetCard(const std::string& key_DCCK, const std::string& key_F0015_DACK) const; |
57 | - BasicInfo ReadCardBasicInfo() const; | 62 | + DILICard::BasicInfo ReadCardBasicInfo() const; |
58 | std::string ReadCardServiceInfo(const std::string& key_F0015_DEAK) const; | 63 | std::string ReadCardServiceInfo(const std::string& key_F0015_DEAK) const; |
59 | void WriteCardServiceInfo(const std::string& key_F0015_DAMK1, const std::string& data) const; | 64 | void WriteCardServiceInfo(const std::string& key_F0015_DAMK1, const std::string& data) const; |
60 | bool AuthenticationKey(const std::string sKey) const; | 65 | bool AuthenticationKey(const std::string sKey) const; |
61 | 66 | ||
62 | int M1FindCard() const; | 67 | int M1FindCard() const; |
63 | - BasicInfo M1ReadBasicInfo() const; | ||
64 | - int M1WriteBasicInfo(std::string card_num, std::string card_type_num, std::string market_id, std::string safe_code, std::string m1_type, std::string card_version); | 68 | + DILICard::BasicInfo M1ReadBasicInfo() const; |
69 | + int M1WriteBasicInfo(std::string card_num, std::string card_type_num, std::string market_id, std::string safe_code, std::string m1_type, std::string card_version) const; | ||
65 | 70 | ||
66 | enum KeyType | 71 | enum KeyType |
67 | { | 72 | { |
@@ -69,6 +74,9 @@ namespace DILICard | @@ -69,6 +74,9 @@ namespace DILICard | ||
69 | KT_DEAK, | 74 | KT_DEAK, |
70 | KT_DAMK, | 75 | KT_DAMK, |
71 | }; | 76 | }; |
77 | + | ||
78 | + | ||
79 | + | ||
72 | private: | 80 | private: |
73 | std::string ReadCardFile(const std::string& dir, | 81 | std::string ReadCardFile(const std::string& dir, |
74 | char file_id, | 82 | char file_id, |
@@ -87,6 +95,8 @@ namespace DILICard | @@ -87,6 +95,8 @@ namespace DILICard | ||
87 | const std::string& main_key, | 95 | const std::string& main_key, |
88 | const std::string& install_key, | 96 | const std::string& install_key, |
89 | KeyType emKeyType) const; | 97 | KeyType emKeyType) const; |
98 | + | ||
99 | + | ||
90 | }; | 100 | }; |
91 | } // DILICard | 101 | } // DILICard |
92 | #endif // ETRADECLIENT_HARDWARE_DILI_CARD_DEVICE_H_INCLUDED | 102 | #endif // ETRADECLIENT_HARDWARE_DILI_CARD_DEVICE_H_INCLUDED |
etrade_card_client/ETradeClient/hardware/hardware_cmd.cpp
@@ -44,6 +44,7 @@ namespace StatusCode | @@ -44,6 +44,7 @@ namespace StatusCode | ||
44 | static const std::string DILI_CARD_DEVICE_WRITE_SERVICE_INFO_FAILED = "306"; // 写入卡片业务信息失败. | 44 | static const std::string DILI_CARD_DEVICE_WRITE_SERVICE_INFO_FAILED = "306"; // 写入卡片业务信息失败. |
45 | static const std::string DILI_CARD_DEVICE_WRITE_UNMATCHED_CARD = "307"; // 写卡卡片的序列号不匹配. | 45 | static const std::string DILI_CARD_DEVICE_WRITE_UNMATCHED_CARD = "307"; // 写卡卡片的序列号不匹配. |
46 | static const std::string DILI_CARD_DEVICE_NEED_UPDATE = "308"; //卡片需要升级,请升级后继续使用。 | 46 | static const std::string DILI_CARD_DEVICE_NEED_UPDATE = "308"; //卡片需要升级,请升级后继续使用。 |
47 | + static const std::string DILI_CARD_DEVICE_PARSE_SEVER_DATA_FAILED = "309"; //解析服务器数据失败。 | ||
47 | 48 | ||
48 | static const std::string PWD_MACHINE_CONNECT_FAILED = "401"; // 连接加密机失败. | 49 | static const std::string PWD_MACHINE_CONNECT_FAILED = "401"; // 连接加密机失败. |
49 | static const std::string PWD_MACHINE_GET_KEY_FAILED = "402"; // 从加密机读取密钥失败. | 50 | static const std::string PWD_MACHINE_GET_KEY_FAILED = "402"; // 从加密机读取密钥失败. |
@@ -218,10 +219,6 @@ namespace EncryptTools | @@ -218,10 +219,6 @@ namespace EncryptTools | ||
218 | { | 219 | { |
219 | throw std::exception("9999"); | 220 | throw std::exception("9999"); |
220 | } | 221 | } |
221 | - /*for (int index = 0, iStrIndex = 0; iStrIndex < iLen; ++index, iStrIndex += 2) | ||
222 | - { | ||
223 | - CharToHex(&pStr[iStrIndex], pHex[index]); | ||
224 | - }*/ | ||
225 | 222 | ||
226 | return bResult; | 223 | return bResult; |
227 | } | 224 | } |
@@ -259,7 +256,7 @@ namespace | @@ -259,7 +256,7 @@ namespace | ||
259 | return bank_card_reader; | 256 | return bank_card_reader; |
260 | } | 257 | } |
261 | 258 | ||
262 | - std::string g_sCardNum;//用于办卡时,保证操作的卡片是同一张 | 259 | + std::string g_card_num;//用于办卡时,保证操作的卡片是同一张 |
263 | } | 260 | } |
264 | 261 | ||
265 | ReadPINPadCmd::Reply ReadPINPadCmd::Execute(const std::string& input) | 262 | ReadPINPadCmd::Reply ReadPINPadCmd::Execute(const std::string& input) |
@@ -459,8 +456,8 @@ ReadPINPadCmd::Reply ActivateDILICardCmd::Execute(const std::string& input) | @@ -459,8 +456,8 @@ ReadPINPadCmd::Reply ActivateDILICardCmd::Execute(const std::string& input) | ||
459 | break; | 456 | break; |
460 | } | 457 | } |
461 | 458 | ||
462 | - DILICard::BasicInfo stuCardBasicInfo; | ||
463 | - try { stuCardBasicInfo = dili_card_device.ReadCardBasicInfo(); } | 459 | + DILICard::BasicInfo card_basic_info; |
460 | + try { card_basic_info = dili_card_device.ReadCardBasicInfo(); } | ||
464 | catch (std::exception& ex) | 461 | catch (std::exception& ex) |
465 | { | 462 | { |
466 | LOG_FATAL(L"读取卡片基本信息失败,错误信息: " + str_2_wstr(ex.what())); | 463 | LOG_FATAL(L"读取卡片基本信息失败,错误信息: " + str_2_wstr(ex.what())); |
@@ -469,12 +466,12 @@ ReadPINPadCmd::Reply ActivateDILICardCmd::Execute(const std::string& input) | @@ -469,12 +466,12 @@ ReadPINPadCmd::Reply ActivateDILICardCmd::Execute(const std::string& input) | ||
469 | } | 466 | } |
470 | 467 | ||
471 | LOG_TRACE(L"计算SN。"); | 468 | LOG_TRACE(L"计算SN。"); |
472 | - card_sn = stuCardBasicInfo.chip_num + std::string("44494c49") + stuCardBasicInfo.chip_num; | 469 | + card_sn = card_basic_info.chip_num + std::string("44494c49") + card_basic_info.chip_num; |
473 | 470 | ||
474 | if (slLevel == HardwareCmd::SL_0) | 471 | if (slLevel == HardwareCmd::SL_0) |
475 | { | 472 | { |
476 | - stuCardBasicInfo.device_id = card_sn; | ||
477 | - card_basic_info = stuCardBasicInfo; | 473 | + card_basic_info.device_id = card_sn; |
474 | + card_basic_info = card_basic_info; | ||
478 | reply.error_code = StatusCode::OK; | 475 | reply.error_code = StatusCode::OK; |
479 | break; | 476 | break; |
480 | } | 477 | } |
@@ -589,8 +586,6 @@ ReadPINPadCmd::Reply ActivateDILICardCmd::Execute(const std::string& input) | @@ -589,8 +586,6 @@ ReadPINPadCmd::Reply ActivateDILICardCmd::Execute(const std::string& input) | ||
589 | 586 | ||
590 | ReadPINPadCmd::Reply ResetDILICardCmd::Execute(const std::string& input) | 587 | ReadPINPadCmd::Reply ResetDILICardCmd::Execute(const std::string& input) |
591 | { | 588 | { |
592 | - //const uint8_t BEEP_TIME = 20; // 20 * 10ms | ||
593 | - | ||
594 | 589 | ||
595 | LOG_TRACE(L"卡片撤销激活。"); | 590 | LOG_TRACE(L"卡片撤销激活。"); |
596 | auto& dili_card_device = DILICardRWDevice(); | 591 | auto& dili_card_device = DILICardRWDevice(); |
@@ -642,8 +637,6 @@ ReadPINPadCmd::Reply ResetDILICardCmd::Execute(const std::string& input) | @@ -642,8 +637,6 @@ ReadPINPadCmd::Reply ResetDILICardCmd::Execute(const std::string& input) | ||
642 | break; | 637 | break; |
643 | } | 638 | } |
644 | 639 | ||
645 | - //card_sn = stuCardBasicInfo.device_id; | ||
646 | - | ||
647 | LOG_TRACE(L"计算SN。"); | 640 | LOG_TRACE(L"计算SN。"); |
648 | if (slLevel == HardwareCmd::SL_1) | 641 | if (slLevel == HardwareCmd::SL_1) |
649 | { | 642 | { |
@@ -798,7 +791,7 @@ ReadPINPadCmd::Reply ReadDILICardBasicInfoCmd::Execute(const std::string& input) | @@ -798,7 +791,7 @@ ReadPINPadCmd::Reply ReadDILICardBasicInfoCmd::Execute(const std::string& input) | ||
798 | reply.error_code = StatusCode::DILI_CARD_DEVICE_READ_BASIC_INFO_FAILED; | 791 | reply.error_code = StatusCode::DILI_CARD_DEVICE_READ_BASIC_INFO_FAILED; |
799 | break; | 792 | break; |
800 | } | 793 | } |
801 | - | 794 | + card_basic_info.chip_type = "1";//cpu卡类型 |
802 | 795 | ||
803 | if (SL_2 == ApplicationConfig::Instance().SecurityLevel()) | 796 | if (SL_2 == ApplicationConfig::Instance().SecurityLevel()) |
804 | { | 797 | { |
@@ -869,7 +862,34 @@ ReadPINPadCmd::Reply ReadDILICardBasicInfoCmd::Execute(const std::string& input) | @@ -869,7 +862,34 @@ ReadPINPadCmd::Reply ReadDILICardBasicInfoCmd::Execute(const std::string& input) | ||
869 | //读取m1卡 | 862 | //读取m1卡 |
870 | do | 863 | do |
871 | { | 864 | { |
872 | - | 865 | + //判断是否为cpu卡,以防CPU卡读卡失败 |
866 | + if (card_basic_info.chip_type.compare("1") == 0) | ||
867 | + { | ||
868 | + break; | ||
869 | + } | ||
870 | + | ||
871 | + if (0 != dili_card_device.M1FindCard()) | ||
872 | + { | ||
873 | + reply.error_code = StatusCode::CPU_CARD_DEVICE_CANNOT_FIND_CARD; | ||
874 | + CString error; | ||
875 | + error.Format(L"m1卡寻卡失败,错误信息:%d", reply.error_code); | ||
876 | + LOG_FATAL(error.GetBuffer()); | ||
877 | + break; | ||
878 | + } | ||
879 | + | ||
880 | + try | ||
881 | + { | ||
882 | + card_basic_info = dili_card_device.M1ReadBasicInfo(); | ||
883 | + } | ||
884 | + catch (std::exception& ex) | ||
885 | + { | ||
886 | + LOG_FATAL(L"m1卡读取基本信息失败,错误信息: " + str_2_wstr(ex.what())); | ||
887 | + reply.error_code = StatusCode::DILI_CARD_DEVICE_READ_BASIC_INFO_FAILED; | ||
888 | + break; | ||
889 | + } | ||
890 | + card_basic_info.chip_type = "2";//m1卡类型 | ||
891 | + card_basic_info.device_id = card_basic_info.chip_num; | ||
892 | + reply.error_code = StatusCode::OK; | ||
873 | } while (0); | 893 | } while (0); |
874 | } while (0); | 894 | } while (0); |
875 | 895 | ||
@@ -882,7 +902,10 @@ ReadPINPadCmd::Reply ReadDILICardBasicInfoCmd::Execute(const std::string& input) | @@ -882,7 +902,10 @@ ReadPINPadCmd::Reply ReadDILICardBasicInfoCmd::Execute(const std::string& input) | ||
882 | reply.data.put("type", card_basic_info.type_code); | 902 | reply.data.put("type", card_basic_info.type_code); |
883 | reply.data.put("issuerCode", card_basic_info.issuer_code); | 903 | reply.data.put("issuerCode", card_basic_info.issuer_code); |
884 | reply.data.put("verifyCode", card_basic_info.verify_code); | 904 | reply.data.put("verifyCode", card_basic_info.verify_code); |
885 | - g_sCardNum = card_basic_info.device_id; | 905 | + reply.data.put("subType", card_basic_info.sub_type); |
906 | + reply.data.put("makerVersion", card_basic_info.maker_version); | ||
907 | + reply.data.put("chipType", card_basic_info.chip_type); | ||
908 | + g_card_num = card_basic_info.device_id; | ||
886 | return reply; | 909 | return reply; |
887 | } | 910 | } |
888 | 911 | ||
@@ -928,8 +951,8 @@ ReadPINPadCmd::Reply ReadDILICardServiceInfoCmd::Execute(const std::string& inpu | @@ -928,8 +951,8 @@ ReadPINPadCmd::Reply ReadDILICardServiceInfoCmd::Execute(const std::string& inpu | ||
928 | break; | 951 | break; |
929 | } | 952 | } |
930 | 953 | ||
931 | - DILICard::BasicInfo stuCardBasicInfo; | ||
932 | - try { stuCardBasicInfo = dili_card_device.ReadCardBasicInfo(); } | 954 | + DILICard::BasicInfo card_basic_info; |
955 | + try { card_basic_info = dili_card_device.ReadCardBasicInfo(); } | ||
933 | catch (std::exception& ex) | 956 | catch (std::exception& ex) |
934 | { | 957 | { |
935 | LOG_FATAL(L"读取卡片基本信息失败,错误信息: " + str_2_wstr(ex.what())); | 958 | LOG_FATAL(L"读取卡片基本信息失败,错误信息: " + str_2_wstr(ex.what())); |
@@ -941,11 +964,11 @@ ReadPINPadCmd::Reply ReadDILICardServiceInfoCmd::Execute(const std::string& inpu | @@ -941,11 +964,11 @@ ReadPINPadCmd::Reply ReadDILICardServiceInfoCmd::Execute(const std::string& inpu | ||
941 | std::string sSN; | 964 | std::string sSN; |
942 | if (slLevel == HardwareCmd::SL_1) | 965 | if (slLevel == HardwareCmd::SL_1) |
943 | { | 966 | { |
944 | - sSN = stuCardBasicInfo.device_id; | 967 | + sSN = card_basic_info.device_id; |
945 | } | 968 | } |
946 | else if (slLevel == HardwareCmd::SL_2) | 969 | else if (slLevel == HardwareCmd::SL_2) |
947 | { | 970 | { |
948 | - sSN = stuCardBasicInfo.chip_num + "44494c49" + stuCardBasicInfo.chip_num; | 971 | + sSN = card_basic_info.chip_num + "44494c49" + card_basic_info.chip_num; |
949 | } | 972 | } |
950 | 973 | ||
951 | if (etEncrypType == ET_PWM) | 974 | if (etEncrypType == ET_PWM) |
@@ -1015,14 +1038,13 @@ ReadPINPadCmd::Reply ReadDILICardServiceInfoCmd::Execute(const std::string& inpu | @@ -1015,14 +1038,13 @@ ReadPINPadCmd::Reply ReadDILICardServiceInfoCmd::Execute(const std::string& inpu | ||
1015 | ReadPINPadCmd::Reply WriteDILICardServiceInfoCmd::Execute(const std::string& input) | 1038 | ReadPINPadCmd::Reply WriteDILICardServiceInfoCmd::Execute(const std::string& input) |
1016 | { | 1039 | { |
1017 | const char DATA_SPLITER = ':'; | 1040 | const char DATA_SPLITER = ':'; |
1018 | - SecurityLevel slLevel = (SecurityLevel)ApplicationConfig::Instance().SecurityLevel(); | ||
1019 | - EncryptType etEncrypType = (EncryptType)ApplicationConfig::Instance().EncryptType(); | 1041 | + SecurityLevel secu_level = (SecurityLevel)ApplicationConfig::Instance().SecurityLevel(); |
1042 | + EncryptType encrypt_type = (EncryptType)ApplicationConfig::Instance().EncryptType(); | ||
1020 | 1043 | ||
1021 | LOG_TRACE(L"写入卡片业务信息。"); | 1044 | LOG_TRACE(L"写入卡片业务信息。"); |
1022 | auto& dili_card_device = DILICardRWDevice(); | 1045 | auto& dili_card_device = DILICardRWDevice(); |
1023 | 1046 | ||
1024 | Reply reply; | 1047 | Reply reply; |
1025 | - //std::string card_sn; | ||
1026 | std::string key_w; | 1048 | std::string key_w; |
1027 | do | 1049 | do |
1028 | { | 1050 | { |
@@ -1038,7 +1060,7 @@ ReadPINPadCmd::Reply WriteDILICardServiceInfoCmd::Execute(const std::string& inp | @@ -1038,7 +1060,7 @@ ReadPINPadCmd::Reply WriteDILICardServiceInfoCmd::Execute(const std::string& inp | ||
1038 | } | 1060 | } |
1039 | 1061 | ||
1040 | //安全等级都为0了,还写个毛的业务信息,直接返回! | 1062 | //安全等级都为0了,还写个毛的业务信息,直接返回! |
1041 | - if (slLevel == HardwareCmd::SL_0) | 1063 | + if (secu_level == HardwareCmd::SL_0) |
1042 | { | 1064 | { |
1043 | reply.error_code == StatusCode::OK; | 1065 | reply.error_code == StatusCode::OK; |
1044 | LOG_TRACE(L"读取卡片业务信息成功。"); | 1066 | LOG_TRACE(L"读取卡片业务信息成功。"); |
@@ -1056,25 +1078,24 @@ ReadPINPadCmd::Reply WriteDILICardServiceInfoCmd::Execute(const std::string& inp | @@ -1056,25 +1078,24 @@ ReadPINPadCmd::Reply WriteDILICardServiceInfoCmd::Execute(const std::string& inp | ||
1056 | break; | 1078 | break; |
1057 | } | 1079 | } |
1058 | 1080 | ||
1059 | - DILICard::BasicInfo stuCardBasicInfo; | ||
1060 | - try { stuCardBasicInfo = dili_card_device.ReadCardBasicInfo(); } | 1081 | + DILICard::BasicInfo card_basic_info; |
1082 | + try { card_basic_info = dili_card_device.ReadCardBasicInfo(); } | ||
1061 | catch (std::exception& ex) | 1083 | catch (std::exception& ex) |
1062 | { | 1084 | { |
1063 | LOG_FATAL(L"读取卡片基本信息失败,错误信息: " + str_2_wstr(ex.what())); | 1085 | LOG_FATAL(L"读取卡片基本信息失败,错误信息: " + str_2_wstr(ex.what())); |
1064 | reply.error_code = StatusCode::DILI_CARD_DEVICE_READ_BASIC_INFO_FAILED; | 1086 | reply.error_code = StatusCode::DILI_CARD_DEVICE_READ_BASIC_INFO_FAILED; |
1065 | break; | 1087 | break; |
1066 | } | 1088 | } |
1067 | - //card_sn = stuCardBasicInfo.device_id; | ||
1068 | 1089 | ||
1069 | LOG_TRACE(L"计算SN。"); | 1090 | LOG_TRACE(L"计算SN。"); |
1070 | std::string sSN; | 1091 | std::string sSN; |
1071 | - if (slLevel == HardwareCmd::SL_1) | 1092 | + if (secu_level == HardwareCmd::SL_1) |
1072 | { | 1093 | { |
1073 | - sSN = stuCardBasicInfo.device_id; | 1094 | + sSN = card_basic_info.device_id; |
1074 | } | 1095 | } |
1075 | - else if (slLevel == HardwareCmd::SL_2) | 1096 | + else if (secu_level == HardwareCmd::SL_2) |
1076 | { | 1097 | { |
1077 | - sSN = stuCardBasicInfo.chip_num + "44494c49" + stuCardBasicInfo.chip_num; | 1098 | + sSN = card_basic_info.chip_num + "44494c49" + card_basic_info.chip_num; |
1078 | } | 1099 | } |
1079 | 1100 | ||
1080 | 1101 | ||
@@ -1085,7 +1106,7 @@ ReadPINPadCmd::Reply WriteDILICardServiceInfoCmd::Execute(const std::string& inp | @@ -1085,7 +1106,7 @@ ReadPINPadCmd::Reply WriteDILICardServiceInfoCmd::Execute(const std::string& inp | ||
1085 | reply.error_code = StatusCode::DILI_CARD_DEVICE_WRITE_SERVICE_INFO_FAILED; | 1106 | reply.error_code = StatusCode::DILI_CARD_DEVICE_WRITE_SERVICE_INFO_FAILED; |
1086 | break; | 1107 | break; |
1087 | } | 1108 | } |
1088 | - std::string device_id = g_sCardNum;//用于办卡时,保证操作的卡片是同一张; | 1109 | + std::string device_id = g_card_num;//用于办卡时,保证操作的卡片是同一张; |
1089 | std::string service_data = input.substr(index + 1, input.size() - index - 1); | 1110 | std::string service_data = input.substr(index + 1, input.size() - index - 1); |
1090 | 1111 | ||
1091 | // 验证操作的是否是同一张卡,即device_id是否匹配 | 1112 | // 验证操作的是否是同一张卡,即device_id是否匹配 |
@@ -1096,7 +1117,7 @@ ReadPINPadCmd::Reply WriteDILICardServiceInfoCmd::Execute(const std::string& inp | @@ -1096,7 +1117,7 @@ ReadPINPadCmd::Reply WriteDILICardServiceInfoCmd::Execute(const std::string& inp | ||
1096 | break; | 1117 | break; |
1097 | } | 1118 | } |
1098 | 1119 | ||
1099 | - if (etEncrypType == ET_PWM) | 1120 | + if (encrypt_type == ET_PWM) |
1100 | { | 1121 | { |
1101 | LOG_TRACE(L"加密机模式计算主控秘钥。"); | 1122 | LOG_TRACE(L"加密机模式计算主控秘钥。"); |
1102 | auto& pwd_machine = PWDMachine_(); | 1123 | auto& pwd_machine = PWDMachine_(); |
@@ -1122,7 +1143,7 @@ ReadPINPadCmd::Reply WriteDILICardServiceInfoCmd::Execute(const std::string& inp | @@ -1122,7 +1143,7 @@ ReadPINPadCmd::Reply WriteDILICardServiceInfoCmd::Execute(const std::string& inp | ||
1122 | 1143 | ||
1123 | pwd_machine.Disconnect(); | 1144 | pwd_machine.Disconnect(); |
1124 | } | 1145 | } |
1125 | - else if (etEncrypType == ET_DES) | 1146 | + else if (encrypt_type == ET_DES) |
1126 | { | 1147 | { |
1127 | LOG_TRACE(L"软加密模式计算15写秘钥。"); | 1148 | LOG_TRACE(L"软加密模式计算15写秘钥。"); |
1128 | const char* pDAMKDL = "414d4b31414d4b31"; | 1149 | const char* pDAMKDL = "414d4b31414d4b31"; |
@@ -1151,8 +1172,6 @@ ReadPINPadCmd::Reply WriteDILICardServiceInfoCmd::Execute(const std::string& inp | @@ -1151,8 +1172,6 @@ ReadPINPadCmd::Reply WriteDILICardServiceInfoCmd::Execute(const std::string& inp | ||
1151 | reply.error_code = StatusCode::DILI_CARD_DEVICE_WRITE_SERVICE_INFO_FAILED; | 1172 | reply.error_code = StatusCode::DILI_CARD_DEVICE_WRITE_SERVICE_INFO_FAILED; |
1152 | break; | 1173 | break; |
1153 | } | 1174 | } |
1154 | - | ||
1155 | - | ||
1156 | } while (0); | 1175 | } while (0); |
1157 | 1176 | ||
1158 | dili_card_device.Disconnect(); | 1177 | dili_card_device.Disconnect(); |
@@ -1194,3 +1213,86 @@ ReadPINPadCmd::Reply ReadBankCardNumCmd::Execute(const std::string& input) | @@ -1194,3 +1213,86 @@ ReadPINPadCmd::Reply ReadBankCardNumCmd::Execute(const std::string& input) | ||
1194 | reply.data.put("chipNo", bank_card_no); | 1213 | reply.data.put("chipNo", bank_card_no); |
1195 | return reply; | 1214 | return reply; |
1196 | } | 1215 | } |
1216 | + | ||
1217 | +ReadPINPadCmd::Reply ActivateDILIM1CardCmd::Execute(const std::string& input) | ||
1218 | +{ | ||
1219 | + LOG_TRACE(L"m1卡入库。"); | ||
1220 | + Reply reply; | ||
1221 | + DILICard::BasicInfo card_basic_info; | ||
1222 | + | ||
1223 | + auto& dili_card_device = DILICardRWDevice(); | ||
1224 | + | ||
1225 | + do | ||
1226 | + { | ||
1227 | + try | ||
1228 | + { | ||
1229 | + dili_card_device.Connect(); | ||
1230 | + } | ||
1231 | + catch (std::exception& ex) | ||
1232 | + { | ||
1233 | + LOG_FATAL(L"连接读卡器失败,错误信息: " + str_2_wstr(ex.what())); | ||
1234 | + reply.error_code = StatusCode::CPU_CARD_DEVICE_CONNECT_FAILED; | ||
1235 | + break; | ||
1236 | + } | ||
1237 | + | ||
1238 | + int error_code = dili_card_device.M1FindCard(); | ||
1239 | + if (error_code) | ||
1240 | + { | ||
1241 | + CString error; | ||
1242 | + error.Format(L"m1卡寻卡失败,错误信息: %d", error_code); | ||
1243 | + LOG_FATAL(error.GetBuffer()); | ||
1244 | + reply.error_code = StatusCode::CPU_CARD_DEVICE_CANNOT_FIND_CARD; | ||
1245 | + break; | ||
1246 | + } | ||
1247 | + | ||
1248 | + try | ||
1249 | + { | ||
1250 | + namespace PT = boost::property_tree; | ||
1251 | + PT::ptree ptree; | ||
1252 | + std::stringstream ss; | ||
1253 | + ss << input; | ||
1254 | + PT::read_json(ss, ptree); | ||
1255 | + card_basic_info.chip_num = ptree.get<std::string>("chipNo"); | ||
1256 | + card_basic_info.type_code = ptree.get<std::string>("type"); | ||
1257 | + card_basic_info.issuer_code = ptree.get<std::string>("issuerCode"); | ||
1258 | + card_basic_info.verify_code = ptree.get<std::string>("verifyCode"); | ||
1259 | + card_basic_info.sub_type = ptree.get<std::string>("subType"); | ||
1260 | + card_basic_info.maker_version = ptree.get<std::string>("makerVersion"); | ||
1261 | + card_basic_info.device_id = ptree.get<std::string>("deviceId"); | ||
1262 | + } | ||
1263 | + catch (std::exception& ex) | ||
1264 | + { | ||
1265 | + LOG_FATAL(L"解析服务器数据失败。"); | ||
1266 | + reply.error_code = StatusCode::DILI_CARD_DEVICE_PARSE_SEVER_DATA_FAILED; | ||
1267 | + break; | ||
1268 | + } | ||
1269 | + | ||
1270 | + | ||
1271 | + error_code = dili_card_device.M1WriteBasicInfo(card_basic_info.chip_num, card_basic_info.type_code, card_basic_info.issuer_code,\ | ||
1272 | + card_basic_info.verify_code, card_basic_info.sub_type, card_basic_info.maker_version); | ||
1273 | + if (error_code) | ||
1274 | + { | ||
1275 | + CString error; | ||
1276 | + error.Format(L"m1卡初始化失败,错误信息: %d", error_code); | ||
1277 | + LOG_FATAL(error.GetBuffer()); | ||
1278 | + reply.error_code = StatusCode::DILI_CARD_DEVICE_ACTIVATE_CARD_FAILED; | ||
1279 | + break; | ||
1280 | + } | ||
1281 | + card_basic_info.chip_type = "2"; //m1卡类型 | ||
1282 | + } while (0); | ||
1283 | + | ||
1284 | + dili_card_device.Disconnect(); | ||
1285 | + if (boost::iequals(reply.error_code, StatusCode::OK)) | ||
1286 | + LOG_TRACE(L"卡片激活成功。"); | ||
1287 | + | ||
1288 | + reply.data.put("chipNo", card_basic_info.chip_num); | ||
1289 | + reply.data.put("deviceId", card_basic_info.device_id); | ||
1290 | + reply.data.put("type", card_basic_info.type_code); | ||
1291 | + reply.data.put("issuerCode", card_basic_info.issuer_code); | ||
1292 | + reply.data.put("verifyCode", card_basic_info.verify_code); | ||
1293 | + reply.data.put("subType", card_basic_info.sub_type); | ||
1294 | + reply.data.put("makerVersion", card_basic_info.maker_version); | ||
1295 | + reply.data.put("chipType", card_basic_info.chip_type); | ||
1296 | + return reply; | ||
1297 | + | ||
1298 | +} | ||
1197 | \ No newline at end of file | 1299 | \ No newline at end of file |
etrade_card_client/ETradeClient/hardware/hardware_cmd.h
@@ -86,4 +86,10 @@ class ReadBankCardNumCmd : public HardwareCmd | @@ -86,4 +86,10 @@ class ReadBankCardNumCmd : public HardwareCmd | ||
86 | public: | 86 | public: |
87 | virtual Reply Execute(const std::string& input) override; | 87 | virtual Reply Execute(const std::string& input) override; |
88 | }; | 88 | }; |
89 | + | ||
90 | +class ActivateDILIM1CardCmd : public HardwareCmd | ||
91 | +{ | ||
92 | +public: | ||
93 | + virtual Reply Execute(const std::string& input) override; | ||
94 | +}; | ||
89 | #endif // ETRADECLIENT_HARDWARE_HARDWARE_CMD_H_INCLUDED | 95 | #endif // ETRADECLIENT_HARDWARE_HARDWARE_CMD_H_INCLUDED |