📄 bms_pub.c
字号:
#include <stdio.h>#include <stdlib.h>#include <string.h>#include <time.h>#include <memory.h>#include "etc.h"#include "apgloble.h"void pub_FAX_get_date( char *str) ;void pub_get_date( char *str) ;char Host_Ip[ 20 + 1] ;int Host_Port ;char etcfile[128];char dbfile[128];int ActiveLog = 0;char uid[32], pwd[32], svc[32];char max_limit_amt[32];double Max_Limit_Amt = 0.00;int GetError( char *Error, short result, int side);int IsRemoteTx(int optcode);char *get_time_ymd(const char *format, char *str);extern int RetCode;extern int DB_connectDB(char *uid, char *pwd, char *svc);extern int DB_GenSerialNo(int *ActiveLog, BIG_STRC *bs);extern int DB_LogTransaction(int ActiveLog, BIG_STRC *bs);/* 可以增加读配置程序 */int get_profile(BIG_STRC *bs){ /* 主机交易配置文件 */ memset(etcfile, 0, sizeof(etcfile)); sprintf(etcfile, "%s/etc/host.cfg", getenv("HOME")); /* 数据库配置文件 */ memset(dbfile, 0, sizeof(dbfile)); sprintf(dbfile, "%s/etc/database.cfg", getenv("HOME")); /* uid */ memset(uid, 0, sizeof(uid)); if(GetValueFromEtcFile(etcfile, "DATABASE", "userid", uid, 32)!=ETC_OK) { bms_trace("GetValueFromEtcFile FOR DATABASE failed"); return FAILURE; } /* pwd */ memset(pwd, 0, sizeof(pwd)); if(GetValueFromEtcFile(etcfile, "DATABASE", "password", pwd, 32)!=ETC_OK) { bms_trace("GetValueFromEtcFile FOR DATABASE failed"); return FAILURE; } /* service */ memset(svc, 0, sizeof(svc)); if(GetValueFromEtcFile(etcfile, "DATABASE", "service", svc, 32)!=ETC_OK) { bms_trace("GetValueFromEtcFile FOR DATABASE failed"); return FAILURE; } /* max_limit_amt */ memset(max_limit_amt, 0, sizeof(max_limit_amt)); if(GetValueFromEtcFile(etcfile, "BMS_PARAM", "max_limit_amt", max_limit_amt, 32)!=ETC_OK) { bms_trace("GetValueFromEtcFile FOR BMS_PARAM failed"); return FAILURE; } Max_Limit_Amt = atof(max_limit_amt); if ( DB_connectDB(uid, pwd, svc) < SUCCESS ) { fprintf( stdout, "Connected to Database Server FAILURE!\n") ; return( FAILURE) ; } bms_trace("Connected to Database Server OK!\n") ; return( SUCCESS) ;}/* 可以增加事前处理程序 */int begin_work(TRADE_HEAD *tr_h, BIG_STRC *bs){ char key[128]; char tmp[1024]; int flag = -1; if(DB_GenSerialNo(&ActiveLog, bs) ) { bs->result = 1005; return FAILURE; } if( IsRemoteTx(bs->optcode) == TRUE ) { memset(key, 0, sizeof(key)); sprintf(key, "BITMAPS %04d", bs->optcode); memset(tmp, 0, sizeof(tmp)); if(GetValueFromEtcFile(etcfile, key, "RSPN_DTL", tmp, 512) != ETC_OK) { bms_trace("RSPN [%d] failed", bs->optcode); bs->result = 1408; return FAILURE; } if( strcmp(tmp, "NONE") && strcmp(tmp, "") ) { sprintf(bs->address, "%05d.%04d",bs->trade_serial,bs->optcode); //sprintf(bs->address, "%d%d",bs->trade_serial,bs->optcode); } } return( SUCCESS) ;}/* 可以增加事后处理程序 */int end_work( BIG_STRC *bs){ if(strlen(bs->errinfo) == 0) GetError(bs->errinfo, bs->result, 1); if(bs->optcode != 9002 && bs->optcode != 9613 && bs->optcode != 9616 && bs->optcode != 9617 && bs->optcode != 9618 && bs->optcode != 9619 && bs->optcode != 9620 && bs->optcode != 9621 && bs->optcode != 9622 && bs->optcode != 9051 && bs->optcode != 1901 && bs->optcode != 1907 ) { DB_LogTransaction(ActiveLog, bs); } return( SUCCESS) ;}/* 可以增加程序退出前处理 */int sys_exit(){ DB_closeDB() ; return( SUCCESS) ;}void fdis_bs( FILE *oFp, BIG_STRC *bs){ char str[ 30] ; pub_get_date( str) ;fprintf( oFp, "BMS[%d] [%s]--------- Big Strucr Begin ------>>\n", mypid, str) ;fprintf( oFp, "Optcode=[%d] Form1=[%s] Form2=[%s]\n", trade_ctl.optcode, trade_ctl.form1, trade_ctl.form2) ;fprintf( oFp, "Side=[%d] Serv_type=[%s] Busin_type=[%d] Trade_type=[%d]\n", bs->side, bs->serv_type, bs->busin_type, bs->trade_type) ; fprintf( oFp, "Teller=[%s] Zoneno=[%d] Ctype=[%d] Cid=[%s] Bid=[%d] Serial=[%ld]\n", bs->teller, bs->zoneno, bs->ctype, bs->cid, bs->bid, bs->trade_serial) ;fprintf( oFp, "Result=[%d] Svr_date=[%s] Svr_time=[%s]\n", bs->result, bs->serv_date, bs->serv_time) ; fprintf( oFp, "Debi_aid=[%s] Debi_acct_type=[%d] Debi_bank=[%s] Debi_acct=[%s]\n", bs->debi_aid, bs->debi_acct_type, bs->debi_bank, bs->debi_acct) ;fprintf( oFp, "Cred_aid=[%s] Cred_acct_type=[%d] Cred_bank=[%s] Cred_acct=[%s]\n", bs->cred_aid, bs->cred_acct_type, bs->cred_bank, bs->cred_acct) ;fprintf( oFp, "Debi_amt=[%lf] Cred_amt=[%lf] Debi_curr[%d]\n", bs->debi_amt, bs->cred_amt, bs->debi_curr) ;fprintf( oFp, "Debi_bala=[%lf] Cred_bala=[%lf] Cred_curr[%d]\n", bs->debi_bala, bs->cred_bala, bs->cred_curr) ; fprintf( oFp, "Abstract=[%s] Deduct_type=[%d] Pz_type=[%d] Pz_num=[%s]\n", bs->abstract, bs->deduct_type, bs->pz_type, bs->pz_num) ;fprintf( oFp, "Bill_flg=[%d] Source_typ=[%d] Source_ser=[%ld] Sonsign=[%s] ", bs->bill_flg, bs->source_typ, bs->source_ser, bs->sonsign_no) ;fprintf( oFp, "Purchase=[%ld]\n", bs->purchase_num) ;fprintf( oFp, "Address=[%s] Name=[%s] Detail_num[%d] ", bs->address, bs->name, bs->detail_num);fprintf( oFp, "Postcode=[%s] Tele=[%s] Index=[%s]\n", bs->postcode, bs->tele, bs->index) ;fprintf( oFp, "Termno=[%s] Incall_num=[%s] Call_id=[%s]\n", bs->term_no, bs->incall_num, bs->call_id) ;fprintf( oFp, "Notes1=[%s] Notes2=[%s] Notes3=[%s] ", bs->notes1, bs->notes2, bs->notes3) ;fprintf( oFp, "Notes4=[%s] Notes5=[%s]\n", bs->notes4, bs->notes5) ;fprintf( oFp, "City=[%s] Brch=[%s] Date1=[%s] Date2=[%s] Flag[%s]\n", bs->city_no, bs->trade_brch, bs->date1, bs->date2, bs->flag) ;fprintf( oFp, "Passwd1=[%s] Passwd2=[%s] errinfo=[%s]\n", bs->passwd1, bs->passwd2,bs->errinfo) ;fprintf( oFp, "RetBuf=[%s] \n", bs->buf) ;fprintf( oFp, "Notes6=[%s] ", bs->notes6) ;fprintf( oFp, "Notes7=[%s] ", bs->notes7) ;fprintf( oFp, "Notes8=[%s] ", bs->notes8) ;fprintf( oFp, "Notes9=[%s] ", bs->notes9) ;fprintf( oFp, "Notes10=[%s] \n", bs->notes10) ;fprintf( oFp, "--------------------------- END -------------------------<<\n");fflush(oFp);}void dis_big_strc(char *cmd, BIG_STRC *bs){ if(!debug) return ; printf("[%s] ================>\n", cmd); fdis_bs(stdout, bs); printf("END ===================================================<\n"); return ;}void print_fax_head( FILE *fp, char *title, char *file_abs){ fprintf( fp, " 包头商业银行%s交易明细单\n",file_abs) ; fprintf( fp, "帐号:%s\n\n", title) ; return ;}void print_fax_tail( FILE *fp){ char tmp[60]; memset(tmp, 0, sizeof(tmp)); pub_FAX_get_date( tmp) ; fprintf( fp, "|\n 查询时间:%s|\n", tmp) ; fprintf( fp, "|欢迎使用包头商业银行96016电话银行系统,传真仅供参考.|\n"); return ;}int GetError( char *Error, short result, int side){ FILE *fp ; char filename[ 80], str[ 256] ; char error1[64], error2[64]; char tmp[ 10] ; sprintf( filename, "%s/dat/error.dat", getenv("HOME")) ; if ( (fp=fopen( filename, "rb+")) == NULL ) { sprintf( Error, "错误码对应文件不存在."); return( FAILURE) ; } while (!feof( fp)) { memset( str, '\0', sizeof( str)) ; if ( fgets( str, 256, fp) == NULL ) break ; if ( str[ 0] == '-' || str[ 0] == '[' || str[ 0] == '#' ) continue ; memset( tmp, '\0', sizeof( tmp)) ; memset( error1, '\0', sizeof( error1)) ; memset( error2, '\0', sizeof( error2)) ; if ( sscanf( str, "%s %s %s\n", tmp, error1, error2) != 3 ) { continue ; } if ( atoi( tmp) == result ) { if( side == 1) { strcpy(Error, error1); } else { strcpy(Error, error2); } fclose( fp) ; return( SUCCESS) ; } } fclose( fp) ; sprintf( Error, "请先配置对应的错误信息."); return( SUCCESS) ;}char *alltrim(char *str){ static char buffer[81]; int i, j, k; for (i = 0; str[i] == ' ' && str[i] != '\0'; i++); for (j = strlen(str) - 1; str[j] == ' ' && j >= 0 ; j--); for (k = 0; k <= j - i; k++) buffer[k] = str[k + i]; buffer[k] = '\0'; return buffer;}int getfiledes( char *filename, FILE **ivrfp, FILE **faxfp ){ char ivr[80], fax[80]; sprintf( ivr, "%s/tmp/%s.ivr",getenv("HOME"), filename) ;/*IVR语音文件名*/ sprintf( fax, "%s/tmp/%s.fax",getenv("HOME"), filename) ;/*传真文件名*/ bms_trace("filename %s",filename); if ( (*ivrfp=fopen( ivr, "wb+")) == NULL || (*faxfp=fopen( fax, "wb+")) == NULL ) { fclose( *ivrfp ) ; fclose( *faxfp ) ; unlink( ivr ) ; unlink( fax ) ; return( FAILURE) ; } return( SUCCESS );}void GetValue(char *value, char *str, int len, int pos){ int i,j; int pps; char tmp[512]; pps = pos-1; memset(tmp,'\0',sizeof(tmp)); j=0; for (i=0;i<len;i++) { if (pps==0) { tmp[j] = str[i]; j++; } if (str[i]=='|') { pps = pps - 1; if (pps<0) { tmp[j-1] = '\0'; tmp[j]='\0'; break; } } } memset(value,'\0',sizeof(value)); strcpy(value, tmp);}int get_ini_data( char *inifilename, char *optcode, char *data ){ int i=0 ; char tmp1[10], proxyfile[80]; char str[256], field1[ 50], field2[50]; FILE *fp; sprintf( proxyfile, "%s/dat/%s.ini", getenv("HOME"),inifilename); sprintf(tmp1,"%s",optcode );/* sprintf(tmp2,unitno );*/ if( (fp = fopen( proxyfile, "r")) != NULL) { while( !feof( fp)){ if ( fgets( str, 256, fp) == NULL ) break ; if ( str[ 0] == '-' || str[ 0] == '[' || str[ 0] == '#' ) continue ; if ( sscanf( str, "%s %s", field1, field2) != 2) continue; if(strcmp( field1, tmp1) == 0) { i++; sprintf(data,field2); break; } } fclose( fp) ; } if (i==0) { return(FAILURE) ; } return( SUCCESS) ;}int get_curr( char *code,char *index ,char *content){ struct { char curr[ 3] ; char index[12]; char content[ 12] ; } arr[ 11]={ "01", "人民币","人民币 ", "12", "英镑","英镑 ", "13", "港币","港币 ", "14", "美元","美元 ", "15", "瑞士法朗","瑞士法朗 ", "16", "德国马克","德国马克 ", "17", "法国法朗","法国法朗 ", "27", "日元","日元 ", "28", "加拿大元","加拿大元 ", "29", "澳大利亚元","澳大利亚元", "38", "欧元", "欧元 " } ; int i ; for ( i = 0 ; i < 11 ; i ++ ) { if ( strcmp( arr[ i].curr, code) == 0 ) { strcpy( content, arr[ i].content) ; strcpy( index, arr[ i].index) ; return( SUCCESS) ; } } return( FAILURE) ;}int get_jdbz( char *code,char *index ,char *content){ struct { char curr[2] ; char index[12]; char content[ 12] ; } arr[ 11]={ "0", "借","借", "1", "贷","贷", } ; int i ; for ( i = 0 ; i < 11 ; i ++ ) { if ( strcmp( arr[ i].curr, code) == 0 ) { strcpy( content, arr[ i].content) ; strcpy( index, arr[ i].index) ; return( SUCCESS) ; } } return( FAILURE) ;}int get_zhlx( int code,char *index ){ struct { int code; char index[12]; } arr[ 11]={ 0, "(约定)", 1, "", } ; int i ; for ( i = 0 ; i < 11 ; i ++ ) { if ( arr[ i].code== code ) { strcpy( index, arr[ i].index) ; return( SUCCESS) ; } } return( FAILURE) ;}void pub_get_year_second( char *str){ struct tm *current_time, time_buf ; time_t t1 ; time( &t1) ; current_time = localtime ( &t1) ; current_time -> tm_year = current_time -> tm_year + 1900 ; sprintf( str , "%04d-%02d-%02d %02d:%02d:%02d", current_time -> tm_year, current_time -> tm_mon + 1, current_time -> tm_mday, current_time -> tm_hour, current_time -> tm_min, current_time -> tm_sec) ; return ;}int dis_hex( char *file,int iLine,unsigned char *buf, int len){ int i, j, line ; unsigned char *p, *q ; char str[ 30] ; char sFile[60],sTime[20] ; FILE *fp ; memset(sFile, 0, sizeof(sFile)); sprintf(sFile, "%s/log/hex.%08ld", getenv("HOME"), GetDate()); if ( (fp=fopen( sFile, "ab+")) == NULL ) return 0 ; fprintf( fp, "F[%s],L[%d] %s <%05d> dis_hex >>\n",file,iLine,getpid()); p = buf ; q = buf ; line = len / 16 ; for ( i = 0 ; i < line ; i++ ) { fprintf( fp, "HEX%07d=< ", i*16) ; for ( j = 0 ; j < 16 ; j++ ) fprintf( fp, "%02x ", *p++) ; fprintf( fp, "> ") ; for ( j = 0 ; j < 16 ; j++, q++) fprintf( fp, "%c",(*q>32) ? ((*q<128) ? *q :'*') :'.') ; fprintf( fp, "\n") ; } i = len - line * 16 ; if ( i > 0) { fprintf( fp, "HEX%07d=< ", line*16) ; for( j = 0 ; j < i ; j++ ) fprintf( fp, "%02x ", *p++) ; for( j = i ; j < 16 ; j++) fprintf( fp, " ") ; fprintf( fp, "> ") ; for ( j = 0 ; j < i ; j++, q++) fprintf( fp, "%c",(*q>32) ? ((*q<128) ? *q :'*') :'.') ; fprintf( fp, "\n") ; } fprintf( fp, "F[%s],L[%d] <%05d> dis_hex <<\n", file,iLine,getpid()) ; fclose( fp) ; return( 0) ;}int IsRemoteTx(int optcode){ int i=0 ; char CodeFile[128]; char str[256]; char field1[10], field2[10]; FILE *fp; memset(CodeFile, 0, sizeof(CodeFile)); sprintf( CodeFile, "%s/etc/txcode.ini", getenv("HOME")); if((fp = fopen(CodeFile, "r")) != NULL) { while(!feof(fp)) { if(fgets(str, 256, fp) == NULL ) break ; if(str[0] == '-' || str[0] == '[' || str[0] == '#' ) { continue; } if(sscanf(str, "%s %s", field1, field2) != 2) { continue; } if( optcode == atoi(field1) ) { i++; break; } } fclose( fp) ; } if(i==0) { return(FALSE) ; } return(TRUE) ;} /*** 函数原型: char *gettime(const char *format, char *string) ** 说 明: 按format格式化时间到string中,返回string*/char *get_time_ymd(const char *format, char *str) { time_t current; current = time(NULL); strftime(str, 30, format, localtime((const time_t *)¤t)); return str;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -