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
}

  

posted @ 2022-07-10 11:19  PHP小媛  阅读(157)  评论(0编辑  收藏  举报