Action()
{
/*
主流程:登录->下订单->支付订单->获取订单列表
定义事物
1)登录
2)下订单
3)支付订单
4)获取订单列表
接口为:application/json
思路:用户在app登录后,获取token供用户后续进行操作业务时使用
参数化:登录用的手机号、GQID号、密码
*/
//定义变量
//char *invoiceTitle = "发票抬头001";
//char *remark = "备注001";
char md5pwd[9] = "123456789";
lr_convert_string_encoding("发票抬头001",LR_ENC_SYSTEM_LOCALE,LR_ENC_UTF8,"tempInvoiceTitle");
lr_convert_string_encoding("备注信息001",LR_ENC_SYSTEM_LOCALE,LR_ENC_UTF8,"tempRemark");
lr_save_string(lr_eval_string("{tempInvoiceTitle}"), "invoiceTitle");
lr_save_string(lr_eval_string("{tempRemark}"), "remark");
lr_save_string("手机号码", "mobile");
lr_save_string("4089021", "gqid");
lr_save_string("密码", "password");
//1、设置新支付密码
lr_save_string(CMd5(md5pwd), "newmd5pwd");
//2、设置服务器IP地址
lr_save_string("ip:8080", "ip");
//停顿2秒
lr_think_time(2);
//3、设置头信息
//web_add_auto_header("Accept", "application/json");
//web_add_auto_header("Content-Type", "application/json;charset=utf-8");
//4、设置html支持的字符长度为1024
web_set_max_html_param_len("1024");
//5、设置关联
web_reg_save_param("code",
"LB=\"code\":",
"RB=,\"msg\"",
LAST);
//6、获取token值
web_reg_save_param("token",
"LB=\"token\":\"",
"RB=\",\"identity\"",
LAST);
//开始登陆事物
lr_start_transaction("提交登录");
//7、提交登录
web_custom_request("提交登录", "Method=POST",
"URL=http://{ip}/mobile/api/user/login",
"Mode=HTTP",
"EncType=application/json;charset=utf-8",
"RecContentType=application/json",
"Body={\"mobile\":\"{mobile}\",\"gqid\":\"{gqid}\",\"password\":\"{password}\"}",
LAST );
//结束post请求
lr_end_transaction("提交登录", LR_PASS);
//8、判断提交登录是否成功
/*if(atoi(lr_eval_string("{code}")) == 0)
{
//结束post请求
lr_end_transaction("提交登录", LR_PASS);
lr_output_message("提交登录成功");
}
else
{
//结束post请求
lr_end_transaction("提交登录", LR_FAIL);
lr_output_message("提交登录失败");
}*/
//结束登陆事物
//9、获取payId值
web_reg_save_param("payId",
"LB=\"payId\":\"",
"RB=\",",
LAST);
//停顿2秒
lr_think_time(2);
lr_start_transaction("下订单");
//10、下订单
web_custom_request("下订单", "Method=POST",
"URL=http://{ip}/mobile/api/order/addorder",
"Mode=HTTP",
"EncType=application/json;charset=utf-8",
"RecContentType=application/json",
"Body={\"token\": \"{token}\",\"getAddrId\": 1,\"getCarId\": 25,\"payType\": 2,\"remark\": \"{remark}\",\"price\": 66.8,\"orders\": [{\"getTime\": 1450921104000,\"goodss\": [{\"goodsId\": 93,\"count\": 1},{\"goodsId\": 96,\"count\": 1}]}],\"invoiceTitle\": \"{invoiceTitle}\"}",
LAST );
lr_end_transaction("下订单", LR_AUTO);
//停顿2秒
lr_think_time(2);
lr_start_transaction("重置支密码");
//11、支付订单
web_custom_request("重置支密码", "Method=POST",
"URL=http://{ip}/mobile/api/user/modifypaypwd",
"Mode=HTTP",
"EncType=application/json;charset=utf-8",
"RecContentType=application/json",
"Body={\"token\":\"{token}\",\"srcpwd\":\"\",\"newpwd\":\"{newmd5pwd}\"}",
LAST );
lr_end_transaction("重置支密码", LR_AUTO);
//停顿2秒
lr_think_time(2);
lr_start_transaction("支付订单");
//12、支付订单
web_custom_request("支付订单", "Method=POST",
"URL=http://{ip}/mobile/api/pay/pay",
"Mode=HTTP",
"EncType=application/json;charset=utf-8",
"RecContentType=application/json",
"Body={\"token\": \"{token}\",\"payId\": \"{payId}\",\"payPwd\": \"{newmd5pwd}\",\"platform\": 3}",
LAST );
lr_end_transaction("支付订单", LR_AUTO);
web_convert_param("token", "SourceEncoding=PLAIN", "TargetEncoding=URL",LAST);
//停顿2秒
lr_think_time(2);
lr_start_transaction("获取订单列表");
//13、获取订单列表
web_url("获取订单列表",
"URL=http://{ip}/mobile/api/order/getorders?token={token}&offset=0&size=15",
"Mode=HTML",
"RecContentType=text/xml;charset=utf-8",
LAST );
lr_end_transaction("获取订单列表", LR_AUTO);
return 0;
}