微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

jmeter 脚本


import org.apache.jmeter.config.Argument; import org.apache.jmeter.config.Arguments; import com.alibaba.fastjson.*; import org.apache.commons.codec.digest.DigestUtils; import java.text.SimpleDateFormat; import java.util.Date; String appsecret = "7d50aee234532aa1aea0"; //appsercet 随环境而改变 /*-----------取http请求中的body值---------------*/ SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式 String date = df.format(new Date());// new Date()为获取当前系统时间 String requestUrl = "/api/route1r/rest?app_key=234545928&customer_id=reebok&format=json&method=member.register&sign_method=md5&timestamp="+date; //json格式的请求数据 Arguments arguments = sampler.getArguments(); // 调用时注意sampler小写 String requestBody = arguments.getArgument(0).getValue(); int position = requestUrl.indexOf('?'); String requestUrl = requestUrl.substring(position + 1); String[] keyvalueArr = requestUrl.split("&"); /// Arrays.toString(keyvalueArr); // String.valueOf(keyvalueArr.length) String result = ""; for(int i=0;i < keyvalueArr.length;i++){ String[] keyvalue = keyvalueArr[i].split("="); result = result + keyvalue[0]+ keyvalue[1]; } //result = result.substring(0,result.length()-11); //拼接字符串 md5Str = appsecret + result + requestBody + appsecret; String sign = DigestUtils.md5Hex(md5Str).toupperCase(); vars.put("timestamp",date); vars.put("sign",sign);

  BeanShell 后置处理器

prev.setDataEncoding("UTF-8");

  

 

 请求值

{
    "mobile": "${__time(/100000,)}${__RandomString(3,0123456789,)}",
    "mobile_area_code": "86",
    "channel": "mp",
    "source": "",
    "source_media": "",
    "store": "reebok_mp",
    "register_time": "${__time(yyyy-MM-dd HH:mm:ss,)}",
    "member_select_store": "Reebok\u9510\u6b65\u5546\u57ce\u5c0f\u7a0b\u5e8f",
    "last_name": "",
    "first_name": "",
    "full_name": "${__RandomString(8,0123456789,)}",
    "card_no": "",
    "area_code": "",
    "country": "",
    "province": "",
    "city": "",
    "district": "",
    "address": "",
    "gender": 0,
    "birthday_type": "",
    "birthday": "",
    "email": "",
    "union_id": "${__RandomString(4,qwertyuioplkjhgfdsazxcvbnm,)}-${__RandomString(8,0123456789,)}",
    "wechat_nick": "",
    "open_id": "o4y2t5Ev1mljuINsrREL7ZuTd97Q",
    "register_uid": "${__RandomString(6,qwertyuioplkjhgfdsazxcvbnm,)}-${__RandomString(8,0123456789,)}",
    "sales_no": "",
    "interests": "",
    "education_background": "",
    "industry": "",
    "income": "",
    "style": "",
    "size": "",
    "appellation": "",
    "field_2": 0
}

  

原文地址:https://www.cnblogs.com/stj123/p/16462823.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐