>[info] 快速导航
[TOC]
## 接口配置
在使用API之前你需要在后台做一个简单的API配置,如下图:
![](https://box.kancloud.cn/e41db0b7698a94c70d6a8a1a47467fe4_1966x1264.png)
## 接口签名(sign)
>[info] 所有API接口调用必须要带签名参数sign
> 签名规则:md5(时间戳+API签名秘钥)
> 时间戳格式:yyyy-MM-dd HH:mm:ss
## [list] 内容列表
>[info]接口地址:/cms/api/list
请求方式:GET/POST
| 属性名 | 类型 | 必须 | 默认 | 说明
| --- | --- | --- | --- | --- |
| cid | int/var | 是 | 0 | 分类ID,cid和mid最少传一个 |
| mid | int/var | 是 | 0 | 模型ID,cid和mid最少传一个 |
| orderby | string | 否 | id desc | 结果排序 |
| attr | string/array | 否 | | 扩展属性 |
| keyword | string/var | 否 | | 通过关键字搜索title |
| limit | int | 否 | 20 | 返回结果条数 |
| pagesize | int | 否 | 0 | 分页大小 |
| field | string | 否 | | 设置返回的字段 |
| flag | string | 否 | | 通过推荐旗帜筛选内容 |
| tag | string | 否 | | 通过标签筛选内容 |
| where | array | 否 | | 自定义查询条件 |
>[danger] 如果需要自定义where条件时,请使用POST方式请求此接口。
where格式:\[\['字段名1', '表达式', '值'\], \['字段名2', '表达式', '值'\]\]
>[info] 示例代码
```
/* 微信小程序示例 */
wx.request({
url: 'https://cms.hisiphp.com/cms/api/list',
data: {
cid: 49,
pagesize: 20,
orderby: 'view desc',
timestamp: '2019-05-01 12:12:12',// 时间戳
sign: 'cddb29f7db9647274fc604531ff82cea'// 签名
},
header: {
'content-type': 'application/x-www-form-urlencoded'
},
method: 'POST',
success: function (res) {
console.log(res);
}
});
/* jquery示例 */
$.get(
'/cms/api/list',
{
cid: 49,
pagesize: 20,
orderby: 'view desc',
timestamp: '2019-05-01 12:12:12',// 时间戳
sign: 'cddb29f7db9647274fc604531ff82cea'// 签名
},
function(res) {
console.log(res);
}, 'json');
```
## [detail] 内容详情
>[info]接口地址:/cms/api/detail
请求方式:GET/POST
| 属性名 | 类型 | 必须 | 默认 | 说明
| --- | --- | --- | --- | --- |
| id | int | 是 | | 内容ID |
>[info] 示例代码:
```
/* 微信小程序示例 */
wx.request({
url: 'https://cms.hisiphp.com/cms/api/detail',
data: {
id: 49,
timestamp: '2019-05-01 12:12:12',// 时间戳
sign: 'cddb29f7db9647274fc604531ff82cea'// 签名
},
header: {
'content-type': 'application/x-www-form-urlencoded'
},
method: 'POST',
success: function (res) {
console.log(res);
}
});
/* jquery示例 */
$.get(
'/cms/api/detail',
{
id: 49,
timestamp: '2019-05-01 12:12:12',// 时间戳
sign: 'cddb29f7db9647274fc604531ff82cea'// 签名
},
function(res) {
console.log(res);
}, 'json');
```
## [category] 栏目列表
>[info]接口地址:/cms/api/category
请求方式:GET/POST
| 属性名 | 类型 | 必须 | 默认 | 说明
| --- | --- | --- | --- | --- |
| cid | int/var | 是 | 0 | 分类ID,cid和mid最少传一个 |
| mid | int/var | 是 | 2 | 模型ID,cid和mid最少传一个 |
| level | int | 否 | 0 | 返回层级数,0为不限制 |
>[info] 示例代码
```
/* 微信小程序示例 */
wx.request({
url: 'https://cms.hisiphp.com/cms/api/category',
data: {
cid: 49,
level: 3,
timestamp: '2019-05-01 12:12:12',// 时间戳
sign: 'cddb29f7db9647274fc604531ff82cea'// 签名
},
header: {
'content-type': 'application/x-www-form-urlencoded'
},
method: 'GET',
success: function (res) {
console.log(res);
}
});
/* jquery示例 */
$.get(
'/cms/api/category',
{
cid: 49,
level: 3,
timestamp: '2019-05-01 12:12:12',// 时间戳
sign: 'cddb29f7db9647274fc604531ff82cea'// 签名
},
function(res) {
console.log(res);
}, 'json');
```
## [tag] 标签
>[info]接口地址:/cms/api/tag
请求方式:GET/POST
| 属性名 | 类型 | 必须 | 默认 | 说明
| --- | --- | --- | --- | --- |
| mid | int/var| 是 | | 指定模型ID |
| orderby | string | 否 | search\_count desc | 排序 |
| limit | int | 否 | 10 | 限制返回数量 |
>[info] 示例代码
```
/* 微信小程序示例 */
wx.request({
url: 'https://cms.hisiphp.com/cms/api/tag',
data: {
mid: 2,
limit: 15,
timestamp: '2019-05-01 12:12:12',// 时间戳
sign: 'cddb29f7db9647274fc604531ff82cea'// 签名
},
header: {
'content-type': 'application/x-www-form-urlencoded'
},
method: 'GET',
success: function (res) {
console.log(res);
}
});
/* jquery示例 */
$.get(
'/cms/api/tag',
{
mid: 2,
limit: 15,
timestamp: '2019-05-01 12:12:12',// 时间戳
sign: 'cddb29f7db9647274fc604531ff82cea'// 签名
},
function(res) {
console.log(res);
}, 'json');
```
## [block] 碎片块
>[info]接口地址:/cms/api/block
请求方式:GET/POST
| 属性名 | 类型 | 必须 | 默认 | 说明
| --- | --- | --- | --- | --- |
| name | string | 是 | | 碎片名称 |
>[info] 示例代码
```
/* 微信小程序示例 */
wx.request({
url: 'https://cms.hisiphp.com/cms/api/block',
data: {
name: 'about',
timestamp: '2019-05-01 12:12:12',// 时间戳
sign: 'cddb29f7db9647274fc604531ff82cea'// 签名
},
header: {
'content-type': 'application/x-www-form-urlencoded'
},
method: 'GET',
success: function (res) {
console.log(res);
}
});
/* jquery示例 */
$.get(
'/cms/api/block',
{
name: 'about',
timestamp: '2019-05-01 12:12:12',// 时间戳
sign: 'cddb29f7db9647274fc604531ff82cea'// 签名
},
function(res) {
console.log(res);
}, 'json');
```
## [nav] 导航
>[info]接口地址:/cms/api/nav
请求方式:GET/POST
| 属性名 | 类型 | 必须 | 默认 | 说明
| --- | --- | --- | --- | --- |
| group | string | 否 | | 返回指定分组 |
| limit | int | 否 | 10 | 限制返回数量 |
| cache | bool | 否 | false | 缓存结果集 |
>[info] 示例代码
```
/* 微信小程序示例 */
wx.request({
url: 'https://cms.hisiphp.com/cms/api/nav',
data: {
group: 'home',
timestamp: '2019-05-01 12:12:12',// 时间戳
sign: 'cddb29f7db9647274fc604531ff82cea'// 签名
},
header: {
'content-type': 'application/x-www-form-urlencoded'
},
method: 'GET',
success: function (res) {
console.log(res);
}
});
/* jquery示例 */
$.get(
'/cms/api/nav',
{
group: 'home',
timestamp: '2019-05-01 12:12:12',// 时间戳
sign: 'cddb29f7db9647274fc604531ff82cea'// 签名
},
function(res) {
console.log(res);
}, 'json');
```
## [link] 友情链接
>[info]接口地址:/cms/api/link
请求方式:GET/POST
| 属性名 | 类型 | 必须 | 默认 | 说明
| --- | --- | --- | --- | --- |
| type | string | 是 | | 类型,可选值:image,text,all |
| group | string | 否 | | 返回指定分组 |
| orderby | string | 否 | sort asc | 排序 |
| limit | int | 否 | 10 | 限制返回数量 |
>[info] 示例代码
```
/* 微信小程序示例 */
wx.request({
url: 'https://cms.hisiphp.com/cms/api/link',
data: {
type: 'text',
group: 'home',
timestamp: '2019-05-01 12:12:12',// 时间戳
sign: 'cddb29f7db9647274fc604531ff82cea'// 签名
},
header: {
'content-type': 'application/x-www-form-urlencoded'
},
method: 'GET',
success: function (res) {
console.log(res);
}
});
/* jquery示例 */
$.get(
'/cms/api/link',
{
type: 'text',
group: 'home',
timestamp: '2019-05-01 12:12:12',// 时间戳
sign: 'cddb29f7db9647274fc604531ff82cea'// 签名
},
function(res) {
console.log(res);
}, 'json');
```
## [slide] 幻灯片
>[info]接口地址:/cms/api/slide
请求方式:GET/POST
| 属性名 | 类型 | 必须 | 默认 | 说明
| --- | --- | --- | --- | --- |
| type | string | 否 | pc | 类型,可选值:pc,wap |
| group | string | 否 | | 返回指定分组 |
| orderby | string | 否 | sort asc | 排序 |
| limit | int | 否 | 10 | 限制返回数量 |
>[info] 示例代码
```
/* 微信小程序示例 */
wx.request({
url: 'https://cms.hisiphp.com/cms/api/slide',
data: {
type: 'wap',
group: 'home',
timestamp: '2019-05-01 12:12:12',// 时间戳
sign: 'cddb29f7db9647274fc604531ff82cea'// 签名
},
header: {
'content-type': 'application/x-www-form-urlencoded'
},
method: 'GET',
success: function (res) {
console.log(res);
}
});
/* jquery示例 */
$.get(
'/cms/api/slide',
{
type: 'wap',
group: 'home',
timestamp: '2019-05-01 12:12:12',// 时间戳
sign: 'cddb29f7db9647274fc604531ff82cea'// 签名
},
function(res) {
console.log(res);
}, 'json');
```
## [rec] 推荐:rec
>[info]接口地址:/cms/api/rec
请求方式:GET/POST
| 属性名 | 类型 | 必须 | 默认 | 说明
| --- | --- | --- | --- | --- |
| name | string | 是 | | 调用名称 |
>[info] 示例代码
```
/* 微信小程序示例 */
wx.request({
url: 'https://cms.hisiphp.com/cms/api/rec',
data: {
name: 'product',
timestamp: '2019-05-01 12:12:12',// 时间戳
sign: 'cddb29f7db9647274fc604531ff82cea'// 签名
},
header: {
'content-type': 'application/x-www-form-urlencoded'
},
method: 'GET',
success: function (res) {
console.log(res);
}
});
/* jquery示例 */
$.get(
'/cms/api/rec',
{
name: 'product',
timestamp: '2019-05-01 12:12:12',// 时间戳
sign: 'cddb29f7db9647274fc604531ff82cea'// 签名
},
function(res) {
console.log(res);
}, 'json');
```
## [type] 栏目类型
>[info]接口地址:/cms/api/type
请求方式:GET/POST
| 属性名 | 类型 | 必须 | 默认 | 说明
| --- | --- | --- | --- | --- |
| tid | int | 是 | | 类型ID |
>[info] 示例代码
```
/* 微信小程序示例 */
wx.request({
url: 'https://cms.hisiphp.com/cms/api/type',
data: {
tid: 123,
timestamp: '2019-05-01 12:12:12',// 时间戳
sign: 'cddb29f7db9647274fc604531ff82cea'// 签名
},
header: {
'content-type': 'application/x-www-form-urlencoded'
},
method: 'GET',
success: function (res) {
console.log(res);
}
});
/* jquery示例 */
$.get(
'/cms/api/type',
{
tid: 123,
timestamp: '2019-05-01 12:12:12',// 时间戳
sign: 'cddb29f7db9647274fc604531ff82cea'// 签名
},
function(res) {
console.log(res);
}, 'json');
```
## [form] 表单
>[info]接口地址:/cms/api/form
请求方式:GET/POST
| 属性名 | 类型 | 必须 | 默认 | 说明
| --- | --- | --- | --- | --- |
| name | string | 是 | | 表单名称 |
>[info] 示例代码
```
/* 微信小程序示例 */
wx.request({
url: 'https://cms.hisiphp.com/cms/api/form',
data: {
name: 'test',
timestamp: '2019-05-01 12:12:12',// 时间戳
sign: 'cddb29f7db9647274fc604531ff82cea'// 签名
},
header: {
'content-type': 'application/x-www-form-urlencoded'
},
method: 'GET',
success: function (res) {
console.log(res);
}
});
/* jquery示例 */
$.get(
'/cms/api/form',
{
name: 'test',
timestamp: '2019-05-01 12:12:12',// 时间戳
sign: 'cddb29f7db9647274fc604531ff82cea'// 签名
},
function(res) {
console.log(res);
}, 'json');
```
## [like] 喜欢/点赞
>[info]接口地址:/cms/api/like
请求方式:GET/POST
| 属性名 | 类型 | 必须 | 默认 | 说明
| --- | --- | --- | --- | --- |
| id | int | 是 | | 内容ID |
>[info] 示例代码:
```
/* 微信小程序示例 */
wx.request({
url: 'https://cms.hisiphp.com/cms/api/like',
data: {
id: 49,
timestamp: '2019-05-01 12:12:12',// 时间戳
sign: 'cddb29f7db9647274fc604531ff82cea'// 签名
},
header: {
'content-type': 'application/x-www-form-urlencoded'
},
method: 'POST',
success: function (res) {
console.log(res);
}
});
/* jquery示例 */
$.get('/cms/api/like', {
id: 49,
timestamp: '2019-05-01 12:12:12',// 时间戳
sign: 'cddb29f7db9647274fc604531ff82cea'// 签名
}, function(res) {
console.log(res);
}, 'json');
```
## [dislike] 踩/不喜欢
>[info]接口地址:/cms/api/dislike
请求方式:GET/POST
| 属性名 | 类型 | 必须 | 默认 | 说明
| --- | --- | --- | --- | --- |
| id | int | 是 | | 内容ID |
>[info] 示例代码:
```
/* 微信小程序示例 */
wx.request({
url: 'https://cms.hisiphp.com/cms/api/dislike',
data: {
id: 49,
timestamp: '2019-05-01 12:12:12',// 时间戳
sign: 'cddb29f7db9647274fc604531ff82cea'// 签名
},
header: {
'content-type': 'application/x-www-form-urlencoded'
},
method: 'POST',
success: function (res) {
console.log(res);
}
});
/* jquery示例 */
$.get('/cms/api/dislike', {
id: 49,
timestamp: '2019-05-01 12:12:12',// 时间戳
sign: 'cddb29f7db9647274fc604531ff82cea'// 签名
}, function(res) {
console.log(res);
}, 'json');
```
## [batch] 批量获取接口数据
>[info]接口地址:/cms/api/batch
请求方式:POST
```
// 小程序请求示例
wx.request({
method: 'POST',
url: 'http://www.hisiphp.com/cms/api/batch',
data: {
// 接口名: {参数名: 参数值}
list: {cid: 1},// 请求内容列表接口
category: {cid: 0},// 请求分类接口
slide: {type: 'mini'},// 请求幻灯片接口
timestamp: '2019-05-01 12:12:12',// 时间戳
sign: 'cddb29f7db9647274fc604531ff82cea'// 签名
// 更多接口....
},
success:function(res) {
console.log(res)
}
});
// AJAX请求示例
$.ajax({
type: 'POST',
url: 'http://api.demo.hisiphp.com/v1/articles',
data: {
// 接口名: {参数名: 参数值}
list: {cid: 1},// 请求内容列表接口
category: {cid: 0},// 请求分类接口
slide: {type: 'mini'},// 请求幻灯片接口
timestamp: '2019-05-01 12:12:12',// 时间戳
sign: 'cddb29f7db9647274fc604531ff82cea'// 签名
// 更多接口....
},
success: function(res) {
console.log(res)
}
});
```
>[warning] 上面示例代码的data对象里面的key就是需要获取的对应接口名(比如列表接口list,栏目接口category等等)