Esempio n. 1
0
//执行PBOC指令 SAM
int CYCTReaderInterface::SAM_APDU_Cmd(int nSamSlot, unsigned char *sSendData, unsigned char nSendDatalen,
									  unsigned char* sRespData,unsigned char &nRespDatalen )
{	
	SendDataLen=0;
	RecvDataLen=0;
	memset(SendData,0,   sizeof SendData);
	memset(RetCode, 0xFF,sizeof RetCode);
	memset(RecvData,0,   sizeof RecvData);
	
	if( nSamSlot==0 ) nSamSlot=1;
	SendData[0]=nSamSlot;
	SendData[1]=nSendDatalen/2;
	AscToBcd(sSendData,nSendDatalen,SendData+2);
	SendDataLen=nSendDatalen/2;
	SendDataLen++;
	SendDataLen++;
	SendReaderCommand(m_sCom,0x32,SendData,SendDataLen,RetCode,RecvData,&RecvDataLen);
	if( RetCode[0] ) return RetCode[0];
	if( RecvDataLen>2 )nRespDatalen=RecvDataLen-2;	
	memcpy(sRespData,RecvData,nRespDatalen);
	if( RecvData[RecvDataLen-2]==0x90 && RecvData[RecvDataLen-1]==0x00 )
	{
		return 0;
	}
	return (int)(RecvData[RecvDataLen-2]*256+RecvData[RecvDataLen-1]);
}
Esempio n. 2
0
/*****************************************************************
** 功    能:设置TLV中Value值
** 输入参数:
**		szValue		Value值
**		iLen		Value长度
**		iValueType	Value类型
**				0:普通类型,数据原样拷贝,不做处理
**				1:BCD码压缩(右对齐),数据以BCD码压缩,长度为奇数时,左补0对齐
**				2:BCD码压缩(左对齐),数据以BCD码压缩,长度为奇数时,右补0对齐
** 输出参数:
**		szValueBuf	格式化后Value值
** 返 回 值: 
**		>0		Len占用字节数
**		0		读取失败
** 作    者:
**		fengwei
** 日    期:
**		2012/09/24
** 调用说明:
**		仅供tlv库函数内部调用,外部不调用
** 修改日志:
****************************************************************/
static int _set_value(char* szValue, int iLen, int iValueType, char* szValueBuf)
{
	char szTmpBuf[MAX_VALUE_LEN+1];
	int iValueLen;

	memset(szTmpBuf, 0, sizeof(szTmpBuf));

	switch(iValueType)
	{
		case VALUE_NORMAL:
			memcpy(szTmpBuf, szValue, iLen);
			iValueLen = iLen;
			break;
		case VALUE_BCD_RIGHT:
			AscToBcd(szValue, iLen, 1, szTmpBuf);	
			if(iLen%2 == 0 )
			{
				iValueLen = iLen/2;
			}
			else
			{
				iValueLen = iLen/2 + 1;
			}
			break;
		case VALUE_BCD_LEFT:
			AscToBcd(szValue, iLen, 0, szTmpBuf);	
			if(iLen%2 == 0 )
			{
				iValueLen = iLen/2;
			}
			else
			{
				iValueLen = iLen/2 + 1;
			}
			break;
		default:
			iValueLen = -1;
			break;
	}

	if (iValueLen > 0 && iValueLen <= MAX_VALUE_LEN)
	{
		memcpy(szValueBuf, szTmpBuf, iValueLen);
	}

	return iValueLen;
}
Esempio n. 3
0
/* ----------------------------------------------------------------
 * 功    能:读取密钥分量并合成
 * 输入参数:iComp   分量值(第几组分量)
 * 输出参数:uszKeyComp  合成后的密钥明文
 * 返 回 值:无
 * 作    者:陈建荣
 * 日    期:2012/12/7
 * 调用说明:
 * 修改日志:修改日期    修改者      修改内容简述
 * ----------------------------------------------------------------
 */
void setKeyComp(int iComp,  unsigned char *uszKeyComp)
{
    int iredo = 0, inum, iInAgain, i;
    unsigned char usaComp[2][100];
    unsigned char tmp[100];

    do{
        iInAgain = 0;
        memset(usaComp, 0, sizeof(usaComp));

        do{
            fflush(NULL);
            PrtComConHead();
    
            iredo == 0 ?  printf(COMCON_INPUT, iComp + 1)
                       :  printf(COMCON_REIN, iComp + 1);
    
            inum = 0;
            printf(COMCON_INLEN, inum);
            
            /* 根据密钥长度从标准输入读取密钥分量 */
            while (inum < iKeyLen)
            {
                if (getch(&usaComp[iredo][inum]) == -1)
                {
                    exit(0);
                }
    
                inum++;
                inum < 11 ? printf("\b") : printf("\b\b");
                printf("%d", inum);
            }
    
            iredo++;
        }while(iredo < 2);
    
        /* 两次输入一致性判断 */
        if (memcmp(usaComp[0], usaComp[1], iKeyLen) != 0)
        {
            printf(COMCON_ICON);
            getchar();
            iredo = 0;
            iInAgain = 1;
        }
    }while (iInAgain);

    /* 合成分量 */
    AscToBcd(usaComp[0], iKeyLen, 0, tmp);
    for (i=0; i< (iKeyLen+1) / 2; i++)
    {
        uszKeyComp[i] ^= tmp[i]; 
    }
}
Esempio n. 4
0
/* ----------------------------------------------------------------
 * 功    能:密码明文与账号异或处理
 * 输入参数:szPan        账号
 *           uszPasswd    密码明文
 *           iPwdLen      密码长度
 * 输出参数:uszResult    异或后结果
 * 返 回 值:SUCC  成功   FAIL  失败
 * 作    者:
 * 日    期:
 * 调用说明:
 * 修改日志:修改日期    修改者      修改内容简述
 * ----------------------------------------------------------------
 */
int A_(unsigned char *uszPasswd, char *szPan, int iPwdLen, unsigned char *uszResult)
{
    unsigned char  uszPasswd0[17], tmp[17], tmp1[10];
    int            i;
    	
    memcpy (uszPasswd0, uszPasswd, iPwdLen);
    
    for (i = iPwdLen; i < 16; i++)  
    {
        uszPasswd0 [ i ] = 'F'; 
    }
    
    AscToBcd(uszPasswd0, 16, 0, tmp1);
    memcpy (tmp, szPan + 3, 13);
    
    for (i = 0; i < 13; i++) 
    {
        if (tmp[i] < '0' || tmp[i] > '9')	
        {
            tmp [ i ] = 'F';
        }
    }

    AscToBcd(tmp, 12, 0, uszPasswd0);
    	
    sprintf((char *)tmp, "0%d", iPwdLen);
    AscToBcd(tmp, 2, 0, uszResult);
    
    * (++uszResult) = tmp1[0];
    
    uszResult ++;
    
    for (i = 0; i <= 5; i++) 
    {
        *(uszResult + i) = tmp1[i + 1] ^ uszPasswd0[i];
    }
    
    return SUCC;
}
Esempio n. 5
0
/****************************************************************
** 功    能:PinBlock转加密
** 输入参数:
**        ptApp           app结构指针
**        iHost           主机号
** 输出参数:
**        无
** 返 回 值:
**        SUCC            处理成功
**        FAIL            处理失败
** 作    者:
**        fengwei
** 日    期:
**        2013/06/13
** 调用说明:
**
** 修改日志:
****************************************************************/
int ConvertPin(T_App* ptApp, int iHost)
{
    char    szPinKey[32+1];
    char    szPIK[16+1];
	char    szSourcePan[20];
	char    szTargetPan[20];

    /* 获取PinKey */
    memset(szPinKey, 0, sizeof(szPinKey));
    if(GetHostTermKey(ptApp, iHost, PIN_KEY, szPinKey) != SUCC)
    {
        return FAIL;
    }

	memset(szPIK, 0, sizeof(szPIK));
	AscToBcd(szPinKey, 32, 0, szPIK);

    memset(szSourcePan, 0, sizeof(szSourcePan));
    memset(szTargetPan, 0, sizeof(szTargetPan));

	if(strlen(ptApp->szPan) < 16)
	{
		/*右对齐左补零*/
		memset(szSourcePan, '0', 16);
		memcpy(szSourcePan+16-strlen(ptApp->szPan), ptApp->szPan, strlen(ptApp->szPan));
	}
	else
	{
		/*后16位*/
		memset(szSourcePan, '0', 16);
		memcpy(szSourcePan, ptApp->szPan+strlen(ptApp->szPan)-16, 16);
	}
	strcpy(szTargetPan, szSourcePan);

	if(HsmChangePin(ptApp, 1, TRIPLE_DES, ptApp->szPinKey, szPIK, szSourcePan, szTargetPan) != SUCC)
	{
		WriteLog(ERROR, "PinBlock转加密失败!");

		strcpy(ptApp->szRetCode, ERR_SYSTEM_ERROR);

		return FAIL;
	}

	return SUCC;
}
Esempio n. 6
0
/* ----------------------------------------------------------------
 * 功    能:密码明文还原
 * 输入参数:uszValuse    被账号异或后的密码
 *           szPan        账号
 * 输出参数:uszResult    密码明文
 * 返 回 值:SUCC  成功   FAIL  失败
 * 作    者:
 * 日    期:
 * 调用说明:
 * 修改日志:修改日期    修改者      修改内容简述
 * ----------------------------------------------------------------
 */
int _A_(unsigned char *uszValue, char *szPan, unsigned char *uszResult)
{
    unsigned char  tmp[17], tmp1[17], passwd0[17];
    int            i, len;
    
    memcpy(tmp, szPan + 3, 13);
    
    for (i = 0; i < 13; i++) 
    {
        if (tmp[i] < '0' || tmp[i] > '9')	
        {
            tmp[i] = 'F';
        }
    }
    
    AscToBcd(tmp, 12, 0, tmp1);
    
    tmp[0] = uszValue[0];
    tmp[1] = uszValue[1];
    
    for (i = 0; i < 6; i++) 
    {
        tmp[i+2] = uszValue[2+i]^tmp1[i];
    }
    
    BcdToAsc(tmp, 16, 0, passwd0);
    
    memcpy((char *) tmp1, (char *)passwd0, 2);
    tmp1[2] = '\0';
    
    len = atoi (tmp1);
    
    if (len > 8)
    {
        return FAIL;
    }
    
    memcpy((char *)uszResult, (char *)passwd0 + 2, len);
    uszResult[len] = '\0';
    
    return SUCC;
}
Esempio n. 7
0
/*****************************************************************
** 功    能:将源PIN密文用源PIK解密,进行PIN格式转换,然后用目的PIK加密输出.
** 输入参数:
           tInterface->szData 帐号(16字节)+密码密文(8字节)
** 输出参数:
           tInterface->szData 转加密后的密码密文(8字节)
** 返 回 值:
           成功 - SUCC
           失败 - FAIL
** 作    者:
** 日    期:
** 调用说明:
** 修改日志:mod by wukj 20121031规范命名及排版修订
**          
****************************************************************/
int Sjl06eRacalChangePin(T_Interface *tInterface)
{
    char    szInData[1024], szOutData[1024], szPanBlock[17];
    char    szSndData[1024], szRcvData[1024];
    int     iLen, iRet, iSndLen;

    sprintf( szPanBlock, "%12.12s", tInterface->szData+3 );
    szPanBlock[12] = 0;

    iLen = 0;
    memcpy( szInData, "CA", 2 );    /* 命令 */
    iLen += 2;

    /* 源PIK密钥长度标识,16位长 */
    szInData[iLen] = 'X';    
    iLen ++;

    /* 源PIK密钥密文 */
    BcdToAsc( (uchar *)(tInterface->szPinKey), 32, 0 , (uchar *)(szInData+iLen));    
    iLen += 32;

    /* 目的PIK密钥长度标识,16位长 */
    szInData[iLen] = 'X';    
    iLen ++;

    /* 目的PIK密钥密文 */
    BcdToAsc( (uchar *)(tInterface->szMacKey), 32, 0 , (uchar *)(szInData+iLen));    
    iLen += 32;
    /* 最大PIN长度 */
    memcpy( szInData+iLen, "12", 2 );    
    iLen += 2;

    /* 源PinBlock密文 */
    BcdToAsc( (uchar *)(tInterface->szData+16), 16, 0 , (uchar *)(szInData+iLen));    
    iLen += 16;

    /* 源PinBlock格式 */
    memcpy( szInData+iLen, "01", 2 );    
    iLen += 2;

    /* 目的PinBlock格式 */
    memcpy( szInData+iLen, "01", 2 );    
    iLen += 2;

    /* 源帐号 */
    memcpy( szInData+iLen, szPanBlock, 12 );    
    iLen += 12;
    szInData[iLen] = 0;

    memset( szRcvData, 0, 1024 );
    memset( szOutData, 0, 1024 );
    memcpy( szSndData, SJL06E_RACAL_HEAD_DATA, SJL06E_RACAL_HEAD_LEN );    
    memcpy( szSndData+SJL06E_RACAL_HEAD_LEN, szInData, iLen );    
    iLen += SJL06E_RACAL_HEAD_LEN;
    iRet = CommuWithHsm( szSndData, iLen, szRcvData ); 
    if(iRet == FAIL)
    {
        WriteLog( ERROR, "commu with hsm fail" );
        return FAIL;
    }
    else if( iRet - SJL06E_RACAL_HEAD_LEN >= 0)
    {
        memcpy( szOutData, szRcvData+SJL06E_RACAL_HEAD_LEN, iRet-SJL06E_RACAL_HEAD_LEN );
    }
    else
    {
        WriteLog(ERROR,"请检查加密机消息头长度,是否>=[%d]" , SJL06E_RACAL_HEAD_LEN );
        return FAIL;
    }

    if( memcmp(szOutData, "CB", 2) != 0 ||
        memcmp(szOutData+2, "00", 2) != 0 )
    {
        DispSjl06eRacalErrorMsg( szOutData+2, tInterface->szReturnCode );
        WriteLog( ERROR, "hsm pin change fail[%2.2s]", szOutData+2 );
        return SUCC;
    }

    AscToBcd( (uchar *)(szOutData+6), 16, 0 ,(uchar *)(tInterface->szData));
    tInterface->iDataLen = 8;

    strcpy( tInterface->szReturnCode, TRANS_SUCC );
   
    return SUCC;
}
Esempio n. 8
0
/*****************************************************************
** 功    能:MAC计算 
** 输入参数:
           tInterface->szData 参与MAC运算的数据,长度由tInterface->iDataLen指定
** 输出参数:
           tInterface->szData MAC(8字节)
** 返 回 值:
           成功 - SUCC
           失败 - FAIL
** 作    者:
** 日    期:
** 调用说明:
** 修改日志:mod by wukj 20121031规范命名及排版修订
**          
****************************************************************/
int Sjl06eRacalCalcMac(T_Interface *tInterface)
{
    char    szInData[1024], szOutData[1024];
    char    szSndData[1024], szRcvData[1024], szTmpStr[20];
       int     iLen, iRet, iSndLen;

    iLen = 0;
    memcpy( szInData, "MS", 2 );    /* 命令 */
    iLen += 2;

    /*消息块号:0-仅1块 1-第1块 2-中间块 3-尾块 */
    memcpy( szInData+iLen, "0", 1 );
    iLen += 1;

    /*密钥类型:0-TAK终端认证密钥 1-ZAK区域认证密钥 */
    memcpy( szInData+iLen, "0", 1 );
    iLen += 1;

    /*密钥长度:0-单倍长度 1-双倍长度 */
    memcpy( szInData+iLen, "1", 1 );
    iLen += 1;

    /*消息类型:0-二进制 1-扩展十六进制 */
    memcpy( szInData+iLen, "0", 1 );
    iLen += 1;

    /*MAC密钥方案 */
    memcpy( szInData+iLen, "X", 1 );
    iLen += 1;

    /*MAC密钥密文*/
    BcdToAsc((uchar *)(tInterface->szMacKey), 32, 0 , (uchar *)(szInData+iLen));    
    iLen += 32;

    /* MAC算法 1-XOR 2-X9.9 3-X9.19 */
    if( tInterface->iAlog == XOR_CALC_MAC )
    {
        /*消息长度*/
        memcpy( szInData+iLen, "0008", 8 );
        iLen += 4;

        /*消息块*/
        XOR( tInterface->szData, tInterface->iDataLen, szOutData );
           memcpy( szInData+iLen, szOutData, 8 );
        iLen += 8;
    }
    else
    {
        /*消息长度*/
        szTmpStr[0] = tInterface->iDataLen/256;
        szTmpStr[1] = tInterface->iDataLen%256;
        BcdToAsc( (uchar *)szTmpStr, 4, 0 , (uchar *)(szInData+iLen));
        iLen += 4;

        /*消息块*/
           memcpy( szInData+iLen, tInterface->szData, tInterface->iDataLen );
        iLen = iLen+tInterface->iDataLen;
    }
    szInData[iLen] = 0;

    memset( szRcvData, 0, 1024 );
    memset( szOutData, 0, 1024 );
    memcpy( szSndData, SJL06E_RACAL_HEAD_DATA, SJL06E_RACAL_HEAD_LEN );    
    memcpy( szSndData+SJL06E_RACAL_HEAD_LEN, szInData, iLen );    
    iLen += SJL06E_RACAL_HEAD_LEN;
    iRet = CommuWithHsm( szSndData, iLen, szRcvData ); 
    if(iRet == FAIL)
    {
        WriteLog( ERROR, "commu with hsm fail" );
        return FAIL;
    }
    else if( iRet - SJL06E_RACAL_HEAD_LEN >= 0)
    {
        memcpy( szOutData, szRcvData+SJL06E_RACAL_HEAD_LEN, iRet-SJL06E_RACAL_HEAD_LEN );
    }
    else
    {
        WriteLog(ERROR,"请检查加密机消息头长度,是否>=[%d]" , SJL06E_RACAL_HEAD_LEN );
        return FAIL;
    }
    if( memcmp(szOutData, "MT", 2) != 0 ||
        memcmp(szOutData+2, "00", 2) != 0 )
    {
        DispSjl06eRacalErrorMsg( szOutData+2, tInterface->szReturnCode );
        WriteLog( ERROR, "hsm calc mac fail[%2.2s]", szOutData+2 );
        return SUCC;
    }

    AscToBcd( (uchar *)(szOutData+4), 16, 0 ,(uchar *)(tInterface->szData));

    tInterface->iDataLen = 8;

    strcpy( tInterface->szReturnCode, TRANS_SUCC );
   
    return SUCC;
}
Esempio n. 9
0
int CPayment::SendPaymentData(LPCTSTR sfxm,LONG Money,LPCTSTR bz)
{
	bool bIsStand = true;

	szPayState = "3";//请求正在处理

	//组包
	CIso8583Package *package = new CIso8583Package();
	if (package == NULL) 
	{
		szPayState = "E7";
		return -1;   //不成功,返回错误码
	}
	char c48Field[255];
	memset(c48Field,0,sizeof(c48Field));

	if( strcmp(sfxm,"3001") == 0)
	{
		bIsStand = false;
		const char *split = "|"; 
		char *pTemp = new char[128];
		strcpy(pTemp,bz);
		char *pToken = strtok (pTemp,split); 
		if( pToken == NULL ) return -1;
		int nOffset = strlen(pToken);
		memcpy(c48Field,pToken,strlen(pToken));
		pToken = strtok(NULL,"|");
		if( pToken == NULL ) return -1;
		memcpy(c48Field + nOffset,pToken,strlen(pToken));
		nOffset += strlen(pToken);
		pToken = strtok(NULL,"|");
		if( pToken == NULL ) return -1;
		memcpy(c48Field + nOffset,pToken,strlen(pToken));
		nOffset += strlen(pToken);
		pToken = strtok(NULL,"|");
		if( pToken == NULL ) return -1;
		memcpy(c48Field + nOffset,pToken,strlen(pToken));
		nOffset += strlen(pToken);

		package->SetFieldData(48,nOffset,(BYTE *)c48Field);//48域,目前随便填写,银联无法处理该业务

	}
	else
	{//处理其他收费项目
		int nOffset = 0;
		nOffset = strlen(sfxm);
		memcpy(c48Field,sfxm,nOffset);
		memcpy(c48Field + nOffset,bz,strlen(bz));
		nOffset += strlen(bz);
		package->SetFieldData(48,nOffset,(BYTE *)c48Field);//48域,目前随便填写,银联无法处理该业务
	}

	int iRes = BuildPackage(package,Money);
	if (iRes != 0) 
	{
		szPayState = "E7";
		return iRes;   //组包不成功,返回错误码
	}

	BYTE cHeader[30];
	int nOffset = 0;
	AscToBcd(cHeader + nOffset,(unsigned char *)szTPDU.GetBuffer(),szTPDU.GetLength());
	nOffset += szTPDU.GetLength() / 2;
	AscToBcd(cHeader + nOffset,(unsigned char *)szHeader.GetBuffer(),szHeader.GetLength());
	nOffset += szHeader.GetLength() / 2;
	cHeader[nOffset] = 0x02;
	nOffset += 1;
	cHeader[nOffset] = 0x00;
	nOffset += 1;

	BYTE cData[512];
	memset(cData,0,512);

	unsigned int nLen = package->GetData(cData,512,cHeader,nOffset,false);
	delete package;

	char cLen[5] = {'\0'};
	itoa_hex(nLen,cLen,2);
	unsigned char cDataLen[3] = {'\0'};
	AscToBcd(cDataLen,(unsigned char *)cLen,4);
	BYTE cPackageData[512];
	memset(cPackageData,0,sizeof(cPackageData));
	memcpy(cPackageData,cDataLen,2);
	memcpy(cPackageData + 2,cData,nLen);

	TCHAR szCurPath[MAX_PATH];
	GetCurrentDirectory(sizeof(szCurPath),szCurPath);
	_tcscat(szCurPath,TEXT("\\Reversal.ini"));

	CSocket client;
	if( client.InitSocket() == FALSE)
	{
		szPayState = "E7";
		return -1;
	}
	if( client.Connect(szServerIP,atoi(szPort)) == false)
	{
		szPayState = "E7";
		return -1;
	}
	gLog.Log(cPackageData,nLen + 2);
	client.Send(cPackageData,nLen + 2);
	BYTE RecvData[1024];
	memset(RecvData,0,1024);
	nLen = client.Receive(RecvData,1024);
	if(nLen != 0)
	{
		gLog.Log(RecvData,nLen);
		CIso8583Parse *receivePackage = new CIso8583Parse();
		char cResult[128];
		memset(cResult,0,128);
		Read8583Package(receivePackage,RecvData,39,2,(BYTE *)cResult);
		delete receivePackage;

		LONG lProCode = atol(szTraceCode.GetBuffer()) + 1;
		unsigned char cAsciiBuff[12];
		memset(cAsciiBuff,0,sizeof(cAsciiBuff));
		BinToAsc(cAsciiBuff,lProCode,6);
		WritePrivateProfileString(TEXT("TraceCode"),TEXT("TraceCode"),(char *)cAsciiBuff,szCurPath);
		if(strcmp(cResult,"A0") == 0) //根据银联网络的说法,MAC错误也需要冲正
		{
			WritePrivateProfileString(TEXT("Reversal"),TEXT("Ack"),"A0",szCurPath);
			WritePrivateProfileString(TEXT("Reversal"),TEXT("Flag"),"0",szCurPath);//0 -- 未处理
			CReversalTransaction transaction;
			transaction.SendReversalTransactionData();//冲正处理
		}
		else if( strcmp(cResult,"05") == 0)
		{//认证失败
			szPayState = "E2";
			return -1;
		}
		else if( strcmp(cResult,"51") == 0)
		{
			szPayState = "E5";
			return -1;
		}
		else if( strcmp(cResult, "55") == 0)
		{
			szPayState = "E2";
			return -1;
		}
		else if( strcmp(cResult, "75") == 0)
		{
			szPayState = "E1";
			return -1;
		}
		szPayState = "1";//交易成功
	}
	else
	{//网络原因,消费冲正
		szPayState = "E6";
		WritePrivateProfileString(TEXT("Reversal"),TEXT("Ack"),"98",szCurPath);//POS终端在时限内未能收到POS中心的应答消息而引发
		WritePrivateProfileString(TEXT("Reversal"),TEXT("Flag"),"0",szCurPath);//0 -- 未处理
		CReversalTransaction transaction;
		transaction.SendReversalTransactionData();//冲正处理
	}

	return 1;//交易成功
}
Esempio n. 10
0
void CMainFrame::OnRegRightModify() 
{
 	char m_KeyName[1024] = {0};
 	if(!GetMyRegLeftPath(pRegTreeView->GetTreeCtrl().
		GetSelectedItem(),m_KeyName))
  		return;
  
 	int nItem = -1;
 	nItem = pRegListView->GetListCtrl().GetNextItem(-1,LVNI_SELECTED);
 
 	char m_Name[1024] = {0};
 	char m_Value[1024] = {0};
 	char m_OldValue[1024] = {0};
 	BOOL m_IsDigital = FALSE;
 
 	strcpy(m_Name,(LPCTSTR) pRegListView->GetListCtrl().GetItemText(nItem,0));
 	strcpy(m_Value,(LPCTSTR) pRegListView->GetListCtrl().GetItemText(nItem,2));
 	strcpy(m_OldValue,m_Value);
 	if(pRegListView->GetListCtrl().GetItemText(nItem,1) == "REG_DWORD")
  		m_IsDigital = REG_VALUE_INT;
  	else if(pRegListView->GetListCtrl().GetItemText(nItem,1) == "REG_SZ")
  		m_IsDigital = REG_VALUE_STR;
  	else
  		m_IsDigital = REG_VALUE_BIN;
  
 	CMyRegEditValue dlg(m_Name,m_Value,m_IsDigital);
 	if(dlg.DoModal() != IDOK) return;
  	strcpy(m_Value,(LPCTSTR) dlg.m_Value);
 	m_MissionData.m_Command = CLIENT_REG_EDIT_VALUE;
 	memset(m_MissionData.m_TransData,0,2048);
 	strcat(m_KeyName,m_Name);
 	memcpy(m_MissionData.m_TransData,m_KeyName,1024);
 	if(m_IsDigital == REG_VALUE_BIN)
  		AscToBcd((BYTE*) m_Value,(BYTE*) 
		&m_MissionData.m_TransData[1024] , strlen(m_Value));
  	else
  		memcpy(&m_MissionData.m_TransData[1024],m_Value,1024);
  
 	m_MissionData.m_TransData[2048] = m_IsDigital;
 	m_MissionData.m_TransData[2049] = strlen(m_Value)/2;
 	m_MissionData.m_TransLen = 2050;
 	if(!ProcessOneTrans(&m_MissionData))
 	{
 		ShowResponse(m_MissionData.m_Command);
 		pRegListView->GetListCtrl().SetItemText(nItem,2,m_OldValue);
 		return ;
 	}
 	if(m_MissionData.m_Command != 0)
 	{
 		ShowResponse(m_MissionData.m_Command);
 		pRegListView->GetListCtrl().SetItemText(nItem,2,m_OldValue);
 		return ;
 	}
 	if(m_IsDigital == REG_VALUE_INT)
 	{
 		char m_Tmpbuf[40] = {0};
 		sprintf(m_Tmpbuf,"0x%08x(%d)",atol(m_Value),
 			atol(m_Value));
 		pRegListView->GetListCtrl().SetItemText(nItem,2,m_Tmpbuf);
 	}
 	else
 		pRegListView->GetListCtrl().SetItemText(nItem,2,m_Value);
}
Esempio n. 11
0
/*****************************************************************
** 功    能:验证终端上送的PIN是否与数据库中的PIN一致
            分2步:
            1、用PIK对PIN明文加密
            2、与终端上送的密文进行比较
** 输入参数:
           tInterface->szData 数据库中密码明文(8字节)+终端PIN密文(8字节)
           iSekPosIndex     加密PIK的存储加密密钥索引
** 输出参数:
           tInterface->szData SUCC-一致  FAIL-不一致
** 返 回 值:
           成功 - SUCC
           失败 - FAIL
** 作    者:Robin     
** 日    期:2009/08/25 
** 调用说明:
** 修改日志:mod by wukj 20121031规范命名及排版修订
**          
****************************************************************/
int Sjl06sVerifyPin(T_Interface *tInterface, int iSekPosIndex)
{
    char    szInData[1024], szOutData[1024], szPanBlock[17], szEncPin[17];
    int     iLen, iRet, iSndLen;

    memset( szPanBlock, '0', 16 );
    szPanBlock[16] = 0;

    iLen = 0;
    memcpy( szInData, "XI", 2 );    /* 命令 */
    iLen += 2;

    /*PIN类型 ANSIX9.8算法*/ 
    memcpy( szInData+iLen, "3", 1 );    
    iLen += 1;

    /* 加密PIK的存储加密密钥索引 */
    sprintf( szInData+iLen, "%03ld", iSekPosIndex );
    iLen += 3;

    /* PIK密钥密文 */
    BcdToAsc( (uchar *)(tInterface->szPinKey), 32, 0 , (uchar *)(szInData+iLen));    
    iLen += 32;

    /* PIN明文 */
    memcpy( szInData+iLen, "08", 2 );
    iLen += 2;
    memcpy( szInData+iLen, tInterface->szData, 8 );
    iLen += 8;
    memcpy( szInData+iLen, "FFFFFFFF", 6 );
    iLen += 6;

    /* 帐号 */
    memcpy( szInData+iLen, szPanBlock, 16 );    
    iLen += 16;

    iRet = CommuWithHsm( szInData, iLen, szOutData ); 
    if( iRet == FAIL )
    {
        WriteLog( ERROR, "commu with hsm fail" );
        strcpy( tInterface->szReturnCode, ERR_SYSTEM_ERROR );
        return FAIL;
    }

    if( memcmp(szOutData, "E", 1) == 0 )
    {
        DispUphsmErrorMsg( szOutData+1, tInterface->szReturnCode );
        WriteLog( ERROR, "hsm encrypt pin fail[%2.2s]", szOutData+1 );
        return SUCC;
    }
    else if(memcmp(szOutData, "A", 1) == 0 )
    {
        AscToBcd( (uchar *)(szOutData+1), 16, 0 ,(uchar *)szEncPin);
        if( memcmp( tInterface->szData+8, szEncPin, 8 ) == 0 )
        {
            strcpy( tInterface->szData, "SUCC" );
        }
        else
        {
            strcpy( tInterface->szData, "FAIL" );
        }
        tInterface->iDataLen = 4;
        strcpy( tInterface->szReturnCode, TRANS_SUCC );
    }
   
    return SUCC;
}
Esempio n. 12
0
/*****************************************************************
** 功    能:将源PIN密文用源PIK解密,进行PIN格式转换,然后用目的PIK加密输出。
** 输入参数:
           tInterface->szData 源帐号(16字节)+密码密文(8字节)+目的帐号(16字节)
           iSekPosIndex     加密源PIK的存储加密密钥索引
           iSekHostIndex    加密目的PIK的存储加密密钥索引
** 输出参数:
           tInterface->szData 转加密后的密码密文(8字节)
** 返 回 值:
           成功 - SUCC
           失败 - FAIL
** 作    者:Robin     
** 日    期:2009/08/25 
** 调用说明:
** 修改日志:mod by wukj 20121031规范命名及排版修订
**          
****************************************************************/
int Sjl06sChangePin(T_Interface *tInterface, int iSekPosIndex, int iSekHostIndex)
{
    char    szInData[1024], szOutData[1024], szPanBlock[17], szTargetPan[17];
    int     iLen, iRet, iSndLen;

    sprintf( szPanBlock, "0000%12.12s", tInterface->szData+3 );
    szPanBlock[16] = 0;

    sprintf( szTargetPan, "0000%12.12s", tInterface->szData+27 );
    szTargetPan[16] = 0;

    iLen = 0;
    memcpy( szInData, "XP", 2 );    /* 命令 */
    iLen += 2;

    /* 加密源PIK的存储加密密钥索引 */
    sprintf( szInData+iLen, "%03ld", iSekPosIndex );
    iLen += 3;

    /* 源PIK密钥密文 */
    BcdToAsc( (uchar *)(tInterface->szPinKey), 32, 0 , (uchar *)(szInData+iLen));    
    iLen += 32;

    /* 加密目的PIK的存储加密密钥索引 */
    sprintf( szInData+iLen, "%03ld", iSekHostIndex );
    iLen += 3;

    /* 目的PIK密钥密文 */
    BcdToAsc( (uchar *)(tInterface->szMacKey), 32, 0 , (uchar *)(szInData+iLen));    
    iLen += 32;

    /* 源PinBlock密文 */
    BcdToAsc( (uchar *)(tInterface->szData+16), 16, 0 , (uchar *)(szInData+iLen));    
    iLen += 16;

    /* 源帐号 */
    memcpy( szInData+iLen, szPanBlock, 16 );    
    iLen += 16;

    /* 目的帐号 */
    memcpy( szInData+iLen, szTargetPan, 16 );    
    iLen += 16;

    iRet = CommuWithHsm( szInData, iLen, szOutData ); 
    if( iRet == FAIL )
    {
        WriteLog( ERROR, "commu with hsm fail" );
        strcpy( tInterface->szReturnCode, ERR_SYSTEM_ERROR );
        return FAIL;
    }

    if( memcmp(szOutData, "E", 1) == 0 )
    {
        DispUphsmErrorMsg( szOutData+1, tInterface->szReturnCode );
        WriteLog( ERROR, "hsm pin change fail[%2.2s]", szOutData+1 );
        return SUCC;
    }
    else if(memcmp(szOutData, "A", 1) == 0 )
    {
        AscToBcd( (uchar *)(szOutData+1), 16, 0 ,(uchar *)(tInterface->szData));
        tInterface->iDataLen = 8;
        strcpy( tInterface->szReturnCode, TRANS_SUCC );
    }
   
    return SUCC;
}
Esempio n. 13
0
/*****************************************************************
** 功    能:用ANSI X9.9 MAC算法对数据做MAC。 
** 输入参数:
           tInterface->szData 参与MAC运算的数据,长度由data_len指定
           iSekIndex        存储加密密钥索引
** 输出参数:
           tInterface->szData MAC(8字节)
** 返 回 值:
           成功 - SUCC
           失败 - FAIL
** 作    者:Robin     
** 日    期:2009/08/25 
** 调用说明:
** 修改日志:mod by wukj 20121031规范命名及排版修订
**          
****************************************************************/
int Sjl06sCalcMac(T_Interface *tInterface, int iSekIndex)
{
    char    szInData[2048], szOutData[2048], szMacData[17];
    int     iLen, iRet, iSndLen;
    char    szDisp[1024];

    iLen = 0;
    /* 命令 */
    memcpy( szInData, "XR", 2 );    
    iLen += 2;
    /*存储加密密钥索引*/
    sprintf( szInData+iLen, "%03ld", iSekIndex ); 
    iLen += 3;

    /*MAC密钥密文*/
    BcdToAsc( (uchar *)(tInterface->szMacKey), 32, 0 ,(uchar *)(szInData+iLen));
    iLen += 32;

#ifdef TEST_SAFE_PRT
    memset(szDisp, 0x00, sizeof(szDisp));
    BcdToAsc((uchar*)(tInterface->szMacKey), 32, 0,(uchar*)szDisp);
    WriteLog(TRACE, "===mac key[%s]===", szDisp);
#endif
    
    if( tInterface->iAlog == XOR_CALC_MAC )
    {
        XOR( tInterface->szData, tInterface->iDataLen, szMacData );
        sprintf( szInData+iLen, "%03ld", 8 );
        iLen += 3;

        memcpy( szInData+iLen, szMacData, 8 );
        iLen += 8;
    }
    else
    {
        sprintf( szInData+iLen, "%03ld", tInterface->iDataLen );
        iLen += 3;

        memcpy( szInData+iLen, tInterface->szData, tInterface->iDataLen );
        iLen += tInterface->iDataLen;
    }
    
    iRet = CommuWithHsm( szInData, iLen, szOutData ); 
    if( iRet == FAIL )
    {
        WriteLog( ERROR, "commu with hsm fail" );
        strcpy( tInterface->szReturnCode, ERR_SYSTEM_ERROR );
        return FAIL;
    }

    if( memcmp(szOutData, "E", 1) == 0 )
    {
        DispUphsmErrorMsg( szOutData+1, tInterface->szReturnCode );
        WriteLog( ERROR, "hsm calc mac fail[%2.2s]", szOutData+1 );
        return SUCC;
    }
    else if(memcmp(szOutData, "A", 1) == 0 )
    {
        AscToBcd( (uchar *)(szOutData+1), 16, 0 ,(uchar *)(tInterface->szData));
        tInterface->iDataLen = 8;
        strcpy( tInterface->szReturnCode, TRANS_SUCC );
    }
   
    return SUCC;
}
Esempio n. 14
0
int CReversalTransaction::SendReversalTransactionData(char *pAccount,LONG Money,char *cTraceCode,char *cAck)
{
	//组包
	CIso8583Package *package = new CIso8583Package();
	int iRes = BuildPackage(package,pAccount,Money,cTraceCode,cAck);
	if (iRes != 0) return iRes;   //组包不成功,返回错误码

	BYTE cHeader[30];
	int nOffset = 0;
	AscToBcd(cHeader + nOffset,(unsigned char *)szTPDU.GetBuffer(),szTPDU.GetLength());
	nOffset += szTPDU.GetLength() / 2;
	AscToBcd(cHeader + nOffset,(unsigned char *)szHeader.GetBuffer(),szHeader.GetLength());
	nOffset += szHeader.GetLength() / 2;
	cHeader[nOffset] = 0x04;
	nOffset += 1;
	cHeader[nOffset] = 0x00;
	nOffset += 1;

	BYTE cData[512];
	memset(cData,0,512);
	unsigned int nLen = package->GetData(cData,512,cHeader,nOffset,false);
	delete package;

	char cLen[5] = {'\0'};
	itoa_hex(nLen,cLen,2);
	unsigned char cDataLen[3] = {'\0'};
	AscToBcd(cDataLen,(unsigned char *)cLen,4);
	BYTE cPackageData[512];
	memset(cPackageData,0,sizeof(cPackageData));
	memcpy(cPackageData,cDataLen,2);
	memcpy(cPackageData + 2,cData,nLen);

	CSocket client;
	if( client.InitSocket() == FALSE) return -1;
	if( client.Connect(szServerIP,atoi(szPort)) == false) return -1;
	gLog.Log(cData,nLen);
	client.Send(cData,nLen);
	BYTE RecvData[1024];
	memset(RecvData,0,1024);
	nLen = client.Receive(RecvData,1024);
	if(nLen != 0)
	{
		gLog.Log(RecvData,nLen);
		CIso8583Parse *receivePackage = new CIso8583Parse();
		char cResult[128];
		memset(cResult,0,128);
		Read8583Package(receivePackage,RecvData,39,2,(BYTE *)cResult);
		delete receivePackage;
		if(strcmp(cResult,"00") == 0)
		{
			TCHAR szCurPath[MAX_PATH];
			GetCurrentDirectory(sizeof(szCurPath),szCurPath);
			_tcscat(szCurPath,TEXT("\\Reversal.ini"));
			WritePrivateProfileString(TEXT("Reversal"),TEXT("Account"),"",szCurPath);
			WritePrivateProfileString(TEXT("Reversal"),TEXT("TraceCode"),"",szCurPath);
			WritePrivateProfileString(TEXT("Reversal"),TEXT("Money"),"",szCurPath);
			WritePrivateProfileString(TEXT("Reversal"),TEXT("Ack"),"",szCurPath);
			WritePrivateProfileString(TEXT("Reversal"),TEXT("Flag"),"1",szCurPath);//1 -- 已处理
		}
	}

	return 1;
}
Esempio n. 15
0
//读入配置文件
bool LoadConfig()
{
    char cfg_file[PATH_MAX] = {0};
    strcat(cfg_file, "t_ysb_sx_chn.ini");
    IniFile ini(cfg_file);  //INI类

    g_Cfg.nGroupNum = ini.ReadInteger("CUPSINFO", "CUPHOSTNUM", 1);
    switch (g_Cfg.nGroupNum)
    {
    case 1:
    case 2:
    case 4:
    case 8:
        break;
    default:
        trace_log(ERR, "CUPHOSTNUM must be 1,2,4,8.");
        return false;
        break;
    }
    strcpy(g_Cfg.cF62, ini.ReadString("CUPSINFO", "F62", ""));
    AscToBcd((unsigned char*)g_Cfg.MsgHead, (unsigned char*)ini.ReadString("CUPSINFO", "MsgHead", "603100310006"), 12);
    AscToBcd((unsigned char*)g_Cfg.cTpdu, (unsigned char*)ini.ReadString("CUPSINFO", "TPDU", "6000060001"), 10);
    memset(g_Cfg.ChannelName, '\0', sizeof(g_Cfg.ChannelName));
    strcpy(g_Cfg.ChannelName, ini.ReadString("CUPSINFO", "Channel", "POSP"));
    g_Cfg.nSendTimeOut = ini.ReadInteger("CUPSINFO", "SendTimeOut", 60);
    g_Cfg.nServerTimeout = ini.ReadInteger("CUPSINFO", "ServerTimeOut", 300);
    g_Cfg.nTickTime = ini.ReadInteger("CUPSINFO", "TickTime", 60); // 心跳包间隔时间
    
    // 受理机构代码,陕西信合,发送机构代码需要在对应关系取
    //渠道参数 todo 记得将受理机构代码拷到报文头
    memset(g_Cfg.SndBrchCode, 0, sizeof(g_Cfg.SndBrchCode));
    strcpy(g_Cfg.SndBrchCode, ini.ReadString("CHANNEL", "SndBrchCode", "48450000"));
    memset(g_Cfg.RcvBrchCode, 0, sizeof(g_Cfg.RcvBrchCode));
    strcpy(g_Cfg.RcvBrchCode, ini.ReadString("CHANNEL", "RcvBrchCode", "00010000"));
    memset(g_Cfg.SysFlag, 0, sizeof(g_Cfg.SysFlag));
    strcpy(g_Cfg.SysFlag, ini.ReadString("CHANNEL", "SysFlag", "1"));

    // 加载单工服务器配置列表
    char cTmp[100] = {0};
    for (int i=0; i<g_Cfg.nGroupNum; i++)
    {
        memset(cTmp, 0, sizeof(cTmp));
        sprintf(cTmp, "CUPHOST%d", i);
        strcpy(g_Cfg.CupHost[i].Host, ini.ReadString(cTmp, "Host", "127.0.0.1"));
        g_Cfg.CupHost[i].Port = ini.ReadInteger(cTmp, "Port", 9002);
        g_Cfg.CupHost[i].nListenPort = ini.ReadInteger(cTmp, "ListenPort", 60000);
    }

    //加密机服务参数
    strcpy(g_Cfg.EncHost.Host, ini.ReadString("ENCRYPTOR", "Host", "127.0.0.1"));
    g_Cfg.EncHost.Port = ini.ReadInteger("ENCRYPTOR", "Port", 9002);
    g_Cfg.EncHost.Timeout = ini.ReadInteger("ENCRYPTOR", "TimeOut", 40);
    g_Cfg.EncHost.iThdCnt = ini.ReadInteger("ENCRYPTOR", "ThreadCount", 0);

    //数据库连接
    strcpy(g_Cfg.DbsProp.TnsName, ini.ReadString("DBS", "TnsName", "XGD"));
    strcpy(g_Cfg.DbsProp.LgnName, ini.ReadString("DBS", "LgnName", ""));

    char pwd[32] = {0};
    strcpy(pwd, ini.ReadString("DBS", "LgnPwd", ""));
    if (0 != strlen(pwd))   //解密连接密码
        xxTeaString(0, g_Cfg.DbsProp.LgnPwd, pwd);

    //连接池最小连接数
    g_Cfg.DbsProp.nDBPoolMinNum = ini.ReadInteger("DBS", "MinPoolNum", 3);

    LOG_LEVEL = ini.ReadInteger("LOG", "Level", 1);
    LOG_OTHER = ini.ReadInteger("LOG", "Other", 0);

    return true;
}
Esempio n. 16
0
//冲正
int CTradeDoReset::DoPack(SAConnection *saConn, void * pNode,
                        unsigned char * pBuffer, unsigned & iBufLen)
{
    if(saConn == NULL || pNode == NULL || pBuffer == NULL)
    {
        trace_log(ERR, "Paramter error!");
        return RET_SYSEXP;
    }
    TRADEDATA * pData = (TRADEDATA *)pNode;

    CTLVTemplet tlvObj;
    if(1 != tlvObj.UnPackTLVData(pData->TransData.TlvDataLen, pData->TransData.TlvData))
    {
        trace_log(ERR, "UnPackTLVData fail!");
        return RET_SYSEXP;
    }

    bool bFlag = true, bIsICC = false;
    unsigned char cFieldData[FIELD_MAXLEN]={0};//bFieldData[FIELD_MAXLEN]={0}, 
    unsigned int iFieldDataLen = 0;
    POS_TRADE_TYPE posType = (POS_TRADE_TYPE)pData->TransData.HeadData.RTradeType;
    if(m_unTradeOrgMap.empty())
        initTredeTypeMap();

    SAString sSql;
    SACommand Cmd;
    Cmd.setConnection(saConn);
    try
    {
        sSql.Format("select * from T_CHANNEL_RESETLIST where FIELD11='%s' and FIELD41='%s' and FIELD42='%s'"
            " and CRT_TYPE='%c' and CRT_BATCHNO='%s'", pData->TransData.HeadData.OrigLPosSeq,
            pData->TransData.HeadData.arrRTermNo, pData->TransData.HeadData.arrRMerchNo,
            m_unTradeOrgMap[posType], pData->TransData.HeadData.OrigLBatchNo);
        Cmd.setCommandText(sSql);
	    Cmd.Execute();
	    if(!Cmd.FetchNext())
	    {
	        trace_log(ERR, "select original trade record fail[%s]!", _T(sSql));
	        strcpy(pData->TransData.HeadData.RspCode, "25");
	        return RET_SYSEXP;
	    }
		
	    //0消息类型
	    bFlag &= sndObj.SetValueByStr(0, "0400");
	    //2账号
	    SAString str = Cmd.Field("FIELD2").asString();
	    if(str.GetLength() > 0)
	    {
	        bFlag &= sndObj.SetValueByStr(2, _T(str));
	    }
		
	    //3处理码
	    bFlag &= sndObj.SetValueByStr(3, _T(Cmd.Field("FIELD3").asString()));
	    //4金额
	    bFlag &= sndObj.SetValueByStr(4, _T(Cmd.Field("FIELD4").asString()));
	    //11流水号
	    bFlag &= sndObj.SetValueByStr(11, _T(Cmd.Field("FIELD11").asString()));
		
	    //14 卡的有效期
		str = Cmd.Field("FIELD14").asString();
	    if(str.GetLength() > 0)
	    {
	        bFlag &= sndObj.SetValueByStr(14, _T(str));
	    }
			
	    //22服务点输入方式
		/*iFieldDataLen = tlvObj.GetTLVItemByHex(TAG_POSENTMODE, pData->TransData.HeadData.SvrPointCode, 2);
		if(iFieldDataLen > 0)
		{
			bFlag &= sndObj.SetValueByHex(22, pData->TransData.HeadData.SvrPointCode, 2);	

		    if(memcmp(pData->TransData.HeadData.SvrPointCode, "05", 2) == 0 ||
				memcmp(pData->TransData.HeadData.SvrPointCode, "07", 2) == 0  ||
				memcmp(pData->TransData.HeadData.SvrPointCode, "98", 2) == 0 ||
				memcmp(pData->TransData.HeadData.SvrPointCode, "95", 2) == 0)	
		        bIsICC = true;
		}*/
		str = Cmd.Field("FIELD22").asString();
	    if(str.GetLength() > 0)
	    {
	        bFlag &= sndObj.SetValueByStr(22, _T(str));
			//char Field22[3] = {0};
    			//strcpy(Field22,_T(str));
			if(memcmp(_T(str), "05", 2) == 0 ||memcmp(_T(str), "07", 2) == 0  ||
				memcmp(_T(str), "98", 2) == 0 ||memcmp(_T(str), "95", 2) == 0)	
		        bIsICC = true;
			trace_log(DBG, "bIsICC=%d", bIsICC);
	    }
		else
		{
			trace_log(ERR, "get FIELD22 from database failed!");
			return RET_PACK;
		}
		
	    //23IC卡序列号
		if(pData->TransData.HeadData.RTradeType < POS_UNELEWALLETLOAD ||
			pData->TransData.HeadData.RTradeType > POS_UNWALLETDEPOSIT)
		{
			str = Cmd.Field("FIELD23").asString();
		    if(str.GetLength() > 0)
		    {
		        bFlag &= sndObj.SetValueByStr(23, _T(str));
		    }
		}
	     //25服务点条件码
	    	bFlag &= sndObj.SetValueByStr(25, _T(Cmd.Field("FIELD25").asString()));
	    
	    //38原授权码
	    str = Cmd.Field("FIELD38").asString();
	    if(str.GetLength() > 0)
	    {
	        bFlag &= sndObj.SetValueByStr(38, _T(str));
	    }
		else if(posType == POS_UNPREAUTHREVE ||posType == POS_UNPREAUTHCPLREQ)
		{
			trace_log(ERR, "get FIELD38 from database failed!");
			return RET_PACK;
		}
		//39 响应码
		bFlag &= sndObj.SetValueByStr(39, _T(Cmd.Field("FIELD39").asString()));
	     //41终端号
	    bFlag &= sndObj.SetValueByStr(41, _T(Cmd.Field("FIELD41").asString()));
	    //42商户号
	    bFlag &= sndObj.SetValueByStr(42, _T(Cmd.Field("FIELD42").asString()));
	    
	    //48附加数据-私有 
	    if(posType == POS_UNWALLETDEPOSIT || posType == POS_UNECTRANSLOAD)
		{
		    bFlag &= sndObj.SetValueByStr(48, _T(Cmd.Field("FIELD48").asString()));
	    }
	    //49货币代码
	    bFlag &= sndObj.SetValueByStr(49, _T(Cmd.Field("FIELD49").asString()));
		//53安全控制信息 
		if(posType >= POS_UNREPEAL || posType <= POS_UNELEWALLETLOAD)
		{
			str = _T(Cmd.Field("").asString());
		    if(str.GetLength() > 0)
		    {
				bFlag &= sndObj.SetValueByStr(53, _T(Cmd.Field("FIELD53").asString()));
		    	}
	    	}
	    //55IC卡数据
	    if(bIsICC && (posType < POS_UNELEWALLETLOAD || posType > POS_UNWALLETDEPOSIT))
	    {
	        memset(cFieldData, 0, sizeof(cFieldData));
	        CTLVTemplet tlvDB, tlvF55;
	        unsigned char cICData[1024]={0};
	        str = Cmd.Field("FIELD55").asString();
	        iFieldDataLen = str.GetLength();
	        if(iFieldDataLen > 0)
	        {
	            AscToBcd(cICData, (unsigned char *)_T(str), iFieldDataLen);
	            iFieldDataLen /= 2;
	            if(1 != tlvDB.UnPackTLVData(iFieldDataLen, cICData))
	            {
	                trace_log(ERR,"UnPackTLVData error!");
	                strcpy(pData->TransData.HeadData.RspCode, ERR_PACKMESSAGE);
	                return RET_PACK;
	            }
	            if(pData->TransData.HeadData.RTradeType == POS_UNCONSUME ||
	               pData->TransData.HeadData.RTradeType == POS_UNPREAUTH ||
	               pData->TransData.HeadData.RTradeType == POS_UNFILLECASH||
	               pData->TransData.HeadData.RTradeType == POS_UNELECASHLOAD||
	               pData->TransData.HeadData.RTradeType == POS_UNECTRANSLOAD)
	            {//消费冲正或预授权冲正需上送55域
	                iFieldDataLen = tlvObj.GetTLVItemByHex(TAG_TERMVERRET, cFieldData, sizeof(cFieldData));
	                if(iFieldDataLen > 0)
	                {
	                    bFlag &= tlvF55.AddTLVItemByHex(GetTagTxt(TAG_TERMVERRET), iFieldDataLen, cFieldData);
	                }

	                iFieldDataLen = tlvDB.GetTLVItemByHex(TAG_INTDEVSERNO, cFieldData, sizeof(cFieldData));
	                if(iFieldDataLen > 0)
	                {
	                    bFlag &= tlvF55.AddTLVItemByHex(GetTagTxt(TAG_INTDEVSERNO), iFieldDataLen, cFieldData);
	                }

	                iFieldDataLen = tlvObj.GetTLVItemByHex(TAG_ISSAPPDATA, cFieldData, sizeof(cFieldData));
	                if(iFieldDataLen > 0)
	                {
	                    bFlag &= tlvF55.AddTLVItemByHex(GetTagTxt(TAG_ISSAPPDATA), iFieldDataLen, cFieldData);
	                }

	                iFieldDataLen = tlvDB.GetTLVItemByHex(TAG_APPTRACOU, cFieldData, sizeof(cFieldData));
	                if(iFieldDataLen > 0)
	                {
	                    bFlag &= tlvF55.AddTLVItemByHex(GetTagTxt(TAG_APPTRACOU), iFieldDataLen, cFieldData);
	                }

	                iFieldDataLen = tlvObj.GetTLVItemByHex(TAG_ISSCRIRET, cFieldData, sizeof(cFieldData));
	                if(iFieldDataLen > 0)
	                {
	                    bFlag &= tlvF55.AddTLVItemByHex(GetTagTxt(TAG_ISSCRIRET), iFieldDataLen, cFieldData);
	                }

	                iFieldDataLen = sizeof(cFieldData);
	                bFlag &= tlvF55.PackTLVData(cFieldData, (unsigned &)iFieldDataLen);
	                bFlag &= sndObj.SetValueByHex(55, cFieldData, iFieldDataLen);
	            }
	        }
	    }
		//58 PBOC电子钱包/存折标准的交易信息
		if(posType >= POS_UNELEWALLETLOAD && posType <= POS_UNWALLETDEPOSIT)
		{
			bFlag &= sndObj.SetValueByStr(58, _T(Cmd.Field("FIELD58").asString()));
		}
	    //60
	    bFlag &= sndObj.SetValueByStr(60, _T(Cmd.Field("FIELD60").asString()));
		
		//61 原始信息域
		if(posType == POS_UNPREAUTHCPLREQ || (posType >= POS_REPEAL && posType <= POS_FILLECASHREVE))
		{
			bFlag &= sndObj.SetValueByStr(61, _T(Cmd.Field("FIELD61").asString()));
		}
		//62
		if(posType == POS_UNWALLETDEPOSIT || posType == POS_UNECTRANSLOAD || posType == POS_UNCONSUME)
		{
			str = _T(Cmd.Field("FIELD62").asString());
		    if(str.GetLength() > 0)
		    {
				bFlag &= sndObj.SetValueByStr(62, _T(str));
		    	}
		    	else if(posType != POS_UNCONSUME)
		    	{
		    		trace_log(ERR, "get FIELD62 from database failed!");
				return RET_PACK;
		    	}
		}
	}
	catch (SAException &e)
	{
		saConn->Rollback();
		trace_log(ERR,"database exceptions:%s ,SQL = [%s]",_T(e.ErrText()),_T(sSql));
		return -1;
	}
	catch (...)
	{
		trace_log(ERR, "Execute sql fail[sql:%s]!", _T(sSql));
		return -1;
	}
    
     //64MAC
    bFlag &= sndObj.SetValueByHex(64, (unsigned char*)"00000000", 8);
    /*unsigned char cMacBuf[FIELD_MAXLEN] = {0};
	if(1 != sndObj.GetMacData(cMacBuf, sizeof(cMacBuf)))
	{
		trace_log(ERR,"Get mac failed!");
		return RET_GETMACERR;
	}
	bFlag &= sndObj.SetValueByHex(64, cMacBuf, 8);*/
	
    //组包
    iBufLen = PACK_MAXLEN;
    bFlag &= sndObj.Pack(pBuffer, iBufLen);
    if(!bFlag)
    {
        trace_log(ERR, "Pack right CUPS8583 fail!");
        return RET_PACK;
    }
    //计算MAC
    BYTE bMab[PACK_MAXLEN] = {0};
    BYTE bMac[9] = {0};
    BYTE bTak[17] = {0};
    int nMabPos = 2 + 5 + 6;
    int nMacLen = 8;

    Ccommon::Str2Hex((char *)pData->bMacKey, bTak, (sizeof(bTak) - 1)*2);
    memcpy(bMab, pBuffer + nMabPos, iBufLen - nMabPos - nMacLen);
    if(!m_checkMesValue.GenMacData(bMab, iBufLen - nMabPos - nMacLen, bTak, bMac))
    {
        memcpy((pBuffer + iBufLen -nMacLen), bMac, nMacLen);
    }
#if 0
    unsigned char ucMab[1024]={0};
	unsigned char ucTmp[9] = {0};
	// 如果是非指定账户转账类圈存算MAC需要修改为转账类的计算MAC方法
	if (pData->TransData.HeadData.RTradeType == POS_UNECTRANSLOAD)
		ucMab[0] = 1;

    int iMabLen = sndObj.GetMacData(ucMab, sizeof(ucMab));
    if(iMabLen > 0)
    {
        if(!g_EncComm->CalculateMac(g_Cfg.SndBrchCode, g_Cfg.RcvBrchCode,
                ucMab, iMabLen, ucTmp, 2, 0))
        {
            trace_log(ERR,"CalculateMac fail!");
            return RET_SYSEXP;
        }
		BcdToAsc(pBuffer+iBufLen-8, ucTmp, 4);
    }
    else
    {
        trace_log(ERR,"GetMacData fail!");
        return RET_SYSEXP;
    }
#endif
    return RET_SUCCESS;
}