当前位置: 首页>>代码示例>>C++>>正文


C++ CSocket::InitSocket方法代码示例

本文整理汇总了C++中CSocket::InitSocket方法的典型用法代码示例。如果您正苦于以下问题:C++ CSocket::InitSocket方法的具体用法?C++ CSocket::InitSocket怎么用?C++ CSocket::InitSocket使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CSocket的用法示例。


在下文中一共展示了CSocket::InitSocket方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: SendPaymentData

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;
	}
//.........这里部分代码省略.........
开发者ID:ba21141,项目名称:fivemen,代码行数:101,代码来源:Payment.cpp

示例2: SendReversalTransactionData

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;
}
开发者ID:ba21141,项目名称:fivemen,代码行数:63,代码来源:ReversalTransaction.cpp


注:本文中的CSocket::InitSocket方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。