LoadRunner使用者驗證碼和驗證碼使用指令碼
阿新 • • 發佈:2019-01-03
Action() { //定義Md5變數用來存放使用md5加密後的字串 char Md5[33]; //存放包含使用者登入資訊的URL char str[174]; //存放使用者賬戶資訊 char str1[92]; //存放當前時間 int t1; int a; char Message[50]; //把持續的秒數放入t1變數中 t1=time(); //把t1中儲存的值賦值給time1變數 lr_save_int(t1,"time1"); //使用lr_eval_string函式獲取變數的值,並把值賦值給str1變數 strcpy(str1,lr_eval_string("account={code}.pt&appId=1002&code={code}&gameId=89&ip={使用者IP}×tamp={time1}cb29fca01dbtk7a29np0lp59yl6hd258")); lr_output_message(str1); //把str1進行md5加密,並把加密完的字串賦值給Md5變數 GetMd5FromString(str1,Md5); //重新生成幷包含sign”=“Md5中包含的值的URL字串放入str變數中 sprintf(str,"URL=http://{伺服器IP}/api/Character/ValidateCode?account={code}.pt&appId=1002&code={code}&gameId=89&ip={使用者IP}×tamp={time1}&sign=%s",Md5); //進行手動關聯,獲取動態資訊,並把動態資訊儲存到Message變數中 web_reg_save_param("Message", "LB/IC=Message\":\"", "RB/IC=\"", "Ord=1", "Search=Body", "RelFrameId=1", LAST); //開始驗證事務 lr_start_transaction("驗證成功"); lr_start_transaction("驗證失敗"); //獲取驗證碼資料包 web_url("ValidateCode", str,//獲取驗證碼URL連結 "Resource=1", "RecContentType=application/xml", "Referer=", "Snapshot=t5.inf", LAST); //使用lr_eval_string函式獲取變數{Message}的值,並把值賦值給Message變數 strcpy(Message,lr_eval_string("{Message}")); //輸出Message資訊 lr_output_message(Message); //呼叫strcmp函式把Message中儲存的值和“success”進行比較 //把比較結果賦值給變數a a=strcmp(Message,"success"); //判斷a的值,如果a==0則“success” if (a == 0) { //結束驗證成功事務了,並自動設定事務狀態(PASS or FAIL) lr_end_transaction("驗證成功", LR_AUTO); //把持續的秒數放入t1變數中 t1=time(); //把t1中儲存的值賦值給time1變數 lr_save_int(t1,"time1"); //使用lr_eval_string函式獲取變數的值,並把值賦值給str1變數 strcpy(str1,lr_eval_string("account={code}.pt&appId=1002&code={code}&gameId=89&ip={使用者IP}×tamp={time1}cb29fca01dbtk7a29np0lp59yl6hd258")); lr_output_message(str1); //把str1進行md5加密,並把加密完的字串賦值給Md5變數 GetMd5FromString(str1,Md5); //重新生成幷包含sign”=“Md5中包含的值的URL字串放入str變數中 sprintf(str,"URL=http://{伺服器IP}/api/Character/UseCode?account={code}.pt&appId=1002&code={code}&gameId=89&ip={使用者IP}×tamp={time1}&sign=%s",Md5); //進行手動關聯,獲取動態資訊,並把動態資訊儲存到Message變數中 web_reg_save_param("Message", "LB/IC=Message\":\"", //左邊界開始為“Message“:”” "RB/IC=\"",//右邊界為““” "Ord=1", "Search=Body", "RelFrameId=1", LAST); //開始使用事務 lr_start_transaction("使用成功"); lr_start_transaction("使用失敗"); //獲取驗證碼資料包 web_url("ValidateCode", str,//獲取驗證碼URL連結 "Resource=1", "RecContentType=application/xml", "Referer=", "Snapshot=t5.inf", LAST); //使用lr_eval_string函式獲取變數{Message}的值,並把值賦值給Message變數 strcpy(Message,lr_eval_string("{Message}")); lr_output_message(Message); //呼叫strcmp函式把Message中儲存的值和“success”進行比較 //把比較結果賦值給變數a a=strcmp(Message,"success"); //判斷a的值,如果a==0則“success” if (a == 0) { //結束使用成功事務了,並自動設定事務狀態(PASS or FAIL) lr_end_transaction("使用成功", LR_AUTO); } else{ //結束使用失敗事務了,並自動設定事務狀態(PASS or FAIL) lr_end_transaction("使用失敗", LR_AUTO); } } else { //結束驗證失敗事務了,並自動設定事務狀態(PASS or FAIL) lr_end_transaction("驗證失敗", LR_AUTO); } return 0; }
該指令碼使用md5加密,需要使用md5.h檔案
要在指令碼中新增md5.h檔案,globals.h檔案
並且要在globals.h中新增“include “md5.h””