一,要发送的报文,转化成16进制的,报文如下
"\x01\x52"//报文长度338
"\x60\x00\x24\x00\x00"//TPDU
"\x60\x22\x00\x17\x04\x02"//报文头
"\x02\x00"//应用数据
"\x70\x24\x06\xC0\x20\xC0\x9A\x31"//位图2,3,4,11,14,22,23,25,26,35,41,42,49,52,53,55,59,60,64
"\x19"//域2长度
"<借记卡号>"//域2 6225683621000897490 \x62\x25\x68\x36\x21\x00\x08\x97\x49\x00
"\x00\x00\x00"//域3
"\x00\x00\x00\x00\x00\x25"//域4
"<系统跟踪号>"//域11 流水号 \x02\x02\x34
"\x28\x08"//域14卡有效期 有效期不校验
"\x05\x10"//域22
"\x00\x01"//域23
"\x00"//域25
"\x12"//域26
"\x37"//域35长度
"\x62\x25\x68\x36\x21\x00\x08\x97\x49\x3D\x28\x08\x22\x01\x47\x00\x00\x01\x00"//域35 核心第二磁道是否校验 \x62\x14\x62\x21\x43\x00\x00\x88\x28\x3D\x28\x08\x22\x01\x47\x00\x00\x01\x00
"\x31\x31\x30\x30\x30\x30\x30\x31"//域41* 11000001
"\x33\x30\x36\x35\x38\x38\x32\x36\x33\x30\x30\x30\x30\x30\x31"//域42 306588263000001
"\x31\x35\x36"//域49
"\x5A\xB1\xBA\xA5\xBE\x55\xC0\xCE"//域52 PIN 核心校验
"\x26\x00\x00\x00\x00\x00\x00\x00"//域53 2带主账号的加密方式
"\x01\x38"//域55长度
"\x9F\x26\x08\x82\xCD\xFB\x9F\x42\xB3\x51\xF2\x9F\x27\x01\x80\x9F\x10\x13\x07\x01"
"\x01\x03\xA0\xA0\x04\x01\x0A\x01\x00\x00\x00\x00\x00\x16\xEB\xF0\x9B\x9F\x37\x04"
"\xF4\x3E\x4C\x87\x9F\x36\x02\x00\xF1\x95\x05\x08\x00\x04\x60\x00\x9A\x03\x17\x05"
"\x03\x9C\x01\x00\x9F\x02\x06\x00\x00\x00\x00\x00\x25\x5F\x2A\x02\x01\x56\x82\x02"
"\x7C\x00\x9F\x1A\x02\x01\x56\x9F\x33\x03\xE0\xF0\xC8\x9F\x34\x03\x02\x03\x00\x9F"
"\x35\x01\x22\x84\x08\xA0\x00\x00\x03\x33\x01\x01\x01\x9F\x09\x02\x00\x20\x9F\x1E"
"\x08\x38\x34\x36\x37\x36\x39\x35\x39\x9F\x03\x06\x00\x00\x00\x00\x00\x00"//域55 ARQC校验 交换校验IC卡芯片是否为伪芯片
"\x00\x62"//域59长度
"\x41\x32\x30\x35\x37\x30\x31\x30\x30\x32\x30\x32\x30\x32\x30\x30\x38\x38\x34\x36"
"\x37\x36\x39\x35\x39\x30\x33\x30\x30\x36\x30\x38\x38\x32\x38\x33\x30\x34\x30\x30"
"\x38\x20\x20\x20\x20\x20\x20\x20\x20\x30\x35\x30\x30\x38\x31\x37\x30\x34\x30\x32\x20\x20"//域59
"\x00\x19"//域60长度
"\x22\x00\x00\x05\x00\x05\x03\x00\x10\x00"//域60 \x22【\x00\x00\x01批次号每次测试都要改】\x00\x05\x0【3\x00\x1】0\x00 \x22\x00\x00\x01\x00\x05\x09\x00\x10\x00
"\x4D\x1B\x8D\xD9\x04\xF2\xA7\xA8"//域64 MAC 卡交换和核心都校验 如上3001此次改造点
ACTION编写的脚本如下:
#include "lrs.h" typedef long time_t;
struct _timeb
{
time_t time;
unsigned short millitm;
short timezone;
short dstflag;
};
struct _timeb SendTime ;
int toHexString(char* OutStr,char* InStr,int len);
static int ef_millitm=;
static int quchong=;
Action()
{ int rc = ;
int SndBufLen;
int RecBufLen;
char *RecBuf;
double trans_time;
int opt_value;
char tmp[]={};
char res[]={};
char ACC[]={}; ftime(&SendTime); //lr_error_message("time:%d,millitm:%d,ip:%s",SendTime.time,SendTime.millitm,lr_eval_string("<IP_PORT>")); if(ef_millitm==SendTime.millitm)
{
sprintf(tmp,"%03d%03d",(SendTime.time%),(SendTime.millitm+quchong));
quchong++;
}
else
{ sprintf(tmp,"%03d%03d",(SendTime.time%),SendTime.millitm);
quchong=;
} ef_millitm=SendTime.millitm;
//lr_error_message("SendTime.time = %d",SendTime.millitm);
//lr_error_message("SendTime.time = %d",SendTime.time%1000); toHexString(res,tmp,);
toHexString(ACC,lr_eval_string("<AC_1>"),);
//lr_error_message("tes = %s",tmp);
lr_save_string(res,"系统跟踪号");
lr_save_string(ACC,"借记卡号"); // 建立发送通道连接 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
lr_start_transaction("消费"); // 发送报文 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
lr_start_transaction("消费_发送报文");
rc = lrs_send(lr_eval_string("<p_Socket>"), "SendBuf1", LrsLastArg);
if(rc == )
{
lr_end_transaction("消费_发送报文", LR_PASS);
}
else
{
lr_end_transaction("消费_发送报文", LR_FAIL);
lr_end_transaction("消费", LR_FAIL);
lr_error_message("消费_发送报文失败;错误码是:%d;", rc);
// lrs_disable_socket(lr_eval_string("<p_Socket>"), DISABLE_SEND_RECV);
// lrs_close_socket(lr_eval_string("<p_Socket>"));
lr_exit(LR_EXIT_ITERATION_AND_CONTINUE, LR_FAIL);
}
rc = ;
//RecBuf = (char*)calloc(1024, sizeof(char));
// 接收报文 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++=+++++++++++++++++++++++++
lr_start_transaction("消费_接收报文");
rc = lrs_receive(lr_eval_string("<p_Socket>"), "ReceiveBuf1", LrsLastArg); trans_time=lr_get_transaction_duration("消费"); if(trans_time>)
{
lr_error_message("消费响应时间为:%f,请求流水号为:%s",trans_time,res);
} if((rc == )||(rc == ))
{
lrs_get_last_received_buffer(lr_eval_string("<p_Socket>"), &RecBuf, &RecBufLen); if(RecBufLen == )
{
lr_end_transaction("消费_接收报文", LR_FAIL);
lr_end_transaction("消费", LR_FAIL);
//lr_error_message("交易出错!出错的流水号是:%s",lr_eval_string("<DateTime><VuserID><Number>"));
lr_error_message("消费 未接收到返回,卡号:%s,流水号:%s",lr_eval_string("<AC_1>"),tmp);
lr_exit(LR_EXIT_ITERATION_AND_CONTINUE, LR_FAIL);
}
else if(RecBufLen != )
{
lrs_save_param(lr_eval_string("<p_Socket>"),NULL,"rsp_code_1",,);
lr_end_transaction("消费_接收报文", LR_FAIL);
lr_end_transaction("消费", LR_FAIL);
lrs_free_buffer(RecBuf); lr_error_message("消费返回报文不正确,长度:%d,流水号:%s,应答码:%s,ip:%s",RecBufLen,tmp,lr_eval_string("<rsp_code_1>"),lr_eval_string("<IP_PORT>"));
lr_exit(LR_EXIT_ITERATION_AND_CONTINUE, LR_FAIL);
}
lrs_save_param_ex(lr_eval_string("<p_Socket>"), "user", RecBuf, , RecBufLen, "ascii", "NewRecBuf");
//判断卡是否正常 需要删除
// lrs_save_param(lr_eval_string("<p_Socket>"),NULL,"rsp_code_1",74,10);
// if(strcmp(lr_eval_string("<rsp_code_1>"),"00")!= 0)
// {
// lr_error_message("出错报文定位的报文是:%s,卡号:%s,流水号:%s", lr_eval_string("<rsp_code_1>"),lr_eval_string("<AC_1>"),res);
// }
//
lrs_save_param(lr_eval_string("<p_Socket>"),NULL,"rsp_code",,);
//lr_save_var(lr_eval_string("<NewRecBuf>")+182,2,0,"ret"); //lr_error_message("======定位的报文是:%s", lr_eval_string("<rsp_code>")); if(strcmp(lr_eval_string("<rsp_code>"),"")==)
{
lr_end_transaction("消费_接收报文", LR_PASS);
lr_end_transaction("消费", LR_PASS);
}
else
{
lr_end_transaction("消费_接收报文", LR_FAIL);
lr_end_transaction("消费", LR_FAIL);
//lr_error_message("交易出错!出错的流水号是:%s",lr_eval_string("<DateTime><VuserID><Number>"));
lr_error_message("交易出错!卡号:%s,流水号是:%s",lr_eval_string("<AC_1>"),tmp);
}
}
else
{
lr_end_transaction("消费_接收报文", LR_FAIL);
lr_end_transaction("消费", LR_FAIL);
lr_error_message("消费_接收报文失败;错误码是:%d,流水号:%s", rc,res);
lrs_free_buffer(RecBuf);
lr_exit(LR_EXIT_ITERATION_AND_CONTINUE, LR_FAIL);
} lrs_free_buffer(RecBuf); return ;
} //将字符串转换成16进制 //855071 变为\x85\x50\x71
int toHexString(char* OutStr,char* InStr,int len)
{
int i=;
for(;i<len;i++)
{
if((i==)||(i%==))
{
sprintf(OutStr+*i,"%s%c","\\x",(unsigned char)InStr[i]);
}
else
{
sprintf(OutStr+*i+,"%c",(unsigned char)InStr[i]);
}
}
return ;
}