PHPackages                             jiechengyang/i-secure-center - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Security](/categories/security)
4. /
5. jiechengyang/i-secure-center

ActiveLibrary[Security](/categories/security)

jiechengyang/i-secure-center
============================

基于Yii2实现海康威视综合安防管理平台开放api

1.0.0(6y ago)1162Apache-2.0PHPPHP &gt;=5.4.0

Since Aug 28Pushed 6y ago2 watchersCompare

[ Source](https://github.com/jiechengyang/i-secure-center)[ Packagist](https://packagist.org/packages/jiechengyang/i-secure-center)[ RSS](/packages/jiechengyang-i-secure-center/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (3)Versions (4)Used By (0)

iSecureCenter
=============

[](#isecurecenter)

基于yii2开发的海康威视综合安防平台V1.3api接口组件，目前组件封装了资源接口和视频接口，后续打算把全部接口封装。

===============================

[![Latest Stable Version](https://camo.githubusercontent.com/cffc578e9ba65f7cd5015f948b1a93beb0aa9a6a17708efb859cdab38b5982a9/68747470733a2f2f706f7365722e707567782e6f72672f6a69656368656e6779616e672f692d7365637572652d63656e7465722f762f737461626c65)](https://packagist.org/packages/jiechengyang/i-secure-center)[![Total Downloads](https://camo.githubusercontent.com/8f66dc7cb19ed846186b1bb2daee944dad43a5a12b84e7d21317f0e4e22201fd/68747470733a2f2f706f7365722e707567782e6f72672f6a69656368656e6779616e672f692d7365637572652d63656e7465722f646f776e6c6f616473)](https://packagist.org/packages/jiechengyang/i-secure-center)[![Latest Unstable Version](https://camo.githubusercontent.com/901053f9cc16e062406cb30635e0f6df20edc594c932a847c1f3f26944e0a1ba/68747470733a2f2f706f7365722e707567782e6f72672f6a69656368656e6779616e672f692d7365637572652d63656e7465722f762f756e737461626c65)](https://packagist.org/packages/jiechengyang/i-secure-center)[![License](https://camo.githubusercontent.com/3cf2257fc45728f82e48a298306f93075dd869f1d6ccaf207113ab9d313789df/68747470733a2f2f706f7365722e707567782e6f72672f6a69656368656e6779616e672f692d7365637572652d63656e7465722f6c6963656e7365)](https://packagist.org/packages/jiechengyang/i-secure-center)[![composer.lock](https://camo.githubusercontent.com/06ce180315b63cc7879b3c5a0bb873f2daa67e9dc3d82f8de6b4a8a7cf13fc8a/68747470733a2f2f706f7365722e707567782e6f72672f6a69656368656e6779616e672f692d7365637572652d63656e7465722f636f6d706f7365726c6f636b)](https://packagist.org/packages/jiechengyang/i-secure-center)

安装
--

[](#安装)

1. 使用composer composer的安装以及国内镜像设置请点击[此处](http://www.phpcomposer.com/)

    ```
    $ cd /path/to/i-secure-center
    $ composer require "jiechengyang/i-secure-center"
    $ composer install -vvv
    ```
2. 手动导入 下载i-secure-center包后放置在任意目录 然后在yii2 index.php中

    ```
       require "/path/to/i-secure-center/autoload.php";
    ```

关于组件
----

[](#关于组件)

\####设计的想法：

- 组件是继承了yii\\base\\Component,因为想把事件和行为也结合起来使用。写组件的时候，如果不想用事件、行为这些影响性能的特性可以直接继承yii\\base\\BaseObject写。
- 组件提供了before\_send和after\_send两个事件
    - before\_send可以用来修改我们的一些配置参数（比如：安防平台的地址，默认的地址在系统加载就固定了，那如果我们要换成另一个地址就可以在bofore\_send里面处理了），可以加入判断，比如用户权限不过直接return false，就无需请求安防平台了
    - after\_send里面有返回的数据，我们可以做一些参数校验之类的
    - 总而言之，使用事件的好处便是提前把接口请求前后的事情都注入到事件。还有这个组件提供的事件主要还是为了学了yii2的组件的思想，用不用无妨，用的话，可以根据自己的业务好好的完善，我只是提供了一个写yii2组件的demo
- 组件配置的ak配置是为了实现多合作方请求的，使用综合安防的朋友都知道，合作方是有多个的，每个合作方的权限也不一致，请求接口返回的数据也会和合作方的权限有关系，因此在这样的考虑之下，便把它设计成了一个多合作方的操作。`需要强调的是：必须配置一个默认的合作方adminPartner，建议是配置对内合作方`

\####接口实现的想法：

- 这次接口实现有幸在github上看到一位朋友的设计，让我耳目一新，于是我便借着这个思路开发了，以下我将说明这个接口设计。

    \*第一个想法：外部调用组件的send的方法，传递两个参数：A、安防接口地址B、对应A需要的参数。在send里面直接把验签的参数和提交的参数配置，使用http-client处理。

    \*第二个想法：第一想法的诟病就是安防接口地址太长，既然是个组件，用起来不方面，于是乎便想到了枚举，用一个文件专门作一个数组映射，用相近的单词作为key，接口地址作为value。其他和第一个想法一样。

    \*第三个想法：这便是看了那位朋友的设计之后，让我有了相同的想法。我先按照安防接口的大分类定义几个目录，然后把小分类写成文件放在大目录里，这里的文件就是一个接口类，这个接口类都会继承BaseApi的抽象类。外部调用的时候，先实例化某个接口类作为第一个参数，第二个参数则是类里方法名，这个方法名就代表具体的接口地址。

    \*第四个想法：组件的里面加入接口服务层service，由service层具体请求数据，这样组件的send方法便有了第三个参数合作方，这个参数便是实现我们的多合作方请求接口。

**`总结`**
--------

[](#总结)

通过第三、四个想法的结合，我发现了它的一些好处：

1. 我们调用人家的接口总有些必须携带的参数，在接口类的每个方法都预先的做了预警操作，必要的参数外部调用未携带时，send会直接返回错误提示，而像分页参数、时间参数方法里也设置了默认值和时间格式转换，外部调用简单调用就可以了。而这样的想法和上面那位朋友也是不谋而合，因为我没细看他的代码，在我接口调用出现问题时，发现他的做法也是如此。
2. 合理的使用yii2-http-client组件，我封装了http请求组件，因为我在init里面，写了before\_send和after\_send的两个事件。service调用只需把请求的地址，参数，验参的参数提供过去，具体怎么接口认证，那就是before\_send的事了，最后返回的参数需要做一些变化，也是after\_send做的了，service它只需发送了，把想要的数据给它就行了。 哈哈，yii2的思想真的很nice。
3. baseApi代码和注释如下:

```
abstract class BaseApi
{
    protected $error;// 用于存放接口必填参数未填的错误

    protected $_uriMap;// 接口的方法与接口地址的映射，每个接口类都预先设置好的

    protected $requestUri;// 接口地址

    public $requestBody;// 接口请求参数

    /**
     * @return mixed
     */
    public function getUriMap()
    {
        return $this->_uriMap;
    }

    /**
     * @return mixed
     */
    public function getRequestUri()
    {
        return $this->requestUri;
    }

    /**
     * @return mixed
     */
    public function getRequestBody()
    {
        return $this->requestBody;
    }

    public function setRequestBody($requestBody)
    {
        $this->requestBody = $requestBody;
    }

    /**
     * 获取action对应的地址
     * @return mixed
     */
    public function getUri($action)
    {
        if (empty($action) || empty($this->_uriMap[$action])) {
            return null;
        }

        $this->requestUri = $this->_uriMap[$action];

        return $this->requestUri;
    }

    /**
     * 接口存在该方法便调用
     * @return bool
     */
    public function runAction($action, $message = [])
    {
        if (!is_callable([$this, $action])) {
            return false;
        }

        call_user_func([$this, $action], $message);

        return true;
    }

    public function getError()
    {
        return $this->error;
    }

    public function getErrorFormat($glue = PHP_EOL)
    {
        return implode($glue, $this->getError());
    }

    public function setError($error)
    {
        $this->error = $error;
    }
}
```

配置
--

[](#配置)

i-secure-center是作为一个组件提供服务的，所以得配置yii2 iSecureCenter组件。打开common/config/main.php在components块内增加如下配置： 配置见[config/main.php](config/main.php)

http-client说明
-------------

[](#http-client说明)

yii2的http-client默认使用php的stream扩展，如果使用curl,则在实例化之后$client-&gt;setTransport("yii\\httpclient\\CurlTransport")即可。如果需要跳过ssl证书检测则-&gt;setOptions(\[ CURLOPT\_SSL\_VERIFYPEER =&gt; false, CURLOPT\_SSL\_VERIFYHOST =&gt; false, \])

示例
--

[](#示例)

见[examples/demo.php](examples/demo.php)

说明
--

[](#说明)

要在github发布release才可以composer require，不然你只能用dev-master版本

yii2-iSecureCenter 集成了\[\] 常用接口，采用组件的形式主要为了实现参数可配置，事件化处理业务。

***目前组件还在完善中....***

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity12

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~6 days

Total

3

Last Release

2436d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b4d61b39e49aac114dc99b45667b3b2de41d956dd0796e72026fab9d84444198?d=identicon)[jiechengyang](/maintainers/jiechengyang)

---

Top Contributors

[![jiechengyang](https://avatars.githubusercontent.com/u/33148475?v=4)](https://github.com/jiechengyang "jiechengyang (18 commits)")

---

Tags

phpyii2open-apihikvisioniSecure Centerhkjiechengyangi-secure-centerartemis-http-client

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/jiechengyang-i-secure-center/health.svg)

```
[![Health](https://phpackages.com/badges/jiechengyang-i-secure-center/health.svg)](https://phpackages.com/packages/jiechengyang-i-secure-center)
```

###  Alternatives

[hyperia/yii2-secure-headers

Secure headers for your Yii2 app

21189.5k](/packages/hyperia-yii2-secure-headers)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
