Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/luxiaok/phpkit
PHP Kit
https://github.com/luxiaok/phpkit
laravel php qrcode thinkphp yii2
Last synced: 22 days ago
JSON representation
PHP Kit
- Host: GitHub
- URL: https://github.com/luxiaok/phpkit
- Owner: luxiaok
- Created: 2020-04-07T09:56:01.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2020-08-14T09:36:55.000Z (over 4 years ago)
- Last Synced: 2024-11-17T20:51:29.365Z (2 months ago)
- Topics: laravel, php, qrcode, thinkphp, yii2
- Language: PHP
- Size: 87.9 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
PHP Kit
=======
Tools for PHP## Support for Yii2
#### 配置
```php
[
'kit' => [
'class' => 'phpkit\kit',
],
]
];
```#### 应用1:生成随机数
```php
kit->gen_random_str($len);
```#### 应用2:生成二维码
```php
request->get('text','Hello world!');
$type = Yii::$app->request->get('type','text'); // text or url
if ($type=='url') {
$text = urldecode($text);
}
Yii::$app->response->headers->set('Content-type','image/png');
Yii::$app->response->format = \yii\web\Response::FORMAT_RAW;
Yii::$app->kit->qrcode($text);
}```
#### 应用3:解析IP地址
```php
kit->get_client_ip(); //IPv4,例如:121.51.19.218
$location = Yii::$app->kit->get_ip_location($ip); //中国 广东 深圳 腾讯云```
> 使用IP地址解析功能需要下载 `qqwry.dat` 到 `vendor/luxiaok/phpkit/tools` 目录。
#### 应用4:校验商品价格
```php
kit->validatePrice(666); // true
$isPrice = Yii::$app->kit->validatePrice(0.01); // true
$isPrice = Yii::$app->kit->validatePrice(0.012); // false
$isPrice = Yii::$app->kit->validatePrice(-1); // false
$isPrice = Yii::$app->kit->validatePrice(0); // true
```#### 应用5:http请求
```php