lr添加md5方法,字符编码转换,urlcode编码化

 

1、使得写lr脚本时可调用md5方法,需要进行以下操作:

1)将md5.h文件加载到Extra Files下;

lr添加md5方法,字符编码转换,urlcode编码化_第1张图片

2)在globals.h文件中添加  #include“md5.h”

 

lr添加md5方法,字符编码转换,urlcode编码化_第2张图片

3)、打开md5文件,确认该文件方法的函数名

lr添加md5方法,字符编码转换,urlcode编码化_第3张图片

4)要使用该方法时,直接函数名(‘要加密的字符串’),如:lr_save_string(CMd5("123456"),"paypasswd")

 

2、写脚本过程中,若出现请求参数中带中文,导致请求不成功,返回400bad request。可先转码然后去终止符

   例:  lr_convert_string_encoding("测试",NULL,"utf-8","reremark");
            lr_save_string(lr_eval_string("{reremark}"),"remark");

 

3、请求url中带有+号等字符,导致参数请求失败,可以使用web_convert_param()函数

a、web_convert_param()//将html文本转化成纯文本或url,或者将纯文本转化成url

b、 web_convert_param(output_param_name, "SourceEncoding=PLAIN", "TargetEncoding=URL", LAST);    output_param_name参数为要转码字符串的参数名,切不能加{},比如参数变量为token,不能写成web_convert_param("{token}", "SourceEncoding=PLAIN", "TargetEncoding=URL", LAST);  而是web_convert_param("token", "SourceEncoding=PLAIN", "TargetEncoding=URL", LAST);

c、效果:

     urlcode前: token: 4XrN8QoG//ESuKtc0pICg+f5s02EVkdwAh0dfk/hWP8ny+u3u17gcHEmdbAIItNOxRU/jxaEwo/fQbjJJq9BrA==

     urlcode后:token: 4XrN8QoG%2F%2FESuKtc0pICg%2Bf5s02EVkdwAh0dfk%2FhWP8ny%2Bu3u17gcHEmdbAIItNOxRU%2FjxaEwo%2FfQbjJJq9BrA%3D%3D

 c、例子://将字符串编码转为UTF-8
                lr_convert_string_encoding(original, LR_ENC_SYSTEM_LOCALE, LR_ENC_UTF8, "strUTF8");
               //去掉C数组后面的null终止符
               lr_save_string(lr_eval_string("{strUTF8}"), output_param_name);
              //  将UTF-8字符串URL encode
            web_convert_param(output_param_name, "SourceEncoding=PLAIN", "TargetEncoding=URL", LAST);

4、写脚本过程中,若出现响应码返回为乱码,通过设置编码格式依然不行,可先关联你要知道正确中文含义的字段,然后lr_convert_string_encoding()函数转换格式,最后lr_output_message()输出

lr_convert_string_encoding(lr_eval_string("{loginmessage}"),"utf-8",NULL,"msg"); ,第一个参数为要转换的原子段,第二个参数是原字段的编码,第三个为要转换的编码格式,第四个为保存后的参数名

5、注册、登录、重置支付密码,下订单、支付订单、获取订单列表脚本

Action()
{   
    
    
    lr_save_string(CMd5("123456"),"paypasswd");
    lr_save_string("192.168.46.129:8080","IP");
//    注册
    web_reg_save_param_ex(
        "ParamName=注册结果",
        "LB={\"code\":",
        "RB=,\"msg\":",
        "Ordinal=1",
        SEARCH_FILTERS,
        LAST);
    
       web_reg_save_param_ex(
        "ParamName=获取注册mobile",
        "LB=\"mobile\":\"",
        "RB=\",\"email\"",
        "Ordinal=1",
        SEARCH_FILTERS,
        LAST);
    
    
    lr_start_transaction("注册");

    web_custom_request("注册",
        "URL=http://{IP}/mobile/api/user/register",
        "Method=POST",
        "TargetFrame=",
        "Resource=0",
        "Referer=",
        "Mode=HTTP",
        "EncType=application/json;charset=utf-8",
        "Body={\"mobile\":\"1880740{moblie}\",\"password\":\"123456\",\"code\":\"3367\",\"platform\":\"windows\",\"username\":\"\",\"sex\":1,\"age\":20,\"email\":\"\"}",
        LAST);
    
    
    if(strcmp(lr_eval_string("{注册结果}"),"0")==0)
    {
    lr_end_transaction("注册", LR_PASS);
    lr_output_message("注册成功,返回响应码%s",lr_eval_string("{注册结果}"));
    }
    else
    {
    lr_end_transaction("注册", LR_FAIL);
    lr_error_message("注册失败,返回响应码%s",lr_eval_string("{注册结果}"));
    }
    
    
    //登录
    web_reg_save_param_ex(
        "ParamName=登录结果",
        "LB={\"code\":",
        "RB=,\"msg\":",
        "Ordinal=1",
        SEARCH_FILTERS,
        LAST);
    
        web_reg_save_param_ex(
        "ParamName=loginmessage",
        "LB={\"code\":0,\"msg\":\"",
        "RB=,\"data\":",
        "Ordinal=1",
        SEARCH_FILTERS,
        LAST);
    
            web_reg_save_param_ex(
        "ParamName=get_login_token",
        "LB=\"token\":\"",
        "RB=\",\"identity\":\"",
        "Ordinal=1",
        SEARCH_FILTERS,
        LAST);

    lr_start_transaction("登录");

    web_custom_request("登录",
        "URL=http://{IP}/mobile/api/user/login",
        "Method=POST",
        "TargetFrame=",
        "Resource=0",
        "Referer=",
        "Mode=HTTP",
        "EncType=application/json;charset=utf-8",
        "Body={\"mobile\":\"{获取注册mobile}\",\"password\":\"123456\"}",
        LAST);

    lr_convert_string_encoding(lr_eval_string("{loginmessage}"),"utf-8",NULL,"msg");
    lr_output_message("返回响应文:%s",lr_eval_string("{msg}"));
    

       if(strcmp(lr_eval_string("{登录结果}"),"0")==0)
    {
    lr_end_transaction("登录", LR_PASS);
    lr_output_message("登录成功,返回响应码%s",lr_eval_string("{登录结果}"));
    }
    else
    {
    lr_end_transaction("登录", LR_FAIL);
    lr_error_message("登录失败,返回响应码%s",lr_eval_string("{登录结果}"));
    }

    
    //重置支付密码
        web_reg_save_param_ex(
        "ParamName=重置支付密码结果",
        "LB={\"code\":",
        "RB=,\"msg\":",
        "Ordinal=1",
        SEARCH_FILTERS,
        LAST);
    
    lr_start_transaction("重置支付密码");

    web_custom_request("重置支付密码",
        "URL=http://{IP}/mobile/api/user/resetpaypwd",
        "Method=POST",
        "TargetFrame=",
        "Resource=0",
        "Referer=",
        "Mode=HTTP",
        "EncType=application/json;charset=utf-8",
        "Body={\"token\":\"{get_login_token}\",\"password\":\"{paypasswd}\"}",
        LAST);
    
    

       if(strcmp(lr_eval_string("{重置支付密码结果}"),"0")==0)
    {
    lr_end_transaction("重置支付密码", LR_PASS);
    lr_output_message("重置支付密码成功,返回响应码%s",lr_eval_string("{重置支付密码结果}"));
    }
    else
    {
    lr_end_transaction("重置支付密码", LR_FAIL);
    lr_error_message("重置支付密码失败,返回响应码%s",lr_eval_string("{重置支付密码结果}"));
    }


    
    //下订单
        web_reg_save_param_ex(
        "ParamName=下订单结果",
        "LB={\"code\":",
        "RB=,\"msg\":",
        "Ordinal=1",
        SEARCH_FILTERS,
        LAST);
                web_reg_save_param_ex(
        "ParamName=get_payid",
        "LB={\"payId\":\"",
        "RB=\",\"orders\"",
        "Ordinal=1",
        SEARCH_FILTERS,
        LAST);
    
            web_reg_save_param_ex(
        "ParamName=ordermessage",
        "LB=\"msg\":\"",
        "RB=,\"data\":",
        "Ordinal=1",
        SEARCH_FILTERS,
        LAST);
    
    
    lr_start_transaction("下订单");

    web_custom_request("下订单",
        "URL=http://{IP}/mobile/api/order/addorder",
        "Method=POST",
        "TargetFrame=",
        "Resource=1",
        "Referer=",
        "Mode=HTTP",
        "EncType=application/json;charset=utf-8",
        "Body={\"token\":\"{get_login_token}\",\"getAddrId\":1,\"getCarId\":23,\"payType\":2,\"remark\":\"ceshi\",\"price\":69,\"orders\":[{\"getTime\":1450921104000,\"goodss\":[{\"goodsId\":93,\"count\":1},{\"goodsId\":96,\"count\":1}]}],\"invoiceTitle\":\"title\"}",
        LAST);
    
    lr_convert_string_encoding(lr_eval_string("{ordermessage}"),"utf-8",NULL,"ordermsg");
    lr_output_message("下订单返回响应文:%s",lr_eval_string("{ordermsg}"));

       if(strcmp(lr_eval_string("{下订单结果}"),"0")==0)
    {
    lr_end_transaction("下订单", LR_PASS);
    lr_output_message("下订单成功,返回响应码%s",lr_eval_string("{下订单结果}"));
    }
    else
    {
    lr_end_transaction("下订单", LR_FAIL);
    lr_error_message("下订单失败,返回响应码%s",lr_eval_string("{下订单结果}"));
    }    
    
    
        //支付订单
        web_reg_save_param_ex(
        "ParamName=支付订单结果",
        "LB={\"code\":",
        "RB=,\"msg\":",
        "Ordinal=1",
        SEARCH_FILTERS,
        LAST);
    
            web_reg_save_param_ex(
        "ParamName=payordermessage",
        "LB=\"msg\":\"",
        "RB=,\"data\":",
        "Ordinal=1",
        SEARCH_FILTERS,
        LAST);
    
    lr_start_transaction("支付订单");

    web_custom_request("支付订单",
        "URL=http://{IP}/mobile/api/pay/pay",
        "Method=POST",
        "TargetFrame=",
        "Resource=1",
        "Referer=",
        "Mode=HTTP",
        "EncType=application/json;charset=utf-8",
        "Body={\"token\":\"{get_login_token}\",\"payId\":\"{get_payid}\",\"payPwd\":\"{paypasswd}\",\"platform\":2}",
        LAST);
    
    lr_convert_string_encoding(lr_eval_string("{payordermessage}"),"utf-8",NULL,"payordermsg");
    lr_output_message("支付订单返回响应文:%s",lr_eval_string("{payordermsg}"));

       if(strcmp(lr_eval_string("{支付订单结果}"),"0")==0)
    {
    lr_end_transaction("支付订单", LR_PASS);
    lr_output_message("支付订单成功,返回响应码%s",lr_eval_string("{支付订单结果}"));
    }
    else
    {
    lr_end_transaction("支付订单", LR_FAIL);
    lr_error_message("支付订单失败,返回响应码%s",lr_eval_string("{支付订单结果}"));
    }    

    

        //获取订单
        web_reg_save_param_ex(
        "ParamName=获取订单结果",
        "LB={\"code\":",
        "RB=,\"msg\":",
        "Ordinal=1",
        SEARCH_FILTERS,
        LAST);
    
            web_reg_save_param_ex(
        "ParamName=getordermessage",
        "LB=\"msg\":\"",
        "RB=,\"data\":",
        "Ordinal=1",
        SEARCH_FILTERS,
        LAST);
        lr_save_string(lr_eval_string("{get_login_token}"),"token");        /*已证,在urlcode编码化时,lr_save_string()非必须,只是用来去掉转码导致的终止符/x00;经常和web_convert__sting_encoding()搭配;*/
        web_convert_param("token", "SourceEncoding=PLAIN", "TargetEncoding=URL", LAST);
        lr_output_message("urlcode化的token:%s",lr_eval_string("{token}"));
    
    lr_start_transaction("获取订单");

    web_custom_request("获取订单",
        "URL=http://{IP}/mobile/api/order/getorders?token={token}",
        "Method=GET",
        "TargetFrame=",
        "Resource=1",
        "Referer=",
        "Mode=HTTP",
        "EncType=application/json;charset=utf-8",
        LAST);
    
    lr_convert_string_encoding(lr_eval_string("{getordermessage}"),"utf-8",NULL,"getordermsg");
    lr_output_message("获取订单返回响应文:%s",lr_eval_string("{getordermsg}"));

       if(strcmp(lr_eval_string("{获取订单结果}"),"0")==0)
    {
    lr_end_transaction("获取订单", LR_PASS);
    lr_output_message("获取订单成功,返回响应码%s",lr_eval_string("{获取订单结果}"));
    }
    else
    {
    lr_end_transaction("获取订单", LR_FAIL);
    lr_error_message("获取订单失败,返回响应码%s",lr_eval_string("{获取订单结果}"));
    }    
    
    
    return 0;
}

 

转载于:https://www.cnblogs.com/nikeke/p/10708502.html

你可能感兴趣的:(lr添加md5方法,字符编码转换,urlcode编码化)