Ver Fonte

!10893 修改大机卡机、卡库卡机、非接读卡异常的处理逻辑(含卡机公共库);缺陷修复
Merge pull request !10893 from 80174847/ST2

陈礼鹏80274480 há 1 mês atrás
pai
commit
b7db12acc6

+ 29 - 148
DevAdapter/include/CardAssist.cpp

@@ -372,9 +372,8 @@ void CCardProcess::DataInit()
 	//m_bCDA = false;
 
 }
-bool CCardProcess::DetectIfICCard(CardReadType eType, DeviceBaseClass *pCardX, int &cardType, bool bIssue)
+int CCardProcess::DetectIfICCard(CardReadType eType, DeviceBaseClass *pCardX, int &cardType, bool bIssue)
 {
-	//DbgInfo("<DetectIfICCard>, to detect card type.");
 	long l_beginTime, l_endTime;
 	cardType = 0;
 	ErrorCodeEnum eErr;
@@ -386,22 +385,13 @@ bool CCardProcess::DetectIfICCard(CardReadType eType, DeviceBaseClass *pCardX, i
 		eErr = pCardI->ContactIC();
 		l_endTime = GetTickCount();
 
-		if(eErr != Error_Succeed){
-			QueryLastErr(eType, errMsg);
-			setCardAssistLastErr(eErr,errMsg,"DevAdapter::ContactIC");
-			errMsg = CSimpleStringA::Format("DetectIfICCard::ContactIC failed(%s):%s", SpStrError(eErr), errMsg.GetData());
-			//if (eType == CARD_MACHINE_ISSUER) {
-			//	DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setAPI("DevAdapter::ContactIC").setCostTime(l_endTime - l_beginTime).setResultCode("RTA23C7")("DetectIfICCard::ContactIC err=%s", SpStrError(eErr));
-			//	LogWarn(Severity_Middle, Error_Unexpect, CardIssuer_UserErrorCode_ContactIC_Failed, errMsg.GetData());
-			//}
-			//else {
-			//	DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setAPI("DevAdapter::ContactIC").setCostTime(l_endTime - l_beginTime).setResultCode("RTA2WC7")("DetectIfICCard::ContactIC err=%s", SpStrError(eErr));
-			//	LogWarn(Severity_Middle, Error_Unexpect, CardIssuerStore_UserErrorCode_ContactIC_Failed, errMsg.GetData());
-			//}
+		if(eErr != Error_Succeed)
+		{
+			pCardI->ReleaseIC();
+			return -1;
 		}
-		else {
+		else
 			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("DevAdapter::ContactIC").setCostTime(l_endTime - l_beginTime)("DetectIfICCard::ContactIC");
-		}
 
 		l_beginTime = GetTickCount();
 		eErr = pCardI->ActiveICCard();
@@ -409,30 +399,9 @@ bool CCardProcess::DetectIfICCard(CardReadType eType, DeviceBaseClass *pCardX, i
 
 		if (eErr != Error_Succeed)
 		{
-			QueryLastErr(eType, errMsg);
-			setCardAssistLastErr(eErr,errMsg,"DevAdapter::ActiveICCard");
-			errMsg = CSimpleStringA::Format("DetectIfICCard::ActiveICCard failed(%s):%s", SpStrError(eErr), errMsg.GetData());
-			//if (eType == CARD_MACHINE_ISSUER) {
-			//	DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setAPI("DevAdapter::ActiveICCard").setCostTime(l_endTime - l_beginTime).setResultCode("RTA23CT")("DetectIfICCard::ActiveICCard err=%s", SpStrError(eErr));
-			//	if (bIssue) {
-			//		LogWarn(Severity_Middle, Error_Unexpect, CardIssuer_UserErrorCode_IssueCard_ActiveICCard_Failed, errMsg.GetData());
-			//	}
-			//	else {
-			//		LogWarn(Severity_Middle, Error_Unexpect, CardIssuer_UserErrorCode_ActiveICCard_Failed, errMsg.GetData());
-			//	}
-			//}
-			//else {
-			//	DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setAPI("DevAdapter::ActiveICCard").setCostTime(l_endTime - l_beginTime).setResultCode("RTA2WCT")("DetectIfICCard::ActiveICCard err=%s", SpStrError(eErr));
-			//	if (bIssue) {
-			//		LogWarn(Severity_Middle, Error_Unexpect, CardIssuerStore_UserErrorCode_IssueCard_ActiveICCard_Failed, errMsg.GetData());
-			//	}
-			//	else {
-			//		LogWarn(Severity_Middle, Error_Unexpect, CardIssuerStore_UserErrorCode_ActiveICCard_Failed, errMsg.GetData());
-			//	}
-			//}
 			pCardI->DeactivateICCard();
 			pCardI->ReleaseIC();
-			return false;
+			return -2;
 		}
 		else {
 			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("DevAdapter::ActiveICCard").setCostTime(l_endTime - l_beginTime)("DetectIfICCard::ActiveICCard");
@@ -447,17 +416,9 @@ bool CCardProcess::DetectIfICCard(CardReadType eType, DeviceBaseClass *pCardX, i
 		l_endTime = GetTickCount();
 
 		if (eErr != Error_Succeed)
-		{
-			//DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("DetectIfICCard::ActiveContactlessICCard err=%s", SpStrError(eErr));
-			//QueryLastErr(eType, errMsg);
-			//setCardAssistLastErr(eErr,errMsg, "DevAdapter::ActiveContactlessICCard");
-			//errMsg = CSimpleStringA::Format("DetectIfICCard::ActiveContactlessICCard failed(%s):%s", SpStrError(eErr), errMsg.GetData());
-			//LogWarn(Severity_Middle, Error_Unexpect, ContactlessCard_UserErrorCode_ActiveContactlessICCard_Failed, errMsg.GetData());
-			return false;
-		}
-		else {
+			return -3;
+		else
 			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("DevAdapter::ActiveContactlessICCard").setCostTime(l_endTime - l_beginTime)("DetectIfICCard::ActiveContactlessICCard,Detect contactless card type %d", ch);
-		}
 		cardType = ch;
 		
 	}
@@ -470,27 +431,14 @@ bool CCardProcess::DetectIfICCard(CardReadType eType, DeviceBaseClass *pCardX, i
 		l_endTime = GetTickCount();
 		
 		if (eErr != Error_Succeed)
-		{
-			QueryLastErr(eType, errMsg);
-			setCardAssistLastErr(eErr,errMsg,"DevAdapter::ActiveContactlessICCard");
-			errMsg = CSimpleStringA::Format("DetectIfICCard::ActiveContactlessICCard failed(%s):%s", SpStrError(eErr), errMsg.GetData());
-			//if (eType == CARD_MACHINE_ISSUER_RF) {
-			//	LogWarn(Severity_Middle, Error_Unexpect, CardIssuer_UserErrorCode_ActiveContactlessICCard_Failed, errMsg.GetData());
-			//	DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setAPI("DevAdapter::ActiveContactlessICCard").setCostTime(l_endTime - l_beginTime).setResultCode("RTA23C6")("DetectIfICCard::ActiveContactlessICCard err=%s", SpStrError(eErr));
-			//}
-			//else {
-			//	LogWarn(Severity_Middle, Error_Unexpect, CardIssuerStore_UserErrorCode_ActiveContactlessICCard_Failed, errMsg.GetData());
-			//	DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setAPI("DevAdapter::ActiveContactlessICCard").setCostTime(l_endTime - l_beginTime).setResultCode("RTA2WC6")("DetectIfICCard::ActiveContactlessICCard err=%s", SpStrError(eErr));
-			//}
-			return false; 
-		}
+			return -3; 
 		else {
 			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("DevAdapter::ActiveContactlessICCard").setCostTime(l_endTime - l_beginTime)("DetectIfICCard::ActiveContactlessICCard,Detect contactless card type %d", ch);
 		}
 		cardType = ch;
 		
 	}
-	return true;
+	return 0;
 }
 ErrorCodeEnum CCardProcess::BuildSupportedAppList(CardReadType eType,DeviceBaseClass *pCardX,vector<AIDData>& vAIDFromTerm)
 {
@@ -509,7 +457,7 @@ ErrorCodeEnum CCardProcess::BuildSupportedAppList(CardReadType eType,DeviceBaseC
 	char *pse1 = "1PAY.SYS.DDF01";
 	char *pse2 = "2PAY.SYS.DDF01";//oiltmp 20160107 should change to "2PAY.SYS.DDF01"
 	
-	if (eType == CARD_MACHINE_ISSUER || eType == CARD_MACHINE_ISSUER_STORE || eType == CARD_MACHINE_SWIPER)
+	if (eType == CARD_MACHINE_ISSUER || eType == CARD_MACHINE_ISSUER_STORE)
 	{
 		tmpPse1 = strlen(pse1);
 		pData = new BYTE[tmpPse1+1];
@@ -517,7 +465,7 @@ ErrorCodeEnum CCardProcess::BuildSupportedAppList(CardReadType eType,DeviceBaseC
 		memcpy(pData, pse1, tmpPse1);
 		ConstructAPDU(cls, ins, p1, p2, tmpPse1, pData, &le);
 	}
-	else if (eType == CARD_MACHINE_RFIC || eType == CARD_MACHINE_SWIPER_RF || eType == CARD_MACHINE_ISSUER_RF || eType == CARD_MACHINE_ISSUER_STORE_RF)
+	else if (eType == CARD_MACHINE_RFIC || eType == CARD_MACHINE_ISSUER_RF || eType == CARD_MACHINE_ISSUER_STORE_RF)
 	{
 		tmpPse2 = strlen(pse2);
 		pData = new BYTE[tmpPse2+1];
@@ -1212,34 +1160,8 @@ ErrorCodeEnum CCardProcess::AppSelected(CardReadType eType,DeviceBaseClass *pCar
 					}
 				}
 			}
-			else{
-
-				if (eType == CARD_MACHINE_ISSUER)
-				{
-					DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("AppSelected::ICCommand err=%s", SpStrError(eErr));
-				}
-				else if (eType == CARD_MACHINE_ISSUER_STORE)
-				{
-					DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("AppSelected::ICCommand err=%s", SpStrError(eErr));
-				}
-				else if (eType == CARD_MACHINE_ISSUER_RF)
-				{
-					DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("AppSelected::RFTypeABCommand err=%s", SpStrError(eErr));
-				}
-				else if (eType == CARD_MACHINE_ISSUER_STORE_RF)
-				{
-					DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("AppSelected::RFTypeABCommand err=%s", SpStrError(eErr));
-				}
-				else if (eType == CARD_MACHINE_RFIC)
-				{
-					//DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("DevAdapter::RFTypeABCommand").setCostTime(l_endTime - l_beginTime).setResultCode("RTA2J02")("AppSelected::RFTypeABCommand err=%s", SpStrError(eErr));
-				}
-
-				QueryLastErr(eType, errMsg);
-				errMsg = CSimpleStringA::Format("AppSelected::ICCommand 2 failed(%d):%s", eErr, errMsg.GetData());
-				LogWarn(Severity_Middle, Error_Unexpect, errICCommand, errMsg.GetData());
+			else
 				return Error_Interact;
-			}
 		}
 		else {
 			switch(eType)
@@ -1266,32 +1188,7 @@ ErrorCodeEnum CCardProcess::AppSelected(CardReadType eType,DeviceBaseClass *pCar
 		}
 	}
 	else
-	{
-		if (eType == CARD_MACHINE_ISSUER)
-		{
-			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("BuildSupportedAppList::ICCommand err=%s", SpStrError(eErr));
-		}
-		else if (eType == CARD_MACHINE_ISSUER_STORE)
-		{
-			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("BuildSupportedAppList::ICCommand err=%s", SpStrError(eErr));
-		}
-		else if (eType == CARD_MACHINE_ISSUER_RF)
-		{
-			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("BuildSupportedAppList::RFTypeABCommand err=%s", SpStrError(eErr));
-		}
-		else if (eType == CARD_MACHINE_ISSUER_STORE_RF)
-		{
-			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("BuildSupportedAppList::RFTypeABCommand err=%s", SpStrError(eErr));
-		}
-		else if (eType == CARD_MACHINE_RFIC)
-		{
-			//DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("DevAdapter::RFTypeABCommand").setCostTime(l_endTime - l_beginTime).setResultCode("RTA2J02")("BuildSupportedAppList::RFTypeABCommand err=%s", SpStrError(eErr));
-		}
-		QueryLastErr(eType, errMsg);
-		errMsg = CSimpleStringA::Format("AppSelected::ICCommand failed(%d):%s", eErr, errMsg.GetData());
-		LogWarn(Severity_Middle, Error_Unexpect, errICCommand, errMsg.GetData());
 		return Error_Interact;
-	}
 	return Error_Succeed;
 }
 ErrorCodeEnum CCardProcess::ReadData(CardReadType eType,DeviceBaseClass *pCardX,LPBYTE data,DWORD len)
@@ -2680,40 +2577,26 @@ int CCardProcess::SplitOnlineReplyData(const char *pData,int size)
 int CCardProcess::DetectAndReadICData(CardReadType eType, DeviceBaseClass *pCardX, CAutoArray<CSimpleStringA>pAIDs, int &cardType, bool bIssue)
 {
 	LOG_FUNCTION();
-	bool bIC = DetectIfICCard(eType,pCardX,cardType,bIssue);
-	if (!bIC)
-	{
-		DbgWarn("<DetectIfICCard>, not ic card.");
-		return -1;
-	}
-	else {
-		//兼容发卡非接上电有的厂商非IC卡也返回成功,直接返回上电失败
-		if (eType == CARD_MACHINE_ISSUER_RF || eType == CARD_MACHINE_ISSUER_STORE_RF) {
-			if ( bIssue && cardType != 'A' && cardType != 'B' && cardType != 'M') {
-				CSimpleStringA errMsg = CSimpleStringA::Format("{\"ErrCode\":2147483646,\"Description\":\"<DetectIfICCard>, not ic card,cardType=%d\"}", cardType);
-				setCardAssistLastErr(Error_Exception, errMsg.GetData(), "DevAdapter::ActiveContactlessICCard");
-				DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("<DetectIfICCard>, not ic card.");
-				return -1;
-			}
-		}
-	}
-	int bGetICData = -3;
+	int retDetect = DetectIfICCard(eType,pCardX,cardType,bIssue);
+	if (retDetect != 0)
+		return retDetect;
 
-	bGetICData = GetICDataFromCard(eType,pCardX,pAIDs);
+	bool bGetICData = GetICDataFromCard(eType,pCardX,pAIDs);
 
-	if (bGetICData != 0)
+	if (!bGetICData)
 	{
-		CSimpleStringA errMsg = CSimpleStringA::Format("GetICDataFromCard failed(%d)", bGetICData);
-		DbgWarn(errMsg.GetData());
-		return bGetICData;
+		if (eType == CARD_MACHINE_ISSUER || eType == CARD_MACHINE_ISSUER_STORE)
+			return -4;
+		else if (eType == CARD_MACHINE_RFIC || eType == CARD_MACHINE_ISSUER_RF || eType == CARD_MACHINE_ISSUER_STORE_RF)
+			return -5;
 	}
 
-	GetBaseInfoNotInRecord(eType,pCardX);
+	GetBaseInfoNotInRecord(eType,pCardX);//oiltmp ???
 
 	return 0;
 }
 
-int CCardProcess::GetICDataFromCard(CardReadType eType,DeviceBaseClass *pCardX, CAutoArray<CSimpleStringA> pAIDs)
+bool CCardProcess::GetICDataFromCard(CardReadType eType,DeviceBaseClass *pCardX, CAutoArray<CSimpleStringA> pAIDs)
 {
 	LOG_FUNCTION();
 	CSimpleStringA errMsg(true);
@@ -2763,25 +2646,23 @@ int CCardProcess::GetICDataFromCard(CardReadType eType,DeviceBaseClass *pCardX,
 			QueryLastErr(eType, errMsg);
 			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("BuildSupportedAppList failed(%d):%s.", eErr, errMsg.GetData());
 			if(eErr == Error_Interact)
-				return -2;
+				return false;
 			else
 				continue;
 		}
 		//Dbg("[%s]",testIC);
 		eErr = AppSelected(eType,pCardX,vAIDs.at(0).aid,vAIDs.at(0).len);
 		if (eErr == Error_Succeed)
-			return 0;
+			return true;
 		else
 		{
-			QueryLastErr(eType, errMsg);
-			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("AppSelected failed(%d):%s.", eErr, errMsg.GetData());
 			if(eErr == Error_Interact)
-				return -2;
+				return false;
 			else
 				continue;
 		}
 	}
-	return -3;
+	return false;
 }
 
 int CCardProcess::ConstructARQCData(const char *pATC, char *&pDataToARQC, char *&pSomeICData)

+ 16 - 5
DevAdapter/include/CardAssist.h

@@ -15,9 +15,7 @@ using namespace std;
 enum CardReadType
 {
 	CARD_MACHINE_ISSUER = 0,
-	CARD_MACHINE_SWIPER,
 	CARD_MACHINE_RFIC,
-	CARD_MACHINE_SWIPER_RF,
 	CARD_MACHINE_ISSUER_RF,
 	CARD_MACHINE_ISSUER_STORE,
 	CARD_MACHINE_ISSUER_STORE_RF
@@ -65,8 +63,21 @@ public:
 	}
 	~CCardProcess();
 	void DataInit();
-	bool DetectIfICCard(CardReadType eType, DeviceBaseClass* pCardX, int& cardType, bool bIssue = false);//cardType:0x41'A',type A; 0x42'B',type B; 0x4d'M',type M
-	int GetICDataFromCard(CardReadType eType,DeviceBaseClass *pCardX,CAutoArray<CSimpleStringA> pAIDs);
+	//0: success
+	//-1ŁşContactIC failed
+	//-2ŁşActiveICCard failed
+	//-3ŁşActiveContactlessICCard failed
+	int DetectIfICCard(CardReadType eType, DeviceBaseClass* pCardX, int& cardType, bool bIssue = false);//cardType:0x41'A',type A; 0x42'B',type B; 0x4d'M',type M
+	
+	//0: success
+	//-1ŁşContactIC failed
+	//-2ŁşActiveICCard failed
+	//-3ŁşActiveContactlessICCard failed
+	//-4ŁşICCommand failed
+	//-5ŁşRFTypeABCommand failed
+	int DetectAndReadICData(CardReadType eType, DeviceBaseClass* pCardX, CAutoArray<CSimpleStringA>pAIDs, int& cardType, bool bIssue = false);
+
+	bool GetICDataFromCard(CardReadType eType,DeviceBaseClass *pCardX,CAutoArray<CSimpleStringA> pAIDs);
 	//int  SplitICData(vector<ICData>& vResult,LPBYTE* origData,int start,int dataLen,int level);
 	ErrorCodeEnum BuildSupportedAppList(CardReadType eType,DeviceBaseClass *pCardX,vector<AIDData>& vAIDFromTerm);
 	ErrorCodeEnum BuildAppListByAIDs(CardReadType eType,DeviceBaseClass *pCardX,vector<AIDData>& vAIDFromTerm);
@@ -83,7 +94,7 @@ public:
 	void SplitBusinessData(const char *pData,int size);
 	int SplitOnlineReplyData(const char *pData,int size);
 	void GetBaseInfoNotInRecord(CardReadType eType,DeviceBaseClass *pCardX);
-	int DetectAndReadICData(CardReadType eType,DeviceBaseClass *pCardX,CAutoArray<CSimpleStringA>pAIDs,int &cardType, bool bIssue = false);
+	
 	int ConstructARQCData(const char *pATC,char *&pDataToARQC,char *&pSomeICData);
 	int FindTagValue(TagVectorType eType,ICData& data,bool bLevel,int start=0,int end=0);
 	int ToFindTagValue(vector<ICData>& vData,ICData& data,bool bLevel,int start,int end);

+ 133 - 472
Module/mod_CardIssuerStand/CardIssuerStandFSM.cpp

@@ -2246,19 +2246,19 @@ int CCardIssuerFSM::ReadCard_Contact(SpReqAnsContext<CardIssuerStandService_Read
 	else
 	{
 		l_beginTime = GetTickCountRVC();
-		bIC = m_pCardProcess->DetectIfICCard(CARD_MACHINE_ISSUER, m_hDevHelper, activeCardType);
+		int retDetect = m_pCardProcess->DetectIfICCard(CARD_MACHINE_ISSUER, m_hDevHelper, activeCardType);
 		l_endTime = GetTickCountRVC();
-
-		DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("<ReadCard::DetectIfICCard>, bIC:%d", bIC);
-		if (!bIC) {
-			ErrorCodeEnum eErrCode = Error_Unexpect;
-			CSimpleStringA ApiName = "";
-			CSimpleStringA alarmMsg = "";
-			CSimpleStringA csErrMsgWithReturnCode = "";
-			GetCardProcessLastErr(eErrCode, ApiName, alarmMsg, csErrMsgWithReturnCode);
-			DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setAPI(ApiName.GetData()).setCostTime(l_endTime - l_beginTime).setResultCode("RTA23CT")(csErrMsgWithReturnCode.GetData());
-			LogWarn(Severity_Middle, Error_Unexpect, 0x2030000a, alarmMsg.GetData());
+		if (retDetect == 0)//oiltmp for simple to not change bIC
+			bIC = true;
+		else
+		{
+			bIC = false;
+			CSimpleStringA csDevApi("");
+			DWORD dwDevApi = 0;
+			GetDevApiCodeAndName(retDetect, dwDevApi, csDevApi);
+			SetErrorAndLog(Error_Unexpect, dwDevApi, csDevApi, __FUNCTION__, bContinue && IsInBusiness(), l_endTime - l_beginTime);
 		}
+		
 		if (Error_Succeed == eMagReadErr && magTracks.track[1].eStatus == CI_DATA_OK)
 		{
 			if (bIC)
@@ -2334,6 +2334,8 @@ int CCardIssuerFSM::ReadCard_Contact(SpReqAnsContext<CardIssuerStandService_Read
 				ctx->Answer(Error_Unexpect, dwCode);
 			return 1;
 		}
+		else
+			return -1;
 	}
 	else
 	{
@@ -2504,18 +2506,18 @@ int CCardIssuerFSM::ReadCard_RF(SpReqAnsContext<CardIssuerStandService_Read_Req,
 	else
 	{
 		l_beginTime = GetTickCountRVC();
-		bIC = m_pCardProcess->DetectIfICCard(CARD_MACHINE_ISSUER_RF, m_hDevHelper, activeCardType);
+		int retDetect = m_pCardProcess->DetectIfICCard(CARD_MACHINE_ISSUER_RF, m_hDevHelper, activeCardType);
 		l_endTime = GetTickCountRVC();
 
-		DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("<ReadCard::DetectIfICCard>, bIC:%d", bIC);
-		if (!bIC) {
-			ErrorCodeEnum eErrCode = Error_Unexpect;
-			CSimpleStringA ApiName = "";
-			CSimpleStringA alarmMsg = "";
-			CSimpleStringA csErrMsgWithReturnCode = "";
-			GetCardProcessLastErr(eErrCode, ApiName, alarmMsg, csErrMsgWithReturnCode);
-			DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setAPI(ApiName.GetData()).setCostTime(l_endTime - l_beginTime).setResultCode("RTA23C6")(csErrMsgWithReturnCode.GetData());
-			LogWarn(Severity_Middle, Error_Unexpect, 0x20300017, alarmMsg.GetData());
+		if (retDetect == 0)//oiltmp for simple to not change bIC
+			bIC = true;
+		else
+		{
+			bIC = false;
+			CSimpleStringA csDevApi("");
+			DWORD dwDevApi = 0;
+			GetDevApiCodeAndName(retDetect, dwDevApi, csDevApi);
+			SetErrorAndLog(Error_Unexpect, dwDevApi, csDevApi, __FUNCTION__, IsInBusiness(), l_endTime - l_beginTime);
 		}
 		if (!(bIC && activeCardType == 'A'))
 			bIC = false;
@@ -2629,105 +2631,20 @@ int CCardIssuerFSM::PreOnline_Contact(SpReqAnsContext<CardIssuerStandService_Pre
 	DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("<PreOnline>, After invoke DetectAndReadICData, retDetectAndRead:%d, activeCardType:%d", retDetectAndRead, activeCardType);
 	if (retDetectAndRead < 0)
 	{
-		CSimpleStringA xCardName("");
-		if (m_issueStatus && m_currentHopper - 1 >= 0)
-			xCardName = m_PsbNameEx[m_currentHopper - 1];
-		if (retDetectAndRead == -1)
+		DWORD dwDevApiCode = 0;
+		CSimpleStringA csDevApiName(""), csLogCode("");
+		CSimpleStringA csIssueContext = CSimpleStringA::Format("{\"InIssue\":%d}", m_issueStatus);//oiltmp
+		GetDevApiCodeAndName(retDetectAndRead, dwDevApiCode, csDevApiName);
+		if (m_issueStatus)
+			csLogCode = CardIssuerStandService_LogCode_IssueEx;
+		else
+			csLogCode = CardIssuerStandService_LogCode_Read;
+		if (m_bSupportRF) //support RF, to continue read by RF
+			SetErrorAndLog(Error_Unexpect, dwDevApiCode, csDevApiName, __FUNCTION__, false, m_ullEndTime - m_ullBeginTime, csLogCode, csIssueContext);
+		else
 		{
-			ErrorCodeEnum eErrCode = Error_Unexpect;
-			CSimpleStringA ApiName = "";
-			CSimpleStringA alarmMsg = "";
-			CSimpleStringA csErrMsgWithReturnCode = "";
-			GetCardProcessLastErr(eErrCode, ApiName, alarmMsg, csErrMsgWithReturnCode);
-
-			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("检测卡片类型时上电失败");
-			if (!m_bSupportRF)
-			{
-				if (IsInBusiness())
-				{
-					if (m_issueStatus)
-					{
-						DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_USER).setAPI(ApiName.GetData()).setCostTime(l_endTime - l_beginTime).setLogCode("QLR040220320").setResultCode("RTA230V")(csErrMsgWithReturnCode.GetData());
-						LogError(Severity_Middle, Error_Unexpect, CardIssuer_UserErrorCode_IssueCard_ActiveICCard_Failed, alarmMsg.GetData());
-						ctx->Answer(Error_Unexpect, CardIssuer_UserErrorCode_IssueCard_ActiveICCard_Failed);
-					}
-					else
-					{
-						DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_USER).setAPI(ApiName.GetData()).setCostTime(l_endTime - l_beginTime).setLogCode("QLR040220303").setResultCode("RTA230M")(csErrMsgWithReturnCode.GetData());
-						LogError(Severity_Middle, Error_Unexpect, CardIssuer_UserErrorCode_ActiveICCard_Failed, alarmMsg.GetData());
-						ctx->Answer(Error_Unexpect, CardIssuer_UserErrorCode_ActiveICCard_Failed);
-					}
-				}
-				else
-				{
-					if (m_issueStatus)
-					{
-						DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setAPI(ApiName.GetData()).setCostTime(l_endTime - l_beginTime).setLogCode("QLR040220320").setResultCode("RTA230V")(csErrMsgWithReturnCode.GetData());
-						LogWarn(Severity_Middle, Error_Unexpect, CardIssuer_UserErrorCode_IssueCard_ActiveICCard_Failed, alarmMsg.GetData());
-						ctx->Answer(Error_Unexpect, CardIssuer_UserErrorCode_IssueCard_ActiveICCard_Failed);
-					}
-					else
-					{
-						DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setAPI(ApiName.GetData()).setCostTime(l_endTime - l_beginTime).setLogCode("QLR040220303").setResultCode("RTA230M")(csErrMsgWithReturnCode.GetData());
-						LogWarn(Severity_Middle, Error_Unexpect, CardIssuer_UserErrorCode_ActiveICCard_Failed, alarmMsg.GetData());
-						ctx->Answer(Error_Unexpect, CardIssuer_UserErrorCode_ActiveICCard_Failed);
-					}
-				}
-				
-			}
-			else //非终态,还有非接兜底
-			{
-				if (m_issueStatus)
-					DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setAPI(ApiName.GetData()).setCostTime(l_endTime - l_beginTime).setLogCode("QLR040220320").setResultCode("RTA230V")(csErrMsgWithReturnCode.GetData());
-				else
-					DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setAPI(ApiName.GetData()).setCostTime(l_endTime - l_beginTime).setLogCode("QLR040220303").setResultCode("RTA230M")(csErrMsgWithReturnCode.GetData());
-			}
-		}
-		else if (retDetectAndRead == -2){
-			if (!m_bSupportRF)
-			{
-				DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("读取IC数据失败");
-				if (m_issueStatus) {
-					SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_ICCommand, "DevAdapter::ICCommand", __FUNCTION__, IsInBusiness(), l_endTime - l_beginTime, "QLR040220320", "");
-				}
-				else {
-					SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_ICCommand, "DevAdapter::ICCommand", __FUNCTION__, IsInBusiness(), l_endTime - l_beginTime, "QLR040220303", "");
-				}
-				ctx->Answer(Error_Unexpect, GetAlarmDEC());
-			}
-			else //非终态,还有非接兜底
-			{
-				DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("读取IC数据失败");
-				if (m_issueStatus) {
-					SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_ICCommand, "DevAdapter::ICCommand", __FUNCTION__, false, l_endTime - l_beginTime, "QLR040220320", "");
-				}
-				else {
-					SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_ICCommand, "DevAdapter::ICCommand", __FUNCTION__, false, l_endTime - l_beginTime, "QLR040220303", "");
-				}
-			}
-		}else if (retDetectAndRead == -3){
-			if (!m_bSupportRF)
-			{
-				DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("IC卡建立应用列表失败");
-				if (m_issueStatus) {
-					SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_ICCommand, "DevAdapter::ICCommand", __FUNCTION__, IsInBusiness(), l_endTime - l_beginTime, "QLR040220320", "");
-				}
-				else {
-					SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_ICCommand, "DevAdapter::ICCommand", __FUNCTION__, IsInBusiness(), l_endTime - l_beginTime, "QLR040220303", "");
-				}
-				ctx->Answer(Error_Unexpect, GetAlarmDEC());
-				
-			}
-			else //非终态,还有非接兜底
-			{
-				DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("IC卡建立应用列表失败");
-				if (m_issueStatus) {
-					SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_ICCommand, "DevAdapter::ICCommand", __FUNCTION__, false, l_endTime - l_beginTime, "QLR040220320", "");
-				}
-				else {
-					SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_ICCommand, "DevAdapter::ICCommand", __FUNCTION__, false, l_endTime - l_beginTime, "QLR040220303", "");
-				}
-			}
+			DWORD dwCode = SetErrorAndLog(Error_Unexpect, dwDevApiCode, csDevApiName, __FUNCTION__, IsInBusiness(), m_ullEndTime - m_ullBeginTime, csLogCode, csIssueContext);
+			ctx->Answer(Error_Unexpect, dwCode);
 		}
 		bICOK = false;
 		return 0;
@@ -2986,73 +2903,20 @@ int CCardIssuerFSM::PreOnline_RF(SpReqAnsContext<CardIssuerStandService_PreOnlin
 	DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("<PreOnline_RF>, After invoke DetectAndReadICData, retDetectAndRead:%d, activeCardType:%d", retDetectAndRead, activeCardType);
 	if (retDetectAndRead < 0)
 	{
-		CSimpleStringA xCardName("");
-		if (m_issueStatus && m_currentHopper - 1 >= 0)
-			xCardName = m_PsbNameEx[m_currentHopper - 1];
-		if (retDetectAndRead == -1) {
-			ErrorCodeEnum eErrCode = Error_Unexpect;
-			CSimpleStringA ApiName = "";
-			CSimpleStringA alarmMsg = "";
-			CSimpleStringA csErrMsgWithReturnCode = "";
-			GetCardProcessLastErr(eErrCode, ApiName, alarmMsg, csErrMsgWithReturnCode);
-
-			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("检测卡片类型时上电失败(非接)");
-
-			if (m_issueStatus)
-			{
-				if (IsInBusiness())
-				{
-					DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_USER).setAPI(ApiName.GetData()).setCostTime(l_endTime - l_beginTime).setLogCode("QLR040220320").setResultCode("RTA2327")(csErrMsgWithReturnCode.GetData());
-					LogError(Severity_Middle, Error_Unexpect, CardIssuer_UserErrorCode_IssueCard_ActiveRF_Failed, alarmMsg.GetData());
-				}
-				else
-				{
-					DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setAPI(ApiName.GetData()).setCostTime(l_endTime - l_beginTime).setLogCode("QLR040220320").setResultCode("RTA2327")(csErrMsgWithReturnCode.GetData());
-					LogWarn(Severity_Middle, Error_Unexpect, CardIssuer_UserErrorCode_IssueCard_ActiveRF_Failed, alarmMsg.GetData());
-				}
-				ctx->Answer(Error_Unexpect, CardIssuer_UserErrorCode_IssueCard_ActiveRF_Failed);
-			}
-			else
-			{
-				if (IsInBusiness())
-				{
-					DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_USER).setAPI(ApiName.GetData()).setCostTime(l_endTime - l_beginTime).setLogCode("QLR040220303").setResultCode("RTA2326")(csErrMsgWithReturnCode.GetData());
-					LogError(Severity_Middle, Error_Unexpect, CardIssuer_UserErrorCode_ActiveContactlessICCard_Failed, alarmMsg.GetData());
-				}
-				else
-				{
-					DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setAPI(ApiName.GetData()).setCostTime(l_endTime - l_beginTime).setLogCode("QLR040220303").setResultCode("RTA2326")(csErrMsgWithReturnCode.GetData());
-					LogWarn(Severity_Middle, Error_Unexpect, CardIssuer_UserErrorCode_ActiveContactlessICCard_Failed, alarmMsg.GetData());
-				}
-				ctx->Answer(Error_Unexpect, CardIssuer_UserErrorCode_ActiveContactlessICCard_Failed);
-			}
-		}
-		else if (retDetectAndRead == -2) {
-
-			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("读取IC数据失败");
-			if (m_issueStatus) {
-				SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_RFTypeABCommand, "DevAdapter::RFTypeABCommand", __FUNCTION__, IsInBusiness(), l_endTime - l_beginTime, "QLR040220320", "");
-			}
-			else {
-				SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_RFTypeABCommand, "DevAdapter::RFTypeABCommand", __FUNCTION__, IsInBusiness(), l_endTime - l_beginTime, "QLR040220303", "");
-			}
-			ctx->Answer(Error_Unexpect, GetAlarmDEC());
-
-		}
-		else if (retDetectAndRead == -3) {
+		DWORD dwDevApiCode = 0;
+		CSimpleStringA csDevApiName(""), csLogCode("");
+		CSimpleStringA csIssueContext = CSimpleStringA::Format("{\"InIssue\":%d}", m_issueStatus);//oiltmp
+		GetDevApiCodeAndName(retDetectAndRead, dwDevApiCode, csDevApiName);
+		if (m_issueStatus)
+			csLogCode = CardIssuerStandService_LogCode_IssueEx;
+		else
+			csLogCode = CardIssuerStandService_LogCode_Read;
 
-			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("IC卡建立应用列表失败");
-			if (m_issueStatus) {
-				SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_RFTypeABCommand, "DevAdapter::RFTypeABCommand", __FUNCTION__, IsInBusiness(), l_endTime - l_beginTime, "QLR040220320", "");
-			}
-			else {
-				SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_RFTypeABCommand, "DevAdapter::RFTypeABCommand", __FUNCTION__, IsInBusiness(), l_endTime - l_beginTime, "QLR040220303", "");
-			}
-			ctx->Answer(Error_Unexpect, GetAlarmDEC());
-		}
+		DWORD dwCode = SetErrorAndLog(Error_Unexpect, dwDevApiCode, csDevApiName, __FUNCTION__, IsInBusiness(), m_ullEndTime - m_ullBeginTime, csLogCode, csIssueContext);
+		ctx->Answer(Error_Unexpect, dwCode);
 		return 0;
 	}
-
+	
 	m_pCardProcess->TermRiskManage();
 	CSimpleStringA taaResult;
 	BYTE bt9f27 = 0;
@@ -3699,18 +3563,15 @@ bool CCardIssuerFSM::JustReadCardNo()
 	bool bHasAccount = false;
 	int activeCardType;
 	l_beginTime = GetTickCountRVC();
-	bool bIC = m_pCardProcess->DetectIfICCard(CARD_MACHINE_ISSUER, m_hDevHelper, activeCardType);
+	int retDetect = m_pCardProcess->DetectIfICCard(CARD_MACHINE_ISSUER, m_hDevHelper, activeCardType);
 	l_endTime = GetTickCountRVC();
-	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)(CSimpleStringA::Format("DetectIfICCard, bIC:%d, activeCardType:%d", bIC, activeCardType));
-
-	if (bIC)
+	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("retDetect:%d, activeCardType:%d", retDetect, activeCardType);
+	if (retDetect == 0)//oiltmp for simple to not change bIC
 	{
 		//oilyang@20201014 add emv support
-		int bGetICData = m_pCardProcess->GetICDataFromCard(CARD_MACHINE_ISSUER, m_hDevHelper, m_aidList);
-		if(bGetICData != 0)
-		{
-			DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)(CSimpleStringA::Format("<JustReadCardNo::GetICDataFromCard> faile(%d)", bGetICData));
-		}
+		bool bGetICData = m_pCardProcess->GetICDataFromCard(CARD_MACHINE_ISSUER, m_hDevHelper, m_aidList);
+		if (bGetICData != 0)
+			SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_ICCommand, "DevAdapter::ICCommand", __FUNCTION__, false, l_endTime - l_beginTime);
 		ICData track2(false, 0x57, 0x00);
 		string t2ICAccount(""), t2ICCardSerial(""), t2ICCVC(""), t2ICTrack2(""), cardType;
 		if (m_pCardProcess->FindTagValue(TAG_VECTOR_IC, track2, false, 0) == -1)
@@ -3720,19 +3581,19 @@ bool CCardIssuerFSM::JustReadCardNo()
 		else
 		{
 			int pos = FindHexCharPosition(track2.value, 0x0d, track2.lenth);
-			char *pICTrack2 = new char[128];
+			char* pICTrack2 = new char[128];
 			ZeroMemory(pICTrack2, 128);
 			HexBuf2StrBuf(track2.value, &pICTrack2, track2.lenth);
 			pICTrack2[37] = '\0';
 
-			char *ddd = new char[128];
+			char* ddd = new char[128];
 			memset(ddd, 0, 128);
 			memcpy(ddd, pICTrack2, pos - 1);
 			m_currCardNo = ddd;
 			if (m_currCardNo.GetLength() > 1)
 				bHasAccount = true;
 			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)(CSimpleStringA::Format("<JustReadCardNo>, FindHexCharPosition, pos:%d, track2.lenth:%d, m_currCardNo.Len:%d",
-											pos, track2.lenth, m_currCardNo.GetLength()));
+				pos, track2.lenth, m_currCardNo.GetLength()));
 
 			delete[]ddd;
 			delete[]pICTrack2;
@@ -3741,8 +3602,8 @@ bool CCardIssuerFSM::JustReadCardNo()
 		l_beginTime = GetTickCountRVC();
 		eErr = m_hDevHelper->DeactivateICCard();
 		l_endTime = GetTickCountRVC();
-		
-		if (eErr != Error_Succeed){
+
+		if (eErr != Error_Succeed) {
 			SetErrorAndLog(eErr, MEC_DEVAPI_CARDISSUER_DeactivateICCard, "DevAdapter::DeactivateICCard", __FUNCTION__, false, l_endTime - l_beginTime, "", "");
 		}
 		else {
@@ -3752,24 +3613,23 @@ bool CCardIssuerFSM::JustReadCardNo()
 		l_beginTime = GetTickCountRVC();
 		eErr = m_hDevHelper->ReleaseIC();
 		l_endTime = GetTickCountRVC();
-		
 
-		if (eErr != Error_Succeed){
+
+		if (eErr != Error_Succeed) {
 			SetErrorAndLog(eErr, MEC_DEVAPI_CARDISSUER_ReleaseIC, "DevAdapter::ReleaseIC", __FUNCTION__, false, l_endTime - l_beginTime, "", "");
 		}
 		else {
 			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("DevAdapter::ReleaseIC").setCostTime(l_endTime - l_beginTime)("JustReadCardNo::ReleaseIC");
 		}
 	}
-	else {
-		ErrorCodeEnum eErrCode = Error_Unexpect;
-		CSimpleStringA ApiName = "";
-		CSimpleStringA alarmMsg = "";
-		CSimpleStringA csErrMsgWithReturnCode = "";
-		GetCardProcessLastErr(eErrCode, ApiName, alarmMsg, csErrMsgWithReturnCode);
-		DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setAPI(ApiName.GetData()).setCostTime(l_endTime - l_beginTime).setResultCode("RTA23CT")(csErrMsgWithReturnCode.GetData());
-		LogWarn(Severity_Middle, Error_Unexpect, 0x2030000a, alarmMsg.GetData());
+	else
+	{
+		CSimpleStringA csDevApi("");
+		DWORD dwDevApi = 0;
+		GetDevApiCodeAndName(retDetect, dwDevApi, csDevApi);
+		SetErrorAndLog(Error_Unexpect, dwDevApi, csDevApi, __FUNCTION__, false, l_endTime - l_beginTime);
 	}
+
 	if (!bHasAccount)
 	{
 		MagTracks magTracks;
@@ -4662,119 +4522,24 @@ int CCardIssuerFSM::PreOnlineJS_ReadViaContact(SpReqAnsContext<CardIssuerStandSe
 
 	if (retDetectAndRead < 0)
 	{
-		ErrorCodeEnum eErrCode = Error_Unexpect;
-		CSimpleStringA ApiName = "";
-		CSimpleStringA alarmMsg = "";
-		CSimpleStringA csErrMsgWithReturnCode = "";
-
-		if (bContinue) {
-			if (retDetectAndRead == -1) {
-				DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("检测卡片类型时上电失败 to continue");
-				GetCardProcessLastErr(eErrCode, ApiName, alarmMsg, csErrMsgWithReturnCode);
-
-				if (m_issueStatus) {
-					DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setAPI(ApiName.GetData()).setCostTime(m_ullEndTime - m_ullBeginTime).setLogCode("QLR040220320").setResultCode("RTA230V")(csErrMsgWithReturnCode.GetData());
-				}
-				else {
-					DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setAPI(ApiName.GetData()).setCostTime(m_ullEndTime - m_ullBeginTime).setLogCode("QLR040220303").setResultCode("RTA230M")(csErrMsgWithReturnCode.GetData());
-				}
-			}
-			else if (retDetectAndRead == -2) {
-				DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("读取IC数据失败 to continue");
-				if (m_issueStatus) {
-					SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_ICCommand, "DevAdapter::ICCommand", __FUNCTION__, false, m_ullEndTime - m_ullBeginTime, "QLR040220320", "读取IC数据失败");
-				}
-				else {
-					SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_ICCommand, "DevAdapter::ICCommand", __FUNCTION__, false, m_ullEndTime - m_ullBeginTime, "QLR040220303", "读取IC数据失败");
-				}
-			}
-			else if (retDetectAndRead == -3) {
-				DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("IC卡建立应用列表失败 to continue");
-				if (m_issueStatus) {
-					SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_ICCommand, "DevAdapter::ICCommand", __FUNCTION__, false, m_ullEndTime - m_ullBeginTime, "QLR040220320", "retDetectAndRead = -3");
-				}
-				else {
-					SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_ICCommand, "DevAdapter::ICCommand", __FUNCTION__, false, m_ullEndTime - m_ullBeginTime, "QLR040220303", "retDetectAndRead = -3");
-				}
-			}
-		}
-		else {
-			DWORD dwTmpUserErrCode = 0;
-			if (retDetectAndRead == -1) {
-				DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("检测卡片类型时上电失败");
-				GetCardProcessLastErr(eErrCode, ApiName, alarmMsg, csErrMsgWithReturnCode);
-
-				if (m_issueStatus) {
-					if (IsInBusiness()) {
-						DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_USER).setAPI(ApiName.GetData()).setCostTime(m_ullEndTime - m_ullBeginTime).setLogCode("QLR040220320").setResultCode("RTA230V")(csErrMsgWithReturnCode.GetData());
-						LogError(Severity_Middle, Error_Unexpect, CardIssuer_UserErrorCode_IssueCard_ActiveICCard_Failed, alarmMsg.GetData());
-					}
-					else {
-						DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setAPI(ApiName.GetData()).setCostTime(m_ullEndTime - m_ullBeginTime).setLogCode("QLR040220320").setResultCode("RTA230V")(csErrMsgWithReturnCode.GetData());
-						LogWarn(Severity_Middle, Error_Unexpect, CardIssuer_UserErrorCode_IssueCard_ActiveICCard_Failed, alarmMsg.GetData());
-					}
-					if (m_bSingleMagOrIC)
-						ctx->Answer(Error_Unexpect, CardIssuer_UserErrorCode_IssueCard_ActiveICCard_Failed);
-					else
-					{
-						//oilyang@20250828 return ErrorSucceed so that the caller can know the failed reason of both mag&ic
-						ctx->Ans.icMsg = GetErrMsgByCode(CardIssuer_UserErrorCode_IssueCard_ActiveICCard_Failed);
-						ctx->Answer(Error_Succeed);
-					}
-				}
-				else {
-					if (IsInBusiness()) {
-						DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_USER).setAPI(ApiName.GetData()).setCostTime(m_ullEndTime - m_ullBeginTime).setLogCode("QLR040220303").setResultCode("RTA230M")(csErrMsgWithReturnCode.GetData());
-						LogError(Severity_Middle, Error_Unexpect, CardIssuer_UserErrorCode_ActiveICCard_Failed, alarmMsg.GetData());
-					}
-					else {
-						DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setAPI(ApiName.GetData()).setCostTime(m_ullEndTime - m_ullBeginTime).setLogCode("QLR040220303").setResultCode("RTA230M")(csErrMsgWithReturnCode.GetData());
-						LogWarn(Severity_Middle, Error_Unexpect, CardIssuer_UserErrorCode_ActiveICCard_Failed, alarmMsg.GetData());
-					}
-					if (m_bSingleMagOrIC)
-						ctx->Answer(Error_Unexpect, CardIssuer_UserErrorCode_IssueCard_ActiveICCard_Failed);
-					else
-					{
-						//oilyang@20250828 return ErrorSucceed so that the caller can know the failed reason of both mag&ic
-						ctx->Ans.icMsg = GetErrMsgByCode(CardIssuer_UserErrorCode_ActiveICCard_Failed);
-						ctx->Answer(Error_Succeed);
-					}
-				}
-			}
-			else if (retDetectAndRead == -2) {
-				DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("读取IC数据失败");
-				if (m_issueStatus) {
-					dwTmpUserErrCode = SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_ICCommand, "DevAdapter::ICCommand", __FUNCTION__, IsInBusiness(), m_ullEndTime - m_ullBeginTime, "QLR040220320", "读取IC数据失败");
-				}
-				else {
-					dwTmpUserErrCode = SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_ICCommand, "DevAdapter::ICCommand", __FUNCTION__, IsInBusiness(), m_ullEndTime - m_ullBeginTime, "QLR040220303", "读取IC数据失败");
-				}
-				if (m_bSingleMagOrIC)
-					ctx->Answer(Error_Unexpect, CardIssuer_UserErrorCode_IssueCard_ActiveICCard_Failed);
-				else
-				{
-					//oilyang@20250828 return ErrorSucceed so that the caller can know the failed reason of both mag&ic
-					ctx->Ans.icMsg = GetErrMsgByCode(dwTmpUserErrCode);
-					ctx->Answer(Error_Succeed);
-				}
-			}
-			else if (retDetectAndRead == -3) {
-				DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("IC卡建立应用列表失败");
-				DWORD dwTmpUserErrCode = 0;
-				if (m_issueStatus) {
-					dwTmpUserErrCode = SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_ICCommand, "DevAdapter::ICCommand", __FUNCTION__, IsInBusiness(), m_ullEndTime - m_ullBeginTime, "QLR040220320", "retDetectAndRead =-3");
-				}
-				else {
-					dwTmpUserErrCode = SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_ICCommand, "DevAdapter::ICCommand", __FUNCTION__, IsInBusiness(), m_ullEndTime - m_ullBeginTime, "QLR040220303", "retDetectAndRead =-3");
-				}
-				if (m_bSingleMagOrIC)
-					ctx->Answer(Error_Unexpect, CardIssuer_UserErrorCode_IssueCard_ActiveICCard_Failed);
-				else
-				{
-					//oilyang@20250828 return ErrorSucceed so that the caller can know the failed reason of both mag&ic
-					ctx->Ans.icMsg = GetErrMsgByCode(dwTmpUserErrCode);
-					ctx->Answer(Error_Succeed);
-				}
+		DWORD dwDevApiCode = 0;
+		CSimpleStringA csDevApiName(""), csLogCode("");
+		CSimpleStringA csIssueContext = CSimpleStringA::Format("{\"InIssue\":%d}", m_issueStatus);//oiltmp
+		GetDevApiCodeAndName(retDetectAndRead, dwDevApiCode, csDevApiName);
+		if (m_issueStatus)
+			csLogCode = CardIssuerStandService_LogCode_IssueEx;
+		else
+			csLogCode = CardIssuerStandService_LogCode_Read;
+		DWORD dwCode = SetErrorAndLog(Error_Unexpect, dwDevApiCode, csDevApiName, __FUNCTION__, !bContinue && IsInBusiness(), m_ullEndTime - m_ullBeginTime, csLogCode, csIssueContext);
+		if (!bContinue) //no need continue
+		{
+			if (m_bSingleMagOrIC)
+				ctx->Answer(Error_Unexpect, dwCode);
+			else
+			{
+				//oilyang@20250828 return ErrorSucceed so that the caller can know the failed reason of both mag&ic
+				ctx->Ans.icMsg = GetErrMsgByCode(dwCode);
+				ctx->Answer(Error_Succeed);
 			}
 		}
 		return -1;
@@ -4862,129 +4627,27 @@ int CCardIssuerFSM::PreOnlineJS_ReadViaRF(SpReqAnsContext<CardIssuerStandService
 
 	if (retDetectAndRead < 0)
 	{
-		ErrorCodeEnum eErrCode = Error_Unexpect;
-		CSimpleStringA ApiName = "";
-		CSimpleStringA alarmMsg = "";
-		CSimpleStringA csErrMsgWithReturnCode = "";
-		DWORD dwTmpUserErrCode = 0;
-		if (bContinue)
-		{
-			if (retDetectAndRead == -1) {
-				DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("检测卡片类型时上电失败(非接)to continue");
-				GetCardProcessLastErr(eErrCode, ApiName, alarmMsg, csErrMsgWithReturnCode);
-
-				if (m_issueStatus) {
-					DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setAPI(ApiName.GetData()).setCostTime(m_ullEndTime - m_ullBeginTime).setLogCode("QLR040220320").setResultCode("RTA2327")(csErrMsgWithReturnCode.GetData());
-				}
-				else {
-					DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setAPI(ApiName.GetData()).setCostTime(m_ullEndTime - m_ullBeginTime).setLogCode("QLR040220303").setResultCode("RTA2326")(csErrMsgWithReturnCode.GetData());
-				}
-			}
-			else if (retDetectAndRead == -2) {
-
-				DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("读取IC数据失败 to continue");
-				if (m_issueStatus) {
-					SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_RFTypeABCommand, "DevAdapter::RFTypeABCommand", __FUNCTION__, false, m_ullEndTime - m_ullBeginTime, "QLR040220320", "读取IC数据失败");
-				}
-				else {
-					SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_RFTypeABCommand, "DevAdapter::RFTypeABCommand", __FUNCTION__, false, m_ullEndTime - m_ullBeginTime, "QLR040220303", "读取IC数据失败");
-				}
-			}
-			else if (retDetectAndRead == -3) {
-
-				DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("IC卡建立应用列表失败 to continue");
-				if (m_issueStatus) {
-					SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_RFTypeABCommand, "DevAdapter::RFTypeABCommand", __FUNCTION__, false, m_ullEndTime - m_ullBeginTime, "QLR040220320", "retDetectAndRead=-3");
-				}
-				else {
-					SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_RFTypeABCommand, "DevAdapter::RFTypeABCommand", __FUNCTION__, false, m_ullEndTime - m_ullBeginTime, "QLR040220303", "retDetectAndRead=-3");
-				}
-			}
-		}
+		DWORD dwDevApiCode = 0;
+		CSimpleStringA csDevApiName(""), csLogCode("");
+		CSimpleStringA csIssueContext = CSimpleStringA::Format("{\"InIssue\":%d}", m_issueStatus);//oiltmp
+		GetDevApiCodeAndName(retDetectAndRead, dwDevApiCode, csDevApiName);
+		if (m_issueStatus)
+			csLogCode = CardIssuerStandService_LogCode_IssueEx;
 		else
+			csLogCode = CardIssuerStandService_LogCode_Read;
+		DWORD dwCode = SetErrorAndLog(Error_Unexpect, dwDevApiCode, csDevApiName, __FUNCTION__, !bContinue && IsInBusiness(), m_ullEndTime - m_ullBeginTime, csLogCode, csIssueContext);
+		if (!bContinue) //no need continue
 		{
-			if (retDetectAndRead == -1) {
-				DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("检测卡片类型时上电失败(非接)");
-				GetCardProcessLastErr(eErrCode, ApiName, alarmMsg, csErrMsgWithReturnCode);
-
-				if (m_issueStatus) {
-					if (IsInBusiness())
-					{
-						DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_USER).setAPI(ApiName.GetData()).setCostTime(m_ullEndTime - m_ullBeginTime).setLogCode("QLR040220320").setResultCode("RTA2327")(csErrMsgWithReturnCode.GetData());
-						LogError(Severity_Middle, Error_Unexpect, CardIssuer_UserErrorCode_IssueCard_ActiveRF_Failed, alarmMsg.GetData());
-					}
-					else {
-						DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setAPI(ApiName.GetData()).setCostTime(m_ullEndTime - m_ullBeginTime).setLogCode("QLR040220320").setResultCode("RTA2327")(csErrMsgWithReturnCode.GetData());
-						LogWarn(Severity_Middle, Error_Unexpect, CardIssuer_UserErrorCode_IssueCard_ActiveRF_Failed, alarmMsg.GetData());
-					}
-					if (m_bSingleMagOrIC)
-						ctx->Answer(Error_Unexpect, CardIssuer_UserErrorCode_IssueCard_ActiveRF_Failed);
-					else
-					{
-						//oilyang@20250828 return ErrorSucceed so that the caller can know the failed reason of both mag&ic
-						ctx->Ans.icMsg = GetErrMsgByCode(CardIssuer_UserErrorCode_IssueCard_ActiveRF_Failed);
-						ctx->Answer(Error_Succeed);
-					}
-				}
-				else {
-					if (IsInBusiness())
-					{
-						DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_USER).setAPI(ApiName.GetData()).setCostTime(m_ullEndTime - m_ullBeginTime).setLogCode("QLR040220303").setResultCode("RTA2326")(csErrMsgWithReturnCode.GetData());
-						LogError(Severity_Middle, Error_Unexpect, CardIssuer_UserErrorCode_ActiveContactlessICCard_Failed, alarmMsg.GetData());
-					}
-					else
-					{
-						DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setAPI(ApiName.GetData()).setCostTime(m_ullEndTime - m_ullBeginTime).setLogCode("QLR040220303").setResultCode("RTA2326")(csErrMsgWithReturnCode.GetData());
-						LogWarn(Severity_Middle, Error_Unexpect, CardIssuer_UserErrorCode_ActiveContactlessICCard_Failed, alarmMsg.GetData());
-					}
-					if (m_bSingleMagOrIC)
-						ctx->Answer(Error_Unexpect, CardIssuer_UserErrorCode_ActiveContactlessICCard_Failed);
-					else
-					{
-						//oilyang@20250828 return ErrorSucceed so that the caller can know the failed reason of both mag&ic
-						ctx->Ans.icMsg = GetErrMsgByCode(CardIssuer_UserErrorCode_ActiveContactlessICCard_Failed);
-						ctx->Answer(Error_Succeed);
-					}
-				}
-			}
-			else if (retDetectAndRead == -2) {
-
-				DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("读取IC数据失败");
-				if (m_issueStatus) {
-					dwTmpUserErrCode = SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_RFTypeABCommand, "DevAdapter::RFTypeABCommand", __FUNCTION__, IsInBusiness(), m_ullEndTime - m_ullBeginTime, "QLR040220320", "读取IC数据失败");
-				}
-				else {
-					dwTmpUserErrCode = SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_RFTypeABCommand, "DevAdapter::RFTypeABCommand", __FUNCTION__, IsInBusiness(), m_ullEndTime - m_ullBeginTime, "QLR040220303", "读取IC数据失败");
-				}
-				if (m_bSingleMagOrIC)
-					ctx->Answer(Error_Unexpect, dwTmpUserErrCode);
-				else
-				{
-					//oilyang@20250828 return ErrorSucceed so that the caller can know the failed reason of both mag&ic
-					ctx->Ans.icMsg = GetErrMsgByCode(dwTmpUserErrCode);
-					ctx->Answer(Error_Succeed);
-				}
-			}
-			else if (retDetectAndRead == -3) {
-
-				DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("IC卡建立应用列表失败");
-				if (m_issueStatus) {
-					dwTmpUserErrCode = SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_RFTypeABCommand, "DevAdapter::RFTypeABCommand", __FUNCTION__, IsInBusiness(), m_ullEndTime - m_ullBeginTime, "QLR040220320", "retDetectAndRead=-3");
-				}
-				else {
-					dwTmpUserErrCode = SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_RFTypeABCommand, "DevAdapter::RFTypeABCommand", __FUNCTION__, IsInBusiness(), m_ullEndTime - m_ullBeginTime, "QLR040220303", "retDetectAndRead=-3");
-				}
-				if (m_bSingleMagOrIC)
-					ctx->Answer(Error_Unexpect, dwTmpUserErrCode);
-				else
-				{
-					//oilyang@20250828 return ErrorSucceed so that the caller can know the failed reason of both mag&ic
-					ctx->Ans.icMsg = GetErrMsgByCode(dwTmpUserErrCode);
-					ctx->Answer(Error_Succeed);
-				}
+			if (m_bSingleMagOrIC)
+				ctx->Answer(Error_Unexpect, dwCode);
+			else
+			{
+				//oilyang@20250828 return ErrorSucceed so that the caller can know the failed reason of both mag&ic
+				ctx->Ans.icMsg = GetErrMsgByCode(dwCode);
+				ctx->Answer(Error_Succeed);
 			}
 		}
-		return -1;//上电读卡失败
+		return -1;
 	}
 
 	m_pCardProcess->TermRiskManage();
@@ -5454,39 +5117,6 @@ CSimpleStringA CCardIssuerFSM::MaskCardno(const char* cardno)
 	return maskCardno;
 }
 
-void CCardIssuerFSM::GetCardProcessLastErr(ErrorCodeEnum& eErrCode, CSimpleStringA& ApiName, CSimpleStringA& alarmMsg, CSimpleStringA& csErrMsgWithReturnCode)
-{
-	if (m_pCardProcess == NULL) {
-		DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("GetCardProcessLastErr m_pCardProcess is null");
-		eErrCode = Error_Null;
-		ApiName = "";
-		alarmMsg = "";
-		csErrMsgWithReturnCode = "";
-		return;
-	}
-
-	ErrorCodeEnum lastErrCode = Error_Succeed;
-	CSimpleStringA lastErrMsg = "";
-	CSimpleStringA lastApiName = "";
-	m_pCardProcess->getCardAssistLastErr(lastErrCode, lastErrMsg, lastApiName);
-
-	const CSimpleStringA alarmMsgStr = CSimpleStringA::Format("{\"Function\":\"%s\", \"DevApi\":\"%s\", \"ReturnCode\":\"%s\", \"Msg\":\"%s\", \"Context\":\"%s\"}"
-		, __FUNCTION__, lastApiName.GetData(), SpStrError(lastErrCode), lastErrMsg.GetData(), "");
-
-	std::map<std::string, std::string> msgInfo;
-	msgInfo["ReturnCode"] = SpStrError(lastErrCode);
-	msgInfo["ErrMsg"] = lastErrMsg.GetData();
-	msgInfo["Context"] = "";
-	std::pair<bool, std::string> strResult;
-	strResult = generateJsonStr(msgInfo);
-	CSimpleStringA csErrMsgWithReturnCodeStr = strResult.second.c_str();
-
-	eErrCode = lastErrCode;
-	ApiName = lastApiName;
-	alarmMsg = alarmMsgStr.GetData();
-	csErrMsgWithReturnCode = csErrMsgWithReturnCodeStr.GetData();
-}
-
 void CCardIssuerFSM::OnStateTrans(int iSrcState, int iDstState)
 {
 	DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("trans from %s to %s", GetStateName(iSrcState), GetStateName(iDstState));
@@ -5548,4 +5178,35 @@ CSimpleStringA CCardIssuerFSM::GetErrMsgByCode(DWORD dwCode)
 	CSimpleStringA tmpRTA(true), tmpDesc(true);
 	GetEntityBase()->GetFunction()->GetVTMErrMsg(dwCode, tmpDesc, tmpRTA);
 	return CSimpleStringA::Format("[%s]%s", tmpRTA.GetData(), tmpDesc.GetData());
+}
+void CCardIssuerFSM::GetDevApiCodeAndName(int retValue, DWORD& dwDevApiCode, CSimpleStringA& csDevApiName)
+{
+	switch (retValue)
+	{
+	case -1:
+		dwDevApiCode = MEC_DEVAPI_CARDISSUER_ContactIC;
+		csDevApiName = "DevAdapter::ContactIC";
+		break;
+	case -2:
+		dwDevApiCode = MEC_DEVAPI_CARDISSUER_ActiveICCard;
+		csDevApiName = "DevAdapter::ActiveICCard";
+		break;
+	case -3:
+		dwDevApiCode = MEC_DEVAPI_CARDISSUER_ActiveContactlessICCard;
+		csDevApiName = "DevAdapter::ActiveContactlessICCard";
+		break;
+	case -4:
+		dwDevApiCode = MEC_DEVAPI_CARDISSUER_ICCommand;
+		csDevApiName = "DevAdapter::ICCommand";
+		break;
+	case -5:
+		dwDevApiCode = MEC_DEVAPI_CARDISSUER_RFTypeABCommand;
+		csDevApiName = "DevAdapter::RFTypeABCommand";
+		break;
+	default:
+		dwDevApiCode = DEC_NO_E_CARDISSUER_START;
+		csDevApiName = "DevAdapter::SthWrong";
+		break;
+	}
+	return;
 }

+ 1 - 1
Module/mod_CardIssuerStand/CardIssuerStandFSM.h

@@ -732,7 +732,6 @@ public:
 	int PreOnlineJS_ICDataProcess(SpReqAnsContext<CardIssuerStandService_ReadJS_Req, CardIssuerStandService_ReadJS_Ans>::Pointer ctx);
 
 	CSimpleStringA MaskCardno(const char* cardno);
-	void GetCardProcessLastErr(ErrorCodeEnum& eErrCode, CSimpleStringA& lastApiName, CSimpleStringA& alarmMsg, CSimpleStringA& csErrMsgWithReturnCode);
 
 	void SetDoExitFlag(bool bFlag) { m_bDoExit = bFlag; }
 	virtual void OnStateTrans(int iSrcState, int iDstState);
@@ -750,6 +749,7 @@ private:
 	BYTE m_btCID/*9f27*/;
 	void FSMEventDefaultProcess(FSMEvent* pEvt, DWORD dwUserCode);
 	CSimpleStringA GetErrMsgByCode(DWORD dwCode);
+	void GetDevApiCodeAndName(int retValue, DWORD& dwDevApiCode, CSimpleStringA& csDevApiName);
 };
 
 class ReadJSEvent : public FSMEvent

+ 56 - 85
Module/mod_ContactlessCard/ContactlessFSM.cpp

@@ -993,27 +993,14 @@ int CContactlessCardFSM::AcceptCard(SpReqAnsContext<ContactlessCardService_Inser
 			}
 			if (retDetectAndRead < 0)
 			{
-				// -1和-2是上电或APDU交互失败,功能集循环调用
-				if (retDetectAndRead == -1){
-					
-					if (!ctx->Req.reserved1.IsNullOrEmpty() && ctx->Req.reserved1.Compare("P") == 0) {
-						SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_RF_ActiveContactlessICCard, "DevAdapter::ActiveContactlessICCard", __FUNCTION__, false, l_endTime - l_beginTime, "", "");
-					}
-					ctx->Answer(Error_Interact, GetAlarmDEC());
-				}
-				else if (retDetectAndRead == -2){
-					
-					if (!ctx->Req.reserved1.IsNullOrEmpty() && ctx->Req.reserved1.Compare("P") == 0) {
-						SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_RF_RFTypeABCommand, "DevAdapter::RFTypeABCommand", __FUNCTION__, false, l_endTime - l_beginTime, "", "");
-					}
-					ctx->Answer(Error_Interact, GetAlarmDEC());
-				}else if (retDetectAndRead == -3){
-					
-					if (!ctx->Req.reserved1.IsNullOrEmpty() && ctx->Req.reserved1.Compare("P") == 0) {
-						SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_RF_RFTypeABCommand, "DevAdapter::RFTypeABCommand", __FUNCTION__, false, l_endTime - l_beginTime, "", "");
-					}
-					ctx->Answer(Error_Interact, GetAlarmDEC());
+				DWORD dwDevApiCode = 0;
+				CSimpleStringA csDevApiName("");
+				GetDevApiCodeAndName(retDetectAndRead, dwDevApiCode, csDevApiName);
+				if (!ctx->Req.reserved1.IsNullOrEmpty() && ctx->Req.reserved1.Compare("P") == 0) {
+					SetErrorAndLog(Error_Unexpect, dwDevApiCode, csDevApiName, __FUNCTION__, false, l_endTime - l_beginTime, "", "");
 				}
+				ctx->Answer(Error_Interact, GetAlarmDEC());
+
 				return 2;
 			}
 			ctx->Ans.t2Account = ctx->Ans.ICData = "";
@@ -1180,24 +1167,14 @@ int CContactlessCardFSM::PreOnline(SpReqAnsContext<ContactlessCardService_PreOnl
 	}
 	if (retDetectAndRead < 0)
 	{
-		// -1和-2是上电或APDU交互失败,功能集循环调用
-		if (retDetectAndRead == -1){
-			if (!ctx->Req.reserved1.IsNullOrEmpty() && ctx->Req.reserved1.Compare("P") == 0) {
-				SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_RF_ActiveContactlessICCard, "DevAdapter::ActiveContactlessICCard", __FUNCTION__, false, l_endTime - l_beginTime, "", "");
-			}
-			ctx->Answer(Error_Interact, GetAlarmDEC());
-		}
-		else if (retDetectAndRead == -2){
-			if (!ctx->Req.reserved1.IsNullOrEmpty() && ctx->Req.reserved1.Compare("P") == 0) {
-				SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_RF_RFTypeABCommand, "DevAdapter::RFTypeABCommand", __FUNCTION__, false, l_endTime - l_beginTime, "", "");
-			}
-			ctx->Answer(Error_Interact, GetAlarmDEC());
-		}else if (retDetectAndRead == -3){
-			if (!ctx->Req.reserved1.IsNullOrEmpty() && ctx->Req.reserved1.Compare("P") == 0) {
-				SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_RF_RFTypeABCommand, "DevAdapter::RFTypeABCommand", __FUNCTION__, false, l_endTime - l_beginTime, "", "");
-			}
-			ctx->Answer(Error_Interact, GetAlarmDEC());
+		DWORD dwDevApiCode = 0;
+		CSimpleStringA csDevApiName("");
+		GetDevApiCodeAndName(retDetectAndRead, dwDevApiCode, csDevApiName);
+		if (!ctx->Req.reserved1.IsNullOrEmpty() && ctx->Req.reserved1.Compare("P") == 0) {
+			SetErrorAndLog(Error_Unexpect, dwDevApiCode, csDevApiName, __FUNCTION__, false, l_endTime - l_beginTime, "", "");
 		}
+		ctx->Answer(Error_Interact, GetAlarmDEC());
+
 		return 0;
 	}
 	m_pCardProcess->TermRiskManage();
@@ -1554,39 +1531,6 @@ bool CContactlessCardFSM::LoadCMBPrint(CSimpleStringA csBinPath)
 	return result;
 }
 
-void CContactlessCardFSM::GetCardProcessLastErr(ErrorCodeEnum& eErrCode, CSimpleStringA& ApiName, CSimpleStringA& alarmMsg, CSimpleStringA& csErrMsgWithReturnCode)
-{
-	if (m_pCardProcess == NULL) {
-		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("GetCardProcessLastErr m_pCardProcess is null");
-		eErrCode = Error_Null;
-		ApiName = "";
-		alarmMsg = "";
-		csErrMsgWithReturnCode = "";
-		return;
-	}
-
-	ErrorCodeEnum lastErrCode = Error_Succeed;
-	CSimpleStringA lastErrMsg = "";
-	CSimpleStringA lastApiName = "";
-	m_pCardProcess->getCardAssistLastErr(lastErrCode, lastErrMsg, lastApiName);
-
-	const CSimpleStringA alarmMsgStr = CSimpleStringA::Format("{\"Function\":\"%s\", \"DevApi\":\"%s\", \"ReturnCode\":\"%s\", \"Msg\":\"%s\", \"Context\":\"%s\"}"
-		, __FUNCTION__, lastApiName.GetData(), SpStrError(lastErrCode), lastErrMsg.GetData(), "");
-
-	std::map<std::string, std::string> msgInfo;
-	msgInfo["ReturnCode"] = SpStrError(lastErrCode);
-	msgInfo["ErrMsg"] = lastErrMsg.GetData();
-	msgInfo["Context"] = "";
-	std::pair<bool, std::string> strResult;
-	strResult = generateJsonStr(msgInfo);
-	CSimpleStringA csErrMsgWithReturnCodeStr = strResult.second.c_str();
-
-	eErrCode = lastErrCode;
-	ApiName = lastApiName;
-	alarmMsg = alarmMsgStr.GetData();
-	csErrMsgWithReturnCode = csErrMsgWithReturnCodeStr.GetData();
-}
-
 DWORD CContactlessCardFSM::GetFsmStateErrCode()
 {
 	int state = GetFSMState();
@@ -1807,10 +1751,10 @@ int CContactlessCardFSM::InternalAcceptCardJS()
 				LogEvent(Severity_Middle, LOG_EVT_CONTACTLESS_CARD_OP, "Contactless card op.");
 
 				int activeCardType;
-				l_beginTime = SP::Module::Comm::RVCGetTickCount();
-				bool bIC = m_pCardProcess->DetectIfICCard(CARD_MACHINE_RFIC, m_hDevHelper, activeCardType);
+				l_beginTime = SP::Module::Comm::RVCGetTickCount();				 
+				int bIC = m_pCardProcess->DetectIfICCard(CARD_MACHINE_RFIC, m_hDevHelper, activeCardType);
 				l_endTime = SP::Module::Comm::RVCGetTickCount();
-				if (bIC) {
+				if (bIC == 0) {
 					DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("InternalAcceptCardJS::DetectIfICCard activeCardType=%d", activeCardType);
 					if (activeCardType == 'A' || activeCardType == 'B' || activeCardType == 'M') {
 						err = 0;//探测到IC卡
@@ -1900,18 +1844,13 @@ int CContactlessCardFSM::PreOnlineJS(SpReqAnsContext<ContactlessCardService_Read
 	if (retDetectAndRead < 0)
 	{
 		ctx->Ans.icState = 0;//调用失败
-		if (retDetectAndRead == -1) {
-			DWORD dwTmpUserErrCode = SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_RF_ActiveContactlessICCard, "DevAdapter::ActiveContactlessICCard", __FUNCTION__, false, l_endTime - l_beginTime, "", "");
-			ctx->Answer(Error_Exception, dwTmpUserErrCode);
-		}
-		else if (retDetectAndRead == -2) {
-			DWORD dwTmpUserErrCode = SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_RF_RFTypeABCommand, "DevAdapter::RFTypeABCommand", __FUNCTION__, false, l_endTime - l_beginTime, "", "");
-			ctx->Answer(Error_Exception, dwTmpUserErrCode);
-		}
-		else if (retDetectAndRead == -3) {
-			DWORD dwTmpUserErrCode = SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_RF_RFTypeABCommand, "DevAdapter::RFTypeABCommand", __FUNCTION__, false, l_endTime - l_beginTime, "", "");
-			ctx->Answer(Error_Exception, dwTmpUserErrCode);
-		}
+		DWORD dwDevApiCode = 0;
+		CSimpleStringA csDevApiName("");
+		GetDevApiCodeAndName(retDetectAndRead, dwDevApiCode, csDevApiName);
+
+		DWORD dwTmpUserErrCode = SetErrorAndLog(Error_Unexpect, dwDevApiCode, csDevApiName, __FUNCTION__, false, l_endTime - l_beginTime, "", "");
+		ctx->Answer(Error_Exception, dwTmpUserErrCode);
+
 		return -1;
 	}
 
@@ -2127,6 +2066,38 @@ int CContactlessCardFSM::PreOnlineJS(SpReqAnsContext<ContactlessCardService_Read
 
 }
 
+void CContactlessCardFSM::GetDevApiCodeAndName(int retValue, DWORD& dwDevApiCode, CSimpleStringA& csDevApiName)
+{
+	switch (retValue)
+	{
+	case -1:
+		dwDevApiCode = MEC_DEVAPI_CARDISSUER_ContactIC;
+		csDevApiName = "DevAdapter::ContactIC";
+		break;
+	case -2:
+		dwDevApiCode = MEC_DEVAPI_CARDISSUER_ActiveICCard;
+		csDevApiName = "DevAdapter::ActiveICCard";
+		break;
+	case -3:
+		dwDevApiCode = MEC_DEVAPI_RF_ActiveContactlessICCard;
+		csDevApiName = "DevAdapter::ActiveContactlessICCard";
+		break;
+	case -4:
+		dwDevApiCode = MEC_DEVAPI_CARDISSUER_ICCommand;
+		csDevApiName = "DevAdapter::ICCommand";
+		break;
+	case -5:
+		dwDevApiCode = MEC_DEVAPI_RF_RFTypeABCommand;
+		csDevApiName = "DevAdapter::RFTypeABCommand";
+		break;
+	default:
+		dwDevApiCode = DEC_NO_E_CARDISSUER_START;
+		csDevApiName = "DevAdapter::SthWrong";
+		break;
+	}
+	return;
+}
+
 void CContactlessCardFSM::OnStateTrans(int iSrcState, int iDstState)
 {
 	DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("trans from %s to %s", GetStateName(iSrcState), GetStateName(iDstState));

+ 2 - 2
Module/mod_ContactlessCard/ContactlessFSM.h

@@ -348,7 +348,7 @@ public:
 	void SetWaitMore(){m_bWaitAccepteMore = true;}
 	void SetExitFlag(bool bFlag=true){m_bExit = bFlag;}
 	bool LoadCMBPrint(CSimpleStringA csBinPath);
-	void GetCardProcessLastErr(ErrorCodeEnum& eErrCode, CSimpleStringA& lastApiName, CSimpleStringA& alarmMsg, CSimpleStringA& csErrMsgWithReturnCode);
+	
 
 	void SelfTest(EntityTestEnum eTestType,CSmartPointer<ITransactionContext> pTransactionContext)
 	{
@@ -378,7 +378,7 @@ public:
 		DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("rtaMsg=%s",rtaMsg.GetData());
 		return rtaMsg;
 	}
-
+	void GetDevApiCodeAndName(int retValue, DWORD& dwDevApiCode, CSimpleStringA& csDevApiName);
 protected:
 	int m_iInsertTries;
 	int m_resetTries;

+ 170 - 500
Module/mod_cardissuerstore/CardIssuerStoreFSM.cpp

@@ -2878,30 +2878,23 @@ int CCardIssuerFSM::ReadCard_Contact(SpReqAnsContext<CardIssuerStoreService_Read
 		}
 		else//未访问户口系统或户口系统访问失败或户口未告知介质类型(包括插反卡)
 		{
-			int icRetryTimes = 0;
-			while (1)
-			{//for poor mag only card,we always retry...
-				l_beginTime = RVCGetTickCount();
-				bIC = m_pCardProcess->DetectIfICCard(CARD_MACHINE_ISSUER_STORE, m_hDevHelper, activeCardType);
-				l_endTime = RVCGetTickCount();
-				if (!bIC)
-					icRetryTimes++;
-				else
-					break;
-				Sleep(500);
-				if (icRetryTimes >= m_ICRetryTimes)
-					break;
+
+			l_beginTime = RVCGetTickCount();
+			int retDetect = m_pCardProcess->DetectIfICCard(CARD_MACHINE_ISSUER_STORE, m_hDevHelper, activeCardType);
+			l_endTime = RVCGetTickCount();
+
+			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("<ReadCard::DetectIfICCard>, retDetect:%d", retDetect);
+			if (retDetect == 0) {
+				bIC = true;
 			}
-			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("<ReadCard::DetectIfICCard>, bIC:%d", bIC);
-			if (!bIC) {
-				ErrorCodeEnum eErrCode = Error_Unexpect;
-				CSimpleStringA ApiName = "";
-				CSimpleStringA alarmMsg = "";
-				CSimpleStringA csErrMsgWithReturnCode = "";
-				GetCardProcessLastErr(eErrCode, ApiName, alarmMsg, csErrMsgWithReturnCode);
-				DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setAPI(ApiName.GetData()).setCostTime(l_endTime - l_beginTime).setResultCode("RTA2WCT")(csErrMsgWithReturnCode.GetData());
-				LogWarn(Severity_Middle, Error_Unexpect, 0x2200000a, alarmMsg.GetData());
+			else {
+				bIC = false;
+				CSimpleStringA csDevApi("");
+				DWORD dwDevApi = 0;
+				GetDevApiCodeAndName(retDetect, dwDevApi, csDevApi);
+				SetErrorAndLog(Error_Unexpect, dwDevApi, csDevApi, __FUNCTION__, false, l_endTime - l_beginTime);
 			}
+
 			if (Error_Succeed == eMagReadErr && magTracks.track[1].eStatus == CI_DATA_OK)
 			{
 				if (bIC)
@@ -3159,30 +3152,24 @@ int CCardIssuerFSM::ReadCard_RF(SpReqAnsContext<CardIssuerStoreService_Read_Req,
 		}
 		else//未访问户口系统或户口系统访问失败(包括插反卡)
 		{
-			int icRetryTimes = 0;
-			while (1)
-			{//for poor mag only card,we always retry...
-				l_beginTime = RVCGetTickCount();
-				bIC = m_pCardProcess->DetectIfICCard(CARD_MACHINE_ISSUER_STORE_RF, m_hDevHelper, activeCardType);
-				l_endTime = RVCGetTickCount();
-				if (!bIC)
-					icRetryTimes++;
-				else
-					break;
-				Sleep(500);
-				if (icRetryTimes >= m_ICRetryTimes)
-					break;
+
+			l_beginTime = RVCGetTickCount();
+			int retDetect = m_pCardProcess->DetectIfICCard(CARD_MACHINE_ISSUER_STORE_RF, m_hDevHelper, activeCardType);
+			l_endTime = RVCGetTickCount();
+
+			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("<ReadCard::DetectIfICCard>, retDetect:%d", retDetect);
+
+			if (retDetect == 0) {
+				bIC = true;
 			}
-			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("<ReadCard::DetectIfICCard>, bIC:%d", bIC);
-			if (!bIC) {
-				ErrorCodeEnum eErrCode = Error_Unexpect;
-				CSimpleStringA ApiName = "";
-				CSimpleStringA alarmMsg = "";
-				CSimpleStringA csErrMsgWithReturnCode = "";
-				GetCardProcessLastErr(eErrCode, ApiName, alarmMsg, csErrMsgWithReturnCode);
-				DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setAPI(ApiName.GetData()).setCostTime(l_endTime - l_beginTime).setResultCode("RTA2WC6")(csErrMsgWithReturnCode.GetData());
-				LogWarn(Severity_Middle, Error_Unexpect, 0x22000017, alarmMsg.GetData());
+			else {
+				bIC = false;
+				CSimpleStringA csDevApi("");
+				DWORD dwDevApi = 0;
+				GetDevApiCodeAndName(retDetect, dwDevApi, csDevApi);
+				SetErrorAndLog(Error_Unexpect, dwDevApi, csDevApi, __FUNCTION__, false, l_endTime - l_beginTime);
 			}
+
 			if (!(bIC && activeCardType == 'A'))
 				bIC = false;
 			if (Error_Succeed == eMagReadErr && magTracks.track[1].eStatus == CI_DATA_OK)
@@ -3517,138 +3504,32 @@ int CCardIssuerFSM::PreOnline_Contact(SpReqAnsContext<CardIssuerStoreService_Pre
 	DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("<PreOnline>, After invoke DetectAndReadICData, retDetectAndRead:%d, activeCardType:%d", retDetectAndRead, activeCardType);
 	if (retDetectAndRead < 0)
 	{
-		//if ((m_csMachineType.Compare("RVC.CardStore") == 0 || m_csMachineType.Compare("RVC.CardPrinter") == 0)
-		//	&& m_bCrossPreOnline) {
-		//	if (IfUseRf()) {
-		//		bContinue = true; //继续后面的非接流程
-		//	}
-		//	else {
-		//		AfterPreOnlineOnStore(Error_Unexpect, slot);
-		//	}
-		//}
-		CSimpleStringA xCardName("");
-		if (m_issueStatus && m_currentHopper - 1 >= 0)
-			xCardName = m_PsbNameEx[m_currentHopper - 1];
-
-
-		DWORD dwUserErrCode = 0;
-		if (retDetectAndRead == -1){
-
-			ErrorCodeEnum eErrCode = Error_Unexpect;
-			CSimpleStringA ApiName = "";
-			CSimpleStringA alarmMsg = "";
-			CSimpleStringA csErrMsgWithReturnCode = "";
-			GetCardProcessLastErr(eErrCode, ApiName, alarmMsg, csErrMsgWithReturnCode);
 
-			if (m_issueStatus)
-			{
-				DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("发卡时,检测卡片类型时上电失败");
-				if (!IfUseRf())
-				{
-					const DWORD dwCode(CardIssuerStore_UserErrorCode_IssueCard_ActiveICCard_Failed);
-					if (IsInBusiness()) {
-						DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_USER).setAPI(ApiName.GetData()).setCostTime(l_endTime - l_beginTime).setLogCode("QLR040222020").setResultCode("RTA2W0V")(csErrMsgWithReturnCode.GetData());
-						LogError(Severity_Middle, Error_Unexpect, dwCode, alarmMsg.GetData());
-					}
-					else {
-						DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setAPI(ApiName.GetData()).setCostTime(l_endTime - l_beginTime).setLogCode("QLR040222020").setResultCode("RTA2W0V")(csErrMsgWithReturnCode.GetData());
-						LogWarn(Severity_Middle, Error_Unexpect, dwCode, alarmMsg.GetData());
-					}
-					dwUserErrCode = dwCode;
-					//ctx->Answer(Error_Unexpect, dwCode);
-				}
-				else {
-					//使用非接兜底
-					DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setAPI(ApiName.GetData()).setCostTime(l_endTime - l_beginTime).setLogCode("QLR040222020").setResultCode("RTA2W0V")(csErrMsgWithReturnCode.GetData());
-				}
-			}
-			else
-			{
-				DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("检测卡片类型时上电失败");
-				if (!IfUseRf())
-				{
-					if (IsInBusiness())
-					{
-						DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_USER).setAPI(ApiName.GetData()).setCostTime(l_endTime - l_beginTime).setLogCode("QLR040222003").setResultCode("RTA2W0M")(csErrMsgWithReturnCode.GetData());
-						LogError(Severity_Middle, Error_Unexpect, CardIssuerStore_UserErrorCode_ActiveICCard_Failed, alarmMsg.GetData());
-					}
-					else
-					{
-						DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setAPI(ApiName.GetData()).setCostTime(l_endTime - l_beginTime).setLogCode("QLR040222003").setResultCode("RTA2W0M")(csErrMsgWithReturnCode.GetData());
-						LogWarn(Severity_Middle, Error_Unexpect, CardIssuerStore_UserErrorCode_ActiveICCard_Failed, alarmMsg.GetData());
-					}
-					dwUserErrCode = CardIssuerStore_UserErrorCode_ActiveICCard_Failed;
-					//ctx->Answer(Error_Unexpect, CardIssuerStore_UserErrorCode_ActiveICCard_Failed);
-				}
-				else {
-					//使用非接兜底
-					DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setAPI(ApiName.GetData()).setCostTime(l_endTime - l_beginTime).setLogCode("QLR040222003").setResultCode("RTA2W0M")(csErrMsgWithReturnCode.GetData());
-				}
-			}
+		//新的错误返回
+		DWORD dwDevApiCode = 0;
+		CSimpleStringA csDevApiName(""), csLogCode("");
+		GetDevApiCodeAndName(retDetectAndRead, dwDevApiCode, csDevApiName);
+		CSimpleStringA csIssueContext = CSimpleStringA::Format("{\"InIssue\":%d}", m_issueStatus);
+		if (m_issueStatus) {
+			csLogCode = CardIssuerStoreService_LogCode_IssueEx;
 		}
-		else if (retDetectAndRead == -2){
-			
-			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("读取IC数据失败");
-			if (!IfUseRf())
-			{
-				DWORD dwTmpUserErrCode = 0;
-				if (m_issueStatus) {
-					dwTmpUserErrCode = SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_ICCommand, "DevAdapter::ICCommand", __FUNCTION__, IsInBusiness(), l_endTime - l_beginTime, "QLR040222020", "");
-				}
-				else {
-					dwTmpUserErrCode = SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_ICCommand, "DevAdapter::ICCommand", __FUNCTION__, IsInBusiness(), l_endTime - l_beginTime, "QLR040222003", "");
-				}
-				dwUserErrCode = dwTmpUserErrCode;
-				//ctx->Answer(Error_Unexpect, dwTmpUserErrCode);
-				
-			}
-			else {
-				//使用非接兜底
-				if (m_issueStatus) {
-					SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_ICCommand, "DevAdapter::ICCommand", __FUNCTION__, false, l_endTime - l_beginTime, "QLR040222020", "");
-				}
-				else {
-					SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_ICCommand, "DevAdapter::ICCommand", __FUNCTION__, false, l_endTime - l_beginTime, "QLR040222003", "");
-				}
-			}
+		else {
+			csLogCode = CardIssuerStoreService_LogCode_Read;
 		}
-		else if (retDetectAndRead == -3){
-
-			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("IC卡建立应用列表失败");
-			if (!IfUseRf())
-			{
-				DWORD dwTmpUserErrCode = 0;
-				if (m_issueStatus) {
-					dwTmpUserErrCode = SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_ICCommand, "DevAdapter::ICCommand", __FUNCTION__, IsInBusiness(), l_endTime - l_beginTime, "QLR040222020", "");
-				}
-				else {
-					dwTmpUserErrCode = SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_ICCommand, "DevAdapter::ICCommand", __FUNCTION__, IsInBusiness(), l_endTime - l_beginTime, "QLR040222003", "");
-				}
-				dwUserErrCode = dwTmpUserErrCode;
-				//ctx->Answer(Error_Unexpect, dwTmpUserErrCode);
-				
-			}
-			else {
-				//使用非接兜底
-				if (m_issueStatus) {
-					SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_ICCommand, "DevAdapter::ICCommand", __FUNCTION__, false, l_endTime - l_beginTime, "QLR040222020", "");
-				}
-				else {
-					SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_ICCommand, "DevAdapter::ICCommand", __FUNCTION__, false, l_endTime - l_beginTime, "QLR040222003", "");
-				}
-			}
 
+		DWORD dwUserErrCode = 0;
+		if (IfUseRf()) {
+			bContinue = true; //继续后面的非接流程
+			SetErrorAndLog(Error_Unexpect, dwDevApiCode, csDevApiName, __FUNCTION__, false, l_endTime - l_beginTime, csLogCode, csIssueContext);
 		}
+		else {
+			dwUserErrCode = SetErrorAndLog(Error_Unexpect, dwDevApiCode, csDevApiName, __FUNCTION__, IsInBusiness(), l_endTime - l_beginTime, csLogCode, csIssueContext);
 
-		if ((m_csMachineType.Compare("RVC.CardStore") == 0 || m_csMachineType.Compare("RVC.CardPrinter") == 0) && m_bCrossPreOnline) {
-			if (IfUseRf()) {
-				bContinue = true; //继续后面的非接流程
-			}
-			else {
+			//非接不兜底需要移回卡槽
+			if (m_bCrossPreOnline) {
 				AfterPreOnlineOnStore(Error_Unexpect, slot);
 			}
-		}
-		if (!IfUseRf()){
+
 			ctx->Answer(Error_Unexpect, dwUserErrCode);
 		}
 
@@ -3967,85 +3848,24 @@ int CCardIssuerFSM::PreOnline_RF(SpReqAnsContext<CardIssuerStoreService_PreOnlin
 	
 	if (retDetectAndRead < 0)
 	{
-		//非接兜底需要移回卡槽
-		//if ((m_csMachineType.Compare("RVC.CardStore") == 0 || m_csMachineType.Compare("RVC.CardPrinter") == 0) && m_bCrossPreOnline) {
-		//	AfterPreOnlineOnStore(Error_Unexpect, slot);//移回卡槽
-		//}
 
+		//新错误返回
+		DWORD dwDevApiCode = 0;
+		CSimpleStringA csDevApiName(""), csLogCode("");
+		GetDevApiCodeAndName(retDetectAndRead, dwDevApiCode, csDevApiName);
+		CSimpleStringA csIssueContext = CSimpleStringA::Format("{\"InIssue\":%d}", m_issueStatus);
 
-		CSimpleStringA xCardName("");
-		if (m_issueStatus && m_currentHopper - 1 >= 0)
-			xCardName = m_PsbNameEx[m_currentHopper - 1];
-
-		DWORD dwUserErrCode = 0;
-		if (retDetectAndRead == -1) {
-
-			ErrorCodeEnum eErrCode = Error_Unexpect;
-			CSimpleStringA ApiName = "";
-			CSimpleStringA alarmMsg = "";
-			CSimpleStringA csErrMsgWithReturnCode = "";
-			GetCardProcessLastErr(eErrCode, ApiName, alarmMsg, csErrMsgWithReturnCode);
-
-			if (m_issueStatus)
-			{
-				DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("发卡时检测卡片类型时上电失败(非接)");
-				if (IsInBusiness())
-				{
-					DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_USER).setAPI(ApiName.GetData()).setCostTime(l_endTime - l_beginTime).setLogCode("QLR040222020").setResultCode("RTA2W27")(csErrMsgWithReturnCode.GetData());
-					LogError(Severity_Middle, Error_Unexpect, CardIssuerStore_UserErrorCode_IssueCard_ActiveRF_Failed, alarmMsg.GetData());
-				}
-				else
-				{
-					DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setAPI(ApiName.GetData()).setCostTime(l_endTime - l_beginTime).setLogCode("QLR040222020").setResultCode("RTA2W27")(csErrMsgWithReturnCode.GetData());
-					LogWarn(Severity_Middle, Error_Unexpect, CardIssuerStore_UserErrorCode_IssueCard_ActiveRF_Failed, alarmMsg.GetData());
-				}
-				dwUserErrCode = CardIssuerStore_UserErrorCode_IssueCard_ActiveRF_Failed;
-				//ctx->Answer(Error_Unexpect, CardIssuerStore_UserErrorCode_IssueCard_ActiveRF_Failed);
-			}
-			else
-			{
-				DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("检测卡片类型时上电失败(非接)");
-				if (IsInBusiness())
-				{
-					DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_USER).setAPI(ApiName.GetData()).setCostTime(l_endTime - l_beginTime).setLogCode("QLR040222003").setResultCode("RTA2W26")(csErrMsgWithReturnCode.GetData());
-					LogError(Severity_Middle, Error_Unexpect, CardIssuerStore_UserErrorCode_ActiveContactlessICCard_Failed, alarmMsg.GetData());
-				}
-				else
-				{
-					DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setAPI(ApiName.GetData()).setCostTime(l_endTime - l_beginTime).setLogCode("QLR040222003").setResultCode("RTA2W26")(csErrMsgWithReturnCode.GetData());
-					LogWarn(Severity_Middle, Error_Unexpect, CardIssuerStore_UserErrorCode_ActiveContactlessICCard_Failed, alarmMsg.GetData());
-				}
-				dwUserErrCode = CardIssuerStore_UserErrorCode_ActiveContactlessICCard_Failed;
-				//ctx->Answer(Error_Unexpect, CardIssuerStore_UserErrorCode_ActiveContactlessICCard_Failed);
-			}
+		if (m_issueStatus) {
+			csLogCode = CardIssuerStoreService_LogCode_IssueEx;
 		}
-		else if (retDetectAndRead == -2) {
-			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("读取IC数据失败");
-			DWORD dwTmpUserErrCode = 0;
-			if (m_issueStatus) {
-				dwTmpUserErrCode = SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_RFTypeABCommand, "DevAdapter::RFTypeABCommand", __FUNCTION__, IsInBusiness(), l_endTime - l_beginTime, "QLR040222020", "");
-			}
-			else {
-				dwTmpUserErrCode = SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_RFTypeABCommand, "DevAdapter::RFTypeABCommand", __FUNCTION__, IsInBusiness(), l_endTime - l_beginTime, "QLR040222003", "");
-			}
-			dwUserErrCode = dwTmpUserErrCode;
-			//ctx->Answer(Error_Unexpect, dwTmpUserErrCode);
-		}
-		else if (retDetectAndRead == -3) {
-			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("IC卡建立应用列表失败");
-			DWORD dwTmpUserErrCode = 0;
-			if (m_issueStatus) {
-				dwTmpUserErrCode = SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_RFTypeABCommand, "DevAdapter::RFTypeABCommand", __FUNCTION__, IsInBusiness(), l_endTime - l_beginTime, "QLR040222020", "");
-			}
-			else {
-				dwTmpUserErrCode = SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_RFTypeABCommand, "DevAdapter::RFTypeABCommand", __FUNCTION__, IsInBusiness(), l_endTime - l_beginTime, "QLR040222003", "");
-			}
-			dwUserErrCode = dwTmpUserErrCode;
-			//ctx->Answer(Error_Unexpect, dwTmpUserErrCode);
+		else {
+			csLogCode = CardIssuerStoreService_LogCode_Read;
 		}
 
+		DWORD dwUserErrCode = SetErrorAndLog(Error_Unexpect, dwDevApiCode, csDevApiName, __FUNCTION__, IsInBusiness(), l_endTime - l_beginTime, csLogCode, csIssueContext);
+
 		//非接兜底需要移回卡槽
-		if ((m_csMachineType.Compare("RVC.CardStore") == 0 || m_csMachineType.Compare("RVC.CardPrinter") == 0) && m_bCrossPreOnline) {
+		if (m_bCrossPreOnline) {
 			AfterPreOnlineOnStore(Error_Unexpect, slot);//移回卡槽
 		}
 
@@ -4881,18 +4701,20 @@ bool CCardIssuerFSM::JustReadCardNo()
 	m_currCardNo = "";
 	bool bHasAccount = false;
 	int activeCardType;
+	bool bIC = false;
 	l_beginTime = RVCGetTickCount();
-	bool bIC = m_pCardProcess->DetectIfICCard(CARD_MACHINE_ISSUER_STORE, m_hDevHelper, activeCardType);
+	int retDetect = m_pCardProcess->DetectIfICCard(CARD_MACHINE_ISSUER_STORE, m_hDevHelper, activeCardType);
 	l_endTime = RVCGetTickCount();
-	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("DetectIfICCard, bIC:%d, activeCardType:%d", bIC, activeCardType);
 
-	if (bIC)
+	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("DetectIfICCard, retDetect:%d, activeCardType:%d", retDetect, activeCardType);
+
+	if (retDetect == 0)
 	{
 		//oilyang@20201014 add emv support
-		int bGetICData = m_pCardProcess->GetICDataFromCard(CARD_MACHINE_ISSUER_STORE, m_hDevHelper, m_aidList);
-		if(bGetICData != 0)
+		bool bGetICData = m_pCardProcess->GetICDataFromCard(CARD_MACHINE_ISSUER_STORE, m_hDevHelper, m_aidList);
+		if(!bGetICData)
 		{
-			DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("<JustReadCardNo::GetICDataFromCard> faile(%d)", bGetICData);
+			SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_ICCommand, "DevAdapter::ICCommand", __FUNCTION__, false, l_endTime - l_beginTime);
 		}
 		ICData track2(false, 0x57, 0x00);
 		string t2ICAccount(""), t2ICCardSerial(""), t2ICCVC(""), t2ICTrack2(""), cardType;
@@ -4945,14 +4767,12 @@ bool CCardIssuerFSM::JustReadCardNo()
 		}
 	}
 	else {
-		ErrorCodeEnum eErrCode = Error_Unexpect;
-		CSimpleStringA ApiName = "";
-		CSimpleStringA alarmMsg = "";
-		CSimpleStringA csErrMsgWithReturnCode = "";
-		GetCardProcessLastErr(eErrCode, ApiName, alarmMsg, csErrMsgWithReturnCode);
-		DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setAPI(ApiName.GetData()).setCostTime(l_endTime - l_beginTime).setResultCode("RTA2WCT")(csErrMsgWithReturnCode.GetData());
-		LogWarn(Severity_Middle, Error_Unexpect, 0x2200000a, alarmMsg.GetData());
+		CSimpleStringA csDevApi("");
+		DWORD dwDevApi = 0;
+		GetDevApiCodeAndName(retDetect, dwDevApi, csDevApi);
+		SetErrorAndLog(Error_Unexpect, dwDevApi, csDevApi, __FUNCTION__, false, l_endTime - l_beginTime);
 	}
+
 	if (!bHasAccount)
 	{
 		MagTracks magTracks;
@@ -8754,6 +8574,38 @@ int CCardIssuerFSM::ReadJS(SpReqAnsContext<CardIssuerStoreService_ReadJS_Req, Ca
 	}
 }
 
+void CCardIssuerFSM::GetDevApiCodeAndName(int retValue, DWORD& dwDevApiCode, CSimpleStringA& csDevApiName)
+{
+	switch (retValue)
+	{
+	case -1:
+		dwDevApiCode = MEC_DEVAPI_CARDISSUER_ContactIC;
+		csDevApiName = "DevAdapter::ContactIC";
+		break;
+	case -2:
+		dwDevApiCode = MEC_DEVAPI_CARDISSUER_ActiveICCard;
+		csDevApiName = "DevAdapter::ActiveICCard";
+		break;
+	case -3:
+		dwDevApiCode = MEC_DEVAPI_CARDISSUER_ActiveContactlessICCard;
+		csDevApiName = "DevAdapter::ActiveContactlessICCard";
+		break;
+	case -4:
+		dwDevApiCode = MEC_DEVAPI_CARDISSUER_ICCommand;
+		csDevApiName = "DevAdapter::ICCommand";
+		break;
+	case -5:
+		dwDevApiCode = MEC_DEVAPI_CARDISSUER_RFTypeABCommand;
+		csDevApiName = "DevAdapter::RFTypeABCommand";
+		break;
+	default:
+		dwDevApiCode = DEC_NO_E_CARDISSUER_START;
+		csDevApiName = "DevAdapter::SthWrong";
+		break;
+	}
+	return;
+}
+
 DWORD CCardIssuerFSM::GetFsmStateErrCode()
 {
 	int state = GetFSMState();
@@ -9080,30 +8932,21 @@ int CCardIssuerFSM::CheckCardType(CSimpleStringA cardNo, bool bReadMag, int& ICt
 			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("<CheckCardType>, begin detect cardType");
 			//主动探测
 			int activeCardType;
-			int icRetryTimes = 0;
 			bool bIC(false);
-			while (1)
-			{//for poor mag only card,we always retry...
-				l_beginTime = RVCGetTickCount();
-				bIC = m_pCardProcess->DetectIfICCard(CARD_MACHINE_ISSUER_STORE, m_hDevHelper, activeCardType);
-				l_endTime = RVCGetTickCount();
-				if (!bIC)
-					icRetryTimes++;
-				else
-					break;
-				Sleep(500);
-				if (icRetryTimes >= m_ICRetryTimes)
-					break;
+			l_beginTime = RVCGetTickCount();
+			int retDetect = m_pCardProcess->DetectIfICCard(CARD_MACHINE_ISSUER_STORE, m_hDevHelper, activeCardType);
+			l_endTime = RVCGetTickCount();
+
+			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("<CheckCardType::DetectIfICCard>, retDetect:%d", retDetect);
+			if (retDetect == 0) {
+				bIC = true;
 			}
-			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("<CheckCardType::DetectIfICCard>, bIC:%d", bIC);
-			if (!bIC) {
-				ErrorCodeEnum eErrCode = Error_Unexpect;
-				CSimpleStringA ApiName = "";
-				CSimpleStringA alarmMsg = "";
-				CSimpleStringA csErrMsgWithReturnCode = "";
-				GetCardProcessLastErr(eErrCode, ApiName, alarmMsg, csErrMsgWithReturnCode);
-				DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setAPI(ApiName.GetData()).setCostTime(l_endTime - l_beginTime).setResultCode("RTA2WCT")(csErrMsgWithReturnCode.GetData());
-				LogWarn(Severity_Middle, Error_Unexpect, 0x2200000a, alarmMsg.GetData());
+			else {
+				bIC = false;
+				CSimpleStringA csDevApi("");
+				DWORD dwDevApi = 0;
+				GetDevApiCodeAndName(retDetect, dwDevApi, csDevApi);
+				SetErrorAndLog(Error_Unexpect, dwDevApi, csDevApi, __FUNCTION__, false, l_endTime - l_beginTime);
 			}
 
 			//ic探测成功,0.无磁条IC 1.复合 2.磁条 3.纯IC 
@@ -9167,28 +9010,20 @@ int CCardIssuerFSM::CheckCardType(CSimpleStringA cardNo, bool bReadMag, int& ICt
 						DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("DevAdapter::MoveCard").setCostTime(l_endTime - l_beginTime)("CheckCardType::MoveCard, (CI_MOVECARD_RF_POSITION)");
 					}
 
-					icRetryTimes = 0;
+					
 					bool bICRF(false);
-					while (1)
-					{//for poor mag only card,we always retry...
-						bICRF = m_pCardProcess->DetectIfICCard(CARD_MACHINE_ISSUER_STORE_RF, m_hDevHelper, activeCardType);
-						if (!bICRF)
-							icRetryTimes++;
-						else
-							break;
-						Sleep(500);
-						if (icRetryTimes >= m_ICRetryTimes)
-							break;
-					}
-					DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("<CheckCardType::DetectIfICCard_RF>, bIC:%d", bICRF);
-					if (!bICRF) {
-						ErrorCodeEnum eErrCode = Error_Unexpect;
-						CSimpleStringA ApiName = "";
-						CSimpleStringA alarmMsg = "";
-						CSimpleStringA csErrMsgWithReturnCode = "";
-						GetCardProcessLastErr(eErrCode, ApiName, alarmMsg, csErrMsgWithReturnCode);
-						DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setAPI(ApiName.GetData()).setCostTime(l_endTime - l_beginTime).setResultCode("RTA2WC6")(csErrMsgWithReturnCode.GetData());
-						LogWarn(Severity_Middle, Error_Unexpect, 0x22000017, alarmMsg.GetData());
+
+					int retDetect = m_pCardProcess->DetectIfICCard(CARD_MACHINE_ISSUER_STORE_RF, m_hDevHelper, activeCardType);
+
+					DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("<CheckCardType::DetectIfICCard_RF>, retDetect:%d", retDetect);
+					if(retDetect == 0) {
+						bICRF = true;
+					}else{
+						bICRF = false;
+						CSimpleStringA csDevApi("");
+						DWORD dwDevApi = 0;
+						GetDevApiCodeAndName(retDetect, dwDevApi, csDevApi);
+						SetErrorAndLog(Error_Unexpect, dwDevApi, csDevApi, __FUNCTION__, false, l_endTime - l_beginTime);
 					}
 
 					if (!(bICRF && activeCardType == 'A')) {
@@ -9301,74 +9136,24 @@ int CCardIssuerFSM::PreOnlineJS_Contact(SpReqAnsContext<CardIssuerStoreService_R
 
 	if (retDetectAndRead < 0)
 	{
-		ErrorCodeEnum eErrCode = Error_Unexpect;
-		CSimpleStringA ApiName = "";
-		CSimpleStringA alarmMsg = "";
-		CSimpleStringA csErrMsgWithReturnCode = "";
 
+		//新的错误返回
+		DWORD dwDevApiCode = 0;
+		CSimpleStringA csDevApiName(""), csLogCode("");
+		GetDevApiCodeAndName(retDetectAndRead, dwDevApiCode, csDevApiName);
+		CSimpleStringA csIssueContext = CSimpleStringA::Format("{\"InIssue\":%d}", m_issueStatus);//oiltmp
+		csLogCode = CardIssuerStoreService_LogCode_ReadJS;
+
+		DWORD dwUserErrCode = 0;
 		if (IfUseRf()) {
 			bContinue = true; //继续后面的非接流程
-			if (retDetectAndRead == -1) {
-				DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("检测卡片类型时上电失败");
-				GetCardProcessLastErr(eErrCode, ApiName, alarmMsg, csErrMsgWithReturnCode);
-
-				if (m_issueStatus) {
-					DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setAPI(ApiName.GetData()).setCostTime(l_endTime - l_beginTime).setLogCode("QLR040222040").setResultCode("RTA2W0V")(csErrMsgWithReturnCode.GetData());
-					LogWarn(Severity_Middle, Error_Unexpect, CardIssuerStore_UserErrorCode_IssueCard_ActiveICCard_Failed, alarmMsg.GetData());
-				}
-				else {
-					DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setAPI(ApiName.GetData()).setCostTime(l_endTime - l_beginTime).setLogCode("QLR040222040").setResultCode("RTA2W0M")(csErrMsgWithReturnCode.GetData());
-					LogWarn(Severity_Middle, Error_Unexpect, CardIssuerStore_UserErrorCode_ActiveICCard_Failed, alarmMsg.GetData());
-				}
-			}
-			else if (retDetectAndRead == -2) {
-				DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("读取IC数据失败");
-				SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_ICCommand, "DevAdapter::ICCommand", __FUNCTION__, false, l_endTime - l_beginTime, "QLR040222040", "");
-			}
-			else if (retDetectAndRead == -3) {
-				DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("IC卡建立应用列表失败");
-				SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_ICCommand, "DevAdapter::ICCommand", __FUNCTION__, false, l_endTime - l_beginTime, "QLR040222040", "");
-			}
+			SetErrorAndLog(Error_Unexpect, dwDevApiCode, csDevApiName, __FUNCTION__, false, l_endTime - l_beginTime, csLogCode, csIssueContext);
 		}
 		else {
-			if (retDetectAndRead == -1) {
-				DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("检测卡片类型时上电失败");
-				GetCardProcessLastErr(eErrCode, ApiName, alarmMsg, csErrMsgWithReturnCode);
-
-				if (m_issueStatus) {
-					if (IsInBusiness()) {
-						DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_USER).setAPI(ApiName.GetData()).setCostTime(l_endTime - l_beginTime).setLogCode("QLR040222040").setResultCode("RTA2W0V")(csErrMsgWithReturnCode.GetData());
-						LogError(Severity_Middle, Error_Unexpect, CardIssuerStore_UserErrorCode_IssueCard_ActiveICCard_Failed, alarmMsg.GetData());
-					}
-					else {
-						DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setAPI(ApiName.GetData()).setCostTime(l_endTime - l_beginTime).setLogCode("QLR040222040").setResultCode("RTA2W0V")(csErrMsgWithReturnCode.GetData());
-						LogWarn(Severity_Middle, Error_Unexpect, CardIssuerStore_UserErrorCode_IssueCard_ActiveICCard_Failed, alarmMsg.GetData());
-					}
-					ctx->Answer(Error_Unexpect, CardIssuerStore_UserErrorCode_IssueCard_ActiveICCard_Failed);
-				}
-				else {
-					if (IsInBusiness()) {
-						DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_USER).setAPI(ApiName.GetData()).setCostTime(l_endTime - l_beginTime).setLogCode("QLR040222040").setResultCode("RTA2W0M")(csErrMsgWithReturnCode.GetData());
-						LogError(Severity_Middle, Error_Unexpect, CardIssuerStore_UserErrorCode_ActiveICCard_Failed, alarmMsg.GetData());
-					}
-					else {
-						DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setAPI(ApiName.GetData()).setCostTime(l_endTime - l_beginTime).setLogCode("QLR040222040").setResultCode("RTA2W0M")(csErrMsgWithReturnCode.GetData());
-						LogWarn(Severity_Middle, Error_Unexpect, CardIssuerStore_UserErrorCode_ActiveICCard_Failed, alarmMsg.GetData());
-					}
-					ctx->Answer(Error_Unexpect, CardIssuerStore_UserErrorCode_ActiveICCard_Failed);
-				}
-			}
-			else if (retDetectAndRead == -2) {
-				DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("读取IC数据失败");
-				DWORD dwTmpUserErrCode = SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_ICCommand, "DevAdapter::ICCommand", __FUNCTION__, IsInBusiness(), l_endTime - l_beginTime, "QLR040222040", "");
-				ctx->Answer(Error_Unexpect, dwTmpUserErrCode);
-			}
-			else if (retDetectAndRead == -3) {
-				DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("IC卡建立应用列表失败");
-				DWORD dwTmpUserErrCode = SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_ICCommand, "DevAdapter::ICCommand", __FUNCTION__, IsInBusiness(), l_endTime - l_beginTime, "QLR040222040", "");
-				ctx->Answer(Error_Unexpect, dwTmpUserErrCode);
-			}
+			dwUserErrCode = SetErrorAndLog(Error_Unexpect, dwDevApiCode, csDevApiName, __FUNCTION__, IsInBusiness(), l_endTime - l_beginTime, csLogCode, csIssueContext);
+			ctx->Answer(Error_Unexpect, dwUserErrCode);
 		}
+
 		bICOK = false;
 		return 0;//上电读卡失败
 	}
@@ -9684,67 +9469,17 @@ int CCardIssuerFSM::PreOnlineJS_RF(SpReqAnsContext<CardIssuerStoreService_ReadJS
 
 	if (retDetectAndRead < 0)
 	{
-		ErrorCodeEnum eErrCode = Error_Unexpect;
-		CSimpleStringA ApiName = "";
-		CSimpleStringA alarmMsg = "";
-		CSimpleStringA csErrMsgWithReturnCode = "";
-
-		if (retDetectAndRead == -1) {
-			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("检测卡片类型时上电失败(非接)");
-			GetCardProcessLastErr(eErrCode, ApiName, alarmMsg, csErrMsgWithReturnCode);
-
-			if (m_issueStatus) {
-				if (IsInBusiness())
-				{
-					DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_USER).setAPI(ApiName.GetData()).setCostTime(l_endTime - l_beginTime).setLogCode("QLR040222040").setResultCode("RTA2W27")(csErrMsgWithReturnCode.GetData());
-					LogError(Severity_Middle, Error_Unexpect, CardIssuerStore_UserErrorCode_IssueCard_ActiveRF_Failed, alarmMsg.GetData());
-				}
-				else {
-					DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setAPI(ApiName.GetData()).setCostTime(l_endTime - l_beginTime).setLogCode("QLR040222040").setResultCode("RTA2W27")(csErrMsgWithReturnCode.GetData());
-					LogWarn(Severity_Middle, Error_Unexpect, CardIssuerStore_UserErrorCode_IssueCard_ActiveRF_Failed, alarmMsg.GetData());
-				}
-
-				ctx->Answer(Error_Unexpect, CardIssuerStore_UserErrorCode_IssueCard_ActiveRF_Failed);
-			}
-			else {
-				if (IsInBusiness())
-				{
-					DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_USER).setAPI(ApiName.GetData()).setCostTime(l_endTime - l_beginTime).setLogCode("QLR040222040").setResultCode("RTA2W26")(csErrMsgWithReturnCode.GetData());
-					LogError(Severity_Middle, Error_Unexpect, CardIssuerStore_UserErrorCode_ActiveContactlessICCard_Failed, alarmMsg.GetData());
-				}
-				else
-				{
-					DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setAPI(ApiName.GetData()).setCostTime(l_endTime - l_beginTime).setLogCode("QLR040222040").setResultCode("RTA2W26")(csErrMsgWithReturnCode.GetData());
-					LogWarn(Severity_Middle, Error_Unexpect, CardIssuerStore_UserErrorCode_ActiveContactlessICCard_Failed, alarmMsg.GetData());
-				}
 
-				ctx->Answer(Error_Unexpect, CardIssuerStore_UserErrorCode_ActiveContactlessICCard_Failed);
-			}
-		}
-		else if (retDetectAndRead == -2) {
+		//新错误返回
+		DWORD dwDevApiCode = 0;
+		CSimpleStringA csDevApiName(""), csLogCode("");
+		GetDevApiCodeAndName(retDetectAndRead, dwDevApiCode, csDevApiName);
+		CSimpleStringA csIssueContext = CSimpleStringA::Format("{\"InIssue\":%d}", m_issueStatus);//oiltmp
+		csLogCode = CardIssuerStoreService_LogCode_ReadJS;
 
-			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("读取IC数据失败");
-			DWORD dwTmpUserErrCode = 0;
-			if (m_issueStatus) {
-				dwTmpUserErrCode = SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_RFTypeABCommand, "DevAdapter::RFTypeABCommand", __FUNCTION__, IsInBusiness(), l_endTime - l_beginTime, "QLR040222040", "");
-			}
-			else {
-				dwTmpUserErrCode = SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_RFTypeABCommand, "DevAdapter::RFTypeABCommand", __FUNCTION__, IsInBusiness(), l_endTime - l_beginTime, "QLR040222040", "");
-			}
-			ctx->Answer(Error_Unexpect, dwTmpUserErrCode);
-		}
-		else if (retDetectAndRead == -3) {
+		DWORD dwUserErrCode = SetErrorAndLog(Error_Unexpect, dwDevApiCode, csDevApiName, __FUNCTION__, IsInBusiness(), l_endTime - l_beginTime, csLogCode, csIssueContext);
+		ctx->Answer(Error_Unexpect, dwUserErrCode);
 
-			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("IC卡建立应用列表失败");
-			DWORD dwTmpUserErrCode = 0;
-			if (m_issueStatus) {
-				dwTmpUserErrCode = SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_RFTypeABCommand, "DevAdapter::RFTypeABCommand", __FUNCTION__, IsInBusiness(), l_endTime - l_beginTime, "QLR040222040", "");
-			}
-			else {
-				dwTmpUserErrCode = SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_RFTypeABCommand, "DevAdapter::RFTypeABCommand", __FUNCTION__, IsInBusiness(), l_endTime - l_beginTime, "QLR040222040", "");
-			}
-			ctx->Answer(Error_Unexpect, dwTmpUserErrCode);
-		}
 		return 0;//上电读卡失败
 	}
 
@@ -10220,68 +9955,29 @@ int CCardIssuerFSM::PreOnlineCrossJS_Contact(SpReqAnsContext<CardIssuerStoreServ
 	
 	if (retDetectAndRead < 0)
 	{
-		ErrorCodeEnum eErrCode = Error_Unexpect;
-		CSimpleStringA ApiName = "";
-		CSimpleStringA alarmMsg = "";
-		CSimpleStringA csErrMsgWithReturnCode = "";
+		//新的错误返回
+		DWORD dwDevApiCode = 0;
+		CSimpleStringA csDevApiName(""), csLogCode("");
+		GetDevApiCodeAndName(retDetectAndRead, dwDevApiCode, csDevApiName);
+		CSimpleStringA csIssueContext = CSimpleStringA::Format("{\"reqSlot\":%d}", slot);//oiltmp
+		csLogCode = CardIssuerStoreService_LogCode_PreOnlineCrossJS;
 
+		DWORD dwUserErrCode = 0;
 		if (IfUseRf()) {
 			bContinue = true; //继续后面的非接流程
-			if (retDetectAndRead == -1) {
-				DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("跨机检测卡片类型时上电失败,slot:%d",slot);
-				GetCardProcessLastErr(eErrCode, ApiName, alarmMsg, csErrMsgWithReturnCode);
-
-				DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setAPI(ApiName.GetData()).setCostTime(l_endTime - l_beginTime).setLogCode("QLR040222052").setResultCode("RTA2W0M")(csErrMsgWithReturnCode.GetData());
-				LogWarn(Severity_Middle, Error_Unexpect, CardIssuerStore_UserErrorCode_ActiveICCard_Failed, alarmMsg.GetData());
-			}
-			else if (retDetectAndRead == -2) {
-				DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("跨机读取IC数据失败,slot:%d", slot);
-				SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_ICCommand, "DevAdapter::ICCommand", __FUNCTION__, false, l_endTime - l_beginTime, "QLR040222052", "");
-			}
-			else if (retDetectAndRead == -3) {
-				DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("跨机读取IC数据失败,slot:%d", slot);
-				SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_ICCommand, "DevAdapter::ICCommand", __FUNCTION__, false, l_endTime - l_beginTime, "QLR040222052", "");
-			}
+			SetErrorAndLog(Error_Unexpect, dwDevApiCode, csDevApiName, __FUNCTION__, false, l_endTime - l_beginTime, csLogCode, csIssueContext);
 		}
 		else {
-			//CaptureResult = AfterPreOnlineCrossJS(slot, m_currCardNo);//执行移回操作
-			//m_findCard = 4;
-			//ctx->Ans.findCard = 4;
-			//ctx->Ans.cardPos = m_cardPos;
-			DWORD dwUserErrCode = 0;
-			if (retDetectAndRead == -1) {
-
-				DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("跨机检测卡片类型时上电失败,slot:%d", slot);
-				GetCardProcessLastErr(eErrCode, ApiName, alarmMsg, csErrMsgWithReturnCode);
-				if (IsInBusiness()) {
-					DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_USER).setAPI(ApiName.GetData()).setCostTime(l_endTime - l_beginTime).setLogCode("QLR040222052").setResultCode("RTA2W0M")(csErrMsgWithReturnCode.GetData());
-					LogError(Severity_Middle, Error_Unexpect, CardIssuerStore_UserErrorCode_ActiveICCard_Failed, alarmMsg.GetData());
-				}
-				else {
-					DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setAPI(ApiName.GetData()).setCostTime(l_endTime - l_beginTime).setLogCode("QLR040222052").setResultCode("RTA2W0M")(csErrMsgWithReturnCode.GetData());
-					LogWarn(Severity_Middle, Error_Unexpect, CardIssuerStore_UserErrorCode_ActiveICCard_Failed, alarmMsg.GetData());
-				}
-				dwUserErrCode = CardIssuerStore_UserErrorCode_ActiveICCard_Failed;
-				//ctx->Answer(Error_Unexpect, CardIssuerStore_UserErrorCode_ActiveICCard_Failed);
-			}
-			else if (retDetectAndRead == -2) {
-				DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("跨机读取IC数据失败,slot:%d", slot);
-				dwUserErrCode = SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_ICCommand, "DevAdapter::ICCommand", __FUNCTION__, IsInBusiness(), l_endTime - l_beginTime, "QLR040222052", "");
-				//ctx->Answer(Error_Unexpect, dwTmpUserErrCode);
-			}
-			else if (retDetectAndRead == -3) {
-				DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("跨机读取IC数据失败,slot:%d", slot);
-				dwUserErrCode = SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_ICCommand, "DevAdapter::ICCommand", __FUNCTION__, IsInBusiness(), l_endTime - l_beginTime, "QLR040222052", "");
-				//ctx->Answer(Error_Unexpect, dwTmpUserErrCode);
-			}
+			dwUserErrCode = SetErrorAndLog(Error_Unexpect, dwDevApiCode, csDevApiName, __FUNCTION__, IsInBusiness(), l_endTime - l_beginTime, csLogCode, csIssueContext);
 
 			CaptureResult = AfterPreOnlineCrossJS(slot, m_currCardNo);//执行移回操作
 			m_findCard = 4;
 			ctx->Ans.findCard = 4;
 			ctx->Ans.cardPos = m_cardPos;
 
-			ctx->Answer(Error_Unexpect, dwUserErrCode);
+			ctx->Answer(Error_Unexpect, dwTmpUserErrCode);
 		}
+
 		bICOK = false;
 		return 0;//上电读卡失败
 	}
@@ -10591,42 +10287,16 @@ int CCardIssuerFSM::PreOnlineCrossJS_RF(SpReqAnsContext<CardIssuerStoreService_P
 
 	if (retDetectAndRead < 0)
 	{
-		//CaptureResult = AfterPreOnlineCrossJS(slot, m_currCardNo);//执行移回操作
-		//m_findCard = 4;
-		//ctx->Ans.findCard = 4;
-		//ctx->Ans.cardPos = m_cardPos;
 
-		ErrorCodeEnum eErrCode = Error_Unexpect;
-		CSimpleStringA ApiName = "";
-		CSimpleStringA alarmMsg = "";
-		CSimpleStringA csErrMsgWithReturnCode = "";
+		//新错误返回
+		DWORD dwDevApiCode = 0;
+		CSimpleStringA csDevApiName(""), csLogCode("");
+		GetDevApiCodeAndName(retDetectAndRead, dwDevApiCode, csDevApiName);
+		CSimpleStringA csIssueContext = CSimpleStringA::Format("{\"reqSlot\":%d}", slot);//oiltmp
+		csLogCode = CardIssuerStoreService_LogCode_PreOnlineCrossJS;
 
-		DWORD dwUserErrCode = 0;
-		if (retDetectAndRead == -1) {	
-			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("跨机非接检测卡片类型时上电失败,slot:%d", slot);
-			GetCardProcessLastErr(eErrCode, ApiName, alarmMsg, csErrMsgWithReturnCode);
+		DWORD dwUserErrCode = SetErrorAndLog(Error_Unexpect, dwDevApiCode, csDevApiName, __FUNCTION__, IsInBusiness(), l_endTime - l_beginTime, csLogCode, csIssueContext);
 
-			if (IsInBusiness()) {
-				DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_USER).setAPI(ApiName.GetData()).setCostTime(l_endTime - l_beginTime).setLogCode("QLR040222052").setResultCode("RTA2W26")(csErrMsgWithReturnCode.GetData());
-				LogError(Severity_Middle, Error_Unexpect, CardIssuerStore_UserErrorCode_ActiveContactlessICCard_Failed, alarmMsg.GetData());
-			}
-			else {
-				DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setAPI(ApiName.GetData()).setCostTime(l_endTime - l_beginTime).setLogCode("QLR040222052").setResultCode("RTA2W26")(csErrMsgWithReturnCode.GetData());
-				LogWarn(Severity_Middle, Error_Unexpect, CardIssuerStore_UserErrorCode_ActiveContactlessICCard_Failed, alarmMsg.GetData());
-			}
-			dwUserErrCode = CardIssuerStore_UserErrorCode_ActiveContactlessICCard_Failed;
-			//ctx->Answer(Error_Unexpect, CardIssuerStore_UserErrorCode_ActiveContactlessICCard_Failed);		
-		}
-		else if (retDetectAndRead == -2) {
-			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("跨机非接读取IC数据失败,slot:%d", slot);
-			dwUserErrCode = SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_RFTypeABCommand, "DevAdapter::RFTypeABCommand", __FUNCTION__, IsInBusiness(), l_endTime - l_beginTime, "QLR040222052", "");
-			//ctx->Answer(Error_Unexpect, dwTmpUserErrCode);
-		}
-		else if (retDetectAndRead == -3) {
-			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("跨机非接读取IC数据失败,slot:%d", slot);
-			dwUserErrCode = SetErrorAndLog(Error_Unexpect, MEC_DEVAPI_CARDISSUER_RFTypeABCommand, "DevAdapter::RFTypeABCommand", __FUNCTION__, IsInBusiness(), l_endTime - l_beginTime, "QLR040222052", "");
-			//ctx->Answer(Error_Unexpect, dwTmpUserErrCode);
-		}
 		CaptureResult = AfterPreOnlineCrossJS(slot, m_currCardNo);//执行移回操作
 		m_findCard = 4;
 		ctx->Ans.findCard = 4;

+ 3 - 0
Module/mod_cardissuerstore/CardIssuerStoreFSM.h

@@ -1470,6 +1470,7 @@ public:
 #pragma endregion JS接口具体实现方法
 
 #pragma region JS新增接口
+	void GetDevApiCodeAndName(int retValue, DWORD& dwDevApiCode, CSimpleStringA& csDevApiName);
 	DWORD GetFsmStateErrCode();
 	CSimpleStringA MaskCardno(const char* cardno);
 	int PostOnlineJS_Contact(SpReqAnsContext<CardIssuerStoreService_PostOnlineJS_Req, CardIssuerStoreService_PostOnlineJS_Ans>::Pointer ctx, bool& bICOK);
@@ -1508,6 +1509,8 @@ public:
 		result = CSimpleStringA::Format("{\"addition\": \"%s\"}", szMessage);
 		return  result;
 	}
+
+	
 #pragma endregion JS新增接口
 
 #pragma region JS新增字段