在线调试
填写业务相关参数免费在线调试
这是一款专为 ShowDoc 文档平台打造的智能导出工具,支持一键获取完整文档结构与内容。只需提供文档链接,即可快速解析项目下所有页面、目录层级及详细内容,支持密码保护的私有文档访问。接口自动处理复杂的文档树结构,递归获取所有子目录和页面内容,返回结构化 JSON 数据。完美适用于文档备份、迁移、二次开发等场景,让文档管理更轻松高效。
至尊会员->单独包月->次数包->点数计费->账户余额->免费额度
至尊会员有效期内,可免费使用本产品。
| 额度 | 价格 | 有效期 |
|---|---|---|
| 1000 (次) | ¥ 500 低至0.5/次 | 一个月 |
| 免费/测试用户请求频率限制 | 请求频率总限制 | 至尊会员请求频率限制 | 每日请求次数总限制 |
|---|---|---|---|
| 1秒1次 每个免费用户的QPS总限制 | 1秒1次 每个用户QPS总限制 | 1秒10次 每个至尊会员用户的QPS总限制 | 10000 (次) 每个用户每日请求总次数 |
接口地址:https://api.kkjsz.cn/api/swd/index
返回格式:application/json
请求方式:HTTPGET
请求示例:https://api.kkjsz.cn/api/swd/index?key=你的key&url=看文档&pass=看文档
| 名称 | 值 |
|---|---|
| Content-Type | application/x-www-form-urlencoded;charset:utf-8; |
| 名称 | 必填 | 类型 | 示例值 | 说明 |
|---|---|---|---|---|
| url | 是 | string | https://www.showdoc.com.cn/128719739414963 | ShowDoc文档地址,支持数字ID或字符串标识符格式 |
| pass | 否 | string | 123456 | 文档访问密码(如果文档设置了密码保护则必填) |
| 名称 | 类型 | 说明 |
|---|---|---|
| code | int | 状态码(200:成功, 400:参数错误, 401:密码错误, 404:文档不存在, 500:服务器错误, 503:网络请求失败) |
| message | string | 状态信息描述 |
| tip | string | 接口来源提示信息 |
| data | object | 文档数据对象(仅成功时返回) |
| data.item_name | string | 项目名称 |
| data.structure | array | 文档结构数组,包含所有页面和目录的层级关系 |
| structure[].type | string | 节点类型: "page"(页面) 或 "catalog"(目录) |
| structure[].page_id | string | 页面ID(仅type为page时存在) |
| structure[].title | string | 页面标题(仅type为page时存在) |
| structure[].content | string | 页面内容,支持Markdown格式(仅type为page时存在) |
| structure[].name | string | 目录名称(仅type为catalog时存在) |
| structure[].children | array | 子节点数组,递归包含子目录和页面(仅type为catalog时存在) |
本服务仅供个人学习、学术研究目的使用,未经授权,请勿分享、传播输入及生成的文本、图片内容。用户在从事与本服务相关的一切行为(包括但不限于访问浏览、利用、转载、宣传介绍)时,应以善意且谨慎的态度行事并承担相应的风险和责任。用户需确保不得利用本服务进行危害国家安全和社会公共利益、扰乱经济秩序和社会秩序、侵犯他人合法权益等法律、行政法规禁止的活动,并且自定义输入文本不得包含违反法律法规、政治相关、侵犯他人合法权益的内容。对于用户因使用本服务而导致的任何损失或风险,包括但不限于由于使用本服务而产生的错误、疏忽、中断、删除、故障、延迟或通讯线路故障所导致的任何损失或损害,本服务的开发者将不承担任何责任。
{}
- "code": 200,
- "message": "success",
- "tip": "此接口由咔咔云独家开发,购买开源接口源码联系QQ:79087446",
-"data": {}
- "item_name": "黑马优购",
-"structure": []
-{},
- "type": "catalog",
- "name": "首页",
-"children": []
-{},
- "type": "page",
- "page_id": "2513235043485226",
- "title": "轮播图",
- "content": " **简要描述:** - 轮播图 **请求URL:** - `https://api-hmugo-web.itheima.net/api/public/v1/home/swiperdata` **请求方式:** - GET **参数:** 无 **返回示例** ``` json { "message": [ { "image_src": "https://api-hmugo-web.itheima.net/pyg/banner1.png", "open_type": "navigate", "goods_id": 129, "navigator_url": "/pages/goods_detail/index?goods_id=129" } ], "meta": { "msg": "获取成功", "status": 200 } } ``` **返回参数说明** | 参数名 | 类型 | 说明 | | :------------ | :----- | ------------------------------------ | | image_src | string | 图片路径 | | open_type | string | 打开方式 | | goods_id | number | 商品id | | navigator_url | string | 导航链接 | **备注** - 更多返回错误代码请看首页的错误代码描述 "
-{},
- "type": "page",
- "page_id": "2513278140891548",
- "title": "导航",
- "content": "**简要描述:** - 导航菜单 **请求URL:** - ` https://api-hmugo-web.itheima.net/api/public/v1/home/catitems ` **请求方式:** - GET **参数:** 无 **返回示例** ``` { "message": [ { "name": "分类", "image_src": "https://api-hmugo-web.itheima.net/pyg/icon_index_nav_4@2x.png", "open_type": "switchTab", "navigator_url": "/pages/category/index" }, { "name": "秒杀拍", "image_src": "https://api-hmugo-web.itheima.net/pyg/icon_index_nav_3@2x.png" }, { "name": "超市购", "image_src": "https://api-hmugo-web.itheima.net/pyg/icon_index_nav_2@2x.png" }, { "name": "母婴品", "image_src": "https://api-hmugo-web.itheima.net/pyg/icon_index_nav_1@2x.png" } ], "meta": { "msg": "获取成功", "status": 200 } } ``` **返回参数说明** |参数名|类型|说明| |:----- |:-----|----- | |name |string |标题名称 | |image_src |string |图片路径 | **备注** - 更多返回错误代码请看首页的错误代码描述 "
-{}
- "type": "page",
- "page_id": "2513282464078443",
- "title": "楼层",
- "content": "**简要描述:** - 楼层 **请求URL:** - ` https://api-hmugo-web.itheima.net/api/public/v1/home/floordata ` **请求方式:** - GET **参数:** 无 **返回示例** ``` { "message": [ { "floor_title": { "name": "时尚女装", "image_src": "https://api-hmugo-web.itheima.net/pyg/pic_floor01_title.png" }, "product_list": [ { "name": "优质服饰", "image_src": "https://api-hmugo-web.itheima.net/pyg/pic_floor01_1@2x.png", "image_width": "232", "open_type": "navigate", "navigator_url": "/pages/goods_list/index?query=服饰" }, { "name": "春季热门", "image_src": "https://api-hmugo-web.itheima.net/pyg/pic_floor01_2@2x.png", "image_width": "233", "open_type": "navigate", "navigator_url": "/pages/goods_list/index?query=热" }, { "name": "爆款清仓", "image_src": "https://api-hmugo-web.itheima.net/pyg/pic_floor01_3@2x.png", "image_width": "233", "open_type": "navigate", "navigator_url": "/pages/goods_list/index?query=爆款" }, { "name": "倒春寒", "image_src": "https://api-hmugo-web.itheima.net/pyg/pic_floor01_4@2x.png", "image_width": "233", "open_type": "navigate", "navigator_url": "/pages/goods_list/index?query=春季" }, { "name": "怦然心动", "image_src": "https://api-hmugo-web.itheima.net/pyg/pic_floor01_5@2x.png", "image_width": "233", "open_type": "navigate", "navigator_url": "/pages/goods_list/index?query=心动" } ] }, { "floor_title": { "name": "户外活动", "image_src": "https://api-hmugo-web.itheima.net/pyg/pic_floor02_title.png" }, "product_list": [ { "name": "勇往直前", "image_src": "https://api-hmugo-web.itheima.net/pyg/pic_floor02_1@2x.png", "image_width": "232", "open_type": "navigate", "navigator_url": "/pages/goods_list/index?query=户外" }, { "name": "户外登山包", "image_src": "https://api-hmugo-web.itheima.net/pyg/pic_floor02_2@2x.png", "image_width": "273", "open_type": "navigate", "navigator_url": "/pages/goods_list/index?query=登山包" }, { "name": "超强手套", "image_src": "https://api-hmugo-web.itheima.net/pyg/pic_floor02_3@2x.png", "image_width": "193", "open_type": "navigate", "navigator_url": "/pages/goods_list/index?query=手套" }, { "name": "户外运动鞋", "image_src": "https://api-hmugo-web.itheima.net/pyg/pic_floor02_4@2x.png", "image_width": "193", "open_type": "navigate", "navigator_url": "/pages/goods_list/index?query=运动鞋" }, { "name": "冲锋衣系列", "image_src": "https://api-hmugo-web.itheima.net/pyg/pic_floor02_5@2x.png", "image_width": "273", "open_type": "navigate", "navigator_url": "/pages/goods_list/index?query=冲锋衣" } ] }, { "floor_title": { "name": "箱包配饰", "image_src": "https://api-hmugo-web.itheima.net/pyg/pic_floor03_title.png" }, "product_list": [ { "name": "清新气质", "image_src": "https://api-hmugo-web.itheima.net/pyg/pic_floor03_1@2x.png", "image_width": "232", "open_type": "navigate", "navigator_url": "/pages/goods_list?query=饰品" }, { "name": "复古胸针", "image_src": "https://api-hmugo-web.itheima.net/pyg/pic_floor03_2@2x.png", "image_width": "263", "open_type": "navigate", "navigator_url": "/pages/goods_list?query=胸针" }, { "name": "韩版手链", "image_src": "https://api-hmugo-web.itheima.net/pyg/pic_floor03_3@2x.png", "image_width": "203", "open_type": "navigate", "navigator_url": "/pages/goods_list?query=手链" }, { "name": "水晶项链", "image_src": "https://api-hmugo-web.itheima.net/pyg/pic_floor03_4@2x.png", "image_width": "193", "open_type": "navigate", "navigator_url": "/pages/goods_list?query=水晶项链" }, { "name": "情侣表", "image_src": "https://api-hmugo-web.itheima.net/pyg/pic_floor03_5@2x.png", "image_width": "273", "open_type": "navigate", "navigator_url": "/pages/goods_list?query=情侣表" } ] } ], "meta": { "msg": "获取成功", "status": 200 } } ``` **返回参数说明** |参数名|类型|说明| |:----- |:-----|----- | |floor_title |string |一级分类标题 | |product_list |array |一级分类内容 | |name |string |名称 | |image_src |string |图片路径 | |image_width |string |图片宽度 | |open_type |string |打开方式 | |navigator_url |string |跳转连接 | **备注** - 更多返回错误代码请看首页的错误代码描述 "
-{},
- "type": "catalog",
- "name": "分类",
-"children": []
-{}
- "type": "page",
- "page_id": "2516997897914014",
- "title": "商品分类",
- "content": " **简要描述:** - 商品分类 **请求URL:** - ` https://api-hmugo-web.itheima.net/api/public/v1/categories ` **请求方式:** - GET **参数:** 无 **返回示例** ``` json { "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": "https://api-hmugo-web.itheima.net/full/2fb113b32f7a2b161f5ee4096c319afedc3fd5a1.jpg" } ] } ] } ], "meta": { "msg": "获取成功", "status": 200 } } ``` **返回参数说明** |参数名|类型|| |:----- |:-----|----- | |cat_id |int |分类id| |cat_name |string |分类名称| |children |array |子节点| |cat_icon |string |图标| **备注** - 更多返回错误代码请看首页的错误代码描述 "
-{},
- "type": "catalog",
- "name": "商品",
-"children": []
-{},
- "type": "page",
- "page_id": "2526159696464209",
- "title": "商品列表搜索",
- "content": " **简要描述:** - 商品列表搜索 **请求URL:** - ` https://api-hmugo-web.itheima.net/api/public/v1/goods/search ` **请求方式:** - GET **参数:** |参数名|必选|类型|说明| |:---- |:---|:----- |----- | |query |否 |string |关键字 | |cid |否 |string | 分类id | |pagenum |否 |number | 页码 | |pagesize |否 |number | 页容量 | **返回示例** ``` json { "message": { "total": 10, "pagenum": 1, "goods": [ { "goods_id": 57445, "cat_id": 9, "goods_name": "创维(Skyworth)65V9E 65英寸25核4K HDR高清智能电视", "goods_price": 6499, "goods_number": 100, "goods_weight": 100, "goods_big_logo": "", "goods_small_logo": "", "add_time": 1516663280, "upd_time": 1516663280, "hot_mumber": 0, "is_promote": false, "cat_one_id": 1, "cat_two_id": 3, "cat_three_id": 9 } ] }, "meta": { "msg": "获取成功", "status": 200 } } ``` **返回参数说明** | | | | | ---------------- | ------------ | ---- | | 参数名 | 参数说明 | 备注 | | total | 总条数 | | | pagenum | 当前页数 | | | goods_id | 商品ID | | | cat_id | 分类ID | | | goods_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 | 所属三级分类 | | **备注** - 更多返回错误代码请看首页的错误代码描述 "
-{},
- "type": "page",
- "page_id": "2526175298570888",
- "title": "商品详情",
- "content": " **简要描述:** - 商品详情 **请求URL:** - ` https://api-hmugo-web.itheima.net/api/public/v1/goods/detail ` **请求方式:** - GET **参数:** |参数名|必选|类型|说明| |:---- |:---|:----- |----- | |goods_id |是 |number |商品id | **返回示例** ``` { "message": { "goods_id": 8888, "cat_id": 1085, "goods_name": "spike 经典武士大马士革直刀(微型) 户外野营直刀 收藏礼品刀 饰品刀具", "goods_price": 500, "goods_number": 100, "goods_weight": 100, "goods_introduce": "富文本内容", "goods_state": 2, "is_del": "0", "add_time": 1516361489, "upd_time": 1516361489, "delete_time": null, "hot_mumber": 0, "is_promote": false, "cat_one_id": 995, "cat_two_id": 1075, "cat_three_id": 1085, "goods_cat": "995,1075,1085", "pics": [ { "pics_id": 38711, "goods_id": 8888, "pics_big": "http://image1.suning.cn/uimg/b2c/newcatentries/0070134290-000000000149003877_1_800x800.jpg", "pics_mid": "http://image1.suning.cn/uimg/b2c/newcatentries/0070134290-000000000149003877_1_400x400.jpg", "pics_sma": "http://image1.suning.cn/uimg/b2c/newcatentries/0070134290-000000000149003877_1_200x200.jpg", "pics_big_url": "http://image1.suning.cn/uimg/b2c/newcatentries/0070134290-000000000149003877_1_800x800.jpg", "pics_mid_url": "http://image1.suning.cn/uimg/b2c/newcatentries/0070134290-000000000149003877_1_400x400.jpg", "pics_sma_url": "http://image1.suning.cn/uimg/b2c/newcatentries/0070134290-000000000149003877_1_200x200.jpg" } ], "attrs": [ { "goods_id": 8888, "attr_id": 9210, "attr_value": "户外直刀", "add_price": 0, "attr_name": "主体参数-类别", "attr_sel": "only", "attr_write": "manual", "attr_vals": "放大镜" } ] }, "meta": { "msg": "获取成功", "status": 200 } } ``` **返回参数说明** | | | | | ---------------- | ------------ | ---- | | 参数名 | 参数说明 | 备注 | | goods_id | 商品ID | | | cat_id | 分类ID | | | goods_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 | 商品介绍 | | | pics | 商品图片列表 | | | attrs | 商品属性列表 | | **备注** - 更多返回错误代码请看首页的错误代码描述 "
-{}
- "type": "page",
- "page_id": "2526176842444912",
- "title": "商品搜索",
- "content": " **简要描述:** - 搜索建议查询 **请求URL:** - ` https://api-hmugo-web.itheima.net/api/public/v1/goods/qsearch ` **请求方式:** - GET **参数:** |参数名|必选|类型|说明| |:---- |:---|:----- |----- | |query |是 |string |关键字 | **返回示例** ``` { "message": [ { "goods_id": 57444, "goods_name": "创维(Skyworth)42X6 42英寸10核智能酷开网络平板液晶电视(黑色)" } ], "meta": { "msg": "获取成功", "status": 200 } } ``` **返回参数说明** |参数名|类型|说明| |:----- |:-----|----- | |goods_id |number |商品id | |goods_name |string |商品名称 | **备注** - 更多返回错误代码请看首页的错误代码描述 "
-{},
- "type": "catalog",
- "name": "用户",
-"children": []
-{}
- "type": "page",
- "page_id": "2612400282844951",
- "title": "获取用户token",
- "content": " **简要描述:** - 获取用户token **请求URL:** - `https://api-hmugo-web.itheima.net/api/public/v1/users/wxlogin` **请求方式:** - POST **参数:** 以下字段主要用作后台服务器生成用户token所有,无特殊用意 | 参数名 | 必选 | 类型 | 参数说明 | | ------------- | ---- | ---- | ------------------------------ | | encryptedData | 是 | string | 执行小程序 获取用户信息后 得到 | | rawData | 是 | string | 执行小程序 获取用户信息后 得到 | | iv | 是 | string | 执行小程序 获取用户信息后 得到 | | signature | 是 | string | 执行小程序 获取用户信息后 得到 | | code | 是 | string | 执行小程序登录后获取 | **返回示例** ``` json { "message": { "user_id": 23, "user_email_code": null, "is_active": null, "user_sex": "男", "user_qq": "", "user_tel": "", "user_xueli": "本科", "user_hobby": "", "user_introduce": null, "create_time": 1562221487, "update_time": 1562221487, "token": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOjIzLCJpYXQiOjE1NjQ3MzAwNzksImV4cCI6MTAwMTU2NDczMDA3OH0.YPt-XeLnjV-_1ITaXGY2FhxmCe4NvXuRnRB8OMCfnPo" }, "meta": { "msg": "登录成功", "status": 200 } } ``` **返回参数说明** |参数名|类型|说明| |:----- |:-----|----- | |token |string |用户的唯一凭据,后期用在其他敏感接口的验证 | "
-{},
- "type": "catalog",
- "name": "支付",
-"children": []
-{}
- "type": "page",
- "page_id": "2612486239891213",
- "title": "获取支付参数",
- "content": " **简要描述:** - 获取支付参数 **请求URL:** - ` https://api-hmugo-web.itheima.net/api/public/v1/my/orders/req_unifiedorder ` **请求方式:** - POST **请求头参数:** | 参数名 | 必选 | 类型 | 说明 | | ------------- | ---- | ------ | ------------------------- | | Authorization | 是 | string | 用户登录成功获取的token值 | **请求体参数:** | 参数名 | 必选 | 类型 | 说明 | | ------------ | ---- | ------ | -------- | | order_number | 是 | string | 订单编号 | **返回示例** ``` json { "message": { "pay": { "timeStamp": "1564730510", "nonceStr": "SReWbt3nEmpJo3tr", "package": "prepay_id=wx02152148991420a3b39a90811023326800", "signType": "MD5", "paySign": "3A6943C3B865FA2B2C825CDCB33C5304" }, "order_number": "HMDD20190802000000000422" }, "meta": { "msg": "预付订单生成成功", "status": 200 } } ``` **返回参数说明** |参数名|类型|说明| |:----- |:-----|----- | |pay |object |该对象内的参数,为调用微信支付所必须 | "
-{}
- "type": "catalog",
- "name": "订单",
-"children": []
-{},
- "type": "page",
- "page_id": "2612148628877795",
- "title": "创建订单",
- "content": " **简要描述:** - 创建订单 **请求URL:** - ` https://api-hmugo-web.itheima.net/api/public/v1/my/orders/create ` **请求方式:** - POST **请求头参数:** | 参数名 | 必选 | 类型 | 说明 | | ------------- | ---- | ------ | ------------------------- | | Authorization | 是 | string | 用户登录成功获取的token值 | **请求体参数**: |参数名|必选|类型|说明| |:---- |:---|:----- |----- | |order_price |是 |string |订单总价格 | |consignee_addr |是 |string | 收货地址 | |goods |是 |Array | 订单数组 | **goods字段说明** | 参数名 | 必选 | 类型 | 说明 | | ------------ | ---- | ------ | ---------- | | goods_id | 是 | number | 商品id | | goods_number | 是 | number | 购买的数量 | | goods_price | 是 | number | 单价 | **返回示例** ``` { "error_code": 0, "data": { "uid": "1", "username": "12154545", "name": "吴系挂", "groupid": 2 , "reg_time": "1436864169", "last_login_time": "0", } } ``` **返回参数说明** | 参数名 | 类型 | 参数说明 | | -------------- | ------ | ------------ | | order_id | string | 订单唯一ID | | user_id | string | 用户ID | | order_number | string | 订单编号 | | order_price | number | 订单价格 | | order_pay | number | 订单支付方式 | | consignee_addr | string | 订单地址 | | pay_status | number | 订单支付状态 | "
-{},
- "type": "page",
- "page_id": "2612723166377091",
- "title": "查看订单支付状态",
- "content": " **简要描述:** - 查看订单支付状态 **请求URL:** - ` https://api-hmugo-web.itheima.net/api/public/v1/my/orders/chkOrder ` **请求方式:** - POST **请求头参数:** | 参数名 | 必选 | 类型 | 说明 | | ------------- | ---- | ------ | ------------------------- | | Authorization | 是 | string | 用户登录成功获取的token值 | **请求体参数**: | 参数名 | 必选 | 类型 | 说明 | | ------------ | ---- | ------ | -------- | | order_number | 是 | string | 订单编号 | **返回示例** ``` json { "message": "支付成功", "meta": { "msg": "验证成功", "status": 200 } } ``` "
-{}
- "type": "page",
- "page_id": "2612830563673346",
- "title": "历史订单查询",
- "content": " **简要描述:** - 历史订单查询 **请求URL:** - ` https://api-hmugo-web.itheima.net/api/public/v1/my/orders/all ` **请求方式:** - GET **请求头参数:** | 参数名 | 必选 | 类型 | 说明 | | ------------- | ---- | ------ | ------------------------- | | Authorization | 是 | string | 用户登录成功获取的token值 | **请求体参数**: | 参数名 | 必选 | 类型 | 说明 | | ------ | ---- | ------ | ---------------------------- | | type | 是 | number | 1:全部订单 2:待付款 3:待发货 | **返回示例** ``` json { "message": { "count": 1, "orders": [ { "order_id": 428, "user_id": 23, "order_number": "HMDD20190802000000000428", "order_price": 13999, "order_pay": "0", "is_send": "否", "trade_no": "", "order_fapiao_title": "个人", "order_fapiao_company": "", "order_fapiao_content": "", "consignee_addr": "广东省广州市海珠区新港中路397号", "pay_status": "1", "create_time": 1564731518, "update_time": 1564731518, "order_detail": null, "goods": [ { "id": 717, "order_id": 428, "goods_id": 43986, "goods_price": 13999, "goods_number": 1, "goods_total_price": 13999, "goods_name": "海信(Hisense)LED55MU9600X3DUC 55英寸 4K超高清量子点电视 ULED画质 VIDAA系统", "goods_small_logo": "http://image5.suning.cn/uimg/b2c/newcatentries/0000000000-000000000160455569_1_400x400.jpg" } ], "total_count": 1, "total_price": 13999 } ] }, "meta": { "msg": "获取订单列表成功", "status": 200 } } ``` "
| 错误码 | 类型 | 说明 |
|---|---|---|
| 403 | int | 没有权限 |
| 400 | int | 参数传递不正确 |
| 500 | int | 服务器内部错误 |
<?php
/**
* API请求DEMO
*
* 本demo支持常见的HTTP请求方法(GET/POST/PUT/DELETE等)
*/
//基本配置
$api_key = '你的接口密钥,登录控制台后在密钥管理页面申请';
$secret_key = '';
// API请求示例:
try {
$client = new ApiClient($api_key, $secret_key);
$client->setTimeout(10);
$client->setVerifySSL(false); // 关闭SSL验证
// GET请求示例
echo "=== 开始GET请求 ===\n";
$response = $client->get('https://api.kkjsz.cn/api/swd/index', [
'key' => $api_key,
'key2' => '其他参数'
]);
print_r($response);
//print_r($client->getLastRequestInfo());
/*
// POST表单示例
echo "\n=== 开始POST请求 ===\n";
$response = $client->post('接口地址', [
'key' => $api_key,
'key2' => '其他参数'
]);
print_r($response);
print_r($client->getLastRequestInfo());
// POST JSON示例
echo "\n=== 开始POST JSON请求 ===\n";
$response = $client->postJson('接口地址', [
'key' => $api_key,
'key2' => '其他参数'
]);
print_r($response);
print_r($client->getLastRequestInfo());
*/
} catch (ApiClientException $e) {
echo "API请求错误: " . $e->getMessage();
if ($e->getCode() > 0) {
echo " (HTTP状态码: " . $e->getCode() . ")";
}
print_r($client->getLastRequestInfo() ?? []);
}
/**
* API客户端类
*
* 提供了一个简单的HTTP API客户端实现,支持常见的HTTP请求方法(GET/POST/PUT/DELETE等)
* 具有以下主要功能:
* - 支持 API 密钥和签名认证
* - 可配置请求超时和SSL验证
* - 支持自定义请求头
* - 支持表单和JSON格式的请求体
* - 自动解析响应结果
* - 提供详细的请求信息记录
*
* 使用示例:
* ```
* $client = new ApiClient('https://api.example.com', 'api_key', 'secret_key');
* $response = $client->get('/users', ['page' => 1]);
* ```
*
* @throws ApiClientException 当API请求失败时抛出异常
*/
class ApiClient
{
private $apiKey;
private $secretKey;
private $timeout = 30;
private $verifySSL = true;
private $lastRequestInfo = [];
private $defaultHeaders = [];
/**
* 构造函数
*
* @param string $apiKey API密钥(可选)
* @param string $secretKey 签名密钥(可选)
*/
public function __construct(string $apiKey = '', string $secretKey = '')
{
$this->apiKey = $apiKey;
$this->secretKey = $secretKey;
}
/**
* 设置请求超时时间(秒)
*/
public function setTimeout(int $seconds): self
{
$this->timeout = $seconds;
return $this;
}
/**
* 设置是否验证SSL证书
*/
public function setVerifySSL(bool $verify): self
{
$this->verifySSL = $verify;
return $this;
}
/**
* 添加默认请求头
*/
public function addDefaultHeader(string $name, string $value): self
{
$this->defaultHeaders[$name] = $value;
return $this;
}
/**
* 发送GET请求
*
* @param string $endpoint 接口端点
* @param array $query 查询参数
* @param array $headers 额外请求头
*/
public function get(string $endpoint, array $query = [], array $headers = []): array
{
return $this->request('GET', $endpoint, [
'query' => $query,
'headers' => $headers
]);
}
/**
* 发送POST请求(表单格式)
*
* @param string $endpoint 接口端点
* @param array $data POST数据
* @param array $headers 额外请求头
*/
public function post(string $endpoint, array $data = [], array $headers = []): array
{
return $this->request('POST', $endpoint, [
'form_data' => $data,
'headers' => $headers
]);
}
/**
* 发送POST请求(JSON格式)
*
* @param string $endpoint 接口端点
* @param array $data POST数据
* @param array $headers 额外请求头
*/
public function postJson(string $endpoint, array $data = [], array $headers = []): array
{
return $this->request('POST', $endpoint, [
'json' => $data,
'headers' => array_merge(['Content-Type' => 'application/json'], $headers)
]);
}
/**
* 发送PUT请求
*/
public function put(string $endpoint, array $data = [], array $headers = []): array
{
return $this->request('PUT', $endpoint, [
'json' => $data,
'headers' => $headers
]);
}
/**
* 发送DELETE请求
*/
public function delete(string $endpoint, array $data = [], array $headers = []): array
{
return $this->request('DELETE', $endpoint, [
'json' => $data,
'headers' => $headers
]);
}
/**
* 获取最后一次请求的详细信息
*/
public function getLastRequestInfo(): array
{
return $this->lastRequestInfo;
}
/**
* 基础请求方法
*/
private function request(string $method, string $endpoint, array $options = []): array
{
// 初始化cURL
$ch = curl_init();
$url = ltrim($endpoint, '/');
// 准备请求头
$headers = $this->prepareHeaders($options['headers'] ?? []);
// 处理查询参数
if (!empty($options['query'])) {
$url .= '?' . http_build_query($options['query']);
}
// 处理请求体
$postData = null;
if (isset($options['form_data'])) {
$postData = http_build_query($options['form_data']);
$headers[] = 'Content-Type: application/x-www-form-urlencoded';
} elseif (isset($options['json'])) {
$postData = json_encode($options['json']);
$headers[] = 'Content-Type: application/json';
}
// 设置cURL选项
curl_setopt_array($ch, [
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_CUSTOMREQUEST => $method,
CURLOPT_HTTPHEADER => $headers,
CURLOPT_TIMEOUT => $this->timeout,
CURLOPT_SSL_VERIFYPEER => $this->verifySSL,
CURLOPT_SSL_VERIFYHOST => $this->verifySSL,
CURLOPT_HEADER => true,
]);
if ($method !== 'GET' && $postData !== null) {
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
}
// 执行请求
$response = curl_exec($ch);
$error = curl_error($ch);
$info = $this->lastRequestInfo = curl_getinfo($ch);
curl_close($ch);
// 处理错误
if ($error) {
throw new ApiClientException("cURL请求失败: " . $error);
}
// 分离响应头和响应体
$headerSize = $info['header_size'];
$responseHeaders = substr($response, 0, $headerSize);
$responseBody = substr($response, $headerSize);
// 解析响应
$result = json_decode($responseBody, true) ?? $responseBody;
// 检查HTTP状态码
if ($info['http_code'] >= 400) {
$errorMsg = is_array($result) ? ($result['message'] ?? $responseBody) : $responseBody;
throw new ApiClientException("API请求失败: " . $errorMsg, $info['http_code']);
}
return [
'status' => $info['http_code'],
'headers' => $this->parseHeaders($responseHeaders),
'data' => $result
];
}
/**
* 准备请求头(自动添加签名)
*/
private function prepareHeaders(array $headers): array
{
// 合并默认头
$headers = array_merge($this->defaultHeaders, $headers);
// 添加签名头
if ($this->apiKey && $this->secretKey) {
$timestamp = time();
$signString = "key={$this->apiKey}×tamp={$timestamp}";
$signature = hash_hmac('sha256', $signString, $this->secretKey);
$headers['X-Api-Key'] = $this->apiKey;
$headers['X-Api-Timestamp'] = $timestamp;
$headers['X-Api-Sign'] = $signature;
}
// 转换为cURL格式
$curlHeaders = [];
foreach ($headers as $name => $value) {
$curlHeaders[] = "$name: $value";
}
return $curlHeaders;
}
/**
* 解析响应头
*/
private function parseHeaders(string $headers): array
{
$parsed = [];
foreach (explode("\r\n", $headers) as $i => $line) {
if ($i === 0) {
$parsed['HTTP_CODE'] = $line;
} else {
$parts = explode(': ', $line, 2);
if (count($parts) === 2) {
$parsed[$parts[0]] = $parts[1];
}
}
}
return $parsed;
}
}
class ApiClientException extends \Exception
{
// 自定义异常类
}
//jQuery-Ajax
$.ajax({
url: 'https://api.kkjsz.cn/api/swd/index',
data: {
//接口参数,一行一个,可按照接口文档-请求参数 的参数填写,或者直接复制开发工具下面的测试代码。
key: '你的接口密钥,登录控制台后在密钥管理页面申请',
参数名: '参数值',
},
type: 'GET', //请求协议(GET或POST),一般默认GET,部分接口需要POST请求,根据实际情况修改为POST即可。
dataType: 'json',
success: function(data) {
console.log(data); //请求成功,输出结果到控制台
},
timeout: 3000, //超时时间
error: function(data) {
console.log('请求失败'); //失败处理
}
});
| 子程序名 | 返回值类型 | 公开 | 备 注 | ||
| __启动窗口_创建完毕 | |||||
| 子程序名 | 返回值类型 | 公开 | 备 注 | ||
| Send_API | |||||
| 变量名 | 类 型 | 静态 | 数组 | 备 注 | ||
| REQU_Data | 文本型 | 提交字符串 | ||||
| return | 文本型 | 返回字符串 | ||||
| API_URL | 文本型 | 接口地址 | ||||
| API_KEY | 文本型 | 接口密钥 | ||||
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class Test {
public static void main(String[] args) {
try {
URL url = new URL("https://api.kkjsz.cn/api/swd/index?key=你的接口密钥,登录控制台后在密钥管理页面申请");
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
// 设置请求方式
connection.setRequestMethod("GET");
connection.connect();
// 获取响应码
int responseCode = connection.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) {
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
// 读取到的内容给line变量
System.out.println(line);
}
reader.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
package main
import (
"fmt"
"io/ioutil"
"net/http"
)
func main() {
// 发起一个GET请求
resp, err := http.Get("https://api.kkjsz.cn/api/swd/index?key=你的接口密钥,登录控制台后在密钥管理页面申请")
if err != nil {
fmt.Println("http get error", err)
return
}
// 读取响应结果
result, err := ioutil.ReadAll(resp.Body)
if err != nil {
fmt.Println("http read error", err)
return
}
// 关闭响应结果
defer resp.Body.Close()
fmt.Println(string(result))
}
```
# 导入requests库
import requests
# 设置url
url = 'https://api.kkjsz.cn/api/swd/index?key=你的接口密钥,登录控制台后在密钥管理页面申请'
# 发送post请求
response = requests.post(url, data={'key1': 'value1', 'key2': 'value2'})
# 获取响应内容
result = response.json()
# 打印结果
print(result)
```
// 以下是使用Node.js进行GET和POST请求API接口的示例代码:
const https = require('https');
const querystring = require('querystring');
// 定义请求选项
const options = {
hostname: 'api.kkjsz.cn',
path: '/api/swd/index',
method: 'GET'
};
// 发送GET请求
https.get(options, res => {
console.log(`statusCode: ${res.statusCode}`);
res.on('data', d => {
process.stdout.write(d);
});
}).on('error', error => {
console.error(error);
});
// 发送POST请求
const postData = querystring.stringify({
'key1': 'value1',
'key2': 'value2'
});
const postOptions = {
hostname: 'api.kkjsz.cn',
path: '/api/swd/index',
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': Buffer.byteLength(postData)
}
};
const postReq = https.request(postOptions, res => {
console.log(`statusCode: ${res.statusCode}`);
res.on('data', d => {
process.stdout.write(d);
});
});
postReq.on('error', error => {
console.error(error);
});
postReq.write(postData);
postReq.end();
/*
这个示例代码使用Node.js内置的`https`模块进行HTTP请求。
首先定义了一个GET请求的选项,然后使用`https.get()`方法发送了GET请求。在响应流上注册回调函数,以便在收到响应数据时将其输出到控制台。在出现错误时,也注册了错误处理程序。
类似地,我们也定义了一个POST请求选项,并使用`https.request()`方法发送它。需要在请求头中包含适当的`Content-Type`和`Content-Length`以确保服务器可以正确解析请求体。请求体由`write()`方法写入,并在请求结束时通过调用`end()`方法通知请求对象已经完成。
注意,此示例默认使用`querystring`模块将数据作为x-www-form-urlencoded格式进行编码。如果需要使用其他格式(如JSON),则需要相应地更改请求头和请求体的编码方式。
另外,为了确保HTTPS请求的安全性,您也可以添加其他选项,例如验证服务器证书、设置代理等。
*/
以下是使用C语言进行GET和POST请求API接口的示例代码:
``` c
#include
#include
#include
#include // 需要安装curl库
// API地址
const char* url = "https://api.kkjsz.cn/api/swd/index";
// GET请求
void getRequest(CURL* curl) {
CURLcode res;
// 设置URL
curl_easy_setopt(curl, CURLOPT_URL, url);
// 执行请求
res = curl_easy_perform(curl);
if(res != CURLE_OK) {
fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
}
}
// POST请求
void postRequest(CURL* curl) {
CURLcode res;
// 设置URL
curl_easy_setopt(curl, CURLOPT_URL, url);
// 设置POST数据
const char* postData = "key=你的接口密钥,登录控制台后在密钥管理页面申请&key1=value1";
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, postData);
// 执行请求
res = curl_easy_perform(curl);
if(res != CURLE_OK) {
fprintf(stderr, "curl_easy_perform() failed: %s\n", curl_easy_strerror(res));
}
}
int main() {
CURL* curl;
CURLcode res;
// 初始化curl
curl = curl_easy_init();
if(curl) {
// 设置SSL验证
curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 1L);
// GET请求
getRequest(curl);
// POST请求
postRequest(curl);
// 清理curl资源
curl_easy_cleanup(curl);
}
return 0;
}
```
这个示例代码使用了libcurl库进行HTTP请求。
首先,需要设置API地址。然后,基于`CURL`结构体创建curl句柄,并使用`curl_easy_setopt()`函数设置选项。这里设置了SSL验证,以确保请求的安全性。
在GET请求中,只需将URL设置为选项,然后调用`curl_easy_perform()`函数执行请求即可。
在POST请求中,还需要将POST数据作为字符串传递给`CURLOPT_POSTFIELDS`选项。
需要注意的是,为了避免内存泄漏,应该在使用完curl句柄之后调用`curl_easy_cleanup()`函数进行清理。
除了上述示例代码外,libcurl库还提供了更多高级选项,例如处理HTTP头、上传文件等。可以参考文档进行更详细的了解。
以下是一个使用C++请求API接口的示例代码:
```cpp
#include
#include
int main() {
CURL *curl;
CURLcode res;
std::string url = "https://api.kkjsz.cn/api/swd/index?key=你的接口密钥,登录控制台后在密钥管理页面申请";
std::string response;
curl = curl_easy_init();
if (curl) {
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, [](char *ptr, size_t size, size_t nmemb, void *userdata) -> size_t {
std::string *response = reinterpret_cast(userdata);
response->append(ptr, size * nmemb);
return size * nmemb;
});
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &response);
res = curl_easy_perform(curl);
if (res == CURLE_OK) {
std::cout << "Response: " << response << std::endl;
} else {
std::cerr << "Error: " << curl_easy_strerror(res) << std::endl;
}
curl_easy_cleanup(curl);
}
return 0;
}
```
解释:
1. 引入需要的头文件:``用于输出结果,``用于使用libcurl库。
2. 定义需要请求的API接口的URL和存储响应数据的字符串变量。
3. 初始化一个CURL对象。
4. 设置CURL对象的参数:请求的URL(`CURLOPT_URL`)、是否跟随重定向(`CURLOPT_FOLLOWLOCATION`)、响应数据的写入函数(`CURLOPT_WRITEFUNCTION`)和响应数据的写入位置(`CURLOPT_WRITEDATA`)。
5. 发送HTTP请求并获取响应数据,判断返回状态码是否OK。
6. 清理CURL对象。
运行该程序会发送GET请求到指定的API接口URL,并在程序终止前将响应数据输出到终端。注意,在使用该示例代码之前需要安装libcurl库。
以下是一个使用C#请求API接口的示例代码:
```csharp
using System;
using System.Net.Http;
using System.Threading.Tasks;
class Program {
static async Task Main(string[] args) {
HttpClient client = new HttpClient();
string url = "https://api.kkjsz.cn/api/swd/index?key=你的接口密钥,登录控制台后在密钥管理页面申请";
HttpResponseMessage response = await client.GetAsync(url);
if (response.IsSuccessStatusCode) {
string responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine("Response: " + responseBody);
} else {
Console.WriteLine("Error: " + response.StatusCode);
}
}
}
```
解释:
1. 引用需要的命名空间:`System.Net.Http`用于使用HttpClient类,`System.Threading.Tasks`用于异步执行请求操作。
2. 创建一个HttpClient对象。
3. 定义需要请求的API接口的URL。
4. 发送GET请求到指定的API接口URL,并获取响应结果。
5. 判断响应状态是否成功,如果成功则读取响应数据(使用ReadAsStringAsync方法),否则输出错误信息(使用StatusCode属性)。
运行该程序会发送GET请求到指定的API接口URL,并在程序终止前将响应数据输出到终端。注意,在使用该示例代码之前需要安装.NET Framework或.NET Core SDK。
以下是VB请求API接口的示例代码:
```
' 1. 引入Microsoft XML v6.0库
' 2. 创建一个XMLHTTP对象
Dim xhr As XMLHTTP
Set xhr = New XMLHTTP
' 3. 设置请求的URL、方法,以及是否异步等
xhr.Open "GET", "https://api.kkjsz.cn/api/swd/index?key=你的接口密钥,登录控制台后在密钥管理页面申请", False
' 4. 发送请求
xhr.send
' 5. 获取响应结果
Dim responseText As String
responseText = xhr.responseText
' 6. 输出响应结果
Debug.Print responseText
' 7. 释放资源
Set xhr = Nothing
```
在这个示例中,我们创建了一个XMLHTTP对象,用于请求API接口。我们先调用`open`方法来设置请求的URL、方法,以及是否异步。然后,我们发送请求,并使用`responseText`属性来获取响应结果。最后,我们将响应结果打印到控制台,完成操作后释放资源,以防止内存泄漏。请注意,以上示例代码为同步请求,如果想使用异步请求,需要设置第三个参数为`True`,并在请求结束时处理`OnReadyStateChange`事件。
| 参数名 | 填写参数值 |
|---|---|
请 登录 后发表评论
填写业务相关参数免费在线调试
生成符合你的开发语言代码,复制即可
调整你后端部分逻辑代码即可上线使用