码迷,mamicode.com
首页 > Web开发 > 详细

http接口编写

时间:2018-06-06 21:59:49      阅读:373      评论:0      收藏:0      [点我收藏+]

标签:start   sign   sde   set   otf   auto   ddn   请求   输出   

 

appLogin()
{

web_set_max_html_param_len("100000");

web_add_auto_header("appKey","f50c76fbc8271d361e1f6b5973f54585");
web_add_auto_header("clientId", "2014022801010");
web_add_auto_header("appVersion","V0.5.01_0228");
web_add_auto_header("appId","MB-UZHSH-0000");
web_add_auto_header("Content-Type","application/json;charset=UTF-8");
web_add_auto_header("funcName","addBonusPoint");
web_add_auto_header("SysName","SCRM-YXB");
web_add_auto_header("timestamp","20180510113725");


lr_start_transaction("step1-login");

web_save_header(REQUEST, "RequestHeader");// REQUEST为内置变量,保存请求的头信息,需在发送URL请求前注册使用
web_save_header(RESPONSE, "ResponseHeader");// RESPONSE保存响应的头信息
web_reg_save_param("ResponseBody", "LB=", "RB=", "Search=Body", LAST); 
web_reg_save_param("retCode", "LB=\"retCode\":\"", "RB=\",","Notfound=error", "Search=Body", LAST); 
web_reg_save_param("userId", "LB=chiefUserId\":\"", "RB=\",", "Notfound=error","Search=Body", LAST); 
web_reg_save_param("accessToken","LB=accessToken: ","RB=\n","Notfound=error","Search=ALL",LAST);
web_reg_save_param("sdToken","LB=sdToken: ","RB=\n","Notfound=error","Search=ALL",LAST);


web_custom_request("web_custom_request",
"URL=http://210.51.17.150:7500/emuplus/secuag/security/userLogin",
"Method=POST",
"TargetFrame=",
"Resource=0",
"Referer=",
"EncType=application/json",
"Body={\"sequenceId\":\"20140305102633000001\",\"accType\":0,\"loginId\":\"18109286803\",\"password\":\"123456!\",\"thirdpartyAppId\":\"\",\"thirdpartyAccessToken\":\"\",\"loginType\":\"1\"}",
LAST);

//字符转义,转义承UTF-8格式
lr_convert_string_encoding(lr_eval_string("{RequestHeader}"),LR_ENC_UTF8 ,LR_ENC_SYSTEM_LOCALE,"RequestHeaderUTF8");
lr_convert_string_encoding(lr_eval_string("{ResponseHeader}"),LR_ENC_UTF8 ,LR_ENC_SYSTEM_LOCALE,"ResponseHeaderUTF8");
lr_convert_string_encoding(lr_eval_string("{ResponseBody}"),LR_ENC_UTF8 ,LR_ENC_SYSTEM_LOCALE,"ResponseBodyUTF8");

//输出信息

lr_output_message("# 请求头信息:\n %s", lr_eval_string("{RequestHeaderUTF8}")); 
//lr_output_message("# 响应header:\n %s", lr_eval_string("{ResponseHeaderUTF8}"));
//lr_output_message("# 响应Body:\n %s", lr_eval_string("{ResponseBodyUTF8}"));


if(strcmp(lr_eval_string("{retCode}"),"00000")==0){

lr_output_message("登录成功");



}
else {

lr_set_transaction_status(LR_FAIL);
lr_end_transaction("step1-login", LR_AUTO);
return 0;

}


lr_end_transaction("step1-login", LR_AUTO);


lr_start_transaction("step2-getSign");

web_reg_save_param("ResponseBody", "LB=", "RB=", "Search=Body", LAST); 
web_reg_save_param("retCode", "LB=\"retCode\":\"", "RB=\",","Notfound=error", "Search=Body", LAST); 
web_reg_save_param("sign", "LB=data\":\"", "RB=\"", "Notfound=error","Search=Body", LAST); 
web_custom_request("getAddressSign",
"URL=http://210.51.17.150:7500/emuplus/secuag/invite/getSignCode",
"Method=POST",
"TargetFrame=",
"Resource=0",
"Referer=",
"EncType=application/json",
"Body={\"sdToken\": \"{sdToken}\", \"checkIntegral\": \"1\", \"id\": \"\", \"name\": \"张7\", \"phone\": \"13259901209\", \"province\": \"水电\", \"cityCode\": \"0298\", \"city\":\"收到\", \"areaCode\":\"120089\", \"address\": \"金\", \"isDefault\": 1 }",
LAST);

if(strcmp(lr_eval_string("{retCode}"),"00000")==0){

lr_output_message("获取sign成功");
lr_convert_string_encoding(lr_eval_string("{ResponseBody}"),LR_ENC_UTF8 ,LR_ENC_SYSTEM_LOCALE,"ResponseBodyUTF8");
lr_output_message(lr_eval_string("{ResponseBodyUTF8}"));


}
else {

lr_set_transaction_status(LR_FAIL);
lr_end_transaction("step1-login", LR_AUTO);
return 0;

}


lr_end_transaction("step2-getSign", LR_AUTO);


lr_start_transaction("step3-addNewAddress");
web_add_auto_header("sign",lr_eval_string("{sign}"));
web_add_auto_header("accessToken","TGT3150VB9MDDKXF2ENCN6C9RVHMR0");
web_save_header(RESPONSE, "ResponseHeader");// RESPONSE保存响应的头信息
web_reg_save_param("ResponseBody", "LB=", "RB=", "Search=Body", LAST); 
web_save_header(REQUEST, "RequestHeader");
web_custom_request("getAddressSign",
"URL=http://210.51.17.150:7500/emuplus/user/{userId}/addr/v0.1/addAddr",
"Method=POST",
"TargetFrame=",
"Resource=0",
"Referer=",
"EncType=application/json",
"Body={\"sdToken\": \"{sdToken}\", \"checkIntegral\": \"1\", \"id\": \"\", \"name\": \"张7\", \"phone\": \"13259901209\", \"province\": \"水电\", \"cityCode\": \"0298\", \"city\":\"收到\", \"areaCode\":\"120089\", \"address\": \"金\", \"isDefault\": 1 }",
LAST);
lr_convert_string_encoding(lr_eval_string("{RequestHeader}"),LR_ENC_UTF8 ,LR_ENC_SYSTEM_LOCALE,"RequestHeaderUTF8");
lr_convert_string_encoding(lr_eval_string("{ResponseBody}"),LR_ENC_UTF8 ,LR_ENC_SYSTEM_LOCALE,"ResponseBodyUTF8");

lr_output_message(lr_eval_string("{ResponseBodyUTF8}"));
lr_output_message(lr_eval_string("{RequestHeaderUTF8}"));

lr_end_transaction("step3-addNewAddress", LR_AUTO);

 

 

return 0;
}

http接口编写

标签:start   sign   sde   set   otf   auto   ddn   请求   输出   

原文地址:https://www.cnblogs.com/peak911/p/9146210.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!