cxtcpcli.c
上传用户:sdtbys
上传日期:2009-12-06
资源大小:13k
文件大小:6k
- #include <stdio.h>
- #include <stdlib.h>
- #define Ret(M) memset(pk_out,' ',pk_out_len);strcpy(pk_out,M);
- #define pk_in_len 386
- #define pk_out_len 8
- int zhcx_tcpcli(char *pk_in,char *pk_out)
- {
- int sock;
- int ret;
- int time;
- char pkIP[30];
- char pkPORT[10];
- int count;
- int len;
- int i;
- char out[79];
- FILE *fp;
- char filename[20];
-
- memset(pkIP,0,sizeof(pkIP));
- memset(pkPORT,0,sizeof(pkPORT));
-
- memset(filename,0,20);
- ShowId("cxtcpcli:zhcx");
- GetEnv("/usr/zfmm/zfmm.cfg","[银河]IP",pkIP);
- GetEnv("/usr/zfmm/zfmm.cfg","[银河]PORT",pkPORT);
- /*取配置地址、端口*/
- #ifdef DEBUG
- ShowMsg("pktcpcli open IP=%s PORT=%sn",pkIP,pkPORT);
- #endif
- sock=sockClientOpen(pkIP,atoi(pkPORT)); /*连接*/
- if (sock <0)
- {
- #ifdef DEBUG
- ShowMsg("不能正确连接支付密码前置机! error=%dn",sock);
- #endif
- Ret("00004011");
- return (0);
- }
-
- #ifdef DEBUG
- LooKChar(pk_in,strlen(pk_in));
- #endif
- ret=sockSend(sock,pk_in,strlen(pk_in));
- if (ret <0)
- {
- #ifdef DEBUG
- ShowMsg("不能正确发送支付密码通讯包! error=%dn",ret);
- #endif
- Ret("00004012");
- sockClose(sock);
- return (0);
- }
- if (TimeOut(sock,70))
- {
- #ifdef DEBUG
- ShowMsg("接收支付密码前置机输出数据操时!n");
- #endif
- Ret("00004014");
- sockClose(sock);
- return(0);
- }
-
- timeoutopen(70);
- ret=sockRecv(sock,pk_out,pk_out_len);
- time=timeoutclose();
- if (time==0)
- {
- #ifdef DEBUG
- ShowMsg("接收支付密码前置机输出超时!n");
- #endif
- Ret("00004015");
- sockClose(sock);
- return (0);
- }
- if (ret <0)
- {
- #ifdef DEBUG
- ShowMsg("不能正确接收支付密码前置机输出! error=%dn",ret);
- #endif
- Ret("00004016");
- sockClose(sock);
- return (0);
- }
-
- #ifdef DEBUG
- LooKChar(pk_out,pk_out_len);
- #endif
- /****************************/
- count=(pk_out[0]-'0')*1000+(pk_out[1]-'0')*100+(pk_out[2]-'0')*10+(pk_out[3]-'0');
- /*fprintf(stderr,"count=%dn",count);*/
- if (count==0)
- return (0);
- len=79;
- strcat(filename,"/tmp/zhcx");
- strcat(filename,&pk_in[382]);
- fp=fopen(filename,"w");
- if (fp==NULL) return;
- for(i=0;i<count;i++)
- {
-
- timeoutopen(70);
- ret=sockRecv(sock,out,len);
- time=timeoutclose();
- if (time==0)
- {
- #ifdef DEBUG
- ShowMsg("接收支付密码前置机输出超时!n");
- #endif
- goto end;
- }
- if (ret <0)
- {
- #ifdef DEBUG
- ShowMsg("不能正确接收支付密码前置机输出! error=%dn",ret);
- #endif
- goto end;
- }
- #ifdef DEBUG
- LooKChar(out,len);
- #endif
- fwrite(out,8,1,fp);
- fputc('|',fp);
- fwrite(&out[8],2,1,fp);
- fputc('|',fp);
- fwrite(&out[10],32,1,fp);
- fputc('|',fp);
- fwrite(&out[42],10,1,fp);
- fputc('|',fp);
- fwrite(&out[52],1,1,fp);
- fputc('|',fp);
- fwrite(&out[53],1,1,fp);
- fputc('|',fp);
- fwrite(&out[54],8,1,fp);
- fputc('|',fp);
- fwrite(&out[62],8,1,fp);
- fputc('|',fp);
- fwrite(&out[70],8,1,fp);
- fputc('|',fp);
- fwrite(&out[78],1,1,fp);
- fputc('n',fp);
- }//for
- end:
- fclose(fp);
- /***************************/
- sockClose(sock);
- return (0);
-
- }
- int sbcx_tcpcli(char *pk_in,char *pk_out)
- {
- int sock;
- int ret;
- int time;
- char pkIP[30];
- char pkPORT[10];
- int count;
- int len;
- int i;
- char out[52];
- FILE *fp;
- char filename[20];
-
- memset(pkIP,0,sizeof(pkIP));
- memset(pkPORT,0,sizeof(pkPORT));
-
- memset(filename,0,20);
- ShowId("cxtcpcli:sbcx");
- GetEnv("/usr/zfmm/zfmm.cfg","[银河]IP",pkIP);
- GetEnv("/usr/zfmm/zfmm.cfg","[银河]PORT",pkPORT);
- /*取配置地址、端口*/
- #ifdef DEBUG
- ShowMsg("pktcpcli open IP=%s PORT=%sn",pkIP,pkPORT);
- #endif
- sock=sockClientOpen(pkIP,atoi(pkPORT)); /*连接*/
- if (sock <0)
- {
- #ifdef DEBUG
- ShowMsg("不能正确连接支付密码前置机! error=%dn",sock);
- #endif
- Ret("00004011");
- return (0);
- }
-
- #ifdef DEBUG
- LooKChar(pk_in,strlen(pk_in));
- #endif
- ret=sockSend(sock,pk_in,strlen(pk_in));
- if (ret <0)
- {
- #ifdef DEBUG
- ShowMsg("不能正确发送支付密码通讯包! error=%dn",ret);
- #endif
- Ret("00004012");
- sockClose(sock);
- return (0);
- }
- if (TimeOut(sock,70))
- {
- #ifdef DEBUG
- ShowMsg("接收支付密码前置机输出数据操时!n");
- #endif
- Ret("00004014");
- sockClose(sock);
- return(0);
- }
-
- timeoutopen(70);
- ret=sockRecv(sock,pk_out,pk_out_len);
- time=timeoutclose();
- if (time==0)
- {
- #ifdef DEBUG
- ShowMsg("接收支付密码前置机输出超时!n");
- #endif
- Ret("00004015");
- sockClose(sock);
- return (0);
- }
- if (ret <0)
- {
- #ifdef DEBUG
- ShowMsg("不能正确接收支付密码前置机输出! error=%dn",ret);
- #endif
- Ret("00004016");
- sockClose(sock);
- return (0);
- }
-
- #ifdef DEBUG
- LooKChar(pk_out,pk_out_len);
- #endif
- /****************************/
- count=(pk_out[0]-'0')*1000+(pk_out[1]-'0')*100+(pk_out[2]-'0')*10+(pk_out[3]-'0');
- /*fprintf(stderr,"count=%dn",count);*/
- if (count==0)
- return (0);
- len=52;
- strcat(filename,"/tmp/sbcx");
- strcat(filename,&pk_in[382]);
- fp=fopen(filename,"w");
- if (fp==NULL) return;
- for(i=0;i<count;i++)
- {
-
- timeoutopen(70);
- ret=sockRecv(sock,out,len);
- time=timeoutclose();
- if (time==0)
- {
- #ifdef DEBUG
- ShowMsg("接收支付密码前置机输出超时!n");
- #endif
- goto end;
- }
- if (ret <0)
- {
- #ifdef DEBUG
- ShowMsg("不能正确接收支付密码前置机输出! error=%dn",ret);
- #endif
- goto end;
- }
- #ifdef DEBUG
- LooKChar(out,len);
- #endif
- fwrite(out,8,1,fp);
- fputc('|',fp);
- fwrite(&out[8],10,1,fp);
- fputc('|',fp);
- fwrite(&out[18],8,1,fp);
- fputc('|',fp);
- fwrite(&out[26],1,1,fp);
- fputc('|',fp);
- fwrite(&out[27],1,1,fp);
- fputc('|',fp);
- fwrite(&out[28],8,1,fp);
- fputc('|',fp);
- fwrite(&out[36],8,1,fp);
- fputc('|',fp);
- fwrite(&out[44],8,1,fp);
- fputc('n',fp);
- }//for
- end:
- fclose(fp);
- /***************************/
- sockClose(sock);
- return (0);
-
- }