电商项目前后端接口说明
服務器信息
IP:192.168.0.108
Port:9000
云服務器信息
IP:43.142.28.161
端口:9000
狀態碼
| 200 | 請求成功 |
| 500 | 服務器端響應失敗 |
| 401 | 前端傳參為空或空串 |
| 402 | 賬號或密碼錯誤 |
| 501 | 若賬號已存在,以改賬號注冊返回501 |
| 502 | 身份驗證失敗 |
登錄/注冊模塊
用戶注冊接口
注冊頁接口
-
URL:http://IP:Port/xdmall/user/logon
-
請求方式:POST
-
Request Body:
屬性名類型必填備注 accountNum string 是 - password string 是 - role string 是 取值user/business/admin之一 -
示例
//request {"accountNum":"835629801@user","password":"a1b2c3","role":"user" }//response {"data": {"role": "user","accountNum": "835629801@user"},"msg": "logon success.","code": 200 }--------------------------- //賬號已存在,注冊失敗 {"data": null,"msg": "Account already exists","code": 501 }//缺少參數 {"data": null,"msg": "param is null.","code": 401 }
用戶登錄接口
登錄頁接口
-
URL:http://IP:Port/xdmall/user/login
-
請求方式:POST
-
Request Body:
屬性名類型必填備注 accountNum string 是 - password string 是 - role string 是 取值user/business/admin之一 -
示例
//request {"accountNum":"835629801@user","password":"a1b2c3","role":"user" }//response {"data": {"image": “頭像的base64編碼","role": "user","accountNum": "835629801@user"},"msg": "login success.","code": 200 }---------------------------- //賬號不存在 {"data": null,"msg": "user is not exists.","code": 402 }//密碼錯誤 {"data": null,"msg": "password error.","code": 402 }//缺少參數 {"data": null,"msg": "param is null.","code": 401 }
用戶信息修改接口
-
URL:http://IP:Port/xdmall/user/alterUser
-
請求方式:POST
-
Request Body:
屬性名類型必填備注 accountNum string 是 根據用戶賬號修改信息 password string 否 - nickname string 否 - pic string 否 - sex string 否 男/女 tel string 否 - isVip bool 否 - - 注:需要修改那個屬性,json就傳那個key,value
-
示例
request body {"accountNum":"835629801@business","password":"a1b2c3","nickname":"初陽尋風","pic":"base64","sex":"男","tel":"15399413267","isVip":true }response {"data": null,"msg": "success.","code": 200 }
商戶信息修改接口
-
URL:http://IP:Port/xdmall/user/alterBusiness
-
請求方式:POST
-
Request Body:
屬性名類型必填備注 storeName string 否 - owner string 是 根據owner查找該賬號下商店 pic string 否 - address string 否 - zipcode string 否 - tel string 否 - type string 否 - level int 否 - - 注:需要修改那個屬性,json就傳那個key,value
-
示例
request body {"storeName":"黑豬白豬的小店","owner":"835629801@business","pic":"","address":"陜西省西安市蓮湖區紅廟坡街道","zipcode":"710014","tel":"15399413267","type":"花店","level":5 }response {"data": null,"msg": "success.","code": 200 }
管理員信息修改接口
-
URL:http://IP:Port/xdmall/user/alterAdmin
-
請求方式:POST
-
Request Body:
屬性名類型必填備注 accountNum string 是 根據賬號修改信息 adminName string 否 - pic string 否 - tel string 否 - - 注:需要修改那個屬性,json就傳那個key,value
-
示例
request body {"accountNum":"835629801@business","adminName":"黑豬","pic":"","tel":"15399413267" }response {"data": null,"msg": "success.","code": 200 }
用戶/商戶信息查詢
-
URL:http://IP:Port/xdmall/user/query
-
請求方式:GET
-
Request Param:
屬性名類型必填備注 accountNum string 是 - role string 是 - -
示例
request body http://localhost:9000/xdmall/user/query?accountNum=835629801@business&role=businessresponse {"data": {"id": 1,"storeName": "黑豬白豬的小店","owner": "835629801@business","pic": "用戶頭像base64編碼","address": "陜西省西安市蓮湖區紅廟坡街道","zipcode": "710014","tel": "15399413267","type": "花店","level": 5,"picturePath": "", //忽略該字段"role": "business"},"msg": "success.","code": 200 }
商品模塊
商戶添加商品接口
商戶權限下,添加商品接口。注:添加商品要先對商戶信息進行初始化,否則商戶名為默認值:未設置
-
URL:http://IP:Port/xdmall/product/add
-
請求方式:POST
-
Request Body:
屬性名類型必填備注 accountNum string 是 - role string 是 只有business角色能添加商品 product object 是 商品對象,字段詳情見示例 -
示例
商戶/管理員刪除商品接口
商戶、管理員權限下,刪除商品接口
-
URL:http://IP:Port/xdmall/product/drop
-
請求方式:POST
-
Request Body:
屬性名類型必填備注 accountNum string 是 - role string 是 只有business、admin角色能添刪除商品 product object 是 商品對象,字段詳情見示例 -
示例
商戶/管理員/用戶根據商品ID查詢商品詳情接口
商戶、管理員、用戶權限下,查詢商品詳情接口。注意是精確查詢,主要針對商品CURD使用
-
URL:http://IP:Port/xdmall/product/queryById
-
請求方式:POST
-
Request Body:
屬性名類型必填備注 accountNum string 是 - role string 是 user、business、admin角色具有接口權限 product object 是 商品對象,字段詳情見示例 -
示例
商戶修改商品接口
商戶權限下,修改商戶自身商品信息接口
-
URL:http://IP:Port/xdmall/product/alterById
-
請求方式:POST
-
Request Body:
屬性名類型必填備注 accountNum string 是 - role string 是 business角色具有接口權限 product object 是 商品對象,字段詳情見示例 -
示例
批量查詢商品接口
商戶權限下,修改商戶自身商品信息接口
-
URL:http://IP:Port/xdmall/product/query/batch
-
請求方式:GET
-
Request Param:
屬性名類型必填備注 pageNum int 否 頁數,默認1,第一頁為1 pageSize int 否 頁大小,默認10 storeName string 否 商店名,如果為空,表示查詢所有商戶下所有商品 -
示例
搜索模塊
將數據庫中數據導入到Elasticsearch
將數據庫中所有數據導入ES
-
URL:http://IP:Port/xdmall/esProduct/importAll
-
請求方式:POST
-
Request Body:無
-
示例
根據商品ID導入商品到ES
根據商品ID將商品導入ES,商品添加成功后后端調用
- URL:http://IP:Port/xdmall/esProduct/import/{id}
- 請求方式:POST
- Request Body:無
- 示例
根據商品ID刪除ES中記錄
根據商品ID刪除ES中記錄,商品刪除成功后后端調用
- URL:http://IP:Port/xdmall/esProduct/delete/{id}
- 請求方式:GET
- Request Param:無
- 示例
批量刪除ES商品記錄
根據商品ID批量刪除ES中記錄
- URL:http://IP:Port/xdmall/esProduct/delete/batch
- 請求方式:POST
- Request Param:無
- 示例
ES搜索接口
聯想搜索相關接口,可以用于首頁搜索框,商品類別等…
-
URL:http://IP:Port/xdmall/esProduct//search/simple
-
請求方式:GET
-
Request Param:
屬性名類型必填備注 accountNum string 是 記錄用戶搜索歷史,用于首頁商品推薦,搜索歷史保留1年 keyword string 是 關鍵詞,根據商品名、描述、關鍵詞字段進行分詞并查詢 pageNum number 否 默認1,第一頁的頁號為1 pageSize number 否 默認5 -
示例
商品推薦接口
根據用戶歷史搜索記錄進行首頁商品推薦,返回10款商品
-
URL:http://IP:Port/xdmall/esProduct//search/recommend
-
請求方式:GET
-
Request Param:
屬性名類型必填備注 accountNum string 是 記錄用戶搜索歷史,用于首頁商品推薦, pageNum number 否 默認1,第一頁的頁號為1 pageSize number 否 默認5 -
示例
http://192.168.0.108:9000/xdmall/esProduct/search/recommend?accountNum=835629801@business{"data": [{"id": 15,"name": "ipone14","pic": "商品圖片base64編碼","brand": "蘋果","price": 6000.5,"description": "蘋果手機..","number": 0, //忽略該字段"stock": 20, //展示庫存"unit": "部","weight": 500.23,"keywords": "蘋果|ipone|高端手機","picturePath": ""},{"id": 16,"name": "華為 HUAWEI P20 ","pic": "商品圖片base64編碼","brand": "華為","price": 3788.0,"description": "AI智慧全面屏 6GB +64GB 亮黑色 全網通版 移動聯通電信4G手機 雙卡雙待手機 雙卡雙待","number": 0,"stock": 20,"unit": "部","weight": 500.5,"keywords": "華為|全面屏|高端手機|全網通版|雙卡雙待","picturePath": ""}],"msg": "success.","code": 200 }
購物車模塊
添加購物車商品
-
URL:http://IP:Port/xdmall/shopping/add
-
請求方式:POST
-
Request Body:
屬性名類型必填備注 accountNum string 是 - productId number 是 商品ID number number 是 商品數量 -
示例
request body {"accountNum": "835629801@user","productId": 3,"number": 1 }response {"data": {"id": 2 //購物車中記錄ID},"msg": "success.","code": 200 }
修改購物車商品數量
-
URL:http://IP:Port/xdmall/shopping/alter
-
請求方式:POST
-
Request Body:
屬性名類型必填備注 accountNum string 是 - id number 是 購物車記錄ID number number 是 商品數量 -
示例
request body {"accountNum": "835629801@user","id": 2,"number": 2 }response {"data": null,"msg": "success.","code": 200 }
查詢賬戶下購物車信息
-
URL:http://IP:Port/xdmall/shopping/query
-
請求方式:GET
-
Request Param:
屬性名類型必填備注 accountNum string 是 查找某賬戶下購物車信息 -
示例
request param http://localhost:9000/xdmall/shopping/query?accountNum=835629801@userresponse {"data": [{"product": { //商品信息"id": 3,"name": "小米8 全面屏游戲智能手機 6GB+64GB 黑色 全網通4G 雙卡雙待","storeName": "黑豬白豬的小店","pic": "商品圖片base64編碼","brand": "小米","price": 2699.0,"description": "驍龍845處理器,紅外人臉解鎖,AI變焦雙攝,AI語音助手小米6X低至1299,點擊搶購","number": 0,"stock": 30,"unit": "部","weight": 550.53,"keywords": "小米8 全面屏游戲智能手機 6GB+64GB 黑色 全網通4G 雙卡雙待","picturePath": "" //忽略該字段},"number": 2, //購物車商品數量"accountNum": "835629801@user","id": 2 //購物車記錄ID}],"msg": "success.","code": 200 }
刪除購物車商品
-
URL:http://IP:Port/xdmall/shopping/drop
-
請求方式:GET
-
Request Param:
屬性名類型必填備注 id number 是 購物車記錄ID -
示例
request http://localhost:9000/xdmall/shopping/drop?id=1response {"data": null,"msg": "success.","code": 200 }
訂單模塊
添加訂單
-
URL:http://IP:Port/xdmall/order/add
-
請求方式:POST
-
Request Body:
屬性名類型必填備注 accountNum string 是 賬戶 state string 是 訂單狀態,create、run、done shoppingId string 是 購物車ID組合,如2|3表示該訂單由購物車單號2,3組成 -
示例
request body {"accountNum":"835629801@user","state":"create","shoppingId":"2" }response {"data": {"id": 2 //訂單ID},"msg": "success.","code": 200 }
修改訂單狀態
-
URL:http://IP:Port/xdmall/order/alter
-
請求方式:POST
-
Request Body:
屬性名類型必填備注 id string 是 訂單ID state string 是 訂單狀態,create、run、done -
示例
request body {"id":"1","state":"done" }response {"data": null,"msg": "success.","code": 200 }
查詢賬戶下所有訂單
-
URL:http://IP:Port/xdmall/order/query
-
請求方式:GET
-
Request Param:
屬性名類型必填備注 accountNum string 是 賬戶 -
示例
request http://localhost:9000/xdmall/order/query?accountNum=835629801@userresponse {"data": [{"id": 1, //訂單編號"accountNum": "835629801@user", //訂單所屬賬戶"createtime": "2023-06-04 20:51:23", //訂單創建時間"address": "陜西省西安市蓮湖區紅廟坡街道紅東花園1期", //訂單收貨地址"state": "done", //訂單狀態"price": 10796.00, //訂單中商品總額"productAndNumDtoList": [ //訂單由若干商品組成,且包含商品數量{"number": 2, //商品數量"product": { //商品信息"id": 3,"name": "小米8 全面屏游戲智能手機 6GB+64GB 黑色 全網通4G 雙卡雙待","storeName": "黑豬白豬的小店","pic": "商品base64編碼""brand": "小米","price": 2699.0,"description": "驍龍845處理器,紅外人臉解鎖,AI變焦雙攝,AI語音助手小米6X低至1299,點擊搶購","number": 0,"stock": 30,"unit": "部","weight": 550.53,"keywords": "小米8 全面屏游戲智能手機 6GB+64GB 黑色 全網通4G 雙卡雙待","picturePath": ""}},{"number": 2, //商品數量"product": { //商品信息"id": 4,"name": "小米8 全面屏游戲智能手機 6GB+64GB 黑色 全網通4G 雙卡雙待","storeName": "黑豬白豬的小店","pic": "商品base64編碼""brand": "小米","price": 2699.0,"description": "驍龍845處理器,紅外人臉解鎖,AI變焦雙攝,AI語音助手小米6X低至1299,點擊搶購","number": 0,"stock": 30,"unit": "部","weight": 550.53,"keywords": "小米8 全面屏游戲智能手機 6GB+64GB 黑色 全網通4G 雙卡雙待","picturePath": ""}}]},{"id": 2, //同上,第二個訂單"accountNum": "835629801@user","createtime": "2023-06-04 21:03:06","address": "陜西省西安市蓮湖區紅廟坡街道紅東花園1期","state": "create","price": 5398.00,"productAndNumDtoList": [{"number": 2,"product": {"id": 3,"name": "小米8 全面屏游戲智能手機 6GB+64GB 黑色 全網通4G 雙卡雙待","storeName": "黑豬白豬的小店","pic": "商品base64編碼""brand": "小米","price": 2699.0,"description": "驍龍845處理器,紅外人臉解鎖,AI變焦雙攝,AI語音助手小米6X低至1299,點擊搶購","number": 0,"stock": 30,"unit": "部","weight": 550.53,"keywords": "小米8 全面屏游戲智能手機 6GB+64GB 黑色 全網通4G 雙卡雙待","picturePath": ""}}]}],"msg": "success.","code": 200 }
總結
以上是生活随笔為你收集整理的电商项目前后端接口说明的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [bzoj4566][SAM]找相同字符
- 下一篇: python 中的@符号