|
5#
楼主 |
发表于 2008-8-11 11:29:32
|
只看该作者
//Action
#include "lrs.h"
#include "template.h"
typedef long time_t;
struct tm {
int tm_sec; /* seconds after the minute - [0,59] */
int tm_min; /* minutes after the hour - [0,59] */
int tm_hour; /* hours since midnight - [0,23] */
int tm_mday; /* day of the month - [1,31] */
int tm_mon; /* months since January - [0,11] */
int tm_year; /* years since 1900 */
int tm_wday; /* days since Sunday - [0,6] */
int tm_yday; /* days since January 1 - [0,365] */
int tm_isdst; /* daylight savings time flag */
};
char oldField38[7];
char * psTsName = NULL;
Action()
{
int i;
char * templatebuf;
int flag = 0; //交易类型,0-独立交易,1-关联交易
lr_continue_on_error(1);
for (i=0; i<17; i++)
{
flag = msgtemplate.flag;
templatebuf = msgtemplate.msg;
psTsName = msgtemplate.casename;
lr_output_message("Case NO. = [%s], Case Name =[%s]\n",msgtemplate.caseno,msgtemplate.casename);
dotransaction(templatebuf,flag,psTsName);
}
lr_continue_on_error(0);
}
int dotransaction(char *templatebuf, int flag, char * psTsName)
{
int rc,sendlen;
char *inputbuf, buf8583[800], msghead[55], msglen[5], msgtype[5];
memset(msglen,0,sizeof(msglen));
memset(msgtype,0,sizeof(msgtype));
strncpy(msglen, templatebuf, 4);
memcpy(msgtype, templatebuf+50, 4);
sendlen = atoi(msglen);
memset(buf8583, 0, sizeof(buf8583));
memcpy(buf8583, templatebuf+54, sendlen-50);
memset(msghead,0,sizeof(msghead));
memcpy(msghead,templatebuf,54);
init_master_8583();
unpack_master_8583(buf8583);
set_parm(msgtype,flag);
sendlen = pack_master_8583(buf8583);
sendlen += 50;
memset(msglen, 0, sizeof(msglen));
sprintf(msglen,"%04d",sendlen);
memcpy(msghead, msglen, 4);
memcpy(msghead+6, msglen, 4);
inputbuf = (char*)malloc(sendlen+4);
if (NULL == inputbuf)
{
lr_error_message("=====inputbuf内存分配失败!!!!=====");
return -1;
}
memset(inputbuf,0,sendlen+4);
memcpy(inputbuf,msghead,54);
memcpy(inputbuf+54,buf8583,sendlen-50);
lrs_set_send_buffer("socket5",inputbuf,sendlen+4);
lr_start_transaction(psTsName);
rc = lrs_send("socket5", "buf0", LrsLastArg);
if (0!=rc) {
lr_error_message("An error occurred while sending to the socket, Error Code: %d", rc);
lr_end_transaction(psTsName,LR_FAIL);
return -1;
}
lrs_free_buffer(inputbuf);
lr_end_transaction(psTsName,LR_AUTO);
return 0;
}
[ 本帖最后由 豆奶板蓝根 于 2008-8-11 11:32 编辑 ] |
|