JMeter 商城

接口

http 协议,端口为9091

登录

获取accesstoken是调用商城API接口的第一步,相当于创建了一个登录凭证,其它的业务API接口,都需要依赖于accesstoken来鉴权调用者身份。

请求方式: POST(HTTP

请求地址:/api/v1/user/login

请求包体:

{
  "authRequest": {
      "userName": "user01",
      "password": "pwd"
  }
}

参数说明

参数 是否必填 说明
userName 用户名,默认user01
password 密码,默认密码pwd

返回结果:

{
  "access_token": "3b6754f00bb0063071c5b71ce2b56b4ed0ce56a63493e785bea85b74c41ce200", 
  "code": "200", 
  "message": "login success"
}

备注:accesstoken 使用方法:在每个业务接口的headers中添加token键值对,键为“accesstoken”,值为具体的token值。

字段 备注
accesstoken 随机文本,例如“7172bbc7-f81a-4a78-9220-e55e3cfdf98c” 通过登录接口获取

浏览菜单

请求方式: GET(HTTP

请求地址:/api/v1/menu/list

返回结果:

{
  "breakfast": [
    {
      "menu_name": "小笼包", 
      "menu_nunber": "01", 
      "menu_price": 5.5
    }, 
    {
      "menu_name": "八宝粥", 
      "menu_nunber": "02", 
      "menu_price": 3.0
    }, 
    {
      "menu_name": "油条", 
      "menu_nunber": "03", 
      "menu_price": 1.5
    }, 
    {
      "menu_name": "茶叶蛋", 
      "menu_nunber": "04", 
      "menu_price": 1.0
    }, 
    {
      "menu_name": "豆包", 
      "menu_nunber": "05", 
      "menu_price": 1.5
    }, 
    {
      "menu_name": "烧饼", 
      "menu_nunber": "06", 
      "menu_price": 2.0
    }
  ], 
  "code": "200", 
  "dinner": [
    {
      "menu_name": "辣椒炒肉", 
      "menu_nunber": "13", 
      "menu_price": 21.0
    }, 
    {
      "menu_name": "豌豆肉片汤", 
      "menu_nunber": "14", 
      "menu_price": 15.0
    }, 
    {
      "menu_name": "原味五花肉卷", 
      "menu_nunber": "15", 
      "menu_price": 26.0
    }, 
    {
      "menu_name": "醋溜白菜", 
      "menu_nunber": "16", 
      "menu_price": 20.0
    }, 
    {
      "menu_name": "地三鲜", 
      "menu_nunber": "17", 
      "menu_price": 25.5
    }, 
    {
      "menu_name": "红烧排骨", 
      "menu_nunber": "18", 
      "menu_price": 39.0
    }
  ], 
  "lunch": [
    {
      "menu_name": "宫保鸡丁", 
      "menu_nunber": "07", 
      "menu_price": 17.0
    }, 
    {
      "menu_name": "锅包肉", 
      "menu_nunber": "08", 
      "menu_price": 25.0
    }, 
    {
      "menu_name": "糖醋排骨", 
      "menu_nunber": "09", 
      "menu_price": 35.0
    }, 
    {
      "menu_name": "蒜台炒肉片", 
      "menu_nunber": "10", 
      "menu_price": 30.0
    }, 
    {
      "menu_name": "酸辣土豆丝", 
      "menu_nunber": "11", 
      "menu_price": 25.5
    }, 
    {
      "menu_name": "红烧茄子", 
      "menu_nunber": "12", 
      "menu_price": 32.0
    }
  ]
}

乱码解决

String s2 = new String(prev.getResponseData(), "UTF-8");
//---------------一下步骤为转码过程---------------
char aChar;
int len = s2.length();
StringBuffer outBuffer = new StringBuffer(len);
for (int x = 0; x < len;)
{
    aChar = s2.charAt(x++);
    if (aChar == '\\') {
        aChar = s2.charAt(x++);
        if (aChar == 'u') {
            int
            value = 0;
            for (int i = 0;
            i < 4;
            i++
        )
            {
                aChar = s2.charAt(x++);
                switch (aChar) {
                    case'0':
                    case'1':
                    case'2':
                    case'3':
                    case'4':
                    case'5':
                    case'6':
                    case'7':
                    case'8':
                    case'9':
                        value = (value << 4) + aChar - '0';
                        break;
                    case'a':
                    case'b':
                    case'c':
                    case'd':
                    case'e':
                    case'f':
                        value = (value << 4) + 10 + aChar - 'a';
                        break;
                    case'A':
                    case'B':
                    case'C':
                    case'D':
                    case'E':
                    case'F':
                        value = (value << 4) + 10 + aChar - 'A';
                        break;
                    default:
                        throw new IllegalArgumentException(
                            "Malformed   \\uxxxx  encoding.");
                }
            }
            outBuffer.append((char)
            value
        )
            ;
        } else {
            if (aChar == 't')
                aChar = '\t';
            else if (aChar == 'r')
                aChar = '\r';
            else if (aChar == 'n')
                aChar = '\n';
            else if (aChar == 'f')
                aChar = '\f';
            outBuffer.append(aChar);
        }
    } else
        outBuffer.append(aChar);
}
//-----------------以上内容为转码过程---------------------------
//将转成中文的响应结果在查看结果树中显示

prev.setResponseData(outBuffer.toString());

订单确认

请求方式: POST(HTTP

请求地址:/api/v1/menu/confirm

请求包体:

{
    "order_list": [
        {
            "menu_nunber" : "01",
            "number" : 2
        },
        {
            "menu_nunber" : "03",
            "number" : 2
        },
        {
            "menu_nunber" : "04",
            "number" : 2
        },
        {
            "menu_nunber" : "05",
            "number" : 3
        }
    ]
}

参数说明

参数 是否必填 说明
menu_nunber 菜单编号,str
number 数量,int

返回结果:

{
  "code": "200", 
  "message": "Order success.", 
  "total": 9
}

用户注销

请求方式: DELETE(HTTP

请求地址:/api/v1/user/logout

返回结果:

{
  "code": "200", 
  "message": "logout success"
}

登录请求接口,json响应断言校验