api接口名称

用户相关,**用户注册接口**:userRegisterApi,**用户登录接口**:userLoginApi,**获取用户信息接口**:getUserInfoApi,**更新用户信息接口**:updateUserInfoApi,, 商品相关,**查询商品列表接口**:queryProductListApi,**获取商品详情接口**:getProductDetailApi,**添加商品接口**:addProductApi,**更新商品信息接口**:updateProductInfoApi,, 订单相关,**创建订单接口**:createOrderApi,**查询订单列表接口**:queryOrderListApi,**获取订单详情接口**:getOrderDetailApi,**取消订单接口**:cancelOrderApi

API接口名称

api接口名称

一、用户信息相关接口

用户注册接口

接口名称 功能描述 请求方式 请求路径 请求参数 响应参数
UserRegister 实现新用户的注册功能,将用户提交的注册信息保存到系统数据库中 POST /api/user/register {“username”: “string”, “password”: “string”, “email”: “string”, “phone”: “string”} {“code”: “int”, “message”: “string”, “userId”: “int”}
示例请求 {“username”: “testUser”, “password”: “123456”, “email”: “test@example.com”, “phone”: “13800000000”}
示例响应 {“code”: 200, “message”: “注册成功”, “userId”: 1}

用户登录接口

接口名称 功能描述 请求方式 请求路径 请求参数 响应参数
UserLogin 验证用户输入的用户名和密码是否正确,若正确则返回用户相关信息和登录凭证(如token) POST /api/user/login {“username”: “string”, “password”: “string”} {“code”: “int”, “message”: “string”, “token”: “string”, “userId”: “int”, “userInfo”: {“username”: “string”, “email”: “string”, “phone”: “string”}}
示例请求 {“username”: “testUser”, “password”: “123456”}
示例响应 {“code”: 200, “message”: “登录成功”, “token”: “abcdefg1234567”, “userId”: 1, “userInfo”: {“username”: “testUser”, “email”: “test@example.com”, “phone”: “13800000000”}}

获取用户信息接口

接口名称 功能描述 请求方式 请求路径 请求参数 响应参数
GetUserInfo 根据用户ID获取用户的详细信息,包括用户名、邮箱、电话等 GET /api/user/info/{userId} {“code”: “int”, “message”: “string”, “userInfo”: {“userId”: “int”, “username”: “string”, “email”: “string”, “phone”: “string”}}
示例请求 /api/user/info/1
示例响应 {“code”: 200, “message”: “查询成功”, “userInfo”: {“userId”: 1, “username”: “testUser”, “email”: “test@example.com”, “phone”: “13800000000”}}

更新用户信息接口

接口名称 功能描述 请求方式 请求路径 请求参数 响应参数
UpdateUserInfo 允许用户更新自己的部分信息,如密码、邮箱、电话等 PUT /api/user/update {“userId”: “int”, “newPassword”: “string”, “newEmail”: “string”, “newPhone”: “string”} {“code”: “int”, “message”: “string”}
示例请求 {“userId”: 1, “newPassword”: “654321”, “newEmail”: “newtest@example.com”, “newPhone”: “13900000000”}
示例响应 {“code”: 200, “message”: “更新成功”}

二、商品信息相关接口

商品列表接口

接口名称 功能描述 请求方式 请求路径 请求参数 响应参数
GetGoodsList 获取系统中所有商品的列表信息,包括商品名称、价格、库存等基本信息,可按照不同条件进行筛选和排序 GET /api/goods/list {“categoryId”: “int”, “keyword”: “string”, “sortProp”: “string”, “sortOrder”: “string”, “pageNum”: “int”, “pageSize”: “int”} {“code”: “int”, “message”: “string”, “total”: “int”, “list”: [{“goodsId”: “int”, “name”: “string”, “price”: “decimal”, “stock”: “int”, “categoryId”: “int”}]}
示例请求 ?categoryId=1&keyword=手机&sortProp=price&sortOrder=asc&pageNum=1&pageSize=10
示例响应 {“code”: 200, “message”: “查询成功”, “total”: 100, “list”: [{“goodsId”: 1, “name”: “华为手机”, “price”: 3999.00, “stock”: 50, “categoryId”: 1},…]}

商品详情接口

接口名称 功能描述 请求方式 请求路径 请求参数 响应参数
GetGoodsDetail 根据商品ID获取商品的详细信息,包括商品的详细描述、图片列表、规格参数等 GET /api/goods/detail/{goodsId} {“code”: “int”, “message”: “string”, “goodsDetail”: {“goodsId”: “int”, “name”: “string”, “price”: “decimal”, “stock”: “int”, “description”: “string”, “images”: [“string”], “specs”: {“key”: “string”, “value”: “string”}}}
示例请求 /api/goods/detail/1
示例响应 {“code”: 200, “message”: “查询成功”, “goodsDetail”: {“goodsId”: 1, “name”: “华为手机”, “price”: 3999.00, “stock”: 50, “description”: “一款高性能的华为手机…”, “images”: [“http://example.com/image1.jpg”, “http://example.com/image2.jpg”], “specs”: {“颜色”: “黑色”, “内存”: “8GB”, “存储容量”: “128GB”}}}

添加商品接口

接口名称 功能描述 请求方式 请求路径 请求参数 响应参数
AddGoods 管理员或商家添加新商品到系统,需要填写商品的详细信息,包括名称、价格、库存、描述、图片等 POST /api/goods/add {“name”: “string”, “price”: “decimal”, “stock”: “int”, “description”: “string”, “images”: [“string”], “specs”: {“key”: “string”, “value”: “string”}} {“code”: “int”, “message”: “string”, “goodsId”: “int”}
示例请求 {“name”: “小米手机”, “price”: 2999.00, “stock”: 100, “description”: “一款性价比很高的小米手机…”, “images”: [“http://example.com/image3.jpg”, “http://example.com/image4.jpg”], “specs”: {“颜色”: “白色”, “内存”: “6GB”, “存储容量”: “128GB”}}
示例响应 {“code”: 200, “message”: “添加成功”, “goodsId”: 2}

更新商品信息接口

接口名称 功能描述 请求方式 请求路径 请求参数 响应参数
UpdateGoodsInfo 修改已有商品的信息,如价格、库存、描述等,根据商品ID进行更新操作 PUT /api/goods/update/{goodsId} {“name”: “string”, “price”: “decimal”, “stock”: “int”, “description”: “string”, “images”: [“string”], “specs”: {“key”: “string”, “value”: “string”}} {“code”: “int”, “message”: “string”}
示例请求 {“goodsId”: 1, “name”: “华为手机Pro”, “price”: 4999.00, “stock”: 30, “description”: “升级版的华为手机…”, “images”: [“http://example.com/image5.jpg”, “http://example.com/image6.jpg”], “specs”: {“颜色”: “银色”, “内存”: “12GB”, “存储容量”: “256GB”}}
示例响应 {“code”: 200, “message”: “更新成功”}

三、订单信息相关接口

创建订单接口

接口名称 功能描述 请求方式 请求路径 请求参数 响应参数
CreateOrder 用户在购物车中选择商品后,调用该接口生成订单,需要传递购买的商品信息、收货地址、支付方式等参数 POST /api/order/create {“userId”: “int”, “goodsList”: [{“goodsId”: “int”, “quantity”: “int”}], “address”: {“receiver”: “string”, “phone”: “string”, “province”: “string”, “city”: “string”, “area”: “string”, “detailAddress”: “string”}, “paymentMethod”: “string”} {“code”: “int”, “message”: “string”, “orderId”: “int”, “orderAmount”: “decimal”}
示例请求 {“userId”: 1, “goodsList”: [{“goodsId”: 1, “quantity”: 2}, {“goodsId”: 2, “quantity”: 1}], “address”: {“receiver”: “张三”, “phone”: “13600000000”, “province”: “广东省”, “city”: “深圳市”, “area”: “南山区”, “detailAddress”: “科技园路1号”}, “paymentMethod”: “微信支付”}
示例响应 {“code”: 200, “message”: “下单成功”, “orderId”: 1001, “orderAmount”: 7998.00}

查询订单列表接口

接口名称 功能描述 请求方式 请求路径 请求参数 响应参数
GetOrderList 用户可以查询自己所有的订单列表,支持按照订单状态、时间范围等条件进行筛选和排序,分页显示订单信息 GET /api/order/list {“userId”: “int”, “status”: “string”, “startTime”: “string”, “endTime”: “string”, “sortProp”: “string”, “sortOrder”: “string”, “pageNum”: “int”, “pageSize”: “int”} {“code”: “int”, “message”: “string”, “total”: “int”, “list”: [{“orderId”: “int”, “amount”: “decimal”, “status”: “string”, “createTime”: “string”}]}
示例请求 ?userId=1&status=已支付&startTime=2024-01-01&endTime=2024-12-31&sortProp=createTime&sortOrder=desc&pageNum=1&pageSize=10
示例响应 {“code”: 200, “message”: “查询成功”, “total”: 5, “list”: [{“orderId”: 1001, “amount”: 7998.00, “status”: “已支付”, “createTime”: “2024-01-15”},…]}

查询订单详情接口

接口名称 功能描述 请求方式 请求路径 请求参数 响应参数
GetOrderDetail 根据订单ID获取订单的详细信息,包括订单中的商品列表、收货地址、支付方式、订单状态等信息 GET /api/order/detail/{orderId} {“code”: “int”, “message”: “string”, “orderDetail”: {“orderId”: “int”, “userId”: “int”, “amount”: “decimal”, “status”: “string”, “createTime”: “string”, “goodsList”: [{“goodsId”: “int”, “name”: “string”, “price”: “decimal”, “quantity”: “int”}], “address”: {“receiver”: “string”, “phone”: “string”, “province”: “string”, “city”: “string”, “area”: “string”, “detailAddress”: “string”}, “paymentMethod”: “string”}}
示例请求 /api/order/detail/1001
示例响应 {“code”: 200, “message”: “查询成功”, “orderDetail”: {“orderId”: 1001, “userId”: 1, “amount”: 7998.00, “status”: “已支付”, “createTime”: “2024-01-15”, “goodsList”: [{“goodsId”: 1, “name”: “华为手机”, “price”: 3999.00, “quantity”: 2}, {“goodsId”: 2, “name”: “小米手机”, “price”: 2999.00, “quantity”: 1}], “address”: {“receiver”: “张三”, “phone”: “13600000000”, “province”: “广东省”, “city”: “深圳市”, “area”: “南山区”, “detailAddress”: “科技园路1号”}, “paymentMethod”: “微信支付”}}

更新订单状态接口

接口名称 功能描述 请求方式 请求路径 请求参数 响应参数
UpdateOrderStatus 根据订单ID修改订单的状态,如从未支付到已支付,从已发货到已完成等,只有管理员或有权限的用户才能调用此接口进行状态更新操作 PUT /api/order/updateStatus/{orderId} {“status”: “string”} {“code”: “int”, “message”: “string”}
示例请求 {“orderId”: 1001, “status”: “已发货”}
示例响应 {“code”: 200, “message”: “状态更新成功”}

【相关问题与解答】

api接口名称

问题1:如果我要获取特定用户的所有订单,并且只显示订单ID和订单金额,应该如何修改“查询订单列表接口”?

解答:可以在“查询订单列表接口”的响应参数中,只返回orderIdamount字段,修改后的响应参数可能如下:

{
    "code": 200,
    "message": "查询成功",
    "total": 5,
    "list": [
        {"orderId": 1001, "amount": 7998.00},
        {"orderId": 1002, "amount": 5997.00},
        {"orderId": 1003, "amount": 4999.00},
        {"orderId": 1004, "amount": 3999.00},
        {"orderId": 1005, "amount": 2999.00}
    ]
}

这样的修改可以简化前端的数据处理逻辑,减少不必要的数据传输。

问题2:在“创建订单接口”中,如果用户没有选择收货地址,应该如何处理?

api接口名称

解答:在“创建订单接口”中,收货地址是一个必填项,如果用户没有选择收货地址,前端应该在用户提交订单之前进行校验,并提示用户必须填写收货地址,如果后端接收到没有收货地址的订单创建请求,应该返回一个错误码和错误信息,告知用户收货地址不能为空。

{
    "code": 400,
    "message": "收货地址不能为空"
}

这样可以避免因为缺少收货地址而导致的订单处理错误。

各位小伙伴们,我刚刚为大家分享了有关“api接口名称”的知识,希望对你们有所帮助。如果您还有其他相关问题需要解决,欢迎随时提出哦!

【版权声明】:本站所有内容均来自网络,若无意侵犯到您的权利,请及时与我们联系将尽快删除相关内容!

(0)
热舞的头像热舞
上一篇 2025-04-01 16:25
下一篇 2025-04-01 16:28

相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

联系我们

QQ-14239236

在线咨询: QQ交谈

邮件:asy@cxas.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信