api0.php,API接口 · HisiPHP V2开发手册 · 看云

>[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等等)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
首先,需要在腾讯云官网上申请 API 密钥,具体步骤如下: 1. 登录腾讯云控制台,进入 API 密钥管理页面。 2. 点击“新建密钥”按钮,生成 API 密钥。 3. 将密钥保存好,以便在 PHP 代码中调用。 接下来,可以使用 PHP CURL 函数调用腾讯云 API 接口,具体步骤如下: 1. 构造请求 URL,包括接口地址、请求参数、签名等信息; 2. 使用 CURL 函数发送请求,获取服务器响应; 3. 解析服务器响应,提取需要的信息。 下面是一个简单的 PHP 代码示例,演示如何调用腾讯云 API 接口: ``` <?php // 定义 API 地址和请求参数 $url = "https://api.qcloud.com/v2/index.php"; $params = array( "Action" => "DescribeInstances", "Nonce" => rand(), "Region" => "ap-guangzhou", "SecretId" => "your_secret_id", "SignatureMethod" => "HmacSHA256", "Timestamp" => time(), ); // 计算签名 ksort($params); $srcStr = "GET" . $url . "?" . http_build_query($params); $signStr = base64_encode(hash_hmac("sha256", $srcStr, "your_secret_key", true)); $params["Signature"] = $signStr; // 发送请求 $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url . "?" . http_build_query($params)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); curl_close($ch); // 解析响应 $result = json_decode($response, true); print_r($result); ?> ``` 在上面的代码中,需要替换以下参数: - your_secret_id:替换为自己的 API 密钥 ID; - your_secret_key:替换为自己的 API 密钥 Key。 此外,还需要根据接口文档,调整请求参数和响应解析方式。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值