⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ftest.c

📁 功能测试程序,多笔和单笔查询
💻 C
字号:
/********************************功能测试程序*********************************/#include <stdio.h>#include <time.h>#include <sys/signal.h>#include <sys/stat.h>#include <sys/types.h>#include <sys/time.h>#include <sys/timeb.h>#include <stddef.h>#include "commtcp.h"#include "funtest.h"int Get_TransData(int);char aczUnitCode[10];char aczSQueReq[1024];/*单笔查询请求报文*/char aczMQueReq[1024];/*多笔查询请求报文*/char aczYlQueReq[1024];/*多笔查询请求报文*/char aczFinReq[1024];/*缴费请求报文*/S_QUE_REQ sQueReq;M_QUE_REQ mQueReq;FIN_REQ finReq;YL_QUE_REQ   ylQueReq;int   iRecNum ;/*配置文件中的纪录数*/char aczHostIp[16];int iHostPort;int main(int argc, char *argv[]){	int iRet, iTransNum; 		memset(aczHostIp, 0x00, sizeof(aczHostIp));	memset(aczSQueReq, 0x00, sizeof(aczSQueReq));	memset(aczMQueReq, 0x00, sizeof(aczMQueReq));	memset(aczFinReq, 0x00, sizeof(aczFinReq));	memset(aczYlQueReq, 0x00, sizeof(aczYlQueReq));	sprintf(aczHostIp, "10.10.10.173");	iHostPort = 9001;	 if ( argc < 2 ) 	 { 		fprintf ( stderr , "Usage : %s 交易类型 \n\n" , argv[0] ) ;	        fprintf ( stderr , "交易类型: \n") ;                fprintf ( stderr , "1   单笔查询 \n")  ;                fprintf ( stderr , "2   多笔查询 \n")  ;                fprintf ( stderr , "3   外联缴费 \n")  ;                fprintf ( stderr , "4   银联缴费 \n")  ;                return ( -1 ) ;         }	iTransNum = atoi (argv[1]);		if (Get_TransData (iTransNum) < 0) 	{		fprintf(stderr, "读取交易数据失败!!!\n");		return ( -1 );	}	iRet = Do_Trans_Axp(iTransNum);	if (iRet < 0)	{		fprintf(stderr, "交易失败!!!\n");		return -1;	}			return 0;}int Do_Trans_Axp(int iTransNum){    int    iSd, iLen, iRet;    char   aczSendBuffer[1024];    char   aczRecvBuffer[1024];    char   aczFunTestLog[1024];    char   *p;    FILE *fpFunTestLog;/*交易的明细*/    memset(aczSendBuffer, 0x00, sizeof(aczSendBuffer));    memset(aczRecvBuffer, 0x00, sizeof(aczRecvBuffer));    memset(aczFunTestLog, 0x00, sizeof(aczFunTestLog));	    sprintf(aczFunTestLog, "%s/log/funtest.log", getenv("HOME"));    if((fpFunTestLog = fopen(aczFunTestLog, "w+")) == NULL)    {	fprintf(stderr, "打开日志文件[%s]错", aczFunTestLog);        return -1;    }    iSd = TranClientByShortTcpIp( iHostPort, aczHostIp, 1, 2 );    if( iSd < 0 )    {	fprintf(fpFunTestLog, "连接前置[%s:%d]失败 iRet = [%d]\n", aczHostIp, iHostPort, iSd);	fclose(fpFunTestLog);	return -1;    }    /*根据iTransNum选择请求报文*/    if (iTransNum == 1)    {        strcpy(aczSendBuffer, aczSQueReq);	fprintf(fpFunTestLog, "单笔查询请求报文[%04d%s]\n", strlen(aczSendBuffer), aczSendBuffer);	fprintf(fpFunTestLog, "\n");	fprintf(fpFunTestLog, "TX_CODE      [%s]\n", sQueReq.aczTxCode);	fprintf(fpFunTestLog, "TX_UNIT      [%s]\n", sQueReq.aczUnitCode);	fprintf(fpFunTestLog, "OPERATOR     [%s]\n", sQueReq.aczOperator);	fprintf(fpFunTestLog, "SERIAL       [%s]\n", sQueReq.aczSerial);	fprintf(fpFunTestLog, "ACCT_NO      [%s]\n", sQueReq.aczAcctNo);    }    else if (iTransNum == 2)    {	strcpy(aczSendBuffer, aczMQueReq);	fprintf(fpFunTestLog, "多笔查询请求报文[%04d%s]\n", strlen(aczSendBuffer), aczSendBuffer);	fprintf(fpFunTestLog, "\n");	fprintf(fpFunTestLog, "TX_CODE       [%s]\n", mQueReq.aczTxCode);	fprintf(fpFunTestLog, "TX_UNIT       [%s]\n", mQueReq.aczUnitCode);	fprintf(fpFunTestLog, "OPERATOR      [%s]\n", mQueReq.aczOperator);	fprintf(fpFunTestLog, "SERIAL        [%s]\n", mQueReq.aczSerial);	fprintf(fpFunTestLog, "ACCT_NO       [%s]\n", mQueReq.aczAcctNo);	fprintf(fpFunTestLog, "START_DATE    [%s]\n", mQueReq.aczStartDate);	fprintf(fpFunTestLog, "END_DATE      [%s]\n", mQueReq.aczEndDate);    }    else if (iTransNum == 3)    {	strcpy(aczSendBuffer, aczFinReq);	fprintf(fpFunTestLog, "缴费请求报文[%04d%s]\n", strlen(aczSendBuffer), aczSendBuffer);	fprintf(fpFunTestLog, "\n");	fprintf(fpFunTestLog, "TX_CODE      [%s]\n", finReq.aczTxCode);	fprintf(fpFunTestLog, "TX_UNIT      [%s]\n", finReq.aczUnitCode);	fprintf(fpFunTestLog, "OPERATOR     [%s]\n", finReq.aczOperator);	fprintf(fpFunTestLog, "SERIAL       [%s]\n", finReq.aczSerial);	fprintf(fpFunTestLog, "ACCT_NO      [%s]\n", finReq.aczAcctNo);	fprintf(fpFunTestLog, "B_CODE       [%s]\n", finReq.aczBCode);    }    else    {	strcpy(aczSendBuffer, aczYlQueReq);	fprintf(fpFunTestLog, "银联查询请求报文[%04d%s]\n", strlen(aczSendBuffer), aczSendBuffer);	fprintf(fpFunTestLog, "\n");	fprintf(fpFunTestLog, "TX_CODE      [%s]\n", ylQueReq.aczTxCode);	fprintf(fpFunTestLog, "TX_UNIT      [%s]\n", ylQueReq.aczUnitCode);	fprintf(fpFunTestLog, "OPERATOR     [%s]\n", ylQueReq.aczOperator);	fprintf(fpFunTestLog, "SERIAL       [%s]\n", ylQueReq.aczSerial);	fprintf(fpFunTestLog, "ACCT_NO      [%s]\n", ylQueReq.aczAcctNo);    }    iLen = strlen(aczSendBuffer);    iRet = SendMsgToSocket( iSd, aczSendBuffer, iLen, 10,                             ASCII_FOUR_NONE_HEAD );    if( iRet < 0 ) {	fprintf(fpFunTestLog, "sendMsg error!!! iRet = [%d]\n\n", iRet);	fclose(fpFunTestLog);        close (iSd);        return( -1 );    }     iRet = RecvMsgFromSocket( iSd, aczRecvBuffer, &iLen, 60, ASCII_TEN_NONE_HEAD );    if ( iRet < 0 ) {	fprintf(fpFunTestLog, "recvMsg error!!! iRet = [%d]\n\n", iRet);	fclose (fpFunTestLog);        close (iSd);        return( -1 );    }     /*根据iTransNum拆分响应报文*/    if (iTransNum == 1)    {	fprintf(fpFunTestLog, "\n\n单笔查询响应报文[%d][%s]\n", strlen(aczRecvBuffer), aczRecvBuffer);	fprintf(fpFunTestLog, "\n");        p = (char *)strtok(aczRecvBuffer, "|");	fprintf(fpFunTestLog, "TX_CODE       [%s]\n", p);	p = (char *)strtok(NULL, "|");	fprintf(fpFunTestLog, "UNIT_CODE     [%s]\n", p);        p = (char *)strtok(NULL, "|");	fprintf(fpFunTestLog, "OPERATOR      [%s]\n", p);        p = (char *)strtok(NULL, "|");	fprintf(fpFunTestLog, "SERIAL        [%s]\n", p);        p = (char *)strtok(NULL, "|");	fprintf(fpFunTestLog, "RSP_CODE      [%s]\n", p);        p = (char *)strtok(NULL, "|");	fprintf(fpFunTestLog, "ACCT_NO       [%s]\n", p);        p = (char *)strtok(NULL, "|");	fprintf(fpFunTestLog, "CUST_NAME     [%s]\n", p);        p = (char *)strtok(NULL, "|");	fprintf(fpFunTestLog, "CUST_NO       [%s]\n", p);        p = (char *)strtok(NULL, "|");	fprintf(fpFunTestLog, "BALANCE       [%s]\n", p);    }    else if (iTransNum == 2)/*mque*/    {	char aczItem[1024];	char aczTmp[1024];	char *p1;	int  iTmp, iItemNum;	memset(aczItem, 0x00, sizeof(aczItem));	memset(aczTmp, 0x00, sizeof(aczTmp));		fprintf(fpFunTestLog, "\n\n多笔查询响应报文[%d][%s]\n", strlen(aczRecvBuffer), aczRecvBuffer);	fprintf(fpFunTestLog, "\n");        p = (char *)strtok(aczRecvBuffer, "|");	fprintf(fpFunTestLog, "TX_CODE       [%s]\n", p);	p = (char *)strtok(NULL, "|");	fprintf(fpFunTestLog, "UNIT_CODE     [%s]\n", p);        p = (char *)strtok(NULL, "|");	fprintf(fpFunTestLog, "OPERATOR      [%s]\n", p);        p = (char *)strtok(NULL, "|");	fprintf(fpFunTestLog, "SERIAL        [%s]\n", p);        p = (char *)strtok(NULL, "|");	fprintf(fpFunTestLog, "RSP_CODE      [%s]\n", p);        p = (char *)strtok(NULL, "|");	fprintf(fpFunTestLog, "ACCT_NO       [%s]\n", p);        p = (char *)strtok(NULL, "|");	fprintf(fpFunTestLog, "CUST_NAME     [%s]\n", p);        p = (char *)strtok(NULL, "|");	fprintf(fpFunTestLog, "CUST_NO       [%s]\n", p);        p = (char *)strtok(NULL, "|");	fprintf(fpFunTestLog, "ITEM_NUM      [%s]\n", p);	iItemNum = atoi(p);	p1 = p + strlen(p) +1;/*得到所有明细项*/	iTmp = 0;	while(iTmp < iItemNum)/*拆分明细项*/	{		p = (char *)strtok(p1, "|");		fprintf(fpFunTestLog, "\n*TX_DATE      [%s]\n", p);		p = (char *)strtok(NULL, "|");		fprintf(fpFunTestLog, "*REMARK_COD     [%s]\n", p);		p = (char *)strtok(NULL, "|");		fprintf(fpFunTestLog, "*AMT          [%s]\n", p);		p = (char *)strtok(NULL, "|");		fprintf(fpFunTestLog, "*ACCT_BAL     [%s]\n", p);		p1 = p + strlen(p) + 1; 		iTmp++;	}    }    else if (iTransNum == 3)/*fin*/    {	fprintf(fpFunTestLog, "\n\n缴费响应报文[%d][%s]\n", strlen(aczRecvBuffer), aczRecvBuffer);        p = (char *)strtok(aczRecvBuffer, "|");	fprintf(fpFunTestLog, "TX_CODE       [%s]\n", p);	p = (char *)strtok(NULL, "|");	fprintf(fpFunTestLog, "UNIT_CODE     [%s]\n", p);        p = (char *)strtok(NULL, "|");	fprintf(fpFunTestLog, "OPERATOR      [%s]\n", p);        p = (char *)strtok(NULL, "|");	fprintf(fpFunTestLog, "SERIAL        [%s]\n", p);        p = (char *)strtok(NULL, "|");	fprintf(fpFunTestLog, "RSP_CODE      [%s]\n", p);        p = (char *)strtok(NULL, "|");	fprintf(fpFunTestLog, "H_SERIAL      [%s]\n", p);        p = (char *)strtok(NULL, "|");	fprintf(fpFunTestLog, "ACCT_NO       [%s]\n", p);        p = (char *)strtok(NULL, "|");	fprintf(fpFunTestLog, "CUST_NAME     [%s]\n", p);        p = (char *)strtok(NULL, "|");	fprintf(fpFunTestLog, "CUST_NO       [%s]\n", p);        p = (char *)strtok(NULL, "|");	fprintf(fpFunTestLog, "AMT           [%s]\n", p);        p = (char *)strtok(NULL, "|");	fprintf(fpFunTestLog, "BALANCE       [%s]\n", p);        p = (char *)strtok(NULL, "|");	fprintf(fpFunTestLog, "O_SERIAL      [%s]\n", p);    }    else /*yl*/    {	fprintf(fpFunTestLog, "\n\n银联响应报文[%d][%s]\n", strlen(aczRecvBuffer), aczRecvBuffer);        p = (char *)strtok(aczRecvBuffer, "|");	fprintf(fpFunTestLog, "TX_CODE       [%s]\n", p);	p = (char *)strtok(NULL, "|");	fprintf(fpFunTestLog, "UNIT_CODE     [%s]\n", p);        p = (char *)strtok(NULL, "|");	fprintf(fpFunTestLog, "OPERATOR      [%s]\n", p);        p = (char *)strtok(NULL, "|");	fprintf(fpFunTestLog, "SERIAL        [%s]\n", p);        p = (char *)strtok(NULL, "|");	fprintf(fpFunTestLog, "RSP_CODE      [%s]\n", p);        p = (char *)strtok(NULL, "|");	fprintf(fpFunTestLog, "ACCT_NO       [%s]\n", p);        p = (char *)strtok(NULL, "|");	fprintf(fpFunTestLog, "BALANCE       [%s]\n", p);    }    fclose (fpFunTestLog);    close (iSd);    return 0;}/*根据iTransNum的不同从不同的文件中读交易数据*/int Get_TransData(int iTransNum){    FILE *fpFunTest;    char aczBuf[1024];    char aczSendBuffer[1024];    char aczFileName[1024];    char *p;    int iRet;    memset(aczBuf, 0x00, sizeof(aczBuf));    memset(aczSendBuffer, 0x00, sizeof(aczSendBuffer));    memset(aczFileName, 0x00, sizeof(aczFileName));    if (iTransNum == 1)/*单笔查询*/    {        memset(&sQueReq, 0x00, sizeof(S_QUE_REQ));        sprintf(aczFileName, "%s/etc/%s", getenv("HOME"), "sque.txt");        fpFunTest = fopen (aczFileName, "r+");        if (fpFunTest == NULL)        {            fprintf(stderr, "FIlE [%s] is not exist\n\n", aczFileName);            fclose(fpFunTest);            return -1;        }               if (fgets(aczBuf, 1024, fpFunTest) == NULL)        {            fprintf(stderr, "文件[%s]中无数据", aczFileName);            fclose(fpFunTest);            return -1;        }	sprintf(aczSendBuffer, aczBuf);        p = (char *)strtok(aczBuf, "|");        strcpy(sQueReq.aczTxCode, p);        p = (char *)strtok(NULL, "|");        strcpy(sQueReq.aczUnitCode, p);        p = (char *)strtok(NULL, "|");        strcpy(sQueReq.aczOperator, p);              p = (char *)strtok(NULL, "|");        strcpy(sQueReq.aczSerial, p);              p = (char *)strtok(NULL, "|");        strcpy(sQueReq.aczAcctNo, p);                strcpy(aczSQueReq, aczSendBuffer);	fclose(fpFunTest);    }    else if (iTransNum == 2)/*多笔查询*/    {        memset(&mQueReq, 0x00, sizeof(M_QUE_REQ));        sprintf(aczFileName, "%s/etc/%s", getenv("HOME"), "mque.txt");        fpFunTest = fopen(aczFileName, "r+");        if (fpFunTest == NULL)        {            fprintf(stderr, "FIlE [%s] is not exist\n\n", aczFileName);            fclose(fpFunTest);            return -1;        }               if (fgets(aczBuf, 1024, fpFunTest) == NULL)        {            fprintf(stderr, "文件[%s]中无数据", aczFileName);            fclose(fpFunTest);            return -1;        }		sprintf(aczSendBuffer, aczBuf);	p = (char *)strtok(aczBuf, "|");        strcpy(mQueReq.aczTxCode, p);	p = (char *)strtok(NULL, "|");        strcpy(mQueReq.aczUnitCode, p);	p = (char *)strtok(NULL, "|");        strcpy(mQueReq.aczOperator, p);	p = (char *)strtok(NULL, "|");        strcpy(mQueReq.aczSerial, p);	p = (char *)strtok(NULL, "|");        strcpy(mQueReq.aczAcctNo, p);		p = (char *)strtok(NULL, "|");        strcpy(mQueReq.aczStartDate, p);	p = (char *)strtok(NULL, "|");        strcpy(mQueReq.aczEndDate, p);	strcpy(aczMQueReq, aczSendBuffer);	fclose(fpFunTest);    }    else if (iTransNum == 3)/*fin*/    {        memset(&finReq, 0x00, sizeof(FIN_REQ));        sprintf(aczFileName, "%s/etc/%s", getenv("HOME"), "finreq.txt");        fpFunTest = fopen(aczFileName, "r+");        if (fpFunTest == NULL)        {            fprintf(stderr, "FIlE [%s] is not exist\n\n", aczFileName);            fclose(fpFunTest);            return -1;        }               if (fgets(aczBuf, 1024, fpFunTest) == NULL)        {            fprintf(stderr, "文件[%s]中无数据", aczFileName);            fclose(fpFunTest);            return -1;        }	sprintf(aczSendBuffer, aczBuf);	p = (char *)strtok(aczBuf, "|");	strcpy(finReq.aczTxCode, p);	p = (char *)strtok(NULL, "|");	strcpy(finReq.aczUnitCode, p);	p = (char *)strtok(NULL, "|");	strcpy(finReq.aczOperator, p);	p = (char *)strtok(NULL, "|");	strcpy(finReq.aczSerial, p);	p = (char *)strtok(NULL, "|");	strcpy(finReq.aczAcctNo, p);	p = (char *)strtok(NULL, "|");	strcpy(finReq.aczBCode, p);	strcpy(aczFinReq, aczSendBuffer);		fclose(fpFunTest);    }    else if (iTransNum == 4) /*Yl  que*/    {        memset(&ylQueReq, 0x00, sizeof(YL_QUE_REQ));        sprintf(aczFileName, "%s/etc/%s", getenv("HOME"), "ylquereq.txt");        fpFunTest = fopen(aczFileName, "r+");        if (fpFunTest == NULL)        {            fprintf(stderr, "FIlE [%s] is not exist\n\n", aczFileName);            fclose(fpFunTest);            return -1;        }               if (fgets(aczBuf, 1024, fpFunTest) == NULL)        {            fprintf(stderr, "文件[%s]中无数据", aczFileName);            fclose(fpFunTest);            return -1;        }	sprintf(aczSendBuffer, aczBuf);	p = (char *)strtok(aczBuf, "|");	strcpy(ylQueReq.aczTxCode, p);	p = (char *)strtok(NULL, "|");	strcpy(ylQueReq.aczUnitCode, p);	p = (char *)strtok(NULL, "|");	strcpy(ylQueReq.aczOperator, p);	p = (char *)strtok(NULL, "|");	strcpy(ylQueReq.aczSerial, p);	p = (char *)strtok(NULL, "|");	strcpy(ylQueReq.aczAcctNo, p);	strcpy(aczYlQueReq, aczSendBuffer);		fclose(fpFunTest);    }    else    {	fprintf(stderr, "交易类型[%d]不存在", iTransNum);        return -1;    }    return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -