• LR十:MD5接口解密操作_接口签名校验


    很多HTTP接口在传参时,需要先对接口的参数进行数据签名加密
    如以下POST接口

    http://localhost:8080/pinter/com/userInfo

    参数为
    {"phoneNum":"123434","optCode":"testfan","timestamp":"1211212","sign":"fdsfdsaafsasfas"}

    其中,sign字段是按照特定算法进行加密后的数据
    本接口的签名算法为
    sign=Md5(phoneNum+ optCode+ timestamp)

    签名过程中涉及到的C语言函数
    字符串拼接
    char str[50];
    strcat(str,"testfan");
    保存当前时间戳:web_save_timestamp_param("tStamp", LAST );

    注意 引入 md5.h 文件进行算法解密

     1 Action()
     2 {
     3 //定义 字符串类型
     4     char cat[50];
     5 
     6     
     7     web_reg_find("Search=Body",
     8         "SaveCount=find_cnt",
     9         "Text=code":"0"",
    10         LAST);
    11 
    12 
    13 
    14     web_save_timestamp_param("tStamp", LAST );
    15 
    16 //拼接 在一起
    17     strcat(cat, lr_eval_string("135{phoneNum}"));
    18     strcat(cat, "testfan");
    19     strcat(cat, lr_eval_string("{tStamp}"));
    20 
    21 //CMd5 是调用的 MD5.h 这个文件中的 函数进行md5 解码的
    22     lr_save_string(CMd5(cat), "singMd5");
    23 
    24     lr_output_message("==============================%s",CMd5(cat));
    25 
    26 
    27 
    28 
    29     web_add_header("Content-type", "application/json");
    30 
    31     
    32     lr_start_transaction("singmd5");
    33 
    34 
    35     web_custom_request("post", "Method=POST", 
    36 
    37         "URL=http://localhost:8080/pinter/com/userInfo", 
    38 
    39         "Body={"phoneNum":"135{phoneNum}","optCode":"testfan","timestamp":"{tStamp}","sign":"{singMd5}"}", 
    40 
    41         "TargetFrame=", 
    42 
    43         LAST );
    44 
    45     if(atoi(lr_eval_string("{find_cnt}")) > 0 ){
    46         lr_end_transaction("singmd5", LR_PASS);
    47 
    48     }else{
    49         
    50         lr_end_transaction("singmd5", LR_FAIL);
    51 
    52     }
    53     
    54 
    55 
    56 
    57     return 0;
    58 }

     

    运行日志如下:

     1 Virtual User Script started at : 2019-03-16 19:37:16
     2 Starting action vuser_init.
     3 Web Turbo Replay of LoadRunner 11.0.0 for WINXP; build 8859 (Aug 18 2010 20:14:31)      [MsgId: MMSG-27143]
     4 Run Mode: HTML      [MsgId: MMSG-26000]
     5 Run-Time Settings file: "C:	est_huzhenyuScriptsingn\default.cfg"      [MsgId: MMSG-27141]
     6 Ending action vuser_init.
     7 Running Vuser...
     8 Starting iteration 1.
     9 Starting action Action.
    10 Action.c(7): Registering web_reg_find was successful      [MsgId: MMSG-26390]
    11 Action.c(14): Notify: Saving Parameter "tStamp = 1552736236160".
    12 Action.c(14): web_save_timestamp_param("web_save_timestamp_param") was successful      [MsgId: MMSG-26392]
    13 Action.c(17): Notify: Parameter Substitution: parameter "phoneNum" =  "12662118"
    14 Action.c(19): Notify: Parameter Substitution: parameter "tStamp" =  "1552736236160"
    15 Action.c(21): Notify: Saving Parameter "singMd5 = b7f1b1f74de61497d65fd0027b8166fc".
    16 Action.c(23): ==============================b7f1b1f74de61497d65fd0027b8166fc
    17 Action.c(28): Warning -26593: The header being added may cause unpredictable results when applied to all ensuing URLs. It is added anyway      [MsgId: MWAR-26593]
    18 Action.c(28): web_add_header("Content-type") highest severity level was "warning"      [MsgId: MMSG-26391]
    19 Action.c(31): Notify: Transaction "singmd5" started.
    20 Action.c(34): Notify: Parameter Substitution: parameter "phoneNum" =  "12662118"
    21 Action.c(34): Notify: Parameter Substitution: parameter "tStamp" =  "1552736236160"
    22 Action.c(34): Notify: Parameter Substitution: parameter "singMd5" =  "b7f1b1f74de61497d65fd0027b8166fc"
    23 Action.c(34): t=1018ms: 128-byte response headers for "http://localhost:8080/pinter/com/userInfo" (RelFrameId=1, Internal ID=1)
    24 Action.c(34):     HTTP/1.1 200 
    
    25 Action.c(34):     Content-Type: application/json;charset=UTF-8
    
    26 Action.c(34):     Transfer-Encoding: chunked
    
    27 Action.c(34):     Date: Sat, 16 Mar 2019 11:37:16 GMT
    
    28 Action.c(34):     
    
    29 Action.c(34): t=1061ms: 5-byte chunked response overhead for "http://localhost:8080/pinter/com/userInfo" (RelFrameId=1, Internal ID=1)
    30 Action.c(34):     12a
    
    31 Action.c(34): t=1068ms: 2-byte chunked response overhead for "http://localhost:8080/pinter/com/userInfo" (RelFrameId=1, Internal ID=1)
    32 Action.c(34):     
    
    33 Action.c(34): t=1077ms: 298-byte chunked response body for "http://localhost:8080/pinter/com/userInfo" (RelFrameId=1, Internal ID=1)
    34 Action.c(34):     {"code":"0","message":"success","data":{"id":3607,"userName":"鎬ц兘娴嬭瘯","password":nul
    35 Action.c(34):     l,"age":55,"gender":1,"phoneNum":"13512662118","email":"beihe@testfan.com","address":"鍖椾
    36 Action.c(34):     含甯傛槍骞冲尯绉戞槦瑗胯矾106鍙烽櫌锛堝浗椋庣編鍞愯姳鍥�患鍚堟ゼ锛x893鍙锋ゼ1111","creat
    37 Action.c(34):     eTime":null,"updateTime":null}}
    38 Action.c(34): HTML parsing not performed for Content-Type "application/json" ("ParseHtmlContentType" Run-Time Setting is "TEXT"). URL="http://localhost:8080/pinter/com/userInfo"      [MsgId: MMSG-26548]
    39 Action.c(34): t=1122ms: 5-byte chunked response overhead for "http://localhost:8080/pinter/com/userInfo" (RelFrameId=1, Internal ID=1)
    40 Action.c(34):     0
    
    41 Action.c(34):     
    
    42 Action.c(34): Registered web_reg_find successful for "Text=code":"0"" (count=1)      [MsgId: MMSG-26364]
    43 Action.c(34): Notify: Saving Parameter "find_cnt = 1".
    44 Action.c(34): web_custom_request("post") was successful, 298 body bytes, 128 header bytes, 12 chunking overhead bytes      [MsgId: MMSG-26385]
    45 Action.c(44): Notify: Parameter Substitution: parameter "find_cnt" =  "1"
    46 Action.c(45): Notify: Transaction "singmd5" ended with "Pass" status (Duration: 0.7485 Wasted Time: 0.4988).
    47 Ending action Action.
    48 Ending iteration 1.
    49 Ending Vuser...
    50 Starting action vuser_end.
    51 Ending action vuser_end.
    52 Vuser Terminated.
    View Code

  • 相关阅读:
    跟我学android—01.SplashActivity
    eclipse android : A project with that name already exists in the workspace
    冬吴相对论锦言佳句--0005.薄伽梵歌与“印度式管理”
    [转载]Jquery Form插件表单参数
    Form表单学习网站
    [转载]JQuery获取元素文档大小、偏移和位置和滚动条位置的方法集合
    jquery捕捉文本域输入事件
    [转载]js 遍历数组对象
    C#跳出循环的几种方法的区别
    [转载]MVC3缓存:使用页面缓存
  • 原文地址:https://www.cnblogs.com/zhenyu1/p/10544015.html
Copyright © 2020-2023  润新知