# 微信小程序系统课 - 部分 API 接口文档

TIP

本文档旨在为微信小程序系统课的开发者提供一套详尽的 API 接口指南。

通过对这些 API 接口的调用,开发者可以轻松地与后端服务器进行交互,实现微信小程序中所需的各种功能和业务逻辑。

  • 接口概述
  • 接口列表
  • API 接口调用注意事项

# 一、接口概述

TIP

本文档提供了微信小程序系统课的部分相关 API 接口说明,涵盖了查询关键字、用户登录、颜色值获取、课程列表查询、课程分类查询、商城首页数据获取、商品列表查询、以及 《Coffee 项目》首页 和 菜单页数据获取等功能的 API 接口。

# 二、接口列表

TIP

文档详细列出了各个 API 接口的详细信息。每个接口都包括 URL、请求方法、请求参数、响应参数以及示例响应数据等。开发者可以根据需要选择相应的 API 接口进行调用,并参考示例数据了解接口的返回结果。

相关 API 接口根地址:http://applet.icodingedu.cnhttps://applet.icodingedu.cn

# 1、查询关键字

TIP

  • URL/api/words
  • 请求方法:GET
  • 请求参数:无
  • 响应参数
    • data:关键字列表,每个关键字为一个字符串
    • code:状态码(例如:200 表示成功)
    • message:状态信息
  • 响应数据格式
{
  "code": 200,
  "data": [
    {
      "word": "javascript"
    },
    {
      "word": "java"
    },
    {
      "word": "json"
    },
    {
      "word": "python"
    },
    {
      "word": "c/c++"
    },
    {
      "word": "node.js"
    },
    {
      "word": "php"
    }
  ],
  "message": "成功"
}

# 2、用户登录

TIP

  • URL/api/login
  • 请求方法:POST
  • 请求参数
    • username:用户名(字符串)
    • password:密码(字符串)
  • 响应参数
    • token:登录成功后返回的令牌(字符串),此功能暂时用不到令牌
    • data:用户信息(对象)
      • id:用户 ID(字符串)
      • username:用户名
      • email:邮箱地址
      • address:用户地址
      • phone:手机号
      • role:用户角色
      • createTime:创建时间
      • updateTime:更新时间
    • message:状态信息
    • code:状态码
  • 响应数据格式
{
  "code": "0000",
  "data": {
    "id": "10001",
    "username": "admin",
    "email": "u.ljsabxo@hbp.mobi",
    "address": "天津 天津市 红桥区",
    "phone": "14942673430",
    "role": 0,
    "createTime": "1982-04-10 06:29:59",
    "updateTime": "1978-06-30 21:52:24"
  },
  "message": "登录成功"
}

# 3、获取随机颜色值列表

TIP

  • URL/api/color
  • 请求方法:GET
  • 请求参数:无
  • 响应参数
    • color:随机颜色值(数组)
    • message:状态信息
    • code:状态码
  • 响应数据格式
{
  "code": "0000",
  "message": "成功",
  "data": {
    "colorList": [
      "rgba(239,178,138,0.55)",
      "rgba(44,255,252,0.05)",
      "rgba(86,129,66,0.25)",
      "rgba(123,47,191,0.78)",
      "rgba(117,67,4,0.84)",
      "rgba(164,57,205,0.62)",
      "rgba(91,234,15,0.56)",
      "rgba(163,118,184,0.74)",
      "rgba(128,52,170,0.77)",
      "rgba(218,24,249,0.47)"
    ]
  }
}

# 4、获取课程列表(分页查询)

TIP

  • URL/api/course/list
  • 请求方法:GET
  • 请求参数
    • page:页码(整数)
    • count:每页数量(整数)
  • 响应参数
    • list:课程列表(数组,每个课程为一个对象)
      • id:课程 ID(整数)
      • type:课程类型(整数)
      • title:课程标题(字符串)
      • description:课程描述(字符串)
      • price:课程价格(浮点型)
      • createTime:创建时间(日期)
      • salesVolume:销售量(整数)
      • score:星级(整数)
      • category:类型(对象)
        • id :类型 ID(整数)
        • name:类型名称(字符串)
      • coverImage:封面图(对象)
        • id :封面 ID(整数)
        • path:封面图路径(字符串)
      • publisher 发布人
        • id :发布者 ID(整数)
        • nickname:昵称(字符串)
        • avatar:头像路径(字符串)
        • realname:真实姓名(字符串)
        • gender:性别(整数)
    • totalRecord:总课程数(整数)
    • page:页码(整数)
    • count:每页数量(整数)
    • message:状态信息
    • code:状态码
  • 响应数据格式
{
  "list": [
    {
      "id": 1,
      "type": 1,
      "title": "写界象感单里华五内之住候照段",
      "description": "到那到手农对任第流许连今给只市改美线其争种质设由两红类支争。",
      "price": 899.51,
      "createTime": "2009-08-25 09:18:21",
      "salesVolume": 99,
      "score": 5,
      "category": {
        "id": 1,
        "name": "民京"
      },
      "coverImage": {
        "id": 1,
        "path": "http://dummyimage.com/180x190/ffcc33/FFF.png&text=icoding"
      },
      "publisher": {
        "id": 1,
        "nickname": "魏秀英",
        "avatar": "http://dummyimage.com/81x81/7bd802/FFF.png&text=avatar",
        "realname": "汪敏",
        "gender": 1
      }
    },
    {
      "id": 1,
      "type": 1,
      "title": "题次例证花点广该合织子整于外进根非使中",
      "description": "断又年力上建却法心通好设产间去看极通争业展果音长信值农九几事高提气到声处示。",
      "price": 5473.97,
      "createTime": "2013-04-02 17:35:28",
      "salesVolume": 79,
      "score": 5,
      "category": {
        "id": 1,
        "name": "路切"
      },
      "coverImage": {
        "id": 1,
        "path": "http://dummyimage.com/180x190/ffcc33/FFF.png&text=icoding"
      },
      "publisher": {
        "id": 1,
        "nickname": "唐强",
        "avatar": "http://dummyimage.com/81x81/7bd802/FFF.png&text=avatar",
        "realname": "罗艳",
        "gender": 1
      }
    },
    {
      "id": 1,
      "type": 2,
      "title": "接了离保影算受确称",
      "description": "积按支她却连革命复团入队团东矿因按易亲带设共。",
      "price": 4864.38,
      "createTime": "1998-05-02 01:22:13",
      "salesVolume": 57,
      "score": 4,
      "category": {
        "id": 1,
        "name": "入位"
      },
      "coverImage": {
        "id": 1,
        "path": "http://dummyimage.com/180x190/ffcc33/FFF.png&text=icoding"
      },
      "publisher": {
        "id": 1,
        "nickname": "吕芳",
        "avatar": "http://dummyimage.com/81x81/7bd802/FFF.png&text=avatar",
        "realname": "金敏",
        "gender": 0
      }
    },
    {
      "id": 1,
      "type": 1,
      "title": "先细求深同大江国所率必给备",
      "description": "第一四带离六科保新量研下却命任级改科指点了信火龙效生采标红。",
      "price": 3947.85,
      "createTime": "2004-09-01 03:13:45",
      "salesVolume": 62,
      "score": 1,
      "category": {
        "id": 1,
        "name": "果者"
      },
      "coverImage": {
        "id": 1,
        "path": "http://dummyimage.com/180x190/ffcc33/FFF.png&text=icoding"
      },
      "publisher": {
        "id": 1,
        "nickname": "唐涛",
        "avatar": "http://dummyimage.com/81x81/7bd802/FFF.png&text=avatar",
        "realname": "曾秀英",
        "gender": 1
      }
    },
    {
      "id": 1,
      "type": 2,
      "title": "积亲人表义对把给到也领己二",
      "description": "金等级热海意步交劳江系矿事深写具想思气象拉天空出思包研见高过米老布信身品文调对效用为者度道主应。",
      "price": 7436.05,
      "createTime": "1977-02-10 02:28:02",
      "salesVolume": 86,
      "score": 5,
      "category": {
        "id": 1,
        "name": "不状"
      },
      "coverImage": {
        "id": 1,
        "path": "http://dummyimage.com/180x190/ffcc33/FFF.png&text=icoding"
      },
      "publisher": {
        "id": 1,
        "nickname": "金磊",
        "avatar": "http://dummyimage.com/81x81/7bd802/FFF.png&text=avatar",
        "realname": "姚敏",
        "gender": 1
      }
    }
  ],
  "totalRecord": 10,
  "page": 1,
  "count": 5,
  "code": "0000",
  "message": "成功"
}

# 5、获取课程分类

TIP

  • URL/api/course/category
  • 请求方法:GET
  • 请求参数:无
  • 响应参数
    • categories:课程分类列表(数组,每个分类为一个对象)
  • 响应数据格式
[
  {
    "id": 1,
    "name": "Web 前端"
  },
  {
    "id": 2,
    "name": "Java 架构"
  },
  {
    "id": 3,
    "name": "Python 实战"
  },
  {
    "id": 4,
    "name": "Node 后端"
  },
  {
    "id": 5,
    "name": "GO 语言"
  },
  {
    "id": 6,
    "name": "云原生"
  },
  {
    "id": 7,
    "name": "前端架构"
  }
]

# 6、商城首页相关数据

TIP

  • URL/api/mall/index
  • 请求方法:GET
  • 请求参数:无
  • 响应参数
    • swiperList:轮播图列表(数组)
      • id:轮播图 ID(整数)
      • imgUrl:图片路径(字符串)
    • categoryList:商品分类列表(数组)
      • id:分类 ID(整数)
      • categoryName:分类名称(字符串)
      • bgColor:背景颜色(字符串)
      • icon:图标路径(字符串)
    • newProductList:新品上市列表(数组)
      • id:商品 ID(整数)
      • imgUrl:商品地址(字符串)
    • message:状态信息
    • code:状态码
  • 响应数据格式
{
  "code": "0000",
  "data": {
    "swiperList": [
      {
        "id": 1,
        "imgUrl": "https://cdn.cnbj1.fds.api.mi-img.com/mi-mall/19cb37a109aae75e2f9db732efd45931.jpg"
      },
      {
        "id": 2,
        "imgUrl": "https://cdn.cnbj1.fds.api.mi-img.com/mi-mall/d4c792368ff9fb173515bc30871a0c27.jpg"
      },
      {
        "id": 3,
        "imgUrl": "https://cdn.cnbj1.fds.api.mi-img.com/mi-mall/1890c73f4e4ae4a547c438a21a30d9f3.jpg"
      },
      {
        "id": 4,
        "imgUrl": "https://cdn.cnbj1.fds.api.mi-img.com/mi-mall/b7942f2a4ad2f70dfd5be94ff1976597.jpg"
      },
      {
        "id": 5,
        "imgUrl": "https://cdn.cnbj1.fds.api.mi-img.com/mi-mall/693534e5382f540ea7c413563d658884.jpg"
      }
    ],
    "categoryList": [
      {
        "id": 1,
        "categoryName": "水果蔬菜",
        "bgColor": "#BEE570",
        "icon": "https://www.arryblog.com/mall-img/icon/icon-1.png"
      },
      {
        "id": 2,
        "categoryName": "肉禽蛋品",
        "bgColor": "#F8CEB4",
        "icon": "https://www.arryblog.com/mall-img/icon/icon-2.png"
      },
      {
        "id": 3,
        "categoryName": "海鲜水产",
        "bgColor": "#B4DDFF",
        "icon": "https://www.arryblog.com/mall-img/icon/icon-3.png"
      },
      {
        "id": 4,
        "categoryName": "速食冷冻",
        "bgColor": "#9DBAE1",
        "icon": "https://www.arryblog.com/mall-img/icon/icon-4.png"
      },
      {
        "id": 5,
        "categoryName": "粮油食品",
        "bgColor": "#FFE38F",
        "icon": "https://www.arryblog.com/mall-img/icon/icon-5.png"
      },
      {
        "id": 6,
        "categoryName": "夏日特惠",
        "bgColor": "#7AD9E8",
        "icon": "https://www.arryblog.com/mall-img/icon/icon-6.png"
      },
      {
        "id": 7,
        "categoryName": "雪糕冰棍",
        "bgColor": "#C2C1FD",
        "icon": "https://www.arryblog.com/mall-img/icon/icon-7.png"
      },
      {
        "id": 8,
        "categoryName": "休闲零食",
        "bgColor": "#FECD9A",
        "icon": "https://www.arryblog.com/mall-img/icon/icon-8.png"
      },
      {
        "id": 9,
        "categoryName": "酒水饮品",
        "bgColor": "#98E8C1",
        "icon": "https://www.arryblog.com/mall-img/icon/icon-9.png"
      },
      {
        "id": 10,
        "categoryName": "日用百货",
        "bgColor": "#84D1E8",
        "icon": "https://www.arryblog.com/mall-img/icon/icon-10.png"
      }
    ],
    "newProductList": [
      {
        "id": 1,
        "imgUrl": "https://www.arryblog.com/mall-img/product/new-product-1.png"
      },
      {
        "id": 2,
        "imgUrl": "https://www.arryblog.com/mall-img/product/new-product-2.png"
      },
      {
        "id": 3,
        "imgUrl": "https://www.arryblog.com/mall-img/product/new-product-3.png"
      }
    ]
  },
  "message": "成功"
}

# 7、根据商品类型 ID 查询商品列表

TIP

  • URL/api/mall/list
  • 请求方法:GET
  • 请求参数
    • id:商品类型 ID(整数)
  • 响应参数
    • mallList:商品列表(数组,每个商品为一个对象)
      • id:商品 ID(整数)
      • productName:商品名称(字符串)
      • productDesc:商品描述(字符串)
      • olderPrice:原价(浮点型)
      • currentPrice:现价(浮点型)
      • coverImage:商品封面图(字符串)
      • categoryId:类型 ID(整数)
    • message:状态信息
    • code:状态码
  • 响应数据格式
{
  "code": "0000",
  "data": {
    "mallList": [
      {
        "id": 1,
        "productName": "张员手分度速斯民",
        "productDesc": "斗真示带律律看查界各化题队",
        "olderPrice": 78.97,
        "currentPrice": 2.16,
        "coverImage": "http://dummyimage.com/186x160/50B347/FFF&text=186x160",
        "categoryId": 1
      },
      {
        "id": 2,
        "productName": "作消线常己走林许拉",
        "productDesc": "极习作将军决复行常支管王有门",
        "olderPrice": 71.39,
        "currentPrice": 20.68,
        "coverImage": "http://dummyimage.com/186x160/50B347/FFF&text=186x160",
        "categoryId": 2
      },
      {
        "id": 3,
        "productName": "之议油单",
        "productDesc": "样什济队号信成任空合这走矿",
        "olderPrice": 62.64,
        "currentPrice": 17.28,
        "coverImage": "http://dummyimage.com/186x160/50B347/FFF&text=186x160",
        "categoryId": 3
      },
      {
        "id": 4,
        "productName": "么日海京",
        "productDesc": "得油张九书位青相身什都段",
        "olderPrice": 65.32,
        "currentPrice": 13.23,
        "coverImage": "http://dummyimage.com/186x160/50B347/FFF&text=186x160",
        "categoryId": 4
      },
      {
        "id": 5,
        "productName": "必开圆须确业将",
        "productDesc": "位调议设是学行满事亲",
        "olderPrice": 76.06,
        "currentPrice": 19.22,
        "coverImage": "http://dummyimage.com/186x160/50B347/FFF&text=186x160",
        "categoryId": 5
      },
      {
        "id": 6,
        "productName": "机路史引会火王",
        "productDesc": "要压快低话电速员大明角家些",
        "olderPrice": 98.57,
        "currentPrice": 12.31,
        "coverImage": "http://dummyimage.com/186x160/50B347/FFF&text=186x160",
        "categoryId": 6
      },
      {
        "id": 7,
        "productName": "及高你段带了",
        "productDesc": "争后原局放理光打都目被人放",
        "olderPrice": 54.61,
        "currentPrice": 26.03,
        "coverImage": "http://dummyimage.com/186x160/50B347/FFF&text=186x160",
        "categoryId": 7
      },
      {
        "id": 8,
        "productName": "其代深复严已",
        "productDesc": "见北务能向美造或大相劳即广",
        "olderPrice": 55.97,
        "currentPrice": 25.08,
        "coverImage": "http://dummyimage.com/186x160/50B347/FFF&text=186x160",
        "categoryId": 8
      },
      {
        "id": 9,
        "productName": "般阶同斯权信",
        "productDesc": "速内交件强此法及划院科效带国",
        "olderPrice": 86.99,
        "currentPrice": 5.11,
        "coverImage": "http://dummyimage.com/186x160/50B347/FFF&text=186x160",
        "categoryId": 9
      },
      {
        "id": 10,
        "productName": "象利消今响该",
        "productDesc": "组文关备活效与规可者",
        "olderPrice": 59.79,
        "currentPrice": 13.25,
        "coverImage": "http://dummyimage.com/186x160/50B347/FFF&text=186x160",
        "categoryId": 10
      },
      {
        "id": 11,
        "productName": "并制线社局细它县",
        "productDesc": "风层式建安所号处老段要议王许什",
        "olderPrice": 87.63,
        "currentPrice": 1.22,
        "coverImage": "http://dummyimage.com/186x160/50B347/FFF&text=186x160",
        "categoryId": 11
      },
      {
        "id": 12,
        "productName": "照水与务国开入林",
        "productDesc": "么该热资数清方义回同",
        "olderPrice": 52.88,
        "currentPrice": 3.14,
        "coverImage": "http://dummyimage.com/186x160/50B347/FFF&text=186x160",
        "categoryId": 12
      }
    ]
  },
  "message": "成功"
}

# 8、Coffee 项目 - 首页相关数据

TIP

  • URL/api/coffee/index
  • 请求方法:GET
  • 请求参数:无
  • 响应参数
    • advUrl:首页轮播图列表(数组)
      • id:adv 图片 ID(整数)
      • url:图片地址(字符串)
    • newProducts:最新商品 banner(数组)
      • id: ID(整数)
      • url:图片地址(字符串)
    • message:状态信息
    • code:状态码
  • 响应数据格式
{
  "code": "0000",
  "message": "成功",
  "data": {
    "advUrl": [
      {
        "id": 1,
        "url": "https://www.arryblog.com/coffee/index-swiper-1.png"
      },
      {
        "id": 2,
        "url": "https://www.arryblog.com/coffee/index-swiper-2.png"
      },
      {
        "id": 3,
        "url": "https://www.arryblog.com/coffee/index-swiper-3.png"
      }
    ],
    "newProducts": [
      {
        "id": 1,
        "url": "https://www.arryblog.com/mall-img/product/new-product-3.png"
      },
      {
        "id": 2,
        "url": "https://www.arryblog.com/mall-img/product/new-product-2.png"
      },
      {
        "id": 3,
        "url": "https://www.arryblog.com/mall-img/product/new-product-1.png"
      }
    ]
  }
}

# 9、Coffee 项目 - 菜单页相关数据

TIP

  • URL/api/coffee/menu
  • 请求方法:GET
  • 请求参数:无
  • 响应参数
    • navLeftItems:菜单分类列表(数组,每个分类为一个对象)
    • navRightItems:菜单商品列表(数组,每个商品为一个对象)
      • category_id:类型 ID(字符串)
      • title:类型标题(字符串)
      • product:商品信息(数组,每个分类为一个对象)
    • productList:商品列表(数组,每个商品为一个对象)
    • message:状态信息
    • code:状态码
  • 响应数据格式
{
  "code": "0000",
  "message": "成功",
  "data": {
    "navLeftItems": [
      "人气 TOP",
      "爆款套餐",
      "咖啡",
      "奶茶",
      "甜品小点",
      "水果茶",
      "烘焙轻食",
      "纯茶",
      "经典饮品",
      "小黑杯",
      "大师咖啡",
      "生椰家族",
      "不喝咖啡"
    ],
    "navRightItems": [
      [
        {
          "category_id": 1001,
          "title": "人气 TOP",
          "product": [
            {
              "id": "100101",
              "category_id": 1001,
              "productName": "生酪拿铁",
              "desc": "年度拿铁中测冠军",
              "originalPrice": 29,
              "favorablePrice": 18,
              "productImg": "https://www.arryblog.com/coffee/coffee-1.png"
            },
            {
              "id": "100102",
              "category_id": 1001,
              "productName": "丝绒拿铁",
              "desc": "甘甜丝滑",
              "originalPrice": 29,
              "favorablePrice": 21,
              "productImg": "https://www.arryblog.com/coffee/coffee-1.png"
            },
            {
              "id": "100103",
              "category_id": 1001,
              "productName": "相思红豆拿铁",
              "desc": "据说是王维诗里的红豆",
              "originalPrice": 35,
              "favorablePrice": 21,
              "productImg": "https://www.arryblog.com/coffee/coffee-1.png"
            },
            {
              "id": "100104",
              "category_id": 1001,
              "productName": "生椰拿铁",
              "desc": "人气爆款,YYDS 无限回归",
              "originalPrice": 29,
              "favorablePrice": 18,
              "productImg": "https://www.arryblog.com/coffee/coffee-1.png"
            },
            {
              "id": "100105",
              "category_id": 1001,
              "productName": "生椰丝绒拿铁",
              "desc": "双爆款,一口椰香一口丝滑",
              "originalPrice": 32,
              "favorablePrice": 19,
              "productImg": "https://www.arryblog.com/coffee/coffee-1.png"
            }
          ]
        }
      ],
      [
        {
          "category_id": 1002,
          "title": "爆款套餐",
          "product": [
            {
              "id": "100106",
              "category_id": 1002,
              "productName": "2杯贴贴咖啡",
              "desc": "前方高能一起贴贴",
              "originalPrice": 45,
              "favorablePrice": 38.5,
              "productImg": "https://www.arryblog.com/coffee/coffee-1.png"
            },
            {
              "id": "100107",
              "category_id": 1002,
              "productName": "2杯么么咖啡",
              "desc": "甜甜蜜蜜在一起",
              "originalPrice": 39.8,
              "favorablePrice": 31.9,
              "productImg": "https://www.arryblog.com/coffee/coffee-1.png"
            },
            {
              "id": "100108",
              "category_id": 1002,
              "productName": "3杯醒醒咖啡",
              "desc": "欢乐下午茶,享3倍快乐",
              "originalPrice": 56.9,
              "favorablePrice": 46.11,
              "productImg": "https://www.arryblog.com/coffee/coffee-1.png"
            },
            {
              "id": "100109",
              "category_id": 1002,
              "productName": "4杯暖暖咖啡",
              "desc": "成双结对,2对很开心",
              "originalPrice": 79.5,
              "favorablePrice": 63.8,
              "productImg": "https://www.arryblog.com/coffee/coffee-1.png"
            }
          ]
        }
      ]
    ],
    "productList": [
      {
        "id": "100101",
        "category_id": 1001,
        "productName": "生酪拿铁",
        "desc": "年度拿铁中测冠军",
        "detailDesc": "丝滑拿铁口感丝般柔滑,咖啡的香醇和牛奶的丝滑如艺术般完美结合,淡淡丝甜,让你在繁忙中随时享受片刻活力和悠闲。",
        "originalPrice": 29,
        "favorablePrice": 18,
        "productImg": "https://www.arryblog.com/coffee/coffee-1.png",
        "productBannerImg": "https://www.arryblog.com/coffee/product-banner-1.png",
        "stock": 8,
        "specs": [
          {
            "id": 2001,
            "specsName": "规格",
            "specsDesc": [
              {
                "id": 3001,
                "title": "小",
                "isActive": false
              },
              {
                "id": 3002,
                "title": "中",
                "isActive": true
              },
              {
                "id": 3003,
                "title": "大",
                "isActive": false
              }
            ]
          },
          {
            "id": 2002,
            "specsName": "温度",
            "specsDesc": [
              {
                "id": 3004,
                "title": "常温",
                "isActive": true
              },
              {
                "id": 3005,
                "title": "加冰",
                "isActive": false
              },
              {
                "id": 3006,
                "title": "热",
                "isActive": false
              }
            ]
          },
          {
            "id": 2003,
            "specsName": "糖度",
            "specsDesc": [
              {
                "id": 3007,
                "title": "半塘",
                "isActive": true
              },
              {
                "id": 3008,
                "title": "无糖",
                "isActive": false
              },
              {
                "id": 3009,
                "title": "加糖",
                "isActive": false
              }
            ]
          }
        ]
      },
      {
        "id": "100102",
        "category_id": 1001,
        "productName": "丝绒拿铁",
        "desc": "甘甜丝滑",
        "detailDesc": "浓情饮咖啡,清心品淡茶,浓醇的咖啡有苦涩的味道,有糖的甜,有奶的香,喝完一杯咖啡,感受那种百味含混的浓沉醇厚,顿觉熟气腾腾,陶醉不已。",
        "originalPrice": 29,
        "favorablePrice": 21,
        "productImg": "https://www.arryblog.com/coffee/coffee-1.png",
        "productBannerImg": "https://www.arryblog.com/coffee/product-banner-2.png",
        "stock": 6,
        "specs": [
          {
            "id": 2004,
            "specsName": "规格",
            "specsDesc": [
              {
                "id": 3010,
                "title": "小",
                "isActive": false
              },
              {
                "id": 3011,
                "title": "中",
                "isActive": true
              },
              {
                "id": 3012,
                "title": "大",
                "isActive": false
              }
            ]
          },
          {
            "id": 2005,
            "specsName": "温度",
            "specsDesc": [
              {
                "id": 3013,
                "title": "常温",
                "isActive": true
              },
              {
                "id": 3014,
                "title": "加冰",
                "isActive": false
              },
              {
                "id": 3015,
                "title": "热",
                "isActive": false
              }
            ]
          },
          {
            "id": 2006,
            "specsName": "糖度",
            "specsDesc": [
              {
                "id": 3016,
                "title": "半塘",
                "isActive": true
              },
              {
                "id": 3017,
                "title": "无糖",
                "isActive": false
              },
              {
                "id": 3018,
                "title": "加糖",
                "isActive": false
              }
            ]
          }
        ]
      },
      {
        "id": "100103",
        "category_id": 1001,
        "productName": "相思红豆拿铁",
        "desc": "据说是王维诗里的红豆",
        "detailDesc": "品尝一杯咖啡,你喝到甘甜是一种幸福! 咖啡一股香味带有巧克力风味也有香草风味; 咖啡有苦有甜,苦尽甘来; 咖啡是一种暗色调,也是一杯手工创意 !",
        "originalPrice": 35,
        "favorablePrice": 21,
        "productImg": "https://www.arryblog.com/coffee/coffee-1.png",
        "productBannerImg": "https://www.arryblog.com/coffee/product-banner-3.png",
        "stock": 5,
        "specs": [
          {
            "id": 2007,
            "specsName": "规格",
            "specsDesc": [
              {
                "id": 3019,
                "title": "小",
                "isActive": false
              },
              {
                "id": 3020,
                "title": "中",
                "isActive": true
              },
              {
                "id": 3021,
                "title": "大",
                "isActive": false
              }
            ]
          },
          {
            "id": 2008,
            "specsName": "温度",
            "specsDesc": [
              {
                "id": 3022,
                "title": "常温",
                "isActive": true
              },
              {
                "id": 3023,
                "title": "加冰",
                "isActive": false
              },
              {
                "id": 3024,
                "title": "热",
                "isActive": false
              }
            ]
          },
          {
            "id": 2009,
            "specsName": "糖度",
            "specsDesc": [
              {
                "id": 3025,
                "title": "半塘",
                "isActive": true
              },
              {
                "id": 3026,
                "title": "无糖",
                "isActive": false
              },
              {
                "id": 3027,
                "title": "加糖",
                "isActive": false
              }
            ]
          }
        ]
      },
      {
        "id": "100104",
        "category_id": 1001,
        "productName": "生椰拿铁",
        "desc": "人气爆款,YYDS 无限回归",
        "detailDesc": "浓情饮咖啡,清心品淡茶,浓醇的咖啡有苦涩的味道,有糖的甜,有奶的香,喝完一杯咖啡,感受那种百味含混的浓沉醇厚,顿觉熟气腾腾,陶醉不已。",
        "originalPrice": 29,
        "favorablePrice": 18,
        "productImg": "https://www.arryblog.com/coffee/coffee-1.png",
        "productBannerImg": "https://www.arryblog.com/coffee/product-banner-3.png",
        "stock": 6,
        "specs": [
          {
            "id": 2007,
            "specsName": "规格",
            "specsDesc": [
              {
                "id": 3019,
                "title": "小",
                "isActive": false
              },
              {
                "id": 3020,
                "title": "中",
                "isActive": true
              },
              {
                "id": 3021,
                "title": "大",
                "isActive": false
              }
            ]
          },
          {
            "id": 2008,
            "specsName": "温度",
            "specsDesc": [
              {
                "id": 3022,
                "title": "常温",
                "isActive": true
              },
              {
                "id": 3023,
                "title": "加冰",
                "isActive": false
              },
              {
                "id": 3024,
                "title": "热",
                "isActive": false
              }
            ]
          },
          {
            "id": 2009,
            "specsName": "糖度",
            "specsDesc": [
              {
                "id": 3025,
                "title": "半塘",
                "isActive": true
              },
              {
                "id": 3026,
                "title": "无糖",
                "isActive": false
              },
              {
                "id": 3027,
                "title": "加糖",
                "isActive": false
              }
            ]
          }
        ]
      },
      {
        "id": "100105",
        "category_id": 1001,
        "productName": "生椰丝绒拿铁",
        "desc": "双爆款,一口椰香一口丝滑",
        "detailDesc": "咖啡的颜色,是思念一个人时的寂寞,回忆两个人时的神伤;那浓郁的味道,诉说了你我前世不解的情缘,飘去了的,只是过去……",
        "originalPrice": 32,
        "favorablePrice": 19,
        "productImg": "https://www.arryblog.com/coffee/coffee-1.png",
        "productBannerImg": "https://www.arryblog.com/coffee/product-banner-3.png",
        "stock": 3,
        "specs": [
          {
            "id": 2007,
            "specsName": "规格",
            "specsDesc": [
              {
                "id": 3019,
                "title": "小",
                "isActive": false
              },
              {
                "id": 3020,
                "title": "中",
                "isActive": true
              },
              {
                "id": 3021,
                "title": "大",
                "isActive": false
              }
            ]
          },
          {
            "id": 2008,
            "specsName": "温度",
            "specsDesc": [
              {
                "id": 3022,
                "title": "常温",
                "isActive": true
              },
              {
                "id": 3023,
                "title": "加冰",
                "isActive": false
              },
              {
                "id": 3024,
                "title": "热",
                "isActive": false
              }
            ]
          },
          {
            "id": 2009,
            "specsName": "糖度",
            "specsDesc": [
              {
                "id": 3025,
                "title": "半塘",
                "isActive": true
              },
              {
                "id": 3026,
                "title": "无糖",
                "isActive": false
              },
              {
                "id": 3027,
                "title": "加糖",
                "isActive": false
              }
            ]
          }
        ]
      },
      {
        "id": "100106",
        "category_id": 1002,
        "productName": "2杯贴贴咖啡",
        "desc": "前方高能一起贴贴",
        "detailDesc": "温暖的午后,优雅的环境,清彻的音乐,浓浓的咖啡香气,醇厚的口感,变换的花式情趣,让人不知不觉间陶醉在咖啡香里",
        "originalPrice": 45,
        "favorablePrice": 38.5,
        "productImg": "https://www.arryblog.com/coffee/coffee-1.png",
        "productBannerImg": "https://www.arryblog.com/coffee/product-banner-3.png",
        "stock": 7,
        "specs": [
          {
            "id": 2007,
            "specsName": "规格",
            "specsDesc": [
              {
                "id": 3019,
                "title": "小",
                "isActive": false
              },
              {
                "id": 3020,
                "title": "中",
                "isActive": true
              },
              {
                "id": 3021,
                "title": "大",
                "isActive": false
              }
            ]
          },
          {
            "id": 2008,
            "specsName": "温度",
            "specsDesc": [
              {
                "id": 3022,
                "title": "常温",
                "isActive": true
              },
              {
                "id": 3023,
                "title": "加冰",
                "isActive": false
              },
              {
                "id": 3024,
                "title": "热",
                "isActive": false
              }
            ]
          },
          {
            "id": 2009,
            "specsName": "糖度",
            "specsDesc": [
              {
                "id": 3025,
                "title": "半塘",
                "isActive": true
              },
              {
                "id": 3026,
                "title": "无糖",
                "isActive": false
              },
              {
                "id": 3027,
                "title": "加糖",
                "isActive": false
              }
            ]
          }
        ]
      },
      {
        "id": "100107",
        "category_id": 1002,
        "productName": "2杯么么咖啡",
        "desc": "甜甜蜜蜜在一起",
        "detailDesc": "雨天,喝咖啡,在咖啡厅里,隔着若有若无的玻璃,看到外面的世界!喝着期待以久的香浓咖啡 !",
        "originalPrice": 39.8,
        "favorablePrice": 31.9,
        "productImg": "https://www.arryblog.com/coffee/coffee-1.png",
        "productBannerImg": "https://www.arryblog.com/coffee/product-banner-3.png",
        "stock": 2,
        "specs": [
          {
            "id": 2007,
            "specsName": "规格",
            "specsDesc": [
              {
                "id": 3019,
                "title": "小",
                "isActive": false
              },
              {
                "id": 3020,
                "title": "中",
                "isActive": true
              },
              {
                "id": 3021,
                "title": "大",
                "isActive": false
              }
            ]
          },
          {
            "id": 2008,
            "specsName": "温度",
            "specsDesc": [
              {
                "id": 3022,
                "title": "常温",
                "isActive": true
              },
              {
                "id": 3023,
                "title": "加冰",
                "isActive": false
              },
              {
                "id": 3024,
                "title": "热",
                "isActive": false
              }
            ]
          },
          {
            "id": 2009,
            "specsName": "糖度",
            "specsDesc": [
              {
                "id": 3025,
                "title": "半塘",
                "isActive": true
              },
              {
                "id": 3026,
                "title": "无糖",
                "isActive": false
              },
              {
                "id": 3027,
                "title": "加糖",
                "isActive": false
              }
            ]
          }
        ]
      },
      {
        "id": "100108",
        "category_id": 1002,
        "productName": "3杯醒醒咖啡",
        "desc": "欢乐下午茶,享3倍快乐",
        "detailDesc": "没有你的岁月、加了糖的咖啡,也是苦的。陪伴我的依旧是那些忧伤的文字,惊慌的寻找往昔,拼命的翻找,就这样一直在你的世界里辗转,沉湎,而不倦。",
        "originalPrice": 56.9,
        "favorablePrice": 46.11,
        "productImg": "https://www.arryblog.com/coffee/coffee-1.png",
        "productBannerImg": "https://www.arryblog.com/coffee/product-banner-3.png",
        "stock": 5,
        "specs": [
          {
            "id": 2007,
            "specsName": "规格",
            "specsDesc": [
              {
                "id": 3019,
                "title": "小",
                "isActive": false
              },
              {
                "id": 3020,
                "title": "中",
                "isActive": true
              },
              {
                "id": 3021,
                "title": "大",
                "isActive": false
              }
            ]
          },
          {
            "id": 2008,
            "specsName": "温度",
            "specsDesc": [
              {
                "id": 3022,
                "title": "常温",
                "isActive": true
              },
              {
                "id": 3023,
                "title": "加冰",
                "isActive": false
              },
              {
                "id": 3024,
                "title": "热",
                "isActive": false
              }
            ]
          },
          {
            "id": 2009,
            "specsName": "糖度",
            "specsDesc": [
              {
                "id": 3025,
                "title": "半塘",
                "isActive": true
              },
              {
                "id": 3026,
                "title": "无糖",
                "isActive": false
              },
              {
                "id": 3027,
                "title": "加糖",
                "isActive": false
              }
            ]
          }
        ]
      },
      {
        "id": "100109",
        "category_id": 1002,
        "productName": "4杯暖暖咖啡",
        "desc": "成双结对,2对很开心",
        "detailDesc": "煮一壶咖啡,小心滤过,不加糖,不加奶,只加少许盐,赏著多年不用的花式咖啡杯,一时间,所有的人或事,都就著浓浓的雾气,慢慢地,散开,淡去。",
        "originalPrice": 79.5,
        "favorablePrice": 63.8,
        "productImg": "https://www.arryblog.com/coffee/coffee-1.png",
        "productBannerImg": "https://www.arryblog.com/coffee/product-banner-3.png",
        "stock": 4,
        "specs": [
          {
            "id": 2007,
            "specsName": "规格",
            "specsDesc": [
              {
                "id": 3019,
                "title": "小",
                "isActive": false
              },
              {
                "id": 3020,
                "title": "中",
                "isActive": true
              },
              {
                "id": 3021,
                "title": "大",
                "isActive": false
              }
            ]
          },
          {
            "id": 2008,
            "specsName": "温度",
            "specsDesc": [
              {
                "id": 3022,
                "title": "常温",
                "isActive": true
              },
              {
                "id": 3023,
                "title": "加冰",
                "isActive": false
              },
              {
                "id": 3024,
                "title": "热",
                "isActive": false
              }
            ]
          },
          {
            "id": 2009,
            "specsName": "糖度",
            "specsDesc": [
              {
                "id": 3025,
                "title": "半塘",
                "isActive": true
              },
              {
                "id": 3026,
                "title": "无糖",
                "isActive": false
              },
              {
                "id": 3027,
                "title": "加糖",
                "isActive": false
              }
            ]
          }
        ]
      }
    ]
  }
}

# 三、API 接口调用注意事项

TIP

在开发微信小程序时,与后端 API 接口进行交互是不可避免的一部分。为了确保稳定、安全和高效的数据传输,开发者需要遵循一些基本的规则和注意事项。

以下是对这些注意事项的简要介绍

# 1、接口地址选择

TIP

  • 确保使用正确的接口地址,并且优先使用 HTTPS 协议,因为它提供了加密传输,增强了数据安全性。

# 2、请求方法

TIP

  • 严格按照 API 文档中指定的请求方法进行调用,GET 请求用于查询数据,POST 请求用于提交数据等。

# 3、请求参数

TIP

  • 仔细核对请求参数,确保参数名称、数据类型和格式都与 API 文档一致。
  • 对于 POST 请求,通常需要将请求参数放在请求体中,而不是 URL 中。

# 4、请求头设置

TIP

  • 某些 API 可能需要特定的请求头,如 Content-Type(指定请求体的媒体类型),Authorization(用于身份验证)等。
  • 检查是否需要设置额外的请求头,并确保它们被正确设置。

# 5、异常处理

TIP

  • 在调用 API 时,应该有完善的异常处理机制,能够处理网络错误、请求超时、服务器错误等异常情况。
  • 当 API 调用失败时,应该能够给出清晰的错误提示,并尽量提供错误码和错误信息,以便开发者定位问题。

# 6、状态码和消息

TIP

  • 仔细解析 API 返回的状态码和消息,了解 API 调用的结果。
  • 根据状态码进行不同的处理,如成功、失败、需要重试等。

# 7、数据解析

TIP

  • 根据 API 返回的数据格式(如 JSON),使用合适的解析方法将数据解析为程序能够处理的数据结构。
  • 在解析数据时,应该进行类型检查和边界检查,确保数据的正确性和安全性。

# 8、令牌(Token)处理

TIP

  • 虽然用户登录接口暂时用不到令牌,但在其他需要身份验证的 API 中,可能需要使用令牌进行身份验证。
  • 确保正确存储和传递令牌,并在需要时将其包含在请求头中。

# 9、缓存机制

TIP

  • 对于一些不经常变化的数据(如课程分类、颜色值等),可以考虑使用缓存机制来减少网络请求,提高程序性能。
  • 但要注意缓存的更新策略,确保数据的实时性和准确性。

# 10、安全性

TIP

  • 避免在客户端存储敏感信息,如用户名、密码等。
  • 使用 HTTPS 协议进行数据传输,确保数据在传输过程中的安全性。
  • 对于需要身份验证的 API,确保使用安全的身份验证机制,如 JWT(JSON Web Tokens)等。

# 11、错误日志记录

TIP

  • 在调用 API 时,应该记录详细的错误日志,包括请求 URL、请求参数、请求头、响应数据等。
  • 这些日志对于后续的问题排查和性能优化非常重要。

# 12、测试

TIP

  • 在开发过程中,应该对 API 进行充分的测试,包括单元测试、集成测试、性能测试等。
  • 确保 API 的正确性、稳定性和性能满足需求。
上次更新时间: 7/19/2024, 3:10:45 AM

大厂最新技术学习分享群

大厂最新技术学习分享群

微信扫一扫进群,获取资料

X