|
这几天一直在弄一个loadrunner的cs测试脚本,使用windows socket的cs脚本,弄了几天终于弄出点东
东来。
偶的测试脚本如下:
unsigned char uc_key[9];
unsigned char pinkey[17];
unsigned char *mask = (unsigned char *) "19?2<8276:=0839;";
Action()
{
char acTest[512];
char acTest2[512];
char* pcTest3;
int i;
char pinblock[17];
char acct[26];
char acc1[17];
char balance[12];
char seq_str[6];
int i_seq=1;
char socket_desc[10];
int handler;
int ret;
lr_load_dll("mydll.dll");
i_seq++;
sprintf(seq_str,"%.5d",i_seq);
sprintf(socket_desc,"sock%.5d",i_seq);
//char *filename="1.out";
//long filestream;
//filestream=fopen(filename,"w");
lrs_create_socket(socket_desc, "TCP", "RemoteHost=192.168.101.79:7001",
LrsLastArg);
//生成发送的串
sprintf(acTest,"ABCDEA");
strcat(acTest,"1205");
strcat(acTest,"RQK");
strcat(acTest,seq_str);
strcat(acTest,seq_str);
strcat(acTest,"0000000000000000O");
//指定发送的串
lrs_set_send_buffer (socket_desc, acTest, strlen(acTest));
//发送,由于之前运行了lrs_set_send_buffer,所以这里的"buf0"参数无效
lrs_send(socket_desc, "buf0", LrsLastArg);
lrs_set_recv_timeout2(0,0);
//接收返回的串
lrs_receive(socket_desc, "buf1", LrsLastArg);
//把返回的串放到变量中
pcTest3=lrs_get_received_buffer (socket_desc, 0, -1, NULL);
//fprintf(filestream,"recv=[%s]\n",pcTest3);
memcpy(uc_key,pcTest3+18,8);
unshuffle_key(uc_key);
//lr_output_message("recv=[%s]\n",pcTest3);
lr_output_message("uc_key=[%s]\n",uc_key);
memset(pinkey,0,sizeof(pinkey));
for (i = 0; i < strlen(uc_key);i++)
{
pinkey[2*i]='3';
pinkey[2*i+1]=uc_key;
}
lr_output_message("pinkey=[%s]\n",pinkey);
//对返回串中的数据操作
if( (strncmp(pcTest3,"ABP",3))==0 )
{
//modadd((unsigned char *)uc_key,(unsigned char *)"35827629",8);
//lr_output_message("next uc_key=[%s]\n",uc_key);
//String header = "ABCDEA" + terminalid + tranactioncode + seq + seq +
"0124011200000002C";
//header 6+4+3+5+5+17
i_seq++;
sprintf(socket_desc,"sock%.5d",i_seq);
sprintf(seq_str,"%.5d",i_seq);
sprintf(acTest2,"ABCDEA");
strcat(acTest2,"1205");
strcat(acTest2,"INQ");
strcat(acTest2,seq_str);
strcat(acTest2,seq_str);
strcat(acTest2,"0000000000000000O");
//sprintf(acTest,"ABCDEA1205INQ09046090460000000000000000O");
//track3,track2 104+37
strcat
(acTest2,"999551002600007435017=1561560000000000000003000000214000000001
=000000000000=000000000000=0000000274060009551002600007435017
=00002202740600000");
//pinblock
strcpy(pinblock,"1205000006111111");
encrypt_pinblock((unsigned char *)pinblock,pinkey);
lr_output_message("encrypted pinblock=[%s]\n",pinblock);
strcat(acTest2,pinblock);
//account
strcpy(acct,"9551002600000000115000000");
memcpy(acc1,acct+2,16);
shuffle((unsigned char *)acc1, (const unsigned char *)uc_key,(const unsigned
char *)mask, 16);
strcpy(acct,"95");
memcpy(acct+2,acc1,16);
memcpy(acct+2+16,"5000000",7);
strcat(acTest2,acct);
lrs_create_socket(socket_desc, "TCP", "RemoteHost=192.168.101.79:7001",
LrsLastArg);
// handler=lrs_get_socket_handler(socket_desc);
// lr_output_message("handler=[%d]\n",handler);
ret=lrs_set_send_buffer (socket_desc, acTest2, strlen(acTest2));
lr_output_message("ret=[%d]\n",ret);
lrs_send(socket_desc, "buf0", LrsLastArg);
lrs_set_recv_timeout2(0,0);
lrs_receive(socket_desc, "buf1", LrsLastArg);
pcTest3=lrs_get_received_buffer (socket_desc, 0, -1, NULL);
//lr_output_message("recv2=[%s]\n",pcTest3);
memset(balance,0,sizeof(balance));
memcpy(balance,pcTest3+59,11);
unshuffle((unsigned char *)balance, (const unsigned char *)uc_key, (const
unsigned char *)mask, 11);
lr_output_message("balance=[%0.2f]\n",atof(balance));
lrs_free_buffer(pcTest3);
}
//fclose(filestream);
return 0;
}
本文章来自中国IT实验室 |
|