cardissuer_impl.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. #ifndef LIBFRAMEWORK_CARDISSUER_IMPL_H
  2. #define LIBFRAMEWORK_CARDISSUER_IMPL_H
  3. #include <SpBase.h>
  4. #include "CardIssuerClass.h"
  5. #include "../../DeviceSimulator.h"
  6. #include "IHttpFunc.h"
  7. #include "json/json.h"
  8. #include <string>
  9. using namespace std;
  10. typedef struct CommonReq : CHTTPReq {
  11. string m_reqStr;
  12. string ToJson() {
  13. return m_reqStr;
  14. }
  15. } CommonReq;
  16. typedef struct CommonRet : CHTTPRet {
  17. string m_retStr;
  18. bool Parse(string strData) {
  19. m_retStr = strData;
  20. return true;
  21. }
  22. } CommonRet;
  23. class CardIssuerImpl : public CardIssuerClass
  24. {
  25. public:
  26. CardIssuerImpl();
  27. ~CardIssuerImpl();
  28. static void HttpsLogCallBack(const char* logtxt) {}
  29. //DeviceBaseClass
  30. ErrorCodeEnum GetDevCategory(DevCategoryInfo& devCategory);
  31. ErrorCodeEnum Reset();
  32. ErrorCodeEnum DevClose();
  33. ErrorCodeEnum GetLastErr(DevErrorInfo& devErrInfo);
  34. //本接口几乎废弃不用。连接卡机,请使用DevOpenEx替代本接口
  35. ErrorCodeEnum DevOpen(DWORD dwPort, DWORD dwBaudRate) { return Error_NotImpl; }//废弃
  36. // Get card issuer status
  37. //使用(卡库,卡机)
  38. ErrorCodeEnum GetDevStatus(CardIssuerStatus& devStatus);
  39. //
  40. // Get device serial number.
  41. // 设备唯一标识,且需贴在设备外壳上
  42. // 使用(pad)
  43. ErrorCodeEnum GetDeviceSN(char*& pDevSN) ;
  44. //
  45. // Move card to specified position.
  46. // hopperNo:多卡箱发卡时指定发卡箱号(面对发卡机,从左往右依次是1,2,3,...号卡箱)
  47. // 卡库:卡片从卡库加卡箱移动到读卡器,eCardPos为CI_MOVECARD_FROM_HOPPER,hopperNo固定传入99
  48. // 卡库:卡片从卡库加卡箱移动到读卡器,若加卡箱已经无卡,返回Error_Dev_HopperHasNoCard
  49. //使用(卡库,卡机)*****
  50. ErrorCodeEnum MoveCard(CardPosEnum eCardPos, int hopperNo = 1) ;
  51. //
  52. // Set card entry
  53. //使用(卡库,卡机)*****
  54. ErrorCodeEnum SetCardInType(CardInEnum eCardIn) ;
  55. //
  56. // Read data from magnetic track.
  57. //使用(卡库,卡机)
  58. ErrorCodeEnum MagRead(MagTracks& magTracks) ;
  59. // Write data to magnetic track.
  60. //使用(卡库)*****
  61. ErrorCodeEnum MagWrite(MagTracks magTracks, MagWriteModeEnum eWriteMode) ;
  62. //
  63. // Set retract counter
  64. ErrorCodeEnum SetRetractCounter(DWORD dwCount) { return Error_NotImpl; } //废弃
  65. //
  66. // Set issuer counter
  67. // hopperNo:多卡箱发卡时指定发卡箱号(面对发卡机,从左往右依次是1,2,3,...号卡箱)
  68. ErrorCodeEnum SetIssuerCounter(DWORD dwCount, int hopperNo = 1) { return Error_NotImpl; }//废弃
  69. //
  70. // Active contact IC card
  71. //使用(卡库,卡机)*****
  72. ErrorCodeEnum ActiveICCard() ;
  73. //
  74. // Move IC card to contact position
  75. //使用(卡库,卡机)*****
  76. ErrorCodeEnum ContactIC() ;
  77. //
  78. // Release IC contact
  79. //使用(卡库,卡机)*****
  80. ErrorCodeEnum ReleaseIC() ;
  81. //
  82. // Warm reset card(IC)
  83. //使用(卡库,卡机)*****
  84. ErrorCodeEnum WarmReset() ;
  85. // APDU:Application Protocol Data Unit
  86. // CmdSend.lpCmd:Command-APDU
  87. // CmdRecv.lpData:Response-APDU
  88. //使用(卡库,卡机)
  89. ErrorCodeEnum ICCommand(CmdInfo sendBuf, CmdInfo& recvBuf) ;
  90. //////////////////SAM 卡操作部分////////////////////
  91. ErrorCodeEnum SAMActive(BYTE vcc = 0x30) { return Error_NotImpl; }//使用(卡库,卡机)
  92. ErrorCodeEnum SAMDeactivate() { return Error_NotImpl; }//使用(卡库,卡机)
  93. ErrorCodeEnum SAMWarmReset() { return Error_NotImpl; }//使用(卡库,卡机)
  94. ErrorCodeEnum SAMQueryStatus(SAMStatus& samStatus) { return Error_NotImpl; }//使用(卡库,卡机)
  95. ErrorCodeEnum SAMSelect(const int sn) { return Error_NotImpl; }//使用(卡库,卡机)
  96. //即时制卡卡库需要实现SAMCommand,用来执行apdu指令
  97. ErrorCodeEnum SAMCommand(CmdInfo sendBuf, CmdInfo& recvBuf) ;//使用(卡库,卡机)
  98. //即时制卡卡库需要实现ActiveICCardATR,用来激活卡片,返回ATR
  99. ErrorCodeEnum ActiveICCardATR(CmdInfo& atrBuf) ;//使用(卡库,卡机)
  100. ////////////////卡面打印部分(非即时制卡的卡面印刷,即时制卡的卡面打印接口为PrintCardFaceRightNow),部分机型(例如合肥分行大机)有此功能//////////////////
  101. ErrorCodeEnum Print(BYTE*& data, const int dataSize, const int side) { return Error_NotImpl; }//废弃
  102. ErrorCodeEnum QueryPrinterStatus() { return Error_NotImpl; }//废弃
  103. ////////////////////////////////////////////////////////////////////////////
  104. ////////非接(IC)部分 start,没有此部分,在接口实现中直接返回Error_NotImpl///////////////
  105. ////////////////////////////////////////////////////////////////////////////
  106. // Active contactless IC card(Type A,B,Mifare)
  107. // The first,second,third activation order decided by fstType,scdType,thdType respectively
  108. // fstType,scdType,thdType can be one of 'A','B','M','0'(30H,no type)
  109. // outType indicates the type of activation result
  110. //
  111. ErrorCodeEnum ActiveContactlessICCard(char fstType, char scdType, char thdType, char& outType) ;//使用(卡库,卡机)
  112. //
  113. // Deactivate contact IC card *****
  114. //
  115. ErrorCodeEnum DeactivateICCard() ; //使用(卡库,卡机)
  116. //
  117. // Deactivate contactless IC card *****
  118. //
  119. ErrorCodeEnum DeactContactlessICCard() ;//使用(卡库,卡机)
  120. //
  121. // RF Mifare Classic protocol operation
  122. // Arguments:
  123. // - eFunType:function type as load key,authentication and so on
  124. // - sendBuf:[parameter][data]
  125. // - recvBuf:[status(1byte)][return data]
  126. //
  127. ErrorCodeEnum MifareCommand(MifareFuctionEnum eFunType, CmdInfo sendBuf, CmdInfo& recvBuf) { return Error_NotImpl; }//废弃
  128. //
  129. // RF Type A,B command.
  130. // APDU:Application Protocol Data Unit
  131. // Arguments:
  132. // - CmdSend.lpCmd:Command-APDU
  133. // - CmdRecv.lpData:Response-APDU
  134. //
  135. ErrorCodeEnum RFTypeABCommand(CmdInfo sendBuf, CmdInfo& recvBuf) ;//使用(卡库,卡机)
  136. ////////非接(IC)部分 end/////////////////////////////////////////////////////////
  137. // 发卡机调用打开设备
  138. // 1. btOpenType:设定通过哪种方式连接设备,由DevOpenType的枚举值组合。usb及蓝牙设备连接可忽略dwPort,dwBaudRate
  139. // 2.通过pDevSN来指定连接对应设备号的蓝牙发卡机(考虑存在多台发卡机的情况)
  140. // 例如通过蓝牙或者usb连接设备,则btOpenType = (DEV_OPEN_TYPE_USB|DEV_OPEN_TYPE_BLUETOOTH)
  141. // 3. btType返回设备实际通过哪种方式相连,返回值参考DevOpenType(大机,卡库参考下一条)
  142. // 4.对于大机(柜式可视柜台,卡库)dwPort,dwBaudRate传入端口,波特率,btOpenType为DEV_OPEN_TYPE_COM,pDevSN为""
  143. // ,btType返回值表示卡槽数量(例如目前存在单卡槽1,双卡槽2,三卡槽3的机型)
  144. // *****
  145. ErrorCodeEnum DevOpenEx(DWORD dwPort, DWORD dwBaudRate, BYTE btOpenType, const char* pDevSN, BYTE& btType) ;//使用(卡库,卡机)
  146. /////////////////////////////////////////////////////////////////////////
  147. ///以下是便携式卡机特有API,接口实现中其他机型直接返回Error_NotImpl即可//
  148. /////////////////////////////////////////////////////////////////////////
  149. // 返回值Error_Succeed表示成功,其他值表示失败
  150. // iStatus 0:成功 -1:银行公钥不存在 -2:产生设备密钥故障 -x:其他厂商自定义故障
  151. // Cr1:随机数r1的密文; Cr3:随机数r3的密文,dKey:用银行公钥加密的设备公钥密文
  152. // r1,r3第16字节为数据完整性校验字节,例如r1为B1B2...B15B16,则B16=B1^B2^...^B15
  153. ErrorCodeEnum TransferEnInit(int& iStatus, BYTE*& Cr1, int& lenR1, BYTE*& Cr3, int& lenR3, BYTE*& dKey, int& lenKey) ;//使用(刷卡器)
  154. // 返回值Error_Succeed表示成功,其他值表示失败
  155. // iStatus 0:成功 -x:厂商自定义故障
  156. // r2第16字节为数据完整性校验字节,例如r2为B1B2...B15B16,则B16=B1^B2^...^B15
  157. ErrorCodeEnum SetR2(int& iStatus, BYTE* pCr2, int lenR2) ;//使用(刷卡器)
  158. //
  159. // 设置会话密钥
  160. // pWorkingKey:会话密钥,传递16进制的字符形式,例如0x123456FFAB --> "123456FFAB"
  161. ErrorCodeEnum SendWorkingKey(const char* pWorkingKey) ;//使用(刷卡器)
  162. //安全锁接口部分 begin
  163. ErrorCodeEnum SLLoadKey(const SCIKeyInfo key) { return Error_NotImpl; }// 使用(刷卡器) 废弃
  164. //case ParamBeep: value:0,close beep;value:1,open beep
  165. //case ParamLed: value:0,close led;value:1,open led
  166. //case ParamLevelTime: value:the duration of level,100ms per unit
  167. // ex. the value 10 means duration time is 1 second
  168. ErrorCodeEnum SLSetParam(SCIParamType eType, int value) { return Error_NotImpl; }//废弃
  169. ErrorCodeEnum SLLock() { return Error_NotImpl; }//废弃
  170. ErrorCodeEnum SLUnLock(const SCICheckCode checkCode, bool bTemp = true) { return Error_NotImpl; }//废弃
  171. ErrorCodeEnum SLGetTempData(SCITempData& ksnData, SCITempData& ramData) { return Error_NotImpl; }//废弃
  172. ErrorCodeEnum SLOpenDoor(const SCITempData data) { return Error_NotImpl; }//废弃
  173. //安全锁接口部分 end
  174. //蓝牙控制部分 start
  175. //蓝牙指令控制,命令参看SCIBluetoothCMD说明
  176. ErrorCodeEnum BluetoothControl(SCIBluetoothCMD eCmd) { return Error_NotImpl; }//废弃
  177. //修改配对密码
  178. ErrorCodeEnum BluetoothModifyKey(unsigned char* key) { return Error_NotImpl; }//废弃
  179. //修改蓝牙设备名称
  180. ErrorCodeEnum BluetoothModifyName(unsigned char* name) { return Error_NotImpl; }//废弃
  181. //获取版本信息
  182. ErrorCodeEnum BluetoothGetVersion(char*& version) { return Error_NotImpl; }//废弃
  183. //获取连接设备名称
  184. ErrorCodeEnum BluetoothGetConnectName(unsigned char*& name) { return Error_NotImpl; }//废弃
  185. //获取连接设备信号强度
  186. ErrorCodeEnum BluetoothGetSignalStrength(unsigned char*& signal) { return Error_NotImpl; }//废弃
  187. //蓝牙控制部分 end
  188. //控制灯光
  189. //eLight:所控制的灯 ;
  190. //bOnOff:true 亮灯;fasle 灭灯
  191. ErrorCodeEnum LightControl(SCILightType eLight, bool bOnOff) { return Error_NotImpl; }//废弃
  192. //以百分比数值返回剩余电量(1-100),例如剩余51%,则bat赋值为51
  193. ErrorCodeEnum QueryBatteryPower(int& bat) { return Error_NotImpl; }//废弃
  194. //oiltest
  195. //virtual ErrorCodeEnum EncryptData(TempData ramData, TempData bdk, TempData curksn, TempData &encryptedData) ;
  196. //把卡片从读卡器移动到指定卡槽位
  197. ErrorCodeEnum MoveCardToSlot(int slot) ;//使用(卡库,卡机)
  198. //把卡片从指定卡槽位移动到读卡器
  199. ErrorCodeEnum MoveCardFromSlot(int slot) ;//使用(卡库,卡机)
  200. //读取卡号
  201. //优先从IC卡解析卡号,如果纯磁条卡,则返回磁道解析的卡号
  202. ErrorCodeEnum ReadAccount(CardNo& cardNo) ;//使用(卡库,卡机)
  203. //获取总卡槽数
  204. ErrorCodeEnum GetSlotSum(int& sum) ;//使用(卡库,卡机)
  205. //获取卡槽状态
  206. ErrorCodeEnum QuerySlotsStatus(SlotStatus& slots, const int slot, bool bFull = false) ;//使用(卡库,卡机)
  207. //即时制卡卡库专用接口
  208. ErrorCodeEnum PrintCardFaceRightNow(const KakuPrintInfo printInfo) ;//使用(卡库,卡机)
  209. /////////////////////////////////////http实现///////////////////////////////////////
  210. bool GetDevStatusHttp(CardIssuerStatus& devStatus);
  211. bool GetDeviceSNHttp(char*& pDevSN);
  212. bool MoveCardHttp(CardPosEnum eCardPos, int hopperNo = 1);
  213. bool SetCardInTypeHttp(CardInEnum eCardIn);
  214. bool MagReadHttp(MagTracks& magTracks);
  215. bool MagWriteHttp(MagTracks magTracks, MagWriteModeEnum eWriteMode);
  216. bool ActiveICCardHttp();
  217. bool ContactICHttp();
  218. bool ReleaseICHttp();
  219. bool WarmResetHttp();
  220. bool ICCommandHttp(CmdInfo sendBuf, CmdInfo& recvBuf);
  221. //////////////////SAM 卡操作部分////////////////////
  222. bool SAMCommandHttp(CmdInfo sendBuf, CmdInfo& recvBuf);
  223. bool ActiveICCardATRHttp(CmdInfo& atrBuf);
  224. bool ActiveContactlessICCardHttp(char fstType, char scdType, char thdType, char& outType);
  225. bool DeactivateICCardHttp();
  226. bool DeactContactlessICCardHttp();
  227. bool RFTypeABCommandHttp(CmdInfo sendBuf, CmdInfo& recvBuf);
  228. bool DevOpenExHttp(DWORD dwPort, DWORD dwBaudRate, BYTE btOpenType, const char* pDevSN, BYTE& btType);
  229. /////////////////////////////////////////////////////////////////////////
  230. ///以下是便携式卡机刷卡器特有API,接口实现中其他机型直接返回Error_NotImpl即可//
  231. /////////////////////////////////////////////////////////////////////////
  232. bool TransferEnInitHttp(int& iStatus, BYTE*& Cr1, int& lenR1, BYTE*& Cr3, int& lenR3, BYTE*& dKey, int& lenKey);
  233. bool SetR2Http(int& iStatus, BYTE* pCr2, int lenR2);
  234. bool SendWorkingKeyHttp(const char* pWorkingKey);
  235. //////////////卡库使用/////////////////////
  236. bool MoveCardToSlotHttp(int slot);
  237. bool MoveCardFromSlotHttp(int slot);
  238. bool ReadAccountHttp(CardNo& cardNo);
  239. bool GetSlotSumHttp(int& sum);
  240. bool QuerySlotsStatusHttp(SlotStatus& slots, const int slot, bool bFull = false);
  241. bool PrintCardFaceRightNowHttp(const KakuPrintInfo printInfo);
  242. /////////////////////////////////////http实现///////////////////////////////////////
  243. string depCfgPath;
  244. iniReader iniRead;
  245. string getUrl();
  246. bool commonSimpleHttp(string adapterInterName);
  247. };
  248. #endif //LIBFRAMEWORK_CARDISSUER_IMPL_H