0


【微信小程序】电商移动前端API文档

在这里插入图片描述

文章目录


request域名:小程序只支持 https 协议,并且要求是已备案的域名。

https://www.zhengzhicheng.cn
备用:
https://autumnfish.cn/wx
https://www.uinav.com

一、文档更新说明

更新日期 2019-04-01

1、返回值调整

新版接口调整:  res.data.message

旧版接口废弃:  res.data.data

2、分类页图片

新版接口调整:  cat_icon 属性直接返回完整图片 url 地址

旧版接口废弃:  cat_icon 返回相对路径,需要手动拼接路径

3、订单支付接口

新版接口调整:  支付对象数据为 res.data.message.pay

旧版接口废弃:  支付对象数据为 res.data.data.wxorder

二、路径说明

  • 根路径说明
    https://请求域名/api/public/v1
  • 路径权限说明 - 路径所有权限都可以访问 https://请求域名/api/public/v1- 只有登录用户才可以访问路径 https://请求域名/api/public/v1/my

三、电商登录实现方式

  • 采用 jwt 方式进行
  • 实现流程 1. 请求登录2. 获取token3. 访问有权限的路径必须把 token 放置到 http 头中 "Authorization" : token1. token 不过期,长期有效。

四、API详情

1、全局权限访问

  • 访问根路径
    https://请求域名/api/public/v1

(1)主页API

获取首页轮播图数据
  • 请求路径:https://请求域名/api/public/v1/home/swiperdata

  • 请求方法:GET

  • 请求参数
    参数名参数说明备注无

  • 响应参数
    参数名参数说明备注image_src图片路径open_type导航链接类型navigator_url导航链接路径

  • 响应数据参考

{
    "message": [
        {
            "image_src": "https://www.zhengzhicheng.cn/pyg/banner1.png",
            "open_type": "navigate",
            "goods_id": 129,
            "navigator_url": "/pages/goods_detail/main?goods_id=129"
        },
        {
            "image_src": "https://www.zhengzhicheng.cn/pyg/banner2.png",
            "open_type": "navigate",
            "goods_id": 395,
            "navigator_url": "/pages/goods_detail/main?goods_id=395"
        },
        {
            "image_src": "https://www.zhengzhicheng.cn/pyg/banner3.png",
            "open_type": "navigate",
            "goods_id": 38,
            "navigator_url": "/pages/goods_detail/main?goods_id=38"
        }
    ],
    "meta": { "msg": "获取成功", "status": 200 }
}
获取首页分类选项数据
  • 请求路径:https://请求域名/api/public/v1/home/catitems

  • 请求方法:GET

  • 请求参数
    参数名参数说明备注无

  • 响应参数
    参数名参数说明备注name名称image_src图片路径open_type导航链接类型navigator_url导航链接路径

  • 响应数据

{"message":[{"name":"分类","image_src":"https://www.zhengzhicheng.cn/pyg/[email protected]","open_type":"switchTab","navigator_url":"/pages/category/main"},{"name":"秒杀拍","image_src":"https://www.zhengzhicheng.cn/pyg/[email protected]"},{"name":"超市购","image_src":"https://www.zhengzhicheng.cn/pyg/[email protected]"},{"name":"母婴品","image_src":"https://www.zhengzhicheng.cn/pyg/[email protected]"}],"meta":{"msg":"获取成功","status":200}}
获取首页楼层数据
  • 请求路径:https://请求域名/api/public/v1/home/floordata

  • 请求方法:GET

  • 请求参数
    参数名参数说明备注无

  • 响应参数
    参数名参数说明备注floor_title楼层标题product_list楼层内容列表name名称image_src图片路径image_width商品图片宽度open_type导航链接类型navigator_url导航链接路径

  • 响应数据

{"message":[{"floor_title":{"name":"时尚女装","image_src":"https://www.zhengzhicheng.cn/pyg/pic_floor01_title.png"},"product_list":[{"name":"优质服饰","image_src":"https://www.zhengzhicheng.cn/pyg/[email protected]","image_width":"232","open_type":"navigate","navigator_url":"/pages/goods_list?query=服饰"},{"name":"春季热门","image_src":"https://www.zhengzhicheng.cn/pyg/[email protected]","image_width":"233","open_type":"navigate","navigator_url":"/pages/goods_list?query=热"},{"name":"爆款清仓","image_src":"https://www.zhengzhicheng.cn/pyg/[email protected]","image_width":"233","open_type":"navigate","navigator_url":"/pages/goods_list?query=爆款"},{"name":"倒春寒","image_src":"https://www.zhengzhicheng.cn/pyg/[email protected]","image_width":"233","open_type":"navigate","navigator_url":"/pages/goods_list?query=春季"},{"name":"怦然心动","image_src":"https://www.zhengzhicheng.cn/pyg/[email protected]","image_width":"233","open_type":"navigate","navigator_url":"/pages/goods_list?query=心动"}]},{"floor_title":{"name":"户外活动","image_src":"https://www.zhengzhicheng.cn/pyg/pic_floor02_title.png"},"product_list":[{"name":"勇往直前","image_src":"https://www.zhengzhicheng.cn/pyg/[email protected]","image_width":"232","open_type":"navigate","navigator_url":"/pages/goods_list?query=户外"},{"name":"户外登山包","image_src":"https://www.zhengzhicheng.cn/pyg/[email protected]","image_width":"273","open_type":"navigate","navigator_url":"/pages/goods_list?query=登山包"},{"name":"超强手套","image_src":"https://www.zhengzhicheng.cn/pyg/[email protected]","image_width":"193","open_type":"navigate","navigator_url":"/pages/goods_list?query=手套"},{"name":"户外运动鞋","image_src":"https://www.zhengzhicheng.cn/pyg/[email protected]","image_width":"193","open_type":"navigate","navigator_url":"/pages/goods_list?query=运动鞋"},{"name":"冲锋衣系列","image_src":"https://www.zhengzhicheng.cn/pyg/[email protected]","image_width":"273","open_type":"navigate","navigator_url":"/pages/goods_list?query=冲锋衣"}]},{"floor_title":{"name":"箱包配饰","image_src":"https://www.zhengzhicheng.cn/pyg/pic_floor03_title.png"},"product_list":[{"name":"清新气质","image_src":"https://www.zhengzhicheng.cn/pyg/[email protected]","image_width":"232","open_type":"navigate","navigator_url":"/pages/goods_list?query=饰品"},{"name":"复古胸针","image_src":"https://www.zhengzhicheng.cn/pyg/[email protected]","image_width":"263","open_type":"navigate","navigator_url":"/pages/goods_list?query=胸针"},{"name":"韩版手链","image_src":"https://www.zhengzhicheng.cn/pyg/[email protected]","image_width":"203","open_type":"navigate","navigator_url":"/pages/goods_list?query=手链"},{"name":"水晶项链","image_src":"https://www.zhengzhicheng.cn/pyg/[email protected]","image_width":"193","open_type":"navigate","navigator_url":"/pages/goods_list?query=水晶项链"},{"name":"情侣表","image_src":"https://www.zhengzhicheng.cn/pyg/[email protected]","image_width":"273","open_type":"navigate","navigator_url":"/pages/goods_list?query=情侣表"}]}],"meta":{"msg":"获取成功","status":200}}

(2)商品API

商品列表搜索
  • 请求路径:https://请求域名/api/public/v1/goods/search

  • 请求方法:GET

  • 请求参数
    参数名参数说明备注query查询关键词cid分类ID可选pagenum页数索引可选默认第一页pagesize每页长度可选默认20条

  • 响应参数
    参数名参数说明备注total总共记录pagenum当前页数goods_id商品IDcat_id分类IDgoods_name商品名称goods_price商品价格goods_number商品数量goods_weight商品重量goods_big_logo商品大图标goods_small_logo商品小图标add_time商品添加时间upd_time商品更新时间hot_mumber热门商品数cat_one_id所属一级分类cat_two_id所属二级分类cat_three_id所属三级分类

  • 响应数据

{
    "message": {
        "total": 2058,
        "pagenum": "1",
        "goods": [
            {
                "goods_id": 57332,
                "cat_id": 998,
                "goods_name": "400毫升 海鲜食品冷藏冰包 注水冰袋医用冰袋户外冷藏保鲜熟食冷藏反复使用(10个装)",
                "goods_price": 14,
                "goods_number": 100,
                "goods_weight": 100,
                "goods_big_logo": "http://image4.suning.cn/uimg/b2c/newcatentries/0070083251-000000000168369396_1_800x800.jpg",
                "goods_small_logo": "http://image4.suning.cn/uimg/b2c/newcatentries/0070083251-000000000168369396_1_400x400.jpg",
                "add_time": 1516662792,
                "upd_time": 1516662792,
                "hot_mumber": 0,
                "is_promote": false,
                "cat_one_id": 962,
                "cat_two_id": 981,
                "cat_three_id": 998
            },
            {
                "goods_id": 57194,
                "cat_id": 992,
                "goods_name": "亿力洗车工具汽车美容用品海绵刷不伤车漆擦车海棉清洁海绵",
                "goods_price": 29,
                "goods_number": 100,
                "goods_weight": 100,
                "goods_big_logo": "",
                "goods_small_logo": "",
                "add_time": 1516662312,
                "upd_time": 1516662312,
                "hot_mumber": 0,
                "is_promote": false,
                "cat_one_id": 962,
                "cat_two_id": 980,
                "cat_three_id": 992
            }
        ]
    },
    "meta": {
        "msg": "获取成功",
        "status": 200
    }
}
搜索建议查询
  • 请求路径:https://请求域名/api/public/v1/goods/qsearch

  • 请求方法:GET

  • 请求参数
    参数名参数说明备注query查询内容如: goods/qsearch?query=小米

  • 响应参数
    参数名参数说明备注goods_id商品IDgoods_name商品名称

  • 响应数据

{
    "message": [
        {
            "goods_id": 57332,
            "goods_name": "400毫升 海鲜食品冷藏冰包 注水冰袋医用冰袋户外冷藏保鲜熟食冷藏反复使用(10个装)"
        },
        {
            "goods_id": 57194,
            "goods_name": "亿力洗车工具汽车美容用品海绵刷不伤车漆擦车海棉清洁海绵"
        }
    ],
    "meta": {
        "msg": "获取成功",
        "status": 200
    }
}
商品详情
  • 请求路径:https://请求域名/api/public/v1/goods/detail

  • 请求方法:GET

  • 请求参数
    参数名参数说明备注goods_id商品ID必要

  • 响应参数
    参数名参数说明备注goods_id商品IDcat_id分类IDgoods_name商品名称goods_price商品价格goods_number商品数量goods_weight商品重量goods_big_logo商品大图标goods_small_logo商品小图标add_time商品添加时间upd_time商品更新时间hot_mumber热门商品数cat_one_id所属一级分类cat_two_id所属二级分类cat_three_id所属三级分类goods_introduce商品介绍HTML富文本pics商品图片列表attrs商品属性列表

  • 响应数据

{"message":{"goods_id":57332,"cat_id":998,"goods_name":"400毫升 海鲜食品冷藏冰包 注水冰袋医用冰袋户外冷藏保鲜熟食冷藏反复使用(10个装)","goods_price":14,"goods_number":100,"goods_weight":100,"goods_introduce":"<div class=\"lazyimg\"><!-- Save for Web Slices (20170730关联模板.psd) -->\n<p><img data-src=\"//image.suning.cn/uimg/sop/commodity/167890268714163515505319_x.jpg?from=mobile&amp;format=80q.webp\" alt=\"\" usemap=\"#Map\" border=\"0\" src=\"//image.suning.cn/uimg/sop/commodity/167890268714163515505319_x.jpg?from=mobile&format=80q.webp\" width=\"100%\" height=\"auto\"> </p>\n<!-- End Save for Web Slices --><p></p><p><img picsize=\"706KB\" data-src=\"//image.suning.cn/uimg/sop/phonecomm/157271695856956094412300_640x.jpg?from=mobile&amp;format=80q.webp\" alt=\"\" src=\"//image.suning.cn/uimg/sop/phonecomm/157271695856956094412300_640x.jpg?from=mobile&format=80q.webp\" width=\"100%\" height=\"auto\"></p><p><img picsize=\"610KB\" data-src=\"//image.suning.cn/uimg/sop/phonecomm/192892939814201549766135_640x.jpg?from=mobile&amp;format=80q.webp\" alt=\"\" src=\"//image.suning.cn/uimg/sop/phonecomm/192892939814201549766135_640x.jpg?from=mobile&format=80q.webp\" width=\"100%\" height=\"auto\"></p></div>","goods_big_logo":"http://image4.suning.cn/uimg/b2c/newcatentries/0070083251-000000000168369396_1_800x800.jpg","goods_small_logo":"http://image4.suning.cn/uimg/b2c/newcatentries/0070083251-000000000168369396_1_400x400.jpg","goods_state":2,"is_del":"0","add_time":1516662792,"upd_time":1516662792,"delete_time":null,"hot_mumber":0,"is_promote":false,"cat_one_id":962,"cat_two_id":981,"cat_three_id":998,"goods_cat":"962,981,998","pics":[{"pics_id":234751,"goods_id":57332,"pics_big":"http://image4.suning.cn/uimg/b2c/newcatentries/0070083251-000000000168369396_1_800x800.jpg","pics_mid":"http://image4.suning.cn/uimg/b2c/newcatentries/0070083251-000000000168369396_1_400x400.jpg","pics_sma":"http://image4.suning.cn/uimg/b2c/newcatentries/0070083251-000000000168369396_1_200x200.jpg","pics_big_url":"http://image4.suning.cn/uimg/b2c/newcatentries/0070083251-000000000168369396_1_800x800.jpg","pics_mid_url":"http://image4.suning.cn/uimg/b2c/newcatentries/0070083251-000000000168369396_1_400x400.jpg","pics_sma_url":"http://image4.suning.cn/uimg/b2c/newcatentries/0070083251-000000000168369396_1_200x200.jpg"}],"attrs":[{"goods_id":57332,"attr_id":8519,"attr_value":"400","add_price":0,"attr_name":"主体-型号","attr_sel":"only","attr_write":"manual","attr_vals":"Q6"}]},"meta":{"msg":"获取成功","status":200}}

(3)分类API

获取分类数据
  • 请求路径:https://请求域名/api/public/v1/categories

  • 请求方法:GET

  • 请求参数
    参数名参数说明备注无

  • 响应参数
    参数名参数说明备注cat_id分类IDcat_name分类名称cat_level分类级别cat_icon分类图标只有3级别分类采用图标children子分类列表对象数组

  • 响应数据

{"message":[{"cat_id":1,"cat_name":"大家电","cat_pid":0,"cat_level":0,"cat_deleted":false,"cat_icon":"","children":[{"cat_id":3,"cat_name":"电视","cat_pid":1,"cat_level":1,"cat_deleted":false,"cat_icon":"","children":[{"cat_id":5,"cat_name":"曲面电视","cat_pid":3,"cat_level":2,"cat_deleted":false,"cat_icon":"full/2fb113b32f7a2b161f5ee4096c319afedc3fd5a1.jpg"}]}]}],"meta":{"msg":"获取成功","status":200}}

(4)微信用户登录 API

微信登录换取 Token
  • 请求路径:https://请求域名/api/public/v1/users/wxlogin

  • 请求方法:POST

  • 请求参数
    参数名参数说明备注code用户登录凭证必要,可通过 wx.login() 获取encryptedData完整用户信息密文必要,可通过 getUserInfo 获取iv加密算法的初始向量必要,可通过 getUserInfo 获取rawData用户信息原始数据字符串必要,可通过 getUserInfo 获取,JSON.stringify() 转字符串signature使用 sha1得到字符串必要,可通过 getUserInfo 获取

  • 请求数据参考

{"code":"013pZWCt0GniKb1ftkBt0AxfDt0pZWCf","encryptedData":"FGMaNbO4ytTFTUzK3wmtfHWoFeQJYkyMajQ5tVbQglwmnJ46SMi43Thq0OZjSSa5Msmnpdfx7yigYkdvUbsiQFyF9xMGEQLpUFcpNjnYoCQOl2Ka5zEeqpMY91ywYAsPISeu1rwvFCU2Ucenxf7gdcDPQ/jNJdORGb86DR+2gVJeg8TZiXWJ66enpynj35DiaE1jNWUSzpgbOvO40dZrWnHVwDEJN+upeSHRR/IW7t3cgtV63/GeZzNhFbUYqNHO6M1KHetwY1u8mFXuZoXwVV7DrEwEzY1btqcfW93q4ekn2uwAUeJM4U+3roBsIT5ZpEM8YtQZVsAwjaWHBe8id1H4lurEFC5/GwLnRONrIiR7KDF7MPxnMO9flWFQEfay5dt9rBELzk1Efjf2H6UnzYfh+o4MbPxtc0cUiHEnNCVcXjDtulXSRUy7RZQPmjF/tYBHHrXEFubxnK4oRBZz/A==","iv":"y/ESFBaesbEzIbB1th5Knw==","rawData":"{\"nickName\":\"优购\",\"gender\":0,\"language\":\"zh_CN\",\"city\":\"\",\"province\":\"\",\"country\":\"\",\"avatarUrl\":\"https://wx.qlogo.cn/mmopen/vi_32/icWlxE4rARHaIlib1PRmBtRa2tQicUSEHYu8UIGZ0LLic9C0PticibED6brRFCuQYeLGtwTcBYFgMtcF11N31pVhMF8g/132\"}","signature":"d06cd3a54e89e6014e43694844706eaccad109bb"}
  • 响应参数参考
    参数名参数说明备注token身份验证标志user_id用户ID

  • 响应数据

{"message":{"user_id":12,"user_email_code":null,"is_active":null,"user_sex":"男","user_qq":"","user_tel":"","user_xueli":"本科","user_hobby":"","user_introduce":null,"create_time":1525402223,"update_time":1525402223,"token":"Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOjEyLCJpYXQiOjE1MjU0MDIyMjMsImV4cCI6MTUyNTQ4ODYyM30.g-4GtEQNPwT_Xs0Pq7Lrco_9DfHQQsBiOKZerkO-O-o"},"meta":{"msg":"登录成功","status":200}}

2、登录后访问

  • 访问根路径
https://请求域名/api/public/v1/my
  • 访问此系列请求必须在头信息中添加token
"Authorization" : token

(1)订单API

创建订单
  • 请求路径:https://请求域名/api/public/v1/my/orders/create

  • 请求方法:POST

  • 请求参数
    参数名参数说明备注order_price订单价格必要consignee_addr订单地址必要order_detail订单详情可选,字符串格式goods商品列表内部存放商品(goods_id,goods_number和goods_price)列表必要

  • 请求数据参考

{"order_price":0.1,"consignee_addr":"广州市天河区","order_detail":"[{\"goods_id\":55578,\"goods_name\":\"初语2017秋装新款潮牌女装加绒宽松BF风慵懒卫衣女套头连帽上衣\",\"goods_price\":279,\"goods_small_logo\":\"http://image2.suning.cn/uimg/b2c/newcatentries/0070067836-000000000690453616_2_400x400.jpg\",\"counts\":1,\"selectStatus\":true}]","goods":[{"goods_id":5,"goods_number":11,"goods_price":15},{"goods_id":555,"goods_number":1,"goods_price":15}]}
  • 响应参数
    参数名参数说明备注order_id订单唯一IDuser_id用户IDorder_number订单编号order_price订单总金额order_pay订单支付方式支付方式 0未支付 1支付宝 2微信 3银行卡consignee_addr订单地址pay_status订单支付状态订单状态: 0未付款、1已付款

  • 响应数据参考

{"message":{"order_id":45,"user_id":12,"order_number":"GD20180504000000000045","order_price":0.1,"order_pay":"0","is_send":"否","trade_no":"","order_fapiao_title":"个人","order_fapiao_company":"","order_fapiao_content":"","consignee_addr":"广州市天河区","pay_status":"0","create_time":1525408071,"update_time":1525408071,"order_detail":"[{\"goods_id\":55578,\"goods_name\":\"初语2017秋装新款潮牌女装加绒宽松BF风慵懒卫衣女套头连帽上衣\",\"goods_price\":279,\"goods_small_logo\":\"http://image2.suning.cn/uimg/b2c/newcatentries/0070067836-000000000690453616_2_400x400.jpg\",\"counts\":1,\"selectStatus\":true}]","goods":[{"id":64,"order_id":45,"goods_id":5,"goods_price":15,"goods_number":11,"goods_total_price":15}]},"meta":{"msg":"创建订单成功","status":200}}
订单预支付
  • 请求路径:https://请求域名/api/public/v1/my/orders/req_unifiedorder

  • 请求方法:POST

  • 请求参数
    参数名参数说明备注order_number订单编号必要

  • 请求数据

{"order_number":"GD20180507000000000110"}
  • 响应参数
    参数名参数说明备注pay订单对象可通过 wx.requestPayment(OBJECT),发起微信支付timeStamp时间戳nonceStr随机字符串package下单接口返回参数signType签名算法paySign签名order_number订单编号

  • 响应数据

{
  "message": {
    "pay": {
      "timeStamp": "1525681145",
      "nonceStr": "BkPggorBXZwPGXe3",
      "package": "prepay_id=wx071619042918087bb4c1d3d72999385683",
      "signType": "MD5",
      "paySign": "D1642DEEF1663C8012EDEB9297E1D516"
    },
    "order_number": "GD20180507000000000110"
  },
  "meta": { "msg": "预付订单生成成功", "status": 200 }
}
订单支付状态查询
  • 请求路径:https://请求域名/api/public/v1/my/orders/chkOrder

  • 请求方法:POST

  • 请求参数
    参数名参数说明备注order_number订单编号必要

  • 请求数据

{"order_number":"GD20180507000000000050"}
  • 响应参数
    参数名参数说明备注data支付状态meta订单状态

  • 响应数据

// 支付成功
{
    "message":"支付成功",
    "meta":{"msg":"验证成功","status":200}
}

// 支付失败
{ 
    "message": null,
    "meta": { "msg": "订单未支付", "status": 400 } 
}
订单查询
  • 请求路径:https://请求域名/api/public/v1/my/orders/all

  • 请求方法:GET

  • 请求参数
    参数名参数说明备注type11 全部订单 2 代付款订单 3 已付款订单

  • 2响应参数
    参数名参数说明备注order_id订单唯一IDuser_id用户IDorder_number订单编号order_price订单价格order_pay订单支付方式consignee_addr订单地址pay_status订单支付状态

  • 响应数据

{"message":[{"order_id":44,"user_id":12,"order_number":"GD20180507000000000050","order_price":0.1,"order_pay":"0","is_send":"否","trade_no":"","order_fapiao_title":"个人","order_fapiao_company":"","order_fapiao_content":"","consignee_addr":"广州市天河区","pay_status":"0","create_time":1525407814,"update_time":1525407814,"order_detail":"[{\"goods_id\":55578,\"goods_name\":\"初语2017秋装新款潮牌女装加绒宽松BF风慵懒卫衣女套头连帽上衣\",\"goods_price\":279,\"goods_small_logo\":\"http://image2.suning.cn/uimg/b2c/newcatentries/0070067836-000000000690453616_2_400x400.jpg\",\"counts\":1,\"selectStatus\":true}]"}],"meta":{"msg":"获取订单列表成功","status":200}}

本文转载自: https://blog.csdn.net/CSDN_anhl/article/details/127396157
版权归原作者 亮点菌 所有, 如有侵权,请联系我们删除。

“【微信小程序】电商移动前端API文档”的评论:

还没有评论