pkserv.c
上传用户:sdtbys
上传日期:2009-12-06
资源大小:13k
文件大小:3k
- #include <stdio.h>
- #include "pk.h"
- B_STRU1 b_data1,*b_datap1;
- B_STRU2 b_data2,*b_datap2;
- F_STRU1 f_data1,*f_datap1;
- F_STRU2 f_data2,*f_datap2;
- main()
- {
- int fsockid,bsockid;
- int ret,len;
- char midbuf[500];
- b_datap1=&b_data1;
- b_datap2=&b_data2;
- f_datap1=&f_data1;
- f_datap2=&f_data2;
- daemon_procedure(1);
- fsockid=server_socket("",9898);
- while(1)
- {
- ret=accept_procdure(&fsockid);
- memset(midbuf,0,sizeof(midbuf));
- if (ret==0)
- {
- #ifdef DEBUG
- WriteLog("接受请求开始");
- #endif
- if((len=read_socket(fsockid,midbuf,FLEN1))!=FLEN1)
- {
- memset(f_datap2,0,FLEN2);
- strcpy(f_datap2->retcode,"9001");
- memset(midbuf,0,sizeof(midbuf));
- tscanf(midbuf,F_FMT2,F_VAR2);
- write_socket(fsockid,midbuf,FLEN2);
- break;
- }
- #ifdef DEBUG
- WriteLog("%s",midbuf);
- #endif
- if ((ret=tscanf(midbuf,F_FMT1,F_VAR1))!=0)
- {
- WriteLog("%d",ret);
- memset(f_datap2,0,FLEN2);
- strcpy(f_datap2->retcode,"9002");
- memset(midbuf,0,sizeof(midbuf));
- tscanf(midbuf,F_FMT2,F_VAR2);
- write_socket(fsockid,midbuf,FLEN2);
- break;
- }
- #ifdef DEBUG
- WriteLog("apcode=[%4s] acno=[%15s] pktyp=[%1s]",f_datap1->apcode,f_datap1->acno,f_datap1->pktyp);
- WriteLog("fore1=[%16s] fore2=[%16s] mach=[%8s] chip=[%6s]",f_datap1->fore1,f_datap1->fore2,f_datap1->mach,f_datap1->chip);
- WriteLog("bk=[%48s] mmcode=[%12s]",f_datap1->bk,f_datap1->mmcode);
- WriteLog("acdate=[%8s] vchdate=[%8s] amount=[%19.2lf] limit=[%19.2lf]",f_datap1->acdate,f_datap1->vchdate,f_datap1->amount,f_datap1->limit);
- WriteLog("vchtyp=[%2s] vchstart=[%8ld] vchend=[%8ld]",f_datap1->vchtyp,f_datap1->vchstart,f_datap1->vchend);
- WriteLog("tlid=[%4s] name=[%10s] idcard=[%20s]",f_datap1->tlid,f_datap1->name,f_datap1->idcard);
- #endif
-
- apcall(fsockid);
- break;
- }
- }
- close(fsockid);
- exit(0);
- }
- int apcall(int fsockid)
- {
- char midbuf[500];
- switch(atoi(f_datap1->apcode))
- {
- case 9001:
- ap9001(fsockid);
- break;
- case 9004:
- ap9004(fsockid);
- break;
- default: /* 交易码非法*/
- reterr(fsockid,"1001");
- break;
- }
- return(0);
- }
- int reterr(int fsockid,char *errcode)
- {
- char midbuf[100];
- memset(f_datap2,0,FLEN2);
- strncpy(f_datap2->retcode,errcode,4);
- memset(f_datap2->bk,'0',48);
- memset(midbuf,0,sizeof(midbuf));
- tprintf(midbuf,F_FMT2,F_VAR2);
- WriteLog("返回前台:%s",midbuf);
- write_socket(fsockid,midbuf,strlen(midbuf));
- return(0);
- }
- int initbdata1()
- {
- memset((char *)b_datap1,0,BLEN1);
- memset(b_datap1->vflag,'0',1);
- memset(b_datap1->payacc,'0',19);
- memset(b_datap1->accept,'0',16);
- memset(b_datap1->clieno,'0',16);
- memset(b_datap1->machno,'0',8);
- memset(b_datap1->chipno,'0',6);
- memset(b_datap1->passwd,'0',16);
- memset(b_datap1->proofind,'0',2);
- memset(b_datap1->chequeno,'0',8);
- memset(b_datap1->incomacc,'0',19);
- memset(b_datap1->monies,'0',13);
- memset(b_datap1->limonies,'0',13);
- memset(b_datap1->signdate,'0',8);
- memset(b_datap1->bk,'0',48);
- memset(b_datap1->bk2,'0',48);
- memset(b_datap1->usrpasswd,'0',6);
- memset(b_datap1->payno,'0',12);
- memset(b_datap1->openo,'0',6);
- }