char orSignMD5[500];
char orSignMD5str[32];
char time_str[20];
char orSignMD5str_dll[40];
Action()
{
typedef long time_t;
time_t t;
sprintf(time_str, "%ld", time(&t));
strcpy(orSignMD5,"TangMengxi");
//strcat(orSignMD5,time(&t));
strcat(orSignMD5,time_str);
strcat(orSignMD5,lr_get_host_name());//待加密的字符串是 = 自己名字的全拼 + 當前時間到1970年的秒數 + 當前主機的hostname
lr_output_message("需要加密的字符串爲:%s",orSignMD5);
lr_save_string(orSignMD5,"oriMD5");//因爲Change_to_md5轉換結束後orSignMD5數組會被清空,所以需要先把數組內的數據保存在參數列表中
//lr_output_message("%ld",time(&t));
lr_start_transaction("md5_header");
sprintf( orSignMD5str,"%s",Change_to_Md5(orSignMD5)); //需加密字符串內容,頭文件方法,轉換結束後orSignMD5數組會被清空。
lr_end_transaction("md5_header",LR_AUTO);
//lr_output_message("%s",orSignMD5);
lr_save_string( orSignMD5str,"SignMD5" );//頭文件方式MD5加密
lr_output_message("MD5加密後結果爲(頭文件方式):%s",lr_eval_string("{SignMD5}"));
lr_output_message("需要加密的字符串爲:%s",lr_eval_string("{oriMD5}"));
lr_start_transaction("md5_dll");//dll方式MD5加密
md5(lr_eval_string("{oriMD5}"),orSignMD5str_dll);
lr_end_transaction("md5_dll",LR_AUTO);
lr_output_message("MD5加密後結果爲(dll方式):%s",orSignMD5str_dll);
//通過比較兩個事務的Duration可知,使用dll的方式消耗的時間約爲使用header方式的5%-20%之間,在腳本中儘量多的使用dll的方式可以極大的改善腳本的性能
if(strcmp(orSignMD5str,orSignMD5str_dll)==0)
lr_output_message("兩種方式加密結果相同,結果正確");
else
{
lr_output_message("兩種方式加密結果不同,有錯誤");
return -1;
}
return 0;
}
Loadrunner支持MD5加密腳本的編寫
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.