123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365 |
- #ifndef IDCERTFSM_H
- #define IDCERTFSM_H
- #pragma once
- #ifdef RVC_OS_LINUX
- #include "SpFSM.h"
- #include "SpTest.h"
- #include "DevFSMCommBase.hpp"
- #else //windows
- #include "SpFSM.h"
- #include "json/json.h"
- #include <xstring>
- #endif
- #include <unordered_map>
- #ifdef RVC_OS_WIN
- #include "DevFSMCommBase.hpp"
- #include "IHttpFunc.h"
- #define REFLECTION(var) #var
- typedef struct ImgCheckReq : CHTTPReq {
- string terminalNo;
- string name;
- string idNo;
- string nationality;
- string idType;
- string imageBase64;
- string fspId;
- int topN;
- int returnImgBase64;
- string ToJson() {
- Json::Value value;
- value[REFLECTION(terminalNo)] = terminalNo;
- value[REFLECTION(name)] = name;
- value[REFLECTION(idNo)] = idNo;
- value[REFLECTION(nationality)] = nationality;
- value[REFLECTION(idType)] = idType;
- value[REFLECTION(imageBase64)] = imageBase64;
- value[REFLECTION(fspId)] = fspId;
- value[REFLECTION(topN)] = topN;
- value[REFLECTION(returnImgBase64)] = returnImgBase64;
- Json::FastWriter writer;
- string strData = writer.write(value);
- return strData;
- }
- } ImgCheckReq;
- typedef struct ImgCheckRet : CHTTPRet {
- bool m_success;
- bool Parse(string strData) {
- Json::Value root;
- Json::Reader reader;
- reader.parse(strData, root, false);
- if (root["success"].isBool()) {
- m_success = root["success"].asBool();
- }
- else
- {
- m_success = false;
- }
- return true;
- }
- } ImgCheckRet;
- #endif
- enum EvtType
- {
- USER_EVT_TEST = EVT_USER + 1,
- USER_EVT_QUIT,
- USER_EVT_CANCEL_READ,
- USER_EVT_EXIT,
- USER_EVT_GET_DEVINFO,
- USER_EVT_ERROR,
- USER_EVT_INIT_FINISHED,
- USER_EVT_TODO_INIT,
- USER_EVT_TODO_INIT_FINISHED,
- USER_EVT_READ_AND_SCAN_UTF8, //ex1
- USER_EVT_READ_AND_SCAN_UTF8_FINISHED,
- USER_EVT_READ_AND_SCAN_UTF8JS,
- USER_EVT_READ_AND_SCAN_UTF8JS_FINISHED
- };
- enum BmpType
- {
- Bmp_ZP = 1,
- Bmp_SCAN = 2,
- };
- #include "IDCerClass.h"
- #include "IDCertificate_def_g.h"
- #include "IDCertificate_LogCode.h"
- #pragma region forsonar
- typedef IDCertificate::IDCertService_CancelRead_Info IDCert_CancelRead_Info;
- typedef IDCertificate::IDCertService_ReadAndScanUTF8_Req IDCert_ReadAndScanUTF8_Req; //ex2
- typedef IDCertificate::IDCertService_ReadAndScanUTF8_Ans IDCert_ReadAndScanUTF8_Ans;
- typedef IDCertificate::IDCertService_ReadAndScanUTF8JS_Req IDCert_ReadAndScanUTF8JS_Req; //js ReadAndScanUTF8
- typedef IDCertificate::IDCertService_ReadAndScanUTF8JS_Ans IDCert_ReadAndScanUTF8JS_Ans;
- typedef IDCertificate::IDCertService_CancelReadJS_Req IDCert_CancelReadJS_Req; //js CancelRead
- typedef IDCertificate::IDCertService_CancelReadJS_Ans IDCert_CancelReadJS_Ans;
- typedef IDCertificate::IDCertService_GetDevInfo_Req IDCert_GetDevInfo_Req;
- typedef IDCertificate::IDCertService_GetDevInfo_Ans IDCert_GetDevInfo_Ans;
- #pragma endregion forsonar
- #include <map>
- using namespace std;
- struct CtxInfo
- {
- int dataSize;
- LPVOID pCtx;
- };
- struct IDCerTextData
- {
- unsigned char name[1024];
- unsigned char sex[1024];
- unsigned char nation[1024];
- unsigned char birthday[1024];
- unsigned char address[1024];
- unsigned char idno[1024];
- unsigned char department[1024];
- unsigned char startDate[1024];
- unsigned char endDate[1024];
- unsigned char englishName[1024];
- unsigned char nationality[1024];
- unsigned char idVersion[1024];
- unsigned char idType[1024];
- unsigned char reserved[1024];
- unsigned char englishNameEx[1024]; //英文名备用字段
- unsigned char IssuedSN[1024]; //换证次数
- };
- class CancelReadEvent : public FSMEvent
- {
- public:
- CancelReadEvent() : FSMEvent(USER_EVT_CANCEL_READ){}
- virtual ~CancelReadEvent(){}
- virtual void OnUnhandled()
- {
- LOG_TRACE("idcer cancel read not handled");
- }
- };
- class GetDevInfoEvent : public FSMEvent
- {
- public:
- GetDevInfoEvent() : FSMEvent(USER_EVT_GET_DEVINFO){}
- virtual ~GetDevInfoEvent(){}
- SpReqAnsContext<IDCert_GetDevInfo_Req, IDCert_GetDevInfo_Ans>::Pointer ctx;
- virtual void OnUnhandled()
- {
- if (ctx != NULL)
- ctx->Answer(Error_InvalidState);
- }
- };
- class ReadAndScanUTF8Event : public FSMEvent //ex3
- {
- public:
- ReadAndScanUTF8Event() : FSMEvent(USER_EVT_READ_AND_SCAN_UTF8) {}
- virtual ~ReadAndScanUTF8Event() {}
- SpReqAnsContext<IDCert_ReadAndScanUTF8_Req, IDCert_ReadAndScanUTF8_Ans>::Pointer ctx;
- virtual void OnUnhandled()
- {
- if (ctx != NULL)
- ctx->Answer(Error_InvalidState);
- }
- };
- class ReadAndScanUTF8JSEvent : public FSMEvent //ex3
- {
- public:
- ReadAndScanUTF8JSEvent() : FSMEvent(USER_EVT_READ_AND_SCAN_UTF8JS) {}
- virtual ~ReadAndScanUTF8JSEvent() {}
- SpReqAnsContext<IDCert_ReadAndScanUTF8JS_Req, IDCert_ReadAndScanUTF8JS_Ans>::Pointer ctx;
- virtual void OnUnhandled()
- {
- if (ctx != NULL)
- ctx->Answer(Error_InvalidState);
- }
- };
- class CIDCertFSM : public CCommDevFSM<CIDCertFSM, IDCerClass>
- {
- public:
- enum {s0,s1,s2,s3};
- BEGIN_FSM_STATE(CIDCertFSM)
- FSM_STATE_ENTRY(s0,"Normal",s0_on_entry,s0_on_exit,s0_on_event)
- FSM_STATE_ENTRY(s1,"Reading",s1_on_entry,s1_on_exit,s1_on_event)
- FSM_STATE_ENTRY(s2,"Fail",s2_on_entry,s2_on_exit,s2_on_event)
- FSM_STATE_ENTRY(s3, "Init", s3_on_entry, s3_on_exit, s3_on_event)
- END_FSM_STATE()
- BEGIN_FSM_RULE(CIDCertFSM, s3)
- FSM_RULE_ENTRY(s0, s2, USER_EVT_ERROR, 0)
- FSM_RULE_ENTRY(s0, FSM_STATE_EXIT, USER_EVT_QUIT, 0)
- FSM_RULE_ENTRY(s0, s1, USER_EVT_READ_AND_SCAN_UTF8, 0) //ex4
- FSM_RULE_ENTRY(s0, s1, USER_EVT_READ_AND_SCAN_UTF8JS, 0) //ex4
- FSM_RULE_ENTRY(s0, s3, USER_EVT_TODO_INIT_FINISHED, 0)
- FSM_RULE_ENTRY(s1, s0, USER_EVT_READ_AND_SCAN_UTF8_FINISHED, 0)
- FSM_RULE_ENTRY(s1, s0, USER_EVT_READ_AND_SCAN_UTF8_FINISHED, 1)
- FSM_RULE_ENTRY(s1, s0, USER_EVT_READ_AND_SCAN_UTF8_FINISHED, 2)
- FSM_RULE_ENTRY(s1, s3, USER_EVT_READ_AND_SCAN_UTF8_FINISHED, 3)
- FSM_RULE_ENTRY(s1, s0, USER_EVT_READ_AND_SCAN_UTF8JS_FINISHED, 0)
- FSM_RULE_ENTRY(s1, s0, USER_EVT_READ_AND_SCAN_UTF8JS_FINISHED, 1)
- FSM_RULE_ENTRY(s1, s3, USER_EVT_READ_AND_SCAN_UTF8JS_FINISHED, 3)
- FSM_RULE_ENTRY(s1, FSM_STATE_EXIT, USER_EVT_QUIT, 0)
- FSM_RULE_ENTRY(s1, s0, USER_EVT_CANCEL_READ, 2)
- FSM_RULE_ENTRY(s1, s0, USER_EVT_EXIT, 3)
- FSM_RULE_ENTRY(s2, s3, USER_EVT_TODO_INIT_FINISHED, 0)
- FSM_RULE_ENTRY(s3, s0, USER_EVT_INIT_FINISHED, 0)
- FSM_RULE_ENTRY(s3, s2, USER_EVT_INIT_FINISHED, 2)
- END_FSM_RULE()
- CIDCertFSM() :m_bCancelRead(false), m_bReading(false),
- m_bExit(false), m_testResult(Error_Succeed), m_getDevCategory(Error_Unexpect), m_csMachineType(""), m_terminalNo(""), transImgMsg("")
- {
- ZeroMemory(&m_adapterInfo, sizeof(m_adapterInfo));
- HARDWARE_ENTITY_RESET_ENTITYID(m_entCode, 0x201);
- };
- virtual ~CIDCertFSM() {};
- virtual ErrorCodeEnum OnInit();
- virtual ErrorCodeEnum OnExit();
- virtual void s0_on_entry();
- virtual void s0_on_exit();
- virtual unsigned int s0_on_event(FSMEvent* e);
- virtual void s1_on_entry();
- virtual void s1_on_exit();
- virtual unsigned int s1_on_event(FSMEvent* e);
- virtual void s2_on_entry();
- virtual void s2_on_exit();
- virtual unsigned int s2_on_event(FSMEvent* e);
- virtual void s3_on_entry();
- virtual void s3_on_exit();
- virtual unsigned int s3_on_event(FSMEvent* e);
- int ReadAndScanUTF8(SpReqAnsContext<IDCert_ReadAndScanUTF8_Req, IDCert_ReadAndScanUTF8_Ans>::Pointer ctx);
- int ReadAndScanUTF8JS(SpReqAnsContext<IDCert_ReadAndScanUTF8JS_Req, IDCert_ReadAndScanUTF8JS_Ans>::Pointer ctx);
- void SetExitFlag(){m_bExit = true;}
- bool GetReadFlag(){return m_bReading;}
- ErrorCodeEnum GetDevCatInfo(DevCategoryInfo &devInfo, CSimpleStringA& devType);
- void DoExit(CSmartPointer<ITransactionContext> pTransactionContext)
- {
- pTransactionContext->SendAnswer(Error_Succeed);
- }
- int Initial();
- void SelfTest(EntityTestEnum eTestType,CSmartPointer<ITransactionContext> pTransactionContext);
- static void HttpsLogCallBack(const char* logtxt);
- private:
- ErrorCodeEnum GetVendorDllPath(CSimpleStringA &strPath);
- //ErrorCodeEnum GetPngBlob(CBlob &data,bool bClear=false);
- ErrorCodeEnum GetPngBlobEx(CBlob &data, CSimpleStringA fileNamePrefix);
- //type:1,delete img about zp; type:2,delete img about scan ID;type:3,delete both zp and scan ID
- //deleteTiming:0, defalut; deleteTiming:1, delete before Read IDCard; deleteTiming:2, delete after Read IDCard
- void DeleteZP(int type, int deleteTiming = 0);
- //Delete bmp file in dep directory, you should just convey fileName only without paths -Joseph
- //deleteTiming:0, defalut; deleteTiming:1, delete before Read IDCard; deleteTiming:2, delete after Read IDCard
- ErrorCodeEnum DeleteFileIfExisted(LPCTSTR fileName, int deleteTiming = 0);
- void UCS2_to_UTF8(UINT16* ucs2_code, UINT8* utf8_code);
- void GetSexUTF8String(UINT16* in, UINT8* out);
- void GetNationalUTF8String(UINT16* in, UINT8* out);
- void GetDateStandardFormatUTF8(UINT16* in, UINT8* out);
- void RemoveUCS2Blank(UINT16* ucs2_code);
- int GetUCS2ByteLength(UINT16* ucs2_code);
- void CheckHanZi(UINT16* ucs2_code);
- CSimpleStringA GetFileHashStr(CSimpleStringA filePath);
- CSimpleStringA GetFileLastModifyTime(CSimpleStringA filePath);
- template <typename T>
- void CopyIDCerDataToCtx(IDCerInfoEx2 idInfoEx2, T& ctx); //兼容JS接口
- BOOL GetScanImg(IDCerInfoEx2 idInfoEx2, CBlob& frontImg, CBlob& backImg);
- #ifdef RVC_OS_WIN
- char* GetGBKString(UINT16* ucs2_code); //WIN打印源数据日志或其他中文用途
- #endif
- //记录身份证相关图片的最近修改时间,用于上送信息调研,后续下掉 - 2025.6.13 CJL
- void WarnImgCreateTime();
- public:
- std::string checkImgURL;
- private:
- bool m_bCancelRead, m_bReading, m_bExit;
- ErrorCodeEnum m_testResult;
- ErrorCodeEnum m_getDevCategory;
- DevCategoryInfo m_devCatInfo;
- CSimpleStringA m_csMachineType, m_terminalNo;
- CSimpleStringA transImgMsg;
- #ifdef RVC_OS_WIN
- unordered_map<int, wstring> nationalCode;
- #else
- unordered_map<int, string> nationalCode;
- #endif
- BOOL supportUCS2; //支持生僻字
- BOOL igestionVer; //吸入式设备
- BOOL supportNewForeigner; //支持新版外国人永居证 2023.11.10
- BOOL closeImgCheck;
- ULLINT m_ullBeginTime, m_ullEndTime;
- ULLINT OpenRFControlTime;
- ULLINT CloseRFControlTime;
- ULLINT IDCerAuthenticateTime;
- ULLINT IDCerGetDataEx2Time;
- ULLINT ScanIDAndSaveImageTime;
- //记录身份证相关图片的最近修改时间,用于上送信息调研,后续下掉 - 2025.6.13 CJL
- CSimpleStringA headPhotoTimeStr, frontPhotoTimeStr, backPhotoTimeStr;
- time_t headPhotoTime, frontPhotoTime, backPhotoTime, currentSysTime;
- };
- struct ReadAndScanUTF8Task : public ITaskSp //ex8
- {
- CIDCertFSM* fsm;
- SpReqAnsContext<IDCert_ReadAndScanUTF8_Req, IDCert_ReadAndScanUTF8_Ans>::Pointer ctx;
- ReadAndScanUTF8Task(CIDCertFSM* f) : fsm(f) {}
- void Process()
- {
- FSMEvent* e = new FSMEvent(USER_EVT_READ_AND_SCAN_UTF8_FINISHED);
- e->param1 = -1;
- e->param1 = fsm->ReadAndScanUTF8(ctx);
- fsm->PostEventFIFO(e);
- }
- };
- struct ReadAndScanUTF8JSTask : public ITaskSp //ex8
- {
- CIDCertFSM* fsm;
- SpReqAnsContext<IDCert_ReadAndScanUTF8JS_Req, IDCert_ReadAndScanUTF8JS_Ans>::Pointer ctx;
- ReadAndScanUTF8JSTask(CIDCertFSM* f) : fsm(f) {}
- void Process()
- {
- FSMEvent* e = new FSMEvent(USER_EVT_READ_AND_SCAN_UTF8JS_FINISHED);
- e->param1 = -1;
- e->param1 = fsm->ReadAndScanUTF8JS(ctx);
- fsm->PostEventFIFO(e);
- }
- };
- struct InitTask : public ITaskSp
- {
- CIDCertFSM* fsm;
- InitTask(CIDCertFSM* f) : fsm(f) {}
- void Process()
- {
- FSMEvent* e = new FSMEvent(USER_EVT_INIT_FINISHED);
- e->param1 = fsm->Initial();
- fsm->PostEventFIFO(e);
- }
- };
- #endif //IDCERTFSM_H
|