PHPackages                             yiqiang3344/yii2-lib - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. yiqiang3344/yii2-lib

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

yiqiang3344/yii2-lib
====================

yii2公共php库

v1.0.6(2y ago)23MITPHPPHP &gt;=5.4.0

Since Nov 19Pushed 2y ago1 watchersCompare

[ Source](https://github.com/yiqiang3344/yii2-lib)[ Packagist](https://packagist.org/packages/yiqiang3344/yii2-lib)[ Docs](https://github.com/yiqiang3344/yii2-lib#readme)[ RSS](/packages/yiqiang3344-yii2-lib/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (7)Dependencies (3)Versions (9)Used By (0)

简介
==

[](#简介)

库中定义了基于yii2框架的配置文件、数据库、加密、OSS、Redis、参数校验、状态码，以及数组、字符串、金额、图片和时间等常用的工具类。

安装
==

[](#安装)

```
composer require yiqiang3344/yii2-lib
```

功能
==

[](#功能)

config
------

[](#config)

### 配置类 `\yiqiang3344\lib\helper\config\Config`

[](#配置类-yiqiang3344libhelperconfigconfig)

可以以点连接的方式按数据类型读取`Yii::$app->params`中的参数。 比如：

```
//params.php
return [
    'env' => [
        'name' => 'test'
    ],
];
```

```
echo Config::getString('env.name'); //输出为 test
```

db
--

[](#db)

### 数据库类 `\yiqiang3344\lib\helper\db\DB`

[](#数据库类-yiqiang3344libhelperdbdb)

方便自定义的获取数据库实例使用；提供闭包形式的事务方法。

db中配置了credit\_db数据库，则可以继承`DB`类，然后添加`credit_db()`方法来获取数据库连接实例。 `DB`中默认实现了获取db连接实例的方法`default()`。

```
    /**
     * 默认DB
     * @return \yii\db\Connection
     */
    public static function default()
    {
        $db = \Yii::$app->db;
        return $db;
    }
```

闭包形式的事务方法。

```
    return DB::transaction(function (){
        DB::default()->createCommand('select id from User where id=1 for update')->execute();
        //...
        return true;
    });
```

encrypt
-------

[](#encrypt)

### 加密类 `\yiqiang3344\lib\helper\encrypt\Encrypt`

[](#加密类-yiqiang3344libhelperencryptencrypt)

提供`aes-128-cbc`的加密、解密和加签方法。

### RSA加密类 `\yiqiang3344\lib\helper\encrypt\RSAUtil`

[](#rsa加密类-yiqiang3344libhelperencryptrsautil)

提供`OPENSSL_ALGO_SHA256`的加密、解密、加签和验签方法。

oss
---

[](#oss)

### 阿里云OSS类 `\yiqiang3344\lib\helper\oss\Oss`

[](#阿里云oss类-yiqiang3344libhelperossoss)

统一配置的阿里云OSS封装类，提供获取oss实例、上传、下载、删除、获取访问地址方法。

redis
-----

[](#redis)

### Redis类 `\yiqiang3344\lib\helper\redis\Redis`

[](#redis类-yiqiang3344libhelperredisredis)

统一配置的Redis封装类，需要使用其他配置，只需集成此类，并重写`$redisName`属性。

validator
---------

[](#validator)

### 参数校验类 `\yiqiang3344\lib\helper\validator\Validator`

[](#参数校验类-yiqiang3344libhelpervalidatorvalidator)

统一使用`checkParams(&$params, $needParams)`方法来校验输入参数， 支持的参数类型参见`$builtInValidators`列表，且可自行扩展。

AmountHelper 金额工具类
------------------

[](#amounthelper-金额工具类)

获取标准格式化金额，单位元，两位小数点 `format($amount)`

数字转大写的金额 `num2rmb($number = 0, $intUnit = '圆', $isRound = true, $isExtraZero = false)`

ArrayHelper 数组工具类
-----------------

[](#arrayhelper-数组工具类)

把数组转为key-value格式 `listMap(array $array, $key, $columns = null)`

复制一个数组中指定列的数组 `cpList(array $array, array $columns)`

复制数组中的指定列 `cp($item, array $columns)`

CodeMessage 响应结果类
-----------------

[](#codemessage-响应结果类)

可以使用`success($data = [])`或`failed($code, $subMessage = '', $data = [])`来统一输出响应结果。
只需要在controller中`return CodeMessage::success();`即可。

响应状态码在`$codeMap`中定义， 默认正常响应码为1，异常响应码-1， 各应用可继承此类来定义各自应用的响应状态码。

Image 图片工具类
-----------

[](#image-图片工具类)

获取base64格式的图片 `base64EncodeImage($image_file)`

StringHelper 字符工具类
------------------

[](#stringhelper-字符工具类)

驼峰转横杠式 `humpToBar($string)`

遮盖名称 `coverName($string)`

用星星这个指定范围 `coverWithStar($string, $start, $length)`

遮盖字符串的制定范围 `cover($string, $start, $length, $mask = '*', $isUtf8 = false)`

Time
----

[](#time)

获取秒级时间戳 `time()`

获取日期 `now($time = null)`

获取带毫秒的日期 `nowWithMicros()`

获取毫秒时间戳 `getMicrotime()`

获取指定月份后的当前日期 `getNexMonthDay($num = 1, $date = null)`

获取当前日期星期几的中文名 `getDayOfWeek($time)`

当前时间与指定日期相差天数 `getSubDayFromToday($defaultDay = '2015-01-22')`

获取指定时间戳的当日的开始时间 `getDailyStartTime($time = null)`

获取指定时间戳的当天的截止时间 `getDailyEndTime($time = null)`

获取3位毫秒小数的浮点型时间戳 `getFloatMicroTime()`

Deamon 基于swoole可调节子进程数的守护进程
---------------------------

[](#deamon-基于swoole可调节子进程数的守护进程)

Sms 子调节发送及状态同步进程的短信系统
---------------------

[](#sms-子调节发送及状态同步进程的短信系统)

###  Health Score

25

—

LowBetter than 37% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity58

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 ~267 days

Recently: every ~364 days

Total

7

Last Release

764d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2597880?v=4)[sidneyYi](/maintainers/yiqiang3344)[@yiqiang3344](https://github.com/yiqiang3344)

---

Top Contributors

[![yiqiang3344](https://avatars.githubusercontent.com/u/2597880?v=4)](https://github.com/yiqiang3344 "yiqiang3344 (1 commits)")

### Embed Badge

![Health badge](/badges/yiqiang3344-yii2-lib/health.svg)

```
[![Health](https://phpackages.com/badges/yiqiang3344-yii2-lib/health.svg)](https://phpackages.com/packages/yiqiang3344-yii2-lib)
```

PHPackages © 2026

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