PHPackages                             smileyi/ytil - 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. [Image &amp; Media](/categories/media)
4. /
5. smileyi/ytil

ActiveLibrary[Image &amp; Media](/categories/media)

smileyi/ytil
============

v0.1.5(6y ago)36MITPHPPHP &gt;=7.0

Since Apr 10Pushed 6y ago1 watchersCompare

[ Source](https://github.com/smile-yi/Ytil)[ Packagist](https://packagist.org/packages/smileyi/ytil)[ RSS](/packages/smileyi-ytil/feed)WikiDiscussions master Synced 2w ago

READMEChangelogDependenciesVersions (6)Used By (0)

Ytil
====

[](#ytil)

### PHP常用工具包(网络调用、参数校验)

[](#php常用工具包网络调用参数校验)

#### 安装方法

[](#安装方法)

```
composer require smileyi/ytil

```

#### 基础配置

[](#基础配置)

```
use SmileYi\Ytil\Config;

Config::set([
    'log' => [
        // 日志存储路径
        'dir' => dirname(__FILE__) . '/../extra/log/',
    ],
    'common' => [
        //加密盐值
        'salt' => '4ckNt8GrgvqXYg1u',
    ],
    'base64' => [
        // 编码表
        // 'map' => 'OBrsYZabgQRSTUtu3JnoPDChijklWApqKLM6Evw7Ncde45mxGHIfXyz012FV89+/',
        'map' => 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/',
    ],
    'upload' => [
        // 上传目录
        'dir' => dirname(__FILE__) . '/../extra/upload/',
        // 允许的文件类型
        'exts' => ['jpg', 'png', 'jpeg'], // 不限制: ['*']
        // 文件大小限制
        'size' => 1024 * 1024 * 2,
    ],
])

```

#### 工具列表

[](#工具列表)

- 网络调用
- 参数验证
- Base64编码
- 加密解密
- 文件上传
- 日志写入

#### 具体用法

[](#具体用法)

##### Http调用

[](#http调用)

```
use SmileYi\Ytil\Http;
use SmileYi\Ytil\Exception;

$url = 'http://192.144.150.100/api.php?method=get&task_id=1001';
$header = [
    'Content-type' => 'application/json',
    'User-agent' => 'utils/http'
];
$body = [
    'param1' => 'value1'
];

//代理配置
//$proxy = 'http://xxx.xxx.xxx.xxx:8080'
$proxy = null;

//证书配置
// $cert = [
//     'ssl_cert' => 'path',
//     'ssl_key' => 'path',
//     'ca_info' => 'path'
// ];
$cert = null;

try {
    //GET调用
    $result = Http::get($url, $header, $proxy, $cert);
    var_dump($result);

    //POST调用
    $result = Http::post($url, $body, $header, $proxy, $cert);
    var_dump($result);

    //并行调用
    $multi = [];
    $multi['name1'] = [
        'method' => Http::METHOD_GET,
        'url' => $url,
        'header' => $header
    ];
    $multi['name2'] = [
        'method' => Http::METHOD_POST,
        'url' => $url,
        'header' => $header,
        'body' => $body
    ];

    $result = Http::multi($multi);
    var_dump($result);
}catch(Exception $e){
    echo "Errno:" . $e->getCode() . " Error:" . $e->getMessage()."\n";
}

```

##### 日志写入

[](#日志写入)

```
use SmileYi\Ytil\Log;

Log::getInstance()->put('user', ['nickname' => 'smileyi', 'sex' => 1]);

```

##### 常用工具

[](#常用工具)

```
use SmileYi\Ytil\Common;

# 加密解密
$t = 'hahaha';
$dt = Common::encrypt($t);
$et = Common::decrypt($dt);
echo "secret text:" . $dt . "\n";
echo "text:" . $et . "\n\n";

# 耗时计算
Common::exeTime('_start');
sleep(0.1);
Common::exeTime('_end');
echo "Exe time is:" . Common::exeTime('_start', '_end') . "s\n\n";

# 获取随机长度字符串
echo "random string is:" . Common::randStr(10) . "\n\n";

# 获取客户端IP
echo "client ip is:" . Common::getClientIp() . "\n\n";

```

##### Base64编码解码

[](#base64编码解码)

```
use SmileYi\Ytil\Base64;

$text = 'smileyi';

# 编码
$dt = Base64::encode($text);
# 解码
$et = Base64::decode($dt);

echo "text base64 encode is:" . $dt . "\n";
echo "text is:" . $et . "\n\n";

```

##### 参数校验

[](#参数校验)

```
use SmileYi\Ytil\Format;

# 邮箱
$bool = Format::isEmail('haha@gmail.com');

# 手机号
$bool = Format::isMobile('188xxxxxxxx');

# url
$bool = Format::isUrl('http://www.github.com/');

# 身份证号
$bool = Format::isIdCard('1775443288743221234');

# 整数
$bool = Format::isInteger(1001);

# json
$bool = Format::isJson('{"name":"smileyi"}');

# 用户名(6-16位数字+字母+_)
$bool = Format::isUsername('smileyi');

# 密码(6-20位数字+字母+_)
$bool = Format::isPassword('haha1234');

```

###  Health Score

23

—

LowBetter than 26% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity49

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

Total

5

Last Release

2522d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/5610069?v=4)[Matt Mighell](/maintainers/smileyi)[@smileyi](https://github.com/smileyi)

---

Top Contributors

[![smile-yi](https://avatars.githubusercontent.com/u/11816185?v=4)](https://github.com/smile-yi "smile-yi (12 commits)")

---

Tags

httpimagesecretuploadutils

### Embed Badge

![Health badge](/badges/smileyi-ytil/health.svg)

```
[![Health](https://phpackages.com/badges/smileyi-ytil/health.svg)](https://phpackages.com/packages/smileyi-ytil)
```

###  Alternatives

[goat1000/svggraph

Generates SVG graphs

133890.0k3](/packages/goat1000-svggraph)[imagekit/imagekit

PHP library for Imagekit

46877.3k10](/packages/imagekit-imagekit)[gravatarphp/gravatar

Gravatar URL builder which is most commonly called as a Gravatar library

12644.1k2](/packages/gravatarphp-gravatar)

PHPackages © 2026

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