v6
李光春 2 years ago
parent 022a41a2da
commit ce734f671e

6
.gitignore vendored

@ -0,0 +1,6 @@
.env
.git
.svn
.idea
.vscode
.log

@ -1,202 +1,202 @@
## v6.0.132 / 2021-05-29
- 更新 We found potential security vulnerabilities in your dependencies.【phpoffice/phpspreadsheet】
## v6.0.131 / 2020-12-03
- 增加卡券网服务
## v6.0.130 / 2020-11-26
- 优化服务
## v6.0.129 / 2020-11-26
- 优化服务
## v6.0.128 / 2020-11-26
- 优化服务
## v6.0.127 / 2020-11-25
- 修复腾讯云存储
- 数组门面增加方法
## v6.0.126 / 2020-11-19
- 优化淘宝官方SDK
## v6.0.125 / 2020-11-19
- 优化淘宝服务协议
## v6.0.124 / 2020-11-19
- 小范围测试淘宝官方SDK
## v6.0.123 / 2020-11-19
- 测试淘宝官方SDK
## v6.0.122 / 2020-11-18
- 增加订单侠开放平台接口
## v6.0.121 / 2020-11-12
- 修复缴费平台接口
## v6.0.120 / 2020-11-03
- 京东联盟、淘宝联盟、拼多多联盟支持自定义接口
## v6.0.119 / 2020-10-10
- 暂时指定phpoffice/phpspreadsheet的版本
## v6.0.118 / 2020-10-10
- 小数门面的四舍五入方法优化
- IP信息文件调整回旧的方法
- 增加表格服务
## v6.0.117 / 2020-09-25
- 淘宝联盟接口增加
- 小数门面增加函数
## v6.0.116 / 2020-09-22
- 拼多多接口增加
- 优化京东接口
## v6.0.115 / 2020-09-21
- 微信小程序接口增加直播
## v6.0.114 / 2020-09-16
- 优化鼎信缴费平台充值接口
## v6.0.113 / 2020-09-08
- 增加腾讯地图Api接口
- 增加鼎信缴费平台充值接口
## v6.0.112 / 2020-09-08
- 优化接口
## v6.0.111 / 2020-09-08
- 更新微信公众平台的分享接口
## v6.0.110 / 2020-09-06
- 更新拼多多 多客接口
## v6.0.109 / 2020-09-04
- 修复公众号获取access_token问题
## v6.0.108 / 2020-09-03
- 修复数组
## v6.0.107 / 2020-08-15
- 优化
## v6.0.106 / 2020-08-08
- 修复数组门面增加数组删除空格函数问题
## v6.0.105 / 2020-08-08
- 修复数组门面增加数组删除空格函数问题
## v6.0.104 / 2020-08-05
- 修复数组门面增加数组删除空格函数问题
## v6.0.103 / 2020-08-05
- 链接门面增加获取URL文件格式
## v6.0.102 / 2020-08-05
- 数组门面增加数组删除空格
## v6.0.101 / 2020-07-25
- 优化代码
## v6.0.100 / 2020-07-25
- 优化淘宝客
## v6.0.99 / 2020-07-25
- 优化时间门面,增加参数
## v6.0.98 / 2020-07-25
- 优化时间门面
## v6.0.97 / 2020-07-23
- 增加小数门面
## v6.0.96 / 2020-07-23
- 网址管理增加删除协议和判断是否为Url方法
## v6.0.95 / 2020-07-20
- 优化cache和session服务
## v6.0.94 / 2020-07-20
- 优化cache和session服务
## v6.0.93 / 2020-07-20
- 修复请求门面的判断微信和微信小程序环境函数名错误问题
## v6.0.92 / 2020-07-18
- 优化Api加密解密
## v6.0.91 / 2020-07-18
- 修复请求门面手机设备类型
## v6.0.90 / 2020-07-18
- 优化代码
## v6.0.89 / 2020-07-18
- 修复获取配置问题
## v6.0.88 / 2020-07-18
- 优化代码
- 优化Api控制器的加密相关参数
- 请求门面增加获取客户端类型和获取手机设备类型
## v6.0.87 / 2020-07-17
- 优化代码
## v6.0.86 / 2020-07-17
- 优化代码
## v6.0.85 / 2020-07-17
- 扩展包不再包含数据库文件,允许通过配置文件路径的方式
## v6.0.84 / 2020-07-16
- 删除服务器签名验证(js和php方式不一致导致)
## v6.0.83 / 2020-07-16
- 通知签名规则和加密方法使用aes方式
- 更新IP数据库
## v6.0.82 / 2020-07-13
- 优化标准Api控制器基类
- 优化标准Api控制器基类签名
## v6.0.81 / 2020-07-12
- 优化代码质量
- 文件门面增加文件和目录判断
## v6.0.80 / 2020-07-12
- 优化描述
## v6.0.79 / 2020-07-12
- 优化标准Api控制器基类
- 优化描述
## v6.0.78 / 2020-07-12
- 增加标准Api控制器基类
## v6.0.77 / 2020-07-11
- 更新请求门面
- 增加判断是否为微信小程序访问
## v6.0.76 / 2020-07-11
- 淘宝客服务增加api接口
## v6.0.75 / 2020-07-10
- 更新IP数据库
## v6.0.74 / 2020-07-10
- 优化路由服务
## v6.0.73 / 2020-07-09
- 增加路由服务
## v6.0.72 / 2020-07-09
- 删除网易云服务
## v6.0.71 / 2020-07-09
- 更新请求门面
## v6.0.70 / 2020-07-08
- 更新联盟
- 更新数据库
## v6.0.132 / 2021-05-29
- 更新 We found potential security vulnerabilities in your dependencies.【phpoffice/phpspreadsheet】
## v6.0.131 / 2020-12-03
- 增加卡券网服务
## v6.0.130 / 2020-11-26
- 优化服务
## v6.0.129 / 2020-11-26
- 优化服务
## v6.0.128 / 2020-11-26
- 优化服务
## v6.0.127 / 2020-11-25
- 修复腾讯云存储
- 数组门面增加方法
## v6.0.126 / 2020-11-19
- 优化淘宝官方SDK
## v6.0.125 / 2020-11-19
- 优化淘宝服务协议
## v6.0.124 / 2020-11-19
- 小范围测试淘宝官方SDK
## v6.0.123 / 2020-11-19
- 测试淘宝官方SDK
## v6.0.122 / 2020-11-18
- 增加订单侠开放平台接口
## v6.0.121 / 2020-11-12
- 修复缴费平台接口
## v6.0.120 / 2020-11-03
- 京东联盟、淘宝联盟、拼多多联盟支持自定义接口
## v6.0.119 / 2020-10-10
- 暂时指定phpoffice/phpspreadsheet的版本
## v6.0.118 / 2020-10-10
- 小数门面的四舍五入方法优化
- IP信息文件调整回旧的方法
- 增加表格服务
## v6.0.117 / 2020-09-25
- 淘宝联盟接口增加
- 小数门面增加函数
## v6.0.116 / 2020-09-22
- 拼多多接口增加
- 优化京东接口
## v6.0.115 / 2020-09-21
- 微信小程序接口增加直播
## v6.0.114 / 2020-09-16
- 优化鼎信缴费平台充值接口
## v6.0.113 / 2020-09-08
- 增加腾讯地图Api接口
- 增加鼎信缴费平台充值接口
## v6.0.112 / 2020-09-08
- 优化接口
## v6.0.111 / 2020-09-08
- 更新微信公众平台的分享接口
## v6.0.110 / 2020-09-06
- 更新拼多多 多客接口
## v6.0.109 / 2020-09-04
- 修复公众号获取access_token问题
## v6.0.108 / 2020-09-03
- 修复数组
## v6.0.107 / 2020-08-15
- 优化
## v6.0.106 / 2020-08-08
- 修复数组门面增加数组删除空格函数问题
## v6.0.105 / 2020-08-08
- 修复数组门面增加数组删除空格函数问题
## v6.0.104 / 2020-08-05
- 修复数组门面增加数组删除空格函数问题
## v6.0.103 / 2020-08-05
- 链接门面增加获取URL文件格式
## v6.0.102 / 2020-08-05
- 数组门面增加数组删除空格
## v6.0.101 / 2020-07-25
- 优化代码
## v6.0.100 / 2020-07-25
- 优化淘宝客
## v6.0.99 / 2020-07-25
- 优化时间门面,增加参数
## v6.0.98 / 2020-07-25
- 优化时间门面
## v6.0.97 / 2020-07-23
- 增加小数门面
## v6.0.96 / 2020-07-23
- 网址管理增加删除协议和判断是否为Url方法
## v6.0.95 / 2020-07-20
- 优化cache和session服务
## v6.0.94 / 2020-07-20
- 优化cache和session服务
## v6.0.93 / 2020-07-20
- 修复请求门面的判断微信和微信小程序环境函数名错误问题
## v6.0.92 / 2020-07-18
- 优化Api加密解密
## v6.0.91 / 2020-07-18
- 修复请求门面手机设备类型
## v6.0.90 / 2020-07-18
- 优化代码
## v6.0.89 / 2020-07-18
- 修复获取配置问题
## v6.0.88 / 2020-07-18
- 优化代码
- 优化Api控制器的加密相关参数
- 请求门面增加获取客户端类型和获取手机设备类型
## v6.0.87 / 2020-07-17
- 优化代码
## v6.0.86 / 2020-07-17
- 优化代码
## v6.0.85 / 2020-07-17
- 扩展包不再包含数据库文件,允许通过配置文件路径的方式
## v6.0.84 / 2020-07-16
- 删除服务器签名验证(js和php方式不一致导致)
## v6.0.83 / 2020-07-16
- 通知签名规则和加密方法使用aes方式
- 更新IP数据库
## v6.0.82 / 2020-07-13
- 优化标准Api控制器基类
- 优化标准Api控制器基类签名
## v6.0.81 / 2020-07-12
- 优化代码质量
- 文件门面增加文件和目录判断
## v6.0.80 / 2020-07-12
- 优化描述
## v6.0.79 / 2020-07-12
- 优化标准Api控制器基类
- 优化描述
## v6.0.78 / 2020-07-12
- 增加标准Api控制器基类
## v6.0.77 / 2020-07-11
- 更新请求门面
- 增加判断是否为微信小程序访问
## v6.0.76 / 2020-07-11
- 淘宝客服务增加api接口
## v6.0.75 / 2020-07-10
- 更新IP数据库
## v6.0.74 / 2020-07-10
- 优化路由服务
## v6.0.73 / 2020-07-09
- 增加路由服务
## v6.0.72 / 2020-07-09
- 删除网易云服务
## v6.0.71 / 2020-07-09
- 更新请求门面
## v6.0.70 / 2020-07-08
- 更新联盟
- 更新数据库

@ -1,21 +1,21 @@
MIT License
Copyright (c) 2020 李光春
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
MIT License
Copyright (c) 2020 李光春
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

@ -1,145 +1,145 @@
<img align="right" width="100" src="https://kodo-cdn.dtapp.net/04/999e9f2f06d396968eacc10ce9bc8a.png" alt="www.dtapp.net"/>
<h1 align="left"><a href="https://www.dtapp.net/">ThinkPHP6扩展包</a></h1>
📦 ThinkPHP6扩展包
[![Latest Stable Version](https://poser.pugx.org/liguangchun/think-library/v/stable)](https://packagist.org/packages/liguangchun/think-library)
[![Latest Unstable Version](https://poser.pugx.org/liguangchun/think-library/v/unstable)](https://packagist.org/packages/liguangchun/think-library)
[![Total Downloads](https://poser.pugx.org/liguangchun/think-library/downloads)](https://packagist.org/packages/liguangchun/think-library)
[![License](https://poser.pugx.org/liguangchun/think-library/license)](https://packagist.org/packages/liguangchun/think-library)
[![PHP Version](https://img.shields.io/badge/php-%3E%3D7.1-8892BF.svg)](http://www.php.net/)
[![Build Status](https://travis-ci.org/GC0202/ThinkLibrary.svg?branch=6.0)](https://travis-ci.org/GC0202/ThinkLibrary)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/GC0202/ThinkLibrary/badges/quality-score.png?b=6.0)](https://scrutinizer-ci.com/g/GC0202/ThinkLibrary/?branch=6.0)
[![Code Coverage](https://scrutinizer-ci.com/g/GC0202/ThinkLibrary/badges/coverage.png?b=6.0)](https://scrutinizer-ci.com/g/GC0202/ThinkLibrary/?branch=6.0)
## 依赖环境
1. PHP7.1 版本及以上
## 托管
- 国外仓库地址:[https://github.com/GC0202/ThinkLibrary](https://github.com/GC0202/ThinkLibrary)
- 国内仓库地址:[https://gitee.com/liguangchun/ThinkLibrary](https://gitee.com/liguangchun/ThinkLibrary)
- Packagist
地址:[https://packagist.org/packages/liguangchun/think-library](https://packagist.org/packages/liguangchun/think-library)
### 开发版
```text
composer require liguangchun/think-library ^6.x-dev -vvv
```
### 稳定版
```text
composer require liguangchun/think-library ^6.0.* -vvv
```
## 更新
```text
composer update liguangchun/think-library -vvv
```
## 删除
```text
composer remove liguangchun/think-library -vvv
```
## 获取电脑Mac地址服务使用示例
```php
use DtApp\ThinkLibrary\service\SystemService;
dump(SystemService::instance()
->mac());
```
## 百度地图服务使用示例
```php
use DtApp\ThinkLibrary\service\baidu\LbsYunService;
dump(LbsYunService::instance()
->ak("")
->weather());
```
## 高德地图服务使用示例
```php
use DtApp\ThinkLibrary\service\amap\AmApService;
dump(AmApService::instance()
->key("")
->weather());
```
## 抖音服务使用示例
```php
use DtApp\ThinkLibrary\exception\DtaException;
use DtApp\ThinkLibrary\service\douyin\WatermarkService;
try {
// 方法一之网址
dump(WatermarkService::instance()->url('https://v.douyin.com/vPGAdM/')
->getAll()
->toArray());
// 方法一之粘贴
dump(WatermarkService::instance()->url('#在抖音,记录美好生活#美丽电白欢迎您 https://v.douyin.com/vPGAdM/ 复制此链接,打开【抖音短视频】,直接观看视频!')->getAll()->toArray());
// 方法二之网址
$dy = WatermarkService::instance()->url('https://v.douyin.com/vPafcr/');
dump($dy->getAll()->toArray());
// 方法二之粘贴
$dy = WatermarkService::instance()->url('#在抖音,记录美好生活#2020茂名加油广州加油武汉加油中国加油众志成城#航拍 #茂名#武汉 #广州 #旅拍 @抖音小助手 https://v.douyin.com/vPafcr/ 复制此链接,打开【抖音短视频】,直接观看视频!');
dump($dy->getAll()->toArray());
// 获取全部信息
dump(WatermarkService::instance()->url('https://v.douyin.com/vPGAdM/')
->getAll()
->toArray());
// 获取原全部信息
dump(WatermarkService::instance()->url('https://v.douyin.com/vPGAdM/')
->getApi()
->toArray());
// 获取视频信息
dump(WatermarkService::instance()->url('https://v.douyin.com/vPGAdM/')
->getVideoInfo()
->toArray());
// 获取音频信息
dump(WatermarkService::instance()->url('https://v.douyin.com/vPGAdM/')
->getMusicInfo()
->toArray());
// 获取分享信息
dump(WatermarkService::instance()->url('https://v.douyin.com/vPGAdM/')
->getShareInfo()
->toArray());
// 获取作者信息
dump(WatermarkService::instance()->url('https://v.douyin.com/vPGAdM/')
->getAuthorInfo()
->toArray());
// 返回数组数据方法
dump(WatermarkService::instance()->url('https://v.douyin.com/vPGAdM/')
->getAll()
->toArray());
// 返回Object数据方法
dump(WatermarkService::instance()->url('https://v.douyin.com/vPGAdM/')
->getAll()
->toObject());
} catch (DtaException $e) {
// 错误提示
dump($e->getMessage());
}
```
## 纯真数据库
```php
use DtApp\ThinkLibrary\service\QqWryService;
// 获取IP信息
dump(QqWryService::instance()
->getLocation());
```
<img align="right" width="100" src="https://kodo-cdn.dtapp.net/04/999e9f2f06d396968eacc10ce9bc8a.png" alt="www.dtapp.net"/>
<h1 align="left"><a href="https://www.dtapp.net/">ThinkPHP6扩展包</a></h1>
📦 ThinkPHP6扩展包
[![Latest Stable Version](https://poser.pugx.org/liguangchun/think-library/v/stable)](https://packagist.org/packages/liguangchun/think-library)
[![Latest Unstable Version](https://poser.pugx.org/liguangchun/think-library/v/unstable)](https://packagist.org/packages/liguangchun/think-library)
[![Total Downloads](https://poser.pugx.org/liguangchun/think-library/downloads)](https://packagist.org/packages/liguangchun/think-library)
[![License](https://poser.pugx.org/liguangchun/think-library/license)](https://packagist.org/packages/liguangchun/think-library)
[![PHP Version](https://img.shields.io/badge/php-%3E%3D7.1-8892BF.svg)](http://www.php.net/)
[![Build Status](https://travis-ci.org/GC0202/ThinkLibrary.svg?branch=6.0)](https://travis-ci.org/GC0202/ThinkLibrary)
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/GC0202/ThinkLibrary/badges/quality-score.png?b=6.0)](https://scrutinizer-ci.com/g/GC0202/ThinkLibrary/?branch=6.0)
[![Code Coverage](https://scrutinizer-ci.com/g/GC0202/ThinkLibrary/badges/coverage.png?b=6.0)](https://scrutinizer-ci.com/g/GC0202/ThinkLibrary/?branch=6.0)
## 依赖环境
1. PHP7.1 版本及以上
## 托管
- 国外仓库地址:[https://github.com/GC0202/ThinkLibrary](https://github.com/GC0202/ThinkLibrary)
- 国内仓库地址:[https://gitee.com/liguangchun/ThinkLibrary](https://gitee.com/liguangchun/ThinkLibrary)
- Packagist
地址:[https://packagist.org/packages/liguangchun/think-library](https://packagist.org/packages/liguangchun/think-library)
### 开发版
```text
composer require liguangchun/think-library ^6.x-dev -vvv
```
### 稳定版
```text
composer require liguangchun/think-library ^6.0.* -vvv
```
## 更新
```text
composer update liguangchun/think-library -vvv
```
## 删除
```text
composer remove liguangchun/think-library -vvv
```
## 获取电脑Mac地址服务使用示例
```php
use DtApp\ThinkLibrary\service\SystemService;
dump(SystemService::instance()
->mac());
```
## 百度地图服务使用示例
```php
use DtApp\ThinkLibrary\service\baidu\LbsYunService;
dump(LbsYunService::instance()
->ak("")
->weather());
```
## 高德地图服务使用示例
```php
use DtApp\ThinkLibrary\service\amap\AmApService;
dump(AmApService::instance()
->key("")
->weather());
```
## 抖音服务使用示例
```php
use DtApp\ThinkLibrary\exception\DtaException;
use DtApp\ThinkLibrary\service\douyin\WatermarkService;
try {
// 方法一之网址
dump(WatermarkService::instance()->url('https://v.douyin.com/vPGAdM/')
->getAll()
->toArray());
// 方法一之粘贴
dump(WatermarkService::instance()->url('#在抖音,记录美好生活#美丽电白欢迎您 https://v.douyin.com/vPGAdM/ 复制此链接,打开【抖音短视频】,直接观看视频!')->getAll()->toArray());
// 方法二之网址
$dy = WatermarkService::instance()->url('https://v.douyin.com/vPafcr/');
dump($dy->getAll()->toArray());
// 方法二之粘贴
$dy = WatermarkService::instance()->url('#在抖音,记录美好生活#2020茂名加油广州加油武汉加油中国加油众志成城#航拍 #茂名#武汉 #广州 #旅拍 @抖音小助手 https://v.douyin.com/vPafcr/ 复制此链接,打开【抖音短视频】,直接观看视频!');
dump($dy->getAll()->toArray());
// 获取全部信息
dump(WatermarkService::instance()->url('https://v.douyin.com/vPGAdM/')
->getAll()
->toArray());
// 获取原全部信息
dump(WatermarkService::instance()->url('https://v.douyin.com/vPGAdM/')
->getApi()
->toArray());
// 获取视频信息
dump(WatermarkService::instance()->url('https://v.douyin.com/vPGAdM/')
->getVideoInfo()
->toArray());
// 获取音频信息
dump(WatermarkService::instance()->url('https://v.douyin.com/vPGAdM/')
->getMusicInfo()
->toArray());
// 获取分享信息
dump(WatermarkService::instance()->url('https://v.douyin.com/vPGAdM/')
->getShareInfo()
->toArray());
// 获取作者信息
dump(WatermarkService::instance()->url('https://v.douyin.com/vPGAdM/')
->getAuthorInfo()
->toArray());
// 返回数组数据方法
dump(WatermarkService::instance()->url('https://v.douyin.com/vPGAdM/')
->getAll()
->toArray());
// 返回Object数据方法
dump(WatermarkService::instance()->url('https://v.douyin.com/vPGAdM/')
->getAll()
->toObject());
} catch (DtaException $e) {
// 错误提示
dump($e->getMessage());
}
```
## 纯真数据库
```php
use DtApp\ThinkLibrary\service\QqWryService;
// 获取IP信息
dump(QqWryService::instance()
->getLocation());
```

@ -1,72 +1,72 @@
{
"name": "dtapps/think-library",
"description": "ThinkPhP扩展包",
"keywords": [
"dtapps",
"think-library",
"think",
"thinkphp",
"library"
],
"time": "2020-04-13",
"type": "library",
"license": "MIT",
"authors": [
{
"name": "Chaim",
"email": "li.gc@icoud.com",
"homepage": "https://api.dtapp.net"
}
],
"homepage": "https://www.dtapp.net",
"require": {
"php": ">=7.1",
"ext-gd": "*",
"ext-libxml": "*",
"ext-json": "*",
"ext-simplexml": "*",
"ext-zip": "*",
"ext-openssl": "*",
"ext-iconv": "*",
"ext-curl": "*",
"ext-dom": "*",
"topthink/framework": "^6.0.0",
"topthink/think-orm": "^2.0",
"aliyuncs/oss-sdk-php": "^2.3",
"obs/esdk-obs-php": "^3.19",
"baidubce/bce-sdk-php": "^0.8.22",
"qcloud/cos-sdk-v5": "^2.0",
"qiniu/php-sdk": "^7.2",
"upyun/sdk": "^3.4",
"phpoffice/phpspreadsheet": "1.17.1",
"alibabacloud/dysmsapi-20170525": "^1.0"
},
"require-dev": {
"symfony/var-dumper": "^4.2"
},
"autoload": {
"files": [
"src/common.php",
"src/service/taobao/bin/TopSdk.php"
],
"psr-4": {
"DtApp\\ThinkLibrary\\": "src"
}
},
"extra": {
"think": {
"services": [
"DtApp\\ThinkLibrary\\Library"
],
"config": {
"dtapp": "src/config.php"
}
}
},
"repositories": {
"packagist": {
"type": "composer",
"url": "https://mirrors.aliyun.com/composer/"
}
}
}
{
"name": "dtapps/think-library",
"description": "ThinkPhP扩展包",
"keywords": [
"dtapps",
"think-library",
"think",
"thinkphp",
"library"
],
"time": "2020-04-13",
"type": "library",
"license": "MIT",
"authors": [
{
"name": "Chaim",
"email": "li.gc@icoud.com",
"homepage": "https://api.dtapp.net"
}
],
"homepage": "https://www.dtapp.net",
"require": {
"php": ">=7.1",
"ext-gd": "*",
"ext-libxml": "*",
"ext-json": "*",
"ext-simplexml": "*",
"ext-zip": "*",
"ext-openssl": "*",
"ext-iconv": "*",
"ext-curl": "*",
"ext-dom": "*",
"topthink/framework": "^6.0.0",
"topthink/think-orm": "^2.0",
"aliyuncs/oss-sdk-php": "^2.3",
"obs/esdk-obs-php": "^3.19",
"baidubce/bce-sdk-php": "^0.8.22",
"qcloud/cos-sdk-v5": "^2.0",
"qiniu/php-sdk": "^7.2",
"upyun/sdk": "^3.4",
"phpoffice/phpspreadsheet": "1.17.1",
"alibabacloud/dysmsapi-20170525": "^1.0"
},
"require-dev": {
"symfony/var-dumper": "^4.2"
},
"autoload": {
"files": [
"src/common.php",
"src/service/taobao/bin/TopSdk.php"
],
"psr-4": {
"DtApp\\ThinkLibrary\\": "src"
}
},
"extra": {
"think": {
"services": [
"DtApp\\ThinkLibrary\\Library"
],
"config": {
"dtapp": "src/config.php"
}
}
},
"repositories": {
"packagist": {
"type": "composer",
"url": "https://mirrors.aliyun.com/composer/"
}
}
}

3168
composer.lock generated

File diff suppressed because it is too large Load Diff

@ -1,256 +1,256 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary;
use DtApp\ThinkLibrary\helper\ValidateHelper;
use stdClass;
use think\App;
use think\exception\HttpResponseException;
use think\Request;
/**
* 标准Api控制器基类
* Class ApiController
* @package DtApp\ThinkLibrary
*/
abstract class ApiController extends stdClass
{
/**
* 应用容器
* @var App
*/
public $app;
/**
* 请求对象
* @var Request
*/
public $request;
/**
* 解密后数据
* @var
*/
private $aes_decrypt_data;
/**
* 加密相关的东西
* @var string
*/
private $aes_md5, $aes_md5_iv = '';
/**
* ApiController constructor.
* @param App $app
*/
public function __construct(App $app)
{
$this->app = $app;
$this->request = $app->request;
$this->app->bind('DtApp\ThinkLibrary\ApiController', $this);
if (in_array($this->request->action(), get_class_methods(__CLASS__))) {
$this->error('Access without permission.');
}
$this->initialize();
}
/**
* 控制器初始化
*/
protected function initialize()
{
}
/**
* 返回失败的操作
* @param mixed $msg 消息内容
* @param mixed $data 返回数据
* @param integer $code 返回代码
*/
public function error($msg = 'error', $code = 1, $data = []): void
{
throw new HttpResponseException(json([
'code' => $code,
'msg' => $msg,
'timestamp' => time(),
'data' => $data,
]));
}
/**
* 返回成功的操作
* @param mixed $msg 消息内容
* @param mixed $data 返回数据
* @param integer $code 返回代码
*/
public function success($data = [], $msg = 'success', $code = 0): void
{
throw new HttpResponseException(json([
'code' => $code,
'msg' => $msg,
'timestamp' => time(),
'data' => $data,
]));
}
/**
* key
* @param string $name 参数名
* @return $this
*/
public function setAesMd5($name = 'sniff_h5'): self
{
$value = config("dtapp.md5.{$name}");
$this->aes_md5 = $value;
return $this;
}
/**
* iv
* @return $this
*/
private function setAesMd5Iv(): self
{
$value = config("dtapp.md5.bcw");
$this->aes_md5_iv = $value;
return $this;
}
/**
* 返回成功的操作
* @param mixed $data 返回数据
* @param mixed $msg 消息内容
* @param integer $code 返回代码
*/
public function aesSuccess($data = [], $msg = 'success', $code = 0)
{
$timestamp = time();
throw new HttpResponseException(json([
'code' => $code,
'msg' => $msg,
'timestamp' => $timestamp,
'data' => [
'aes' => $this->encrypt($data, $timestamp)
],
]));
}
/**
* URL重定向
* @param string $url 跳转链接
* @param integer $code 跳转代码
*/
public function redirect($url, $code = 301): void
{
throw new HttpResponseException(redirect($url, $code));
}
/**
* @param array $rules
* @param string $type
* @return mixed
*/
protected function _vali(array $rules, $type = '')
{
return ValidateHelper::instance()
->init($rules, $type);
}
/**
* 获取解密后的数据
* @param string $name
* @param null $default
* @return mixed
*/
public function getAesDecryptData(string $name = '', $default = null)
{
if (empty($name)) {
return $this->aes_decrypt_data;
}
return $this->aes_decrypt_data[$name] ?? $default;
}
/**
* 验证接口签名
*/
public function _judgeSign()
{
// 加密的数据参数
$aes = $this->request->post('aes', '');
if (empty($aes)) {
$this->error('数据未签名!', 104);
}
// 获取时间数据
$timestamp = $this->request->get('timestamp', 0);
// 判断是否有时间
if (empty($timestamp)) {
$this->error('数据异常!', 105);
}
// 解密
$aes_decode = $this->decrypt($aes, $timestamp);
if (empty($aes_decode)) {
$this->error('解密失败', 106);
}
$data = json_decode($aes_decode, true);
// 判断是不是小于服务器时间
$before = strtotime('-2minute');
$rear = strtotime('+2minute');
if ($timestamp <= $rear && $timestamp >= $before) {
$this->aes_decrypt_data = $data;
} else {
$this->error('已超时,请重新尝试!');
}
}
/**
* 加密
* @param $data
* @param int $timestamp
* @return bool|string
*/
private function encrypt($data, int $timestamp)
{
if (empty($this->aes_md5)) {
$this->setAesMd5();
}
if (empty($this->aes_md5_iv)) {
$this->setAesMd5Iv();
}
if (!empty(is_array($data))) {
$data = json_encode($data);
}
return urlencode(base64_encode(openssl_encrypt($data, 'AES-128-CBC', $this->aes_md5, 1, $this->aes_md5_iv . $timestamp)));
}
/**
* 解密
* @param string $data
* @param int $timestamp
* @return bool|false|string
*/
private function decrypt(string $data, int $timestamp)
{
if (empty($this->aes_md5)) {
$this->setAesMd5();
}
if (empty($this->aes_md5_iv)) {
$this->setAesMd5Iv();
}
return openssl_decrypt(base64_decode(urldecode($data)), "AES-128-CBC", $this->aes_md5, true, $this->aes_md5_iv . $timestamp);
}
}
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary;
use DtApp\ThinkLibrary\helper\ValidateHelper;
use stdClass;
use think\App;
use think\exception\HttpResponseException;
use think\Request;
/**
* 标准Api控制器基类
* Class ApiController
* @package DtApp\ThinkLibrary
*/
abstract class ApiController extends stdClass
{
/**
* 应用容器
* @var App
*/
public $app;
/**
* 请求对象
* @var Request
*/
public $request;
/**
* 解密后数据
* @var
*/
private $aes_decrypt_data;
/**
* 加密相关的东西
* @var string
*/
private $aes_md5, $aes_md5_iv = '';
/**
* ApiController constructor.
* @param App $app
*/
public function __construct(App $app)
{
$this->app = $app;
$this->request = $app->request;
$this->app->bind('DtApp\ThinkLibrary\ApiController', $this);
if (in_array($this->request->action(), get_class_methods(__CLASS__))) {
$this->error('Access without permission.');
}
$this->initialize();
}
/**
* 控制器初始化
*/
protected function initialize()
{
}
/**
* 返回失败的操作
* @param mixed $msg 消息内容
* @param mixed $data 返回数据
* @param integer $code 返回代码
*/
public function error($msg = 'error', $code = 1, $data = []): void
{
throw new HttpResponseException(json([
'code' => $code,
'msg' => $msg,
'timestamp' => time(),
'data' => $data,
]));
}
/**
* 返回成功的操作
* @param mixed $msg 消息内容
* @param mixed $data 返回数据
* @param integer $code 返回代码
*/
public function success($data = [], $msg = 'success', $code = 0): void
{
throw new HttpResponseException(json([
'code' => $code,
'msg' => $msg,
'timestamp' => time(),
'data' => $data,
]));
}
/**
* key
* @param string $name 参数名
* @return $this
*/
public function setAesMd5($name = 'sniff_h5'): self
{
$value = config("dtapp.md5.{$name}");
$this->aes_md5 = $value;
return $this;
}
/**
* iv
* @return $this
*/
private function setAesMd5Iv(): self
{
$value = config("dtapp.md5.bcw");
$this->aes_md5_iv = $value;
return $this;
}
/**
* 返回成功的操作
* @param mixed $data 返回数据
* @param mixed $msg 消息内容
* @param integer $code 返回代码
*/
public function aesSuccess($data = [], $msg = 'success', $code = 0)
{
$timestamp = time();
throw new HttpResponseException(json([
'code' => $code,
'msg' => $msg,
'timestamp' => $timestamp,
'data' => [
'aes' => $this->encrypt($data, $timestamp)
],
]));
}
/**
* URL重定向
* @param string $url 跳转链接
* @param integer $code 跳转代码
*/
public function redirect($url, $code = 301): void
{
throw new HttpResponseException(redirect($url, $code));
}
/**
* @param array $rules
* @param string $type
* @return mixed
*/
protected function _vali(array $rules, $type = '')
{
return ValidateHelper::instance()
->init($rules, $type);
}
/**
* 获取解密后的数据
* @param string $name
* @param null $default
* @return mixed
*/
public function getAesDecryptData(string $name = '', $default = null)
{
if (empty($name)) {
return $this->aes_decrypt_data;
}
return $this->aes_decrypt_data[$name] ?? $default;
}
/**
* 验证接口签名
*/
public function _judgeSign()
{
// 加密的数据参数
$aes = $this->request->post('aes', '');
if (empty($aes)) {
$this->error('数据未签名!', 104);
}
// 获取时间数据
$timestamp = $this->request->get('timestamp', 0);
// 判断是否有时间
if (empty($timestamp)) {
$this->error('数据异常!', 105);
}
// 解密
$aes_decode = $this->decrypt($aes, $timestamp);
if (empty($aes_decode)) {
$this->error('解密失败', 106);
}
$data = json_decode($aes_decode, true);
// 判断是不是小于服务器时间
$before = strtotime('-2minute');
$rear = strtotime('+2minute');
if ($timestamp <= $rear && $timestamp >= $before) {
$this->aes_decrypt_data = $data;
} else {
$this->error('已超时,请重新尝试!');
}
}
/**
* 加密
* @param $data
* @param int $timestamp
* @return bool|string
*/
private function encrypt($data, int $timestamp)
{
if (empty($this->aes_md5)) {
$this->setAesMd5();
}
if (empty($this->aes_md5_iv)) {
$this->setAesMd5Iv();
}
if (!empty(is_array($data))) {
$data = json_encode($data);
}
return urlencode(base64_encode(openssl_encrypt($data, 'AES-128-CBC', $this->aes_md5, 1, $this->aes_md5_iv . $timestamp)));
}
/**
* 解密
* @param string $data
* @param int $timestamp
* @return bool|false|string
*/
private function decrypt(string $data, int $timestamp)
{
if (empty($this->aes_md5)) {
$this->setAesMd5();
}
if (empty($this->aes_md5_iv)) {
$this->setAesMd5Iv();
}
return openssl_decrypt(base64_decode(urldecode($data)), "AES-128-CBC", $this->aes_md5, true, $this->aes_md5_iv . $timestamp);
}
}

@ -1,159 +1,159 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary;
use stdClass;
use think\App;
use think\exception\HttpResponseException;
use think\Request;
/**
* 标准控制器基类
* Class Controller
* @package DtApp\ThinkLibrary
*/
abstract class Controller extends stdClass
{
/**
* 应用容器
* @var App
*/
public $app;
/**
* 请求对象
* @var Request
*/
public $request;
/**
* Controller constructor.
* @param App $app
*/
public function __construct(App $app)
{
$this->app = $app;
$this->request = $app->request;
$this->app->bind('DtApp\ThinkLibrary\Controller', $this);
if (in_array($this->request->action(), get_class_methods(__CLASS__))) {
$this->error('Access without permission.');
}
$this->initialize();
}
/**
* 控制器初始化
*/
protected function initialize()
{
}
/**
* 返回失败的操作
* @param mixed $info 消息内容
* @param mixed $data 返回数据
* @param integer $code 返回代码
*/
public function error($info, $data = '{-null-}', $code = 0): void
{
if ($data === '{-null-}') {
$data = new stdClass();
}
throw new HttpResponseException(json([
'code' => $code, 'info' => $info, 'data' => $data,
]));
}
/**
* 返回成功的操作
* @param mixed $info 消息内容
* @param mixed $data 返回数据
* @param integer $code 返回代码
*/
public function success($info, $data = '{-null-}', $code = 1): void
{
if ($data === '{-null-}') {
$data = new stdClass();
}
throw new HttpResponseException(json([
'code' => $code, 'info' => $info, 'data' => $data,
]));
}
/**
* URL重定向
* @param string $url 跳转链接
* @param integer $code 跳转代码
*/
public function redirect($url, $code = 301): void
{
throw new HttpResponseException(redirect($url, $code));
}
/**
* 返回视图内容
* @param string $tpl 模板名称
* @param array $vars 模板变量
*/
public function fetch($tpl = '', $vars = []): void
{
foreach ($this as $name => $value) {
$vars[$name] = $value;
}
throw new HttpResponseException(view($tpl, $vars));
}
/**
* 模板变量赋值
* @param mixed $name 要显示的模板变量
* @param mixed $value 变量的值
* @return $this
*/
public function assign($name, $value = ''): self
{
if (is_string($name)) {
$this->$name = $value;
} elseif (is_array($name)) {
foreach ($name as $k => $v) {
if (is_string($k)) {
$this->$k = $v;
}
}
}
return $this;
}
/**
* 数据回调处理机制
* @param string $name 回调方法名称
* @param mixed $one 回调引用参数1
* @param mixed $two 回调引用参数2
* @return boolean
*/
public function callback($name, &$one = [], &$two = []): bool
{
if (is_callable($name)) {
return $name($this, $one, $two);
}
foreach ([$name, "_{$this->app->request->action()}{$name}"] as $method) {
if (method_exists($this, $method) && false === $this->$method($one, $two)) {
return false;
}
}
return true;
}
}
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary;
use stdClass;
use think\App;
use think\exception\HttpResponseException;
use think\Request;
/**
* 标准控制器基类
* Class Controller
* @package DtApp\ThinkLibrary
*/
abstract class Controller extends stdClass
{
/**
* 应用容器
* @var App
*/
public $app;
/**
* 请求对象
* @var Request
*/
public $request;
/**
* Controller constructor.
* @param App $app
*/
public function __construct(App $app)
{
$this->app = $app;
$this->request = $app->request;
$this->app->bind('DtApp\ThinkLibrary\Controller', $this);
if (in_array($this->request->action(), get_class_methods(__CLASS__))) {
$this->error('Access without permission.');
}
$this->initialize();
}
/**
* 控制器初始化
*/
protected function initialize()
{
}
/**
* 返回失败的操作
* @param mixed $info 消息内容
* @param mixed $data 返回数据
* @param integer $code 返回代码
*/
public function error($info, $data = '{-null-}', $code = 0): void
{
if ($data === '{-null-}') {
$data = new stdClass();
}
throw new HttpResponseException(json([
'code' => $code, 'info' => $info, 'data' => $data,
]));
}
/**
* 返回成功的操作
* @param mixed $info 消息内容
* @param mixed $data 返回数据
* @param integer $code 返回代码
*/
public function success($info, $data = '{-null-}', $code = 1): void
{
if ($data === '{-null-}') {
$data = new stdClass();
}
throw new HttpResponseException(json([
'code' => $code, 'info' => $info, 'data' => $data,
]));
}
/**
* URL重定向
* @param string $url 跳转链接
* @param integer $code 跳转代码
*/
public function redirect($url, $code = 301): void
{
throw new HttpResponseException(redirect($url, $code));
}
/**
* 返回视图内容
* @param string $tpl 模板名称
* @param array $vars 模板变量
*/
public function fetch($tpl = '', $vars = []): void
{
foreach ($this as $name => $value) {
$vars[$name] = $value;
}
throw new HttpResponseException(view($tpl, $vars));
}
/**
* 模板变量赋值
* @param mixed $name 要显示的模板变量
* @param mixed $value 变量的值
* @return $this
*/
public function assign($name, $value = ''): self
{
if (is_string($name)) {
$this->$name = $value;
} elseif (is_array($name)) {
foreach ($name as $k => $v) {
if (is_string($k)) {
$this->$k = $v;
}
}
}
return $this;
}
/**
* 数据回调处理机制
* @param string $name 回调方法名称
* @param mixed $one 回调引用参数1
* @param mixed $two 回调引用参数2
* @return boolean
*/
public function callback($name, &$one = [], &$two = []): bool
{
if (is_callable($name)) {
return $name($this, $one, $two);
}
foreach ([$name, "_{$this->app->request->action()}{$name}"] as $method) {
if (method_exists($this, $method) && false === $this->$method($one, $two)) {
return false;
}
}
return true;
}
}

@ -1,80 +1,80 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace DtApp\ThinkLibrary;
use think\App;
use think\Container;
use think\Db;
/**
* 控制器挂件
* Class Helper
* @package DtApp\ThinkLibrary
*/
abstract class Helper
{
/**
* 应用容器
* @var App
*/
public $app;
/**
* 数据库实例
* @var
*/
public $query;
/**
* 控制器实例
* @var Controller
*/
public $class;
/**
* Helper constructor.
* @param Controller $class
* @param App $app
*/
public function __construct(Controller $class, App $app)
{
$this->app = $app;
$this->class = $class;
}
/**
* 获取数据库对象
* @param $dbQuery
* @return Db
*/
protected function buildQuery($dbQuery)
{
return is_string($dbQuery) ? $this->app->db->name($dbQuery) : $dbQuery;
}
/**
* 实例对象反射
* @param mixed ...$args
* @return Helper
*/
public static function instance(...$args): Helper
{
return Container::getInstance()->invokeClass(static::class, $args);
}
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace DtApp\ThinkLibrary;
use think\App;
use think\Container;
use think\Db;
/**
* 控制器挂件
* Class Helper
* @package DtApp\ThinkLibrary
*/
abstract class Helper
{
/**
* 应用容器
* @var App
*/
public $app;
/**
* 数据库实例
* @var
*/
public $query;
/**
* 控制器实例
* @var Controller
*/
public $class;
/**
* Helper constructor.
* @param Controller $class
* @param App $app
*/
public function __construct(Controller $class, App $app)
{
$this->app = $app;
$this->class = $class;
}
/**
* 获取数据库对象
* @param $dbQuery
* @return Db
*/
protected function buildQuery($dbQuery)
{
return is_string($dbQuery) ? $this->app->db->name($dbQuery) : $dbQuery;
}
/**
* 实例对象反射
* @param mixed ...$args
* @return Helper
*/
public static function instance(...$args): Helper
{
return Container::getInstance()->invokeClass(static::class, $args);
}
}

@ -1,69 +1,69 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary;
use think\admin\service\AdminService;
use think\Request;
use think\Service;
/**
* 模块注册服务
* Class Library
* @package DtApp\ThinkLibrary
*/
class Library extends Service
{
/**
* 定义当前版本
*/
const VERSION = '6.0.131';
/**
* 启动服务
*/
public function boot()
{
}
/**
* 初始化服务
*/
public function register()
{
// 输入默认过滤
$this->app->request->filter(['trim']);
// 判断访问模式,兼容 CLI 访问控制器
if (!$this->app->request->isCli()) {
// 注册访问处理中间键
$this->app->middleware->add(function (Request $request) {
$header = [];
if (($origin = $request->header('origin', '*')) !== '*') {
$header['Access-Control-Allow-Origin'] = $origin;
$header['Access-Control-Allow-Methods'] = 'GET,PUT,POST,PATCH,DELETE';
$header['Access-Control-Allow-Headers'] = 'Authorization,Content-Type,If-Match,If-Modified-Since,If-None-Match,If-Unmodified-Since,X-Requested-With,User-Form-Token,User-Token,Token';
$header['Access-Control-Expose-Headers'] = 'User-Form-Token,User-Token,Token';
$header['Access-Control-Allow-Credentials'] = 'true';
}
// 访问模式及访问权限检查
if ($request->isOptions()) {
return response()->code(204)->header($header);
}
}, 'route');
}
}
}
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary;
use think\admin\service\AdminService;
use think\Request;
use think\Service;
/**
* 模块注册服务
* Class Library
* @package DtApp\ThinkLibrary
*/
class Library extends Service
{
/**
* 定义当前版本
*/
const VERSION = '6.0.131';
/**
* 启动服务
*/
public function boot()
{
}
/**
* 初始化服务
*/
public function register()
{
// 输入默认过滤
$this->app->request->filter(['trim']);
// 判断访问模式,兼容 CLI 访问控制器
if (!$this->app->request->isCli()) {
// 注册访问处理中间键
$this->app->middleware->add(function (Request $request) {
$header = [];
if (($origin = $request->header('origin', '*')) !== '*') {
$header['Access-Control-Allow-Origin'] = $origin;
$header['Access-Control-Allow-Methods'] = 'GET,PUT,POST,PATCH,DELETE';
$header['Access-Control-Allow-Headers'] = 'Authorization,Content-Type,If-Match,If-Modified-Since,If-None-Match,If-Unmodified-Since,X-Requested-With,User-Form-Token,User-Token,Token';
$header['Access-Control-Expose-Headers'] = 'User-Form-Token,User-Token,Token';
$header['Access-Control-Allow-Credentials'] = 'true';
}
// 访问模式及访问权限检查
if ($request->isOptions()) {
return response()->code(204)->header($header);
}
}, 'route');
}
}
}

@ -1,64 +1,64 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary;
use think\App;
use think\Container;
/**
* 自定义服务基类
* Class Service
* @package DtApp\ThinkLibrary
*/
abstract class Service
{
/**
* 应用实例
* @var App
*/
protected $app;
/**
* Service constructor.
* @param App $app
*/
public function __construct(App $app)
{
$this->app = $app;
$this->initialize();
}
/**
* 初始化服务
* @return $this
*/
protected function initialize(): Service
{
return $this;
}
/**
* 静态实例对象
* @param array $args
* @return static
*/
public static function instance(...$args): Service
{
return Container::getInstance()
->make(static::class, $args);
}
}
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary;
use think\App;
use think\Container;
/**
* 自定义服务基类
* Class Service
* @package DtApp\ThinkLibrary
*/
abstract class Service
{
/**
* 应用实例
* @var App
*/
protected $app;
/**
* Service constructor.
* @param App $app
*/
public function __construct(App $app)
{
$this->app = $app;
$this->initialize();
}
/**
* 初始化服务
* @return $this
*/
protected function initialize(): Service
{
return $this;
}
/**
* 静态实例对象
* @param array $args
* @return static
*/
public static function instance(...$args): Service
{
return Container::getInstance()
->make(static::class, $args);
}
}

334
src/cache/Mysql.php vendored

@ -1,167 +1,167 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary\cache;
use DtApp\ThinkLibrary\exception\DtaException;
use DtApp\ThinkLibrary\facade\Times;
use think\facade\Db;
/**
* 缓存数据库驱动
* Class Mysql
* @package DtApp\ThinkLibrary\cache
*/
class Mysql
{
private $table = "think_cache";
private $cache_name, $cache_expire = 0;
/**
* 名称
* @param string $cache_name
* @return $this
*/
public function name(string $cache_name): self
{
$this->cache_name = $cache_name;
return $this;
}
/**
* 过期时间
* @param int $cache_expire
* @return $this
*/
public function expire(int $cache_expire): self
{
$this->cache_expire = $cache_expire;
return $this;
}
/**
* 设置
* @param $cache_value
* @return bool
* @throws DtaException
*/
public function set($cache_value): bool
{
$this->judge();
$result = Db::table($this->table)
->insert([
'cache_name' => $this->cache_name,
'cache_value' => $cache_value,
'cache_expire' => Times::dateRear("Y-m-d H:i:s", $this->cache_expire)
]);
return $result ? true : false;
}
/**
* 获取
* @return mixed
* @throws DtaException
*/
public function get()
{
$this->judge();
return Db::table($this->table)
->where('cache_name', $this->cache_name)
->whereTime('cache_expire', '>=', time())
->order('cache_expire desc')
->value('cache_value', '');
}
/**
* 删除
* @return bool
* @throws DtaException
* @throws \think\db\exception\DbException
*/
public function delete(): bool
{
$this->judge();
$result = Db::table($this->table)
->where('cache_name', $this->cache_name)
->delete();
return $result ? true : false;
}
/**
* 更新
* @param $cache_value
* @return bool
* @throws DtaException
* @throws \think\db\exception\DbException
*/
public function update($cache_value): bool
{
$this->judge();
$result = Db::table($this->table)
->where('cache_name', $this->cache_name)
->update([
'cache_value' => $cache_value,
'cache_expire' => Times::dateRear("Y-m-d H:i:s", $this->cache_expire)
]);
return $result ? true : false;
}
/**
* 自增
* @param int $int
* @return bool
* @throws DtaException
* @throws \think\db\exception\DbException
*/
public function inc(int $int = 1): bool
{
$cache_value = (int)$this->get();
$result = Db::table($this->table)
->where('cache_name', $this->cache_name)
->update([
'cache_value' => $cache_value + $int
]);
return $result ? true : false;
}
/**
* 自减
* @param int $int
* @return bool
* @throws DtaException
* @throws \think\db\exception\DbException
*/
public function dec(int $int = 1): bool
{
$cache_value = (int)$this->get();
$result = Db::table($this->table)
->where('cache_name', $this->cache_name)
->update([
'cache_value' => $cache_value - $int
]);
return $result ? true : false;
}
/**
* @throws DtaException
*/
private function judge(): void
{
if (empty($this->cache_name)) {
throw new DtaException("名称未配置");
}
}
}
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary\cache;
use DtApp\ThinkLibrary\exception\DtaException;
use DtApp\ThinkLibrary\facade\Times;
use think\facade\Db;
/**
* 缓存数据库驱动
* Class Mysql
* @package DtApp\ThinkLibrary\cache
*/
class Mysql
{
private $table = "think_cache";
private $cache_name, $cache_expire = 0;
/**
* 名称
* @param string $cache_name
* @return $this
*/
public function name(string $cache_name): self
{
$this->cache_name = $cache_name;
return $this;
}
/**
* 过期时间
* @param int $cache_expire
* @return $this
*/
public function expire(int $cache_expire): self
{
$this->cache_expire = $cache_expire;
return $this;
}
/**
* 设置
* @param $cache_value
* @return bool
* @throws DtaException
*/
public function set($cache_value): bool
{
$this->judge();
$result = Db::table($this->table)
->insert([
'cache_name' => $this->cache_name,
'cache_value' => $cache_value,
'cache_expire' => Times::dateRear("Y-m-d H:i:s", $this->cache_expire)
]);
return $result ? true : false;
}
/**
* 获取
* @return mixed
* @throws DtaException
*/
public function get()
{
$this->judge();
return Db::table($this->table)
->where('cache_name', $this->cache_name)
->whereTime('cache_expire', '>=', time())
->order('cache_expire desc')
->value('cache_value', '');
}
/**
* 删除
* @return bool
* @throws DtaException
* @throws \think\db\exception\DbException
*/
public function delete(): bool
{
$this->judge();
$result = Db::table($this->table)
->where('cache_name', $this->cache_name)
->delete();
return $result ? true : false;
}
/**
* 更新
* @param $cache_value
* @return bool
* @throws DtaException
* @throws \think\db\exception\DbException
*/
public function update($cache_value): bool
{
$this->judge();
$result = Db::table($this->table)
->where('cache_name', $this->cache_name)
->update([
'cache_value' => $cache_value,
'cache_expire' => Times::dateRear("Y-m-d H:i:s", $this->cache_expire)
]);
return $result ? true : false;
}
/**
* 自增
* @param int $int
* @return bool
* @throws DtaException
* @throws \think\db\exception\DbException
*/
public function inc(int $int = 1): bool
{
$cache_value = (int)$this->get();
$result = Db::table($this->table)
->where('cache_name', $this->cache_name)
->update([
'cache_value' => $cache_value + $int
]);
return $result ? true : false;
}
/**
* 自减
* @param int $int
* @return bool
* @throws DtaException
* @throws \think\db\exception\DbException
*/
public function dec(int $int = 1): bool
{
$cache_value = (int)$this->get();
$result = Db::table($this->table)
->where('cache_name', $this->cache_name)
->update([
'cache_value' => $cache_value - $int
]);
return $result ? true : false;
}
/**
* @throws DtaException
*/
private function judge(): void
{
if (empty($this->cache_name)) {
throw new DtaException("名称未配置");
}
}
}

@ -1,48 +1,48 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary\command;
use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\Output;
class Install extends Command
{
/**
* 名称
* @var string
*/
protected $name;
protected function configure()
{
$this->setName('dta:install');
$this->setDescription("Install or update dtapp");
$this->addArgument('name', Argument::OPTIONAL, 'Name', '');
}
protected function execute(Input $input, Output $output)
{
$this->name = trim($input->getArgument('name'));
if (empty($this->name)) {
$this->output->writeln('name of online installation cannot be empty');
} else {
$this->output->writeln("The specified module {$this->name} is not configured with installation rules");
}
}
}
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary\command;
use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\Output;
class Install extends Command
{
/**
* 名称
* @var string
*/
protected $name;
protected function configure()
{
$this->setName('dta:install');
$this->setDescription("Install or update dtapp");
$this->addArgument('name', Argument::OPTIONAL, 'Name', '');
}
protected function execute(Input $input, Output $output)
{
$this->name = trim($input->getArgument('name'));
if (empty($this->name)) {
$this->output->writeln('name of online installation cannot be empty');
} else {
$this->output->writeln("The specified module {$this->name} is not configured with installation rules");
}
}
}

@ -1,36 +1,36 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary\command;
use think\App;
use think\console\Command;
use think\console\Input;
use think\console\Output;
class Version extends Command
{
protected function configure()
{
$this->setName('dta:version');
$this->setDescription("Query ThinkPHP framework version");
}
protected function execute(Input $input, Output $output)
{
$output->writeln('ThinkPHP ' . App::VERSION);
}
}
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary\command;
use think\App;
use think\console\Command;
use think\console\Input;
use think\console\Output;
class Version extends Command
{
protected function configure()
{
$this->setName('dta:version');
$this->setDescription("Query ThinkPHP framework version");
}
protected function execute(Input $input, Output $output)
{
$output->writeln('ThinkPHP ' . App::VERSION);
}
}

@ -1,108 +1,108 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
use DtApp\ThinkLibrary\cache\Mysql;
use DtApp\ThinkLibrary\exception\DtaException;
use DtApp\ThinkLibrary\service\QqWryService;
use DtApp\ThinkLibrary\service\SystemService;
if (!function_exists('get_ip_info')) {
/**
* 获取请求IP信息
* @param string $ip
* @return mixed|null
* @throws DtaException
*/
function get_ip_info($ip = '')
{
if (empty($ip)) {
if (!isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['REMOTE_ADDR'];
} else {
//为了兼容百度的CDN所以转成数组
$arr = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
$ip = $arr[0];
}
}
return QqWryService::instance()->getLocation($ip);
}
}
if (!function_exists('get_ip')) {
/**
* 获取请求IP
* @return string
*/
function get_ip()
{
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
//为了兼容百度的CDN所以转成数组
$arr = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
return $arr[0];
}
return $_SERVER['REMOTE_ADDR'];
}
}
if (!function_exists('uri')) {
/**
* 生成最短 URL 地址
* @param string $url 路由地址
* @param array $vars PATH 变量
* @param boolean|string $suffix 后缀
* @param boolean|string $domain 域名
* @param boolean|string $fillSuffix 补上后缀
* @return string
*/
function uri($url = '', array $vars = [], $suffix = true, $domain = false, $fillSuffix = false)
{
return SystemService::instance()->uri($url, $vars, $suffix, $domain, $fillSuffix);
}
}
if (!function_exists('dtacache')) {
/**
* 缓存
* @param string $name
* @param array $value
* @param int $expire
* @return bool|int|string
* @throws DtaException
* @throws \think\db\exception\DbException
*/
function dtacache($name = '', $value = [], $expire = 6000)
{
$myc = new Mysql();
if (empty($value)) {
return $myc->name($name)
->get();
}
$judge = $myc->name($name)
->get();
if (empty($judge)) {
$myc->name($name)
->expire($expire)
->set($value);
} else {
$myc->name($name)
->expire($expire)
->update($value);
}
return $myc->name($name)
->get();
}
}
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
use DtApp\ThinkLibrary\cache\Mysql;
use DtApp\ThinkLibrary\exception\DtaException;
use DtApp\ThinkLibrary\service\QqWryService;
use DtApp\ThinkLibrary\service\SystemService;
if (!function_exists('get_ip_info')) {
/**
* 获取请求IP信息
* @param string $ip
* @return mixed|null
* @throws DtaException
*/
function get_ip_info($ip = '')
{
if (empty($ip)) {
if (!isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['REMOTE_ADDR'];
} else {
//为了兼容百度的CDN所以转成数组
$arr = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
$ip = $arr[0];
}
}
return QqWryService::instance()->getLocation($ip);
}
}
if (!function_exists('get_ip')) {
/**
* 获取请求IP
* @return string
*/
function get_ip()
{
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
//为了兼容百度的CDN所以转成数组
$arr = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
return $arr[0];
}
return $_SERVER['REMOTE_ADDR'];
}
}
if (!function_exists('uri')) {
/**
* 生成最短 URL 地址
* @param string $url 路由地址
* @param array $vars PATH 变量
* @param boolean|string $suffix 后缀
* @param boolean|string $domain 域名
* @param boolean|string $fillSuffix 补上后缀
* @return string
*/
function uri($url = '', array $vars = [], $suffix = true, $domain = false, $fillSuffix = false)
{
return SystemService::instance()->uri($url, $vars, $suffix, $domain, $fillSuffix);
}
}
if (!function_exists('dtacache')) {
/**
* 缓存
* @param string $name
* @param array $value
* @param int $expire
* @return bool|int|string
* @throws DtaException
* @throws \think\db\exception\DbException
*/
function dtacache($name = '', $value = [], $expire = 6000)
{
$myc = new Mysql();
if (empty($value)) {
return $myc->name($name)
->get();
}
$judge = $myc->name($name)
->get();
if (empty($judge)) {
$myc->name($name)
->expire($expire)
->set($value);
} else {
$myc->name($name)
->expire($expire)
->update($value);
}
return $myc->name($name)
->get();
}
}

@ -1,183 +1,183 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
return [
// 淘宝
'taobao' => [
// 淘宝客
'tbk' => [
'app_key' => '',
'app_secret' => '',
]
],
// 拼多多
'pinduoduo' => [
// 进宝
'jinbao' => [
// 开放平台分配的clientId
'client_id' => '',
// 开放平台分配的clientSecret
'client_secret' => '',
]
],
// 京东
'jd' => [
// 京东联盟
'union' => [
// 联盟分配给应用的appkey
'app_key' => '',
// 联盟分配给应用的secretkey
'secret_key' => '',
]
],
// 宝塔
'bt' => [
// 密钥
'key' => '',
// 网址
'panel' => '',
],
// 百度
'baidu' => [
// 地图
'lbs' => [
'ak' => ''
],
// 百度云
'bos' => [
'access_key_id' => '',
'secret_access_key' => '',
'endpoint' => '',
'bucket' => '',
'url' => '',
]
],
// 高德地图
'amap' => [
'key' => ''
],
// 微信
'wechat' => [
// 公众号
'webapp' => [
'cache' => 'file',
'app_id' => '',
'app_secret' => '',
],
// 小程序
'mini' => [
'cache' => 'file',
'app_key' => '',
'app_secret' => '',
],
// 企业微信
'qy' => [
]
],
// 错误通知
'exception' => [
'type' => 'dingtalk',
// 钉钉
'dingtalk' => [
'access_token' => ''
],
// 企业微信
'qyweixin' => [
'key' => ''
],
// 微信
'wechat' => [
// 通知微信
'openid' => '',
// 网站名称
'node' => '',
// 服务器IP节点
'ip' => ''
]
],
// 阿里云
'aliyun' => [
'oss' => [
'access_key_id' => '',
'access_key_secret' => '',
'endpoint' => '',
'bucket' => '',
'url' => '',
]
],
// 腾讯云
'tencent' => [
'cos' => [
'secret_id' => '',
'secret_key' => '',
'region' => '',
'bucket' => '',
'url' => '',
]
],
// 华为云
'huaweicloud' => [
'obs' => [
'key' => '',
'secret' => '',
'endpoint' => '',
'bucket' => '',
'url' => '',
]
],
// 本地存储
'storage' => [
'path' => '',
'domain_name' => '',
'domain_list' => []
],
// 又拍云
'upyun' => [
// 又拍云存储
'uss' => [
'service_name' => '',
'operator_name' => '',
'operator_password' => '',
'url' => '',
]
],
// 七牛云
'qiniu' => [
// 云存储
'kodo' => [
'access_key' => '',
'secret_key' => '',
'bucket' => '',
'url' => '',
]
],
// 金山云
'ksyun' => [
// 云存储
'ks3' => [
'access_key_iD' => '',
'access_key_secret' => '',
'endpoint' => '',
'bucket' => '',
'url' => '',
]
],
// 验证签名
'md5' => [
]
];
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
return [
// 淘宝
'taobao' => [
// 淘宝客
'tbk' => [
'app_key' => '',
'app_secret' => '',
]
],
// 拼多多
'pinduoduo' => [
// 进宝
'jinbao' => [
// 开放平台分配的clientId
'client_id' => '',
// 开放平台分配的clientSecret
'client_secret' => '',
]
],
// 京东
'jd' => [
// 京东联盟
'union' => [
// 联盟分配给应用的appkey
'app_key' => '',
// 联盟分配给应用的secretkey
'secret_key' => '',
]
],
// 宝塔
'bt' => [
// 密钥
'key' => '',
// 网址
'panel' => '',
],
// 百度
'baidu' => [
// 地图
'lbs' => [
'ak' => ''
],
// 百度云
'bos' => [
'access_key_id' => '',
'secret_access_key' => '',
'endpoint' => '',
'bucket' => '',
'url' => '',
]
],
// 高德地图
'amap' => [
'key' => ''
],
// 微信
'wechat' => [
// 公众号
'webapp' => [
'cache' => 'file',
'app_id' => '',
'app_secret' => '',
],
// 小程序
'mini' => [
'cache' => 'file',
'app_key' => '',
'app_secret' => '',
],
// 企业微信
'qy' => [
]
],
// 错误通知
'exception' => [
'type' => 'dingtalk',
// 钉钉
'dingtalk' => [
'access_token' => ''
],
// 企业微信
'qyweixin' => [
'key' => ''
],
// 微信
'wechat' => [
// 通知微信
'openid' => '',
// 网站名称
'node' => '',
// 服务器IP节点
'ip' => ''
]
],
// 阿里云
'aliyun' => [
'oss' => [
'access_key_id' => '',
'access_key_secret' => '',
'endpoint' => '',
'bucket' => '',
'url' => '',
]
],
// 腾讯云
'tencent' => [
'cos' => [
'secret_id' => '',
'secret_key' => '',
'region' => '',
'bucket' => '',
'url' => '',
]
],
// 华为云
'huaweicloud' => [
'obs' => [
'key' => '',
'secret' => '',
'endpoint' => '',
'bucket' => '',
'url' => '',
]
],
// 本地存储
'storage' => [
'path' => '',
'domain_name' => '',
'domain_list' => []
],
// 又拍云
'upyun' => [
// 又拍云存储
'uss' => [
'service_name' => '',
'operator_name' => '',
'operator_password' => '',
'url' => '',
]
],
// 七牛云
'qiniu' => [
// 云存储
'kodo' => [
'access_key' => '',
'secret_key' => '',
'bucket' => '',
'url' => '',
]
],
// 金山云
'ksyun' => [
// 云存储
'ks3' => [
'access_key_iD' => '',
'access_key_secret' => '',
'endpoint' => '',
'bucket' => '',
'url' => '',
]
],
// 验证签名
'md5' => [
]
];

@ -1,35 +1,35 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary\exception;
use Exception;
/**
* 错误处理
* Class DtaException
* @package DtApp\ThinkLibrary\exception
*/
class DtaException extends Exception
{
/**
* @return string
*/
public function errorMessage()
{
return $this->getMessage();
}
}
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary\exception;
use Exception;
/**
* 错误处理
* Class DtaException
* @package DtApp\ThinkLibrary\exception
*/
class DtaException extends Exception
{
/**
* @return string
*/
public function errorMessage()
{
return $this->getMessage();
}
}

@ -1,114 +1,114 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary\exception;
use DtApp\ThinkLibrary\service\curl\HttpService;
use DtApp\ThinkLibrary\service\DingTalkService;
use DtApp\ThinkLibrary\service\QqWryService;
use DtApp\ThinkLibrary\service\wechat\QyService;
use think\exception\Handle;
use think\exception\HttpException;
use think\exception\ValidateException;
use think\Request;
use think\Response;
use Throwable;
/**
* 异常处理接管
* Class ThinkException
* @package DtApp\ThinkLibrary\exception
*/
class ThinkException extends Handle
{
/**
* 异常处理接管
* @param Request $request
* @param Throwable $e
* @return Response
* @throws DtaException
*/
public function render($request, Throwable $e): Response
{
// 参数验证错误
if ($e instanceof ValidateException) {
return json($e->getError(), 422);
}
// 请求异常
if ($e instanceof HttpException && $request->isAjax()) {
return response($e->getMessage(), $e->getStatusCode());
}
$this->show($e->getMessage());
// 其他错误交给系统处理
return parent::render($request, $e);
}
/**
* @param $msg
* @return bool
* @throws DtaException
*/
private function show($msg): bool
{
if (empty($msg)) {
return true;
}
$nt = config('dtapp.exception.type', '');
if (!empty($nt) && $nt === 'dingtalk') {
$access_token = config('dtapp.exception.dingtalk.access_token', '');
if (!empty($access_token)) {
return DingTalkService::instance()
->accessToken($access_token)
->text($msg);
}
}
if (!empty($nt) && $nt === 'qyweixin') {
$key = config('dtapp.exception.qyweixin.key', '');
if (!empty($key)) {
return QyService::instance()
->key($key)
->text($msg);
}
}
if (!empty($nt) && $nt === 'wechat') {
$openid = config('dtapp.exception.wechat.openid', '');
$ip = config('dtapp.exception.wechat.ip', '未配置');
$seip = get_ip();
$ipinfo = QqWryService::instance()->getLocation($seip);
if (!isset($ipinfo['location_all'])) {
$ipinfo['location_all'] = '';
}
if (!empty($openid)) {
return HttpService::instance()
->url("https://api.dtapp.net/v1/wechatmp/tmplmsgWebError/openid/{$openid}")
->post()
->data([
'domain' => request()->domain(),
'url' => request()->url(),
'node' => config('dtapp.exception.wechat.node', ''),
'info' => "ServerIp" . $ip . "CdnIp" . $_SERVER['REMOTE_ADDR'] . "ClientIp" . get_ip(),
'ip' => $ipinfo['location_all'],
'error' => base64_encode($msg)
])
->toArray();
}
}
return true;
}
}
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary\exception;
use DtApp\ThinkLibrary\service\curl\HttpService;
use DtApp\ThinkLibrary\service\DingTalkService;
use DtApp\ThinkLibrary\service\QqWryService;
use DtApp\ThinkLibrary\service\wechat\QyService;
use think\exception\Handle;
use think\exception\HttpException;
use think\exception\ValidateException;
use think\Request;
use think\Response;
use Throwable;
/**
* 异常处理接管
* Class ThinkException
* @package DtApp\ThinkLibrary\exception
*/
class ThinkException extends Handle
{
/**
* 异常处理接管
* @param Request $request
* @param Throwable $e
* @return Response
* @throws DtaException
*/
public function render($request, Throwable $e): Response
{
// 参数验证错误
if ($e instanceof ValidateException) {
return json($e->getError(), 422);
}
// 请求异常
if ($e instanceof HttpException && $request->isAjax()) {
return response($e->getMessage(), $e->getStatusCode());
}
$this->show($e->getMessage());
// 其他错误交给系统处理
return parent::render($request, $e);
}
/**
* @param $msg
* @return bool
* @throws DtaException
*/
private function show($msg): bool
{
if (empty($msg)) {
return true;
}
$nt = config('dtapp.exception.type', '');
if (!empty($nt) && $nt === 'dingtalk') {
$access_token = config('dtapp.exception.dingtalk.access_token', '');
if (!empty($access_token)) {
return DingTalkService::instance()
->accessToken($access_token)
->text($msg);
}
}
if (!empty($nt) && $nt === 'qyweixin') {
$key = config('dtapp.exception.qyweixin.key', '');
if (!empty($key)) {
return QyService::instance()
->key($key)
->text($msg);
}
}
if (!empty($nt) && $nt === 'wechat') {
$openid = config('dtapp.exception.wechat.openid', '');
$ip = config('dtapp.exception.wechat.ip', '未配置');
$seip = get_ip();
$ipinfo = QqWryService::instance()->getLocation($seip);
if (!isset($ipinfo['location_all'])) {
$ipinfo['location_all'] = '';
}
if (!empty($openid)) {
return HttpService::instance()
->url("https://api.dtapp.net/v1/wechatmp/tmplmsgWebError/openid/{$openid}")
->post()
->data([
'domain' => request()->domain(),
'url' => request()->url(),
'node' => config('dtapp.exception.wechat.node', ''),
'info' => "ServerIp" . $ip . "CdnIp" . $_SERVER['REMOTE_ADDR'] . "ClientIp" . get_ip(),
'ip' => $ipinfo['location_all'],
'error' => base64_encode($msg)
])
->toArray();
}
}
return true;
}
}

@ -1,188 +1,188 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace DtApp\ThinkLibrary\extend;
/**
* 数组扩展
* Class ArraysExtend
* @package DtApp\ThinkLibrary\extend
*/
class ArraysExtend
{
/**
* 数组随机返回一个下标
* @param array $array
* @return mixed
*/
public static function rand(array $array)
{
return array_rand($array);
}
/**
* 数组随机返回一个值
* @param array $array
* @return mixed
*/
public static function randValue(array $array)
{
return $array[array_rand($array)];
}
/**
* 分隔数组
* @param array $array 数组
* @param int $num 数量
* @return array
*/
public static function split(array $array, $num = 5): array
{
$arrRet = array();
if (!isset($array) || empty($array)) {
return $arrRet;
}
$iCount = count($array) / $num;
if (!is_int($iCount)) {
$iCount = ceil($iCount);
} else {
++$iCount;
}
for ($i = 0; $i < $iCount; ++$i) {
$arrInfos = array_slice($array, $i * $num, $num);
if (empty($arrInfos)) {
continue;
}
$arrRet[] = $arrInfos;
unset($arrInfos);
}
return $arrRet;
}
/**
* 多维数组去重
* @param array $array
* @return array
*/
public static function unique(array $array): array
{
$out = array();
foreach ($array as $key => $value) {
if (!in_array($value, $out, true)) {
$out[$key] = $value;
}
}
$out = array_values($out);
return $out;
}
/**
* 二维数组根据某个键排序
* @param array $arrays
* @param string $sort_key
* @param int $sort_order
* @param int $sort_type
* @return array
*/
public static function sort(array $arrays, string $sort_key, $sort_order = SORT_ASC, $sort_type = SORT_NUMERIC): array
{
$key_arrays = array();
if (is_array($arrays)) {
foreach ($arrays as $array) {
if (is_array($array)) {
$key_arrays[] = $array[$sort_key];
} else {
return [];
}
}
} else {
return [];
}
array_multisort($key_arrays, $sort_order, $sort_type, $arrays);
return $arrays;
}
/**
* 数组删除空格
* @param array $arr
* @return array
*/
public static function trimArray(array $arr)
{
if (!is_array($arr)) {
return $arr;
}
foreach ($arr as $key => $value) {
if (is_array($value)) {
$arr[$key] = self::TrimArray($value);
} else {
$arr[$key] = self::trimAll($value);
}
}
return $arr;
}
/**
* 字符串删除空格
* @param $str
* @return string|string[]
*/
private static function trimAll($str)
{
$oldchar = array(" ", " ", "\t", "\n", "\r");
$newchar = array("", "", "", "", "");
return str_replace($oldchar, $newchar, $str);
}
/**
* 把json字符串或json对象转json数组
* @param $output
* @return array
*/
public static function toArray($output): array
{
if (is_array($output)) {
return $output;
}
if (is_object($output)) {
$output = json_encode($output, JSON_UNESCAPED_UNICODE);
}
return json_decode($output, true);
}
/**
* @param $array
* @param $name
* @return array
*/
public static function valChunk($array, $name): array
{
$result = array();
$ar2 = [];
foreach ($array as $key => $value) {
foreach ($array as $k => $val) {
if ($value[(string)($name)] == $val[(string)($name)]) {
$ar2[] = $val;
}
}
$result[$value[(string)($name)]] = $ar2;
$ar2 = [];
}
return $result;
}
}
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace DtApp\ThinkLibrary\extend;
/**
* 数组扩展
* Class ArraysExtend
* @package DtApp\ThinkLibrary\extend
*/
class ArraysExtend
{
/**
* 数组随机返回一个下标
* @param array $array
* @return mixed
*/
public static function rand(array $array)
{
return array_rand($array);
}
/**
* 数组随机返回一个值
* @param array $array
* @return mixed
*/
public static function randValue(array $array)
{
return $array[array_rand($array)];
}
/**
* 分隔数组
* @param array $array 数组
* @param int $num 数量
* @return array
*/
public static function split(array $array, $num = 5): array
{
$arrRet = array();
if (!isset($array) || empty($array)) {
return $arrRet;
}
$iCount = count($array) / $num;
if (!is_int($iCount)) {
$iCount = ceil($iCount);
} else {
++$iCount;
}
for ($i = 0; $i < $iCount; ++$i) {
$arrInfos = array_slice($array, $i * $num, $num);
if (empty($arrInfos)) {
continue;
}
$arrRet[] = $arrInfos;
unset($arrInfos);
}
return $arrRet;
}
/**
* 多维数组去重
* @param array $array
* @return array
*/
public static function unique(array $array): array
{
$out = array();
foreach ($array as $key => $value) {
if (!in_array($value, $out, true)) {
$out[$key] = $value;
}
}
$out = array_values($out);
return $out;
}
/**
* 二维数组根据某个键排序
* @param array $arrays
* @param string $sort_key
* @param int $sort_order
* @param int $sort_type
* @return array
*/
public static function sort(array $arrays, string $sort_key, $sort_order = SORT_ASC, $sort_type = SORT_NUMERIC): array
{
$key_arrays = array();
if (is_array($arrays)) {
foreach ($arrays as $array) {
if (is_array($array)) {
$key_arrays[] = $array[$sort_key];
} else {
return [];
}
}
} else {
return [];
}
array_multisort($key_arrays, $sort_order, $sort_type, $arrays);
return $arrays;
}
/**
* 数组删除空格
* @param array $arr
* @return array
*/
public static function trimArray(array $arr)
{
if (!is_array($arr)) {
return $arr;
}
foreach ($arr as $key => $value) {
if (is_array($value)) {
$arr[$key] = self::TrimArray($value);
} else {
$arr[$key] = self::trimAll($value);
}
}
return $arr;
}
/**
* 字符串删除空格
* @param $str
* @return string|string[]
*/
private static function trimAll($str)
{
$oldchar = array(" ", " ", "\t", "\n", "\r");
$newchar = array("", "", "", "", "");
return str_replace($oldchar, $newchar, $str);
}
/**
* 把json字符串或json对象转json数组
* @param $output
* @return array
*/
public static function toArray($output): array
{
if (is_array($output)) {
return $output;
}
if (is_object($output)) {
$output = json_encode($output, JSON_UNESCAPED_UNICODE);
}
return json_decode($output, true);
}
/**
* @param $array
* @param $name
* @return array
*/
public static function valChunk($array, $name): array
{
$result = array();
$ar2 = [];
foreach ($array as $key => $value) {
foreach ($array as $k => $val) {
if ($value[(string)($name)] == $val[(string)($name)]) {
$ar2[] = $val;
}
}
$result[$value[(string)($name)]] = $ar2;
$ar2 = [];
}
return $result;
}
}

@ -1,91 +1,91 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace DtApp\ThinkLibrary\extend;
/**
* 随机数码管理扩展
* Class CodeExtend
* @package DtApp\ThinkLibrary\extend
*/
class CodeExtend
{
/**
* 获取随机字符串编码
* @param integer $size 编码长度
* @param integer $type 编码类型(1纯数字,2纯字母,3数字字母)
* @param string $prefix 编码前缀
* @return string
* @throws \Exception
*/
public static function random(int $size = 10, int $type = 1, string $prefix = ''): string
{
$numbs = '0123456789';
$chars = 'abcdefghijklmnopqrstuvwxyz';
if ($type === 1) {
$chars = $numbs;
}
if ($type === 3) {
$chars = "{$numbs}{$chars}";
}
$code = $prefix . $chars[random_int(1, strlen($chars) - 1)];
while (strlen($code) < $size) {
$code .= $chars[random_int(0, strlen($chars) - 1)];
}
return $code;
}
/**
* 唯一日期编码
* @param integer $size 编码长度
* @param string $prefix 编码前缀
* @return string
* @throws \Exception
*/
public static function uniqidDate(int $size = 16, string $prefix = ''): string
{
if ($size < 14) {
$size = 14;
}
$code = $prefix . date('Ymd') . (date('H') + date('i')) . date('s');
while (strlen($code) < $size) {
$code .= random_int(0, 9);
}
return $code;
}
/**
* 唯一数字编码
* @param integer $size 编码长度
* @param string $prefix 编码前缀
* @return string
* @throws \Exception
*/
public static function uniqidNumber(int $size = 12, string $prefix = ''): string
{
$time = time() . '';
if ($size < 10) {
$size = 10;
}
$code = $prefix . ((int)$time[0] + (int)$time[1]) . substr($time, 2) . random_int(0, 9);
while (strlen($code) < $size) {
$code .= random_int(0, 9);
}
return $code;
}
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace DtApp\ThinkLibrary\extend;
/**
* 随机数码管理扩展
* Class CodeExtend
* @package DtApp\ThinkLibrary\extend
*/
class CodeExtend
{
/**
* 获取随机字符串编码
* @param integer $size 编码长度
* @param integer $type 编码类型(1纯数字,2纯字母,3数字字母)
* @param string $prefix 编码前缀
* @return string
* @throws \Exception
*/
public static function random(int $size = 10, int $type = 1, string $prefix = ''): string
{
$numbs = '0123456789';
$chars = 'abcdefghijklmnopqrstuvwxyz';
if ($type === 1) {
$chars = $numbs;
}
if ($type === 3) {
$chars = "{$numbs}{$chars}";
}
$code = $prefix . $chars[random_int(1, strlen($chars) - 1)];
while (strlen($code) < $size) {
$code .= $chars[random_int(0, strlen($chars) - 1)];
}
return $code;
}
/**
* 唯一日期编码
* @param integer $size 编码长度
* @param string $prefix 编码前缀
* @return string
* @throws \Exception
*/
public static function uniqidDate(int $size = 16, string $prefix = ''): string
{
if ($size < 14) {
$size = 14;
}
$code = $prefix . date('Ymd') . (date('H') + date('i')) . date('s');
while (strlen($code) < $size) {
$code .= random_int(0, 9);
}
return $code;
}
/**
* 唯一数字编码
* @param integer $size 编码长度
* @param string $prefix 编码前缀
* @return string
* @throws \Exception
*/
public static function uniqidNumber(int $size = 12, string $prefix = ''): string
{
$time = time() . '';
if ($size < 10) {
$size = 10;
}
$code = $prefix . ((int)$time[0] + (int)$time[1]) . substr($time, 2) . random_int(0, 9);
while (strlen($code) < $size) {
$code .= random_int(0, 9);
}
return $code;
}
}

@ -1,196 +1,196 @@
<?php
namespace DtApp\ThinkLibrary\extend;
/**
* 验证管理类
* Class PregSExtend
* @package DtApp\ThinkLibrary\extend
*/
class PregSExtend
{
/**
* 验证手机号码
* @access public
* @param $mobile
* @return bool
*/
public static function isIphone($mobile): bool
{
if (preg_match('/^[1]([3-9])[0-9]{9}$/', $mobile)) {
return true;
}
return false;
}
/**
* 严谨验证手机号码
* 移动134 135 136 137 138 139 147 150 151 152 157 158 159 178 182 183 184 187 188 198
* 联通130 131 132 145 155 156 166 171 175 176 185 186
* 电信133 149 153 173 177 180 181 189 199
* 虚拟运营商: 170 195
* @param $mobile
* @return bool
*/
public static function isIphoneAll($mobile): bool
{
if (preg_match('/^[1](([3][0-9])|([4][5-9])|([5][0-3,5-9])|([6][5,6])|([7][0-8])|([8][0-9])|([9][1,5,8-9]))[0-9]{8}$/', $mobile)) {
return true;
}
return false;
}
/**
* 验证电话号码
* @access public
* @param $tel
* @return bool
*/
public static function isTel($tel): bool
{
if (preg_match("/^(\(\d{3,4}\)|\d{3,4}-)?\d{7,8}$/", $tel)) {
return true;
}
return false;
}
/**
* 验证身份证号15位或18位数字
* @access public
* @param int $id 身份证号码
* @return bool
*/
public static function isIdCard(int $id): bool
{
if (preg_match("/^\d{15}|\d{18}$/", $id)) {
return true;
}
return false;
}
/**
* 验证是否是数字(这里小数点会认为是字符)
* @access public
* @param $digit
* @return bool
*/
public static function isDigit($digit): bool
{
if (preg_match("/^\d*$/", $digit)) {
return true;
}
return false;
}
/**
* 验证是否是数字(可带小数点的数字)
* @access public
* @param $num
* @return bool
*/
public static function isNum($num): bool
{
if (is_numeric($num)) {
return true;
}
return false;
}
/**
* 验证由数字、26个英文字母或者下划线组成的字符串
* @access public
* @param $str
* @return bool
*/
public static function isStr($str): bool
{
if (preg_match("/^\w+$/", $str)) {
return true;
}
return false;
}
/**
* 验证用户密码(以字母开头长度在6-18之间只能包含字符、数字和下划线)
* @access public
* @param $str
* @return bool
*/
public static function isPassword($str): bool
{
if (preg_match("/^[a-zA-Z]\w{5,17}$/", $str)) {
return true;
}
return false;
}
/**
* 验证汉字
* @access public
* @param $str
* @return bool
*/
public static function isChinese($str): bool
{
if (preg_match("/^[\u4e00-\u9fa5],{0,}$/", $str)) {
return true;
}
return false;
}
/**
* 验证Email地址
* @access public
* @param $email
* @return bool
*/
public static function isEmail($email): bool
{
if (preg_match("/^\w+[-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/", $email)) {
return true;
}
return false;
}
/**
* 验证网址URL
* @access public
* @param $url
* @return bool
*/
public static function isLink($url): bool
{
if (preg_match("/http|https:\/\/[\w.]+[\w\/]*[\w.]*\??[\w=&\+\%]*/is", $url)) {
return true;
}
return false;
}
/**
* 腾讯QQ号
* @access public
* @param $qq
* @return bool
*/
public static function isQq($qq): bool
{
if (preg_match("/^[1-9][0-9]{4,}$/", $qq)) {
return true;
}
return false;
}
/**
* 验证IP地址
* @access public
* @param $ip
* @return bool
*/
public static function isIp($ip): bool
{
if (preg_match("/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/", $ip)) {
return true;
}
return false;
}
<?php
namespace DtApp\ThinkLibrary\extend;
/**
* 验证管理类
* Class PregSExtend
* @package DtApp\ThinkLibrary\extend
*/
class PregSExtend
{
/**
* 验证手机号码
* @access public
* @param $mobile
* @return bool
*/
public static function isIphone($mobile): bool
{
if (preg_match('/^[1]([3-9])[0-9]{9}$/', $mobile)) {
return true;
}
return false;
}
/**
* 严谨验证手机号码
* 移动134 135 136 137 138 139 147 150 151 152 157 158 159 178 182 183 184 187 188 198
* 联通130 131 132 145 155 156 166 171 175 176 185 186
* 电信133 149 153 173 177 180 181 189 199
* 虚拟运营商: 170 195
* @param $mobile
* @return bool
*/
public static function isIphoneAll($mobile): bool
{
if (preg_match('/^[1](([3][0-9])|([4][5-9])|([5][0-3,5-9])|([6][5,6])|([7][0-8])|([8][0-9])|([9][1,5,8-9]))[0-9]{8}$/', $mobile)) {
return true;
}
return false;
}
/**
* 验证电话号码
* @access public
* @param $tel
* @return bool
*/
public static function isTel($tel): bool
{
if (preg_match("/^(\(\d{3,4}\)|\d{3,4}-)?\d{7,8}$/", $tel)) {
return true;
}
return false;
}
/**
* 验证身份证号15位或18位数字
* @access public
* @param int $id 身份证号码
* @return bool
*/
public static function isIdCard(int $id): bool
{
if (preg_match("/^\d{15}|\d{18}$/", $id)) {
return true;
}
return false;
}
/**
* 验证是否是数字(这里小数点会认为是字符)
* @access public
* @param $digit
* @return bool
*/
public static function isDigit($digit): bool
{
if (preg_match("/^\d*$/", $digit)) {
return true;
}
return false;
}
/**
* 验证是否是数字(可带小数点的数字)
* @access public
* @param $num
* @return bool
*/
public static function isNum($num): bool
{
if (is_numeric($num)) {
return true;
}
return false;
}
/**
* 验证由数字、26个英文字母或者下划线组成的字符串
* @access public
* @param $str
* @return bool
*/
public static function isStr($str): bool
{
if (preg_match("/^\w+$/", $str)) {
return true;
}
return false;
}
/**
* 验证用户密码(以字母开头长度在6-18之间只能包含字符、数字和下划线)
* @access public
* @param $str
* @return bool
*/
public static function isPassword($str): bool
{
if (preg_match("/^[a-zA-Z]\w{5,17}$/", $str)) {
return true;
}
return false;
}
/**
* 验证汉字
* @access public
* @param $str
* @return bool
*/
public static function isChinese($str): bool
{
if (preg_match("/^[\u4e00-\u9fa5],{0,}$/", $str)) {
return true;
}
return false;
}
/**
* 验证Email地址
* @access public
* @param $email
* @return bool
*/
public static function isEmail($email): bool
{
if (preg_match("/^\w+[-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/", $email)) {
return true;
}
return false;
}
/**
* 验证网址URL
* @access public
* @param $url
* @return bool
*/
public static function isLink($url): bool
{
if (preg_match("/http|https:\/\/[\w.]+[\w\/]*[\w.]*\??[\w=&\+\%]*/is", $url)) {
return true;
}
return false;
}
/**
* 腾讯QQ号
* @access public
* @param $qq
* @return bool
*/
public static function isQq($qq): bool
{
if (preg_match("/^[1-9][0-9]{4,}$/", $qq)) {
return true;
}
return false;
}
/**
* 验证IP地址
* @access public
* @param $ip
* @return bool
*/
public static function isIp($ip): bool
{
if (preg_match("/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/", $ip)) {
return true;
}
return false;
}
}

@ -1,50 +1,50 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace DtApp\ThinkLibrary\facade;
use DtApp\ThinkLibrary\helper\Arrays as helper;
use think\Facade;
/**
* 数组门面
* @see \DtApp\ThinkLibrary\helper\Arrays
* @package DtApp\ThinkLibrary\facade
* @package think\facade
* @mixin helper
*
* @method static mixed rand(array $array) 数组随机返回一个下标
* @method static mixed randValue(array $array) mixed 数组随机返回一个值
* @method static array split(array $array, $num = 5) 分隔数组
* @method static array unique(array $array) 多维数组去重
* @method static array sort(array $arrays, string $sort_key, $sort_order = SORT_ASC, $sort_type = SORT_NUMERIC) 二维数组根据某个键排序
* @method static array trimArray(array $arr) 数组删除空格
* @method static array toArray($output) 把json字符串或json对象转json数组
*/
class Arrays extends Facade
{
/**
* 获取当前Facade对应类名或者已经绑定的容器对象标识
* @access protected
* @return string
*/
protected static function getFacadeClass()
{
return helper::class;
}
}
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace DtApp\ThinkLibrary\facade;
use DtApp\ThinkLibrary\helper\Arrays as helper;
use think\Facade;
/**
* 数组门面
* @see \DtApp\ThinkLibrary\helper\Arrays
* @package DtApp\ThinkLibrary\facade
* @package think\facade
* @mixin helper
*
* @method static mixed rand(array $array) 数组随机返回一个下标
* @method static mixed randValue(array $array) mixed 数组随机返回一个值
* @method static array split(array $array, $num = 5) 分隔数组
* @method static array unique(array $array) 多维数组去重
* @method static array sort(array $arrays, string $sort_key, $sort_order = SORT_ASC, $sort_type = SORT_NUMERIC) 二维数组根据某个键排序
* @method static array trimArray(array $arr) 数组删除空格
* @method static array toArray($output) 把json字符串或json对象转json数组
*/
class Arrays extends Facade
{
/**
* 获取当前Facade对应类名或者已经绑定的容器对象标识
* @access protected
* @return string
*/
protected static function getFacadeClass()
{
return helper::class;
}
}

@ -1,44 +1,44 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace DtApp\ThinkLibrary\facade;
use DtApp\ThinkLibrary\helper\Dates as helper;
use think\Facade;
/**
* 日期门面
* @see \DtApp\ThinkLibrary\helper\Dates
* @package DtApp\ThinkLibrary\facade
* @package think\facade
* @mixin helper
*
* @method static string current(string $format = "Y-m-d H:i:s") 当前日期
*/
class Dates extends Facade
{
/**
* 获取当前Facade对应类名或者已经绑定的容器对象标识
* @access protected
* @return string
*/
protected static function getFacadeClass()
{
return helper::class;
}
}
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace DtApp\ThinkLibrary\facade;
use DtApp\ThinkLibrary\helper\Dates as helper;
use think\Facade;
/**
* 日期门面
* @see \DtApp\ThinkLibrary\helper\Dates
* @package DtApp\ThinkLibrary\facade
* @package think\facade
* @mixin helper
*
* @method static string current(string $format = "Y-m-d H:i:s") 当前日期
*/
class Dates extends Facade
{
/**
* 获取当前Facade对应类名或者已经绑定的容器对象标识
* @access protected
* @return string
*/
protected static function getFacadeClass()
{
return helper::class;
}
}

@ -1,48 +1,48 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace DtApp\ThinkLibrary\facade;
use DtApp\ThinkLibrary\helper\Decimals as helper;
use think\Facade;
/**
* 小数门面
* @see \DtApp\ThinkLibrary\helper\Decimals
* @package DtApp\ThinkLibrary\Decimals
* @package think\facade
* @mixin helper
*
* @method static int intval($num) 直接取整,舍弃小数保留整数
* @method static float round($num, $bl = 0) 四舍五入
* @method static false|float ceil($num) 有小数,就在整数的基础上加一
* @method static false|float floor($num) 有小数,就取整数位
* @method static bool judge($num) 判断是不是小数
*/
class Decimals extends Facade
{
/**
* 获取当前Facade对应类名或者已经绑定的容器对象标识
* @access protected
* @return string
*/
protected static function getFacadeClass()
{
return helper::class;
}
}
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace DtApp\ThinkLibrary\facade;
use DtApp\ThinkLibrary\helper\Decimals as helper;
use think\Facade;
/**
* 小数门面
* @see \DtApp\ThinkLibrary\helper\Decimals
* @package DtApp\ThinkLibrary\Decimals
* @package think\facade
* @mixin helper
*
* @method static int intval($num) 直接取整,舍弃小数保留整数
* @method static float round($num, $bl = 0) 四舍五入
* @method static false|float ceil($num) 有小数,就在整数的基础上加一
* @method static false|float floor($num) 有小数,就取整数位
* @method static bool judge($num) 判断是不是小数
*/
class Decimals extends Facade
{
/**
* 获取当前Facade对应类名或者已经绑定的容器对象标识
* @access protected
* @return string
*/
protected static function getFacadeClass()
{
return helper::class;
}
}

@ -1,50 +1,50 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace DtApp\ThinkLibrary\facade;
use DtApp\ThinkLibrary\helper\Files as helper;
use think\Facade;
/**
* 文件门面
* @see \DtApp\ThinkLibrary\helper\Files
* @package DtApp\ThinkLibrary\facade
* @package think\facade
* @mixin helper
*
* @method static bool delete(string $name) 删除文件
* @method static bool deletes(string $name) 删除文件夹
* @method static bool folderZip(string $name, string $suffix_name = '.png', string $file_name = '*') 把文件夹里面的文件打包成zip文件
* @method static string getFiles(string $path) 获取目录下的所有文件和目录
* @method static bool rmFiles(string $path) 删除目录下的文件
* @method static bool judgeFile(string $path) 判断文件是否存在
* @method static bool judgeContents(string $path) 判断目录是否存在
*/
class Files extends Facade
{
/**
* 获取当前Facade对应类名或者已经绑定的容器对象标识
* @access protected
* @return string
*/
protected static function getFacadeClass()
{
return helper::class;
}
}
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace DtApp\ThinkLibrary\facade;
use DtApp\ThinkLibrary\helper\Files as helper;
use think\Facade;
/**
* 文件门面
* @see \DtApp\ThinkLibrary\helper\Files
* @package DtApp\ThinkLibrary\facade
* @package think\facade
* @mixin helper
*
* @method static bool delete(string $name) 删除文件
* @method static bool deletes(string $name) 删除文件夹
* @method static bool folderZip(string $name, string $suffix_name = '.png', string $file_name = '*') 把文件夹里面的文件打包成zip文件
* @method static string getFiles(string $path) 获取目录下的所有文件和目录
* @method static bool rmFiles(string $path) 删除目录下的文件
* @method static bool judgeFile(string $path) 判断文件是否存在
* @method static bool judgeContents(string $path) 判断目录是否存在
*/
class Files extends Facade
{
/**
* 获取当前Facade对应类名或者已经绑定的容器对象标识
* @access protected
* @return string
*/
protected static function getFacadeClass()
{
return helper::class;
}
}

@ -1,46 +1,46 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace DtApp\ThinkLibrary\facade;
use DtApp\ThinkLibrary\helper\Ints as helper;
use think\Facade;
/**
* 整数门面
* @see \DtApp\ThinkLibrary\helper\Ints
* @package DtApp\ThinkLibrary\Ints
* @package think\facade
* @mixin helper
*
* @method static bool isEvenNumbers(int $num) 判断一个数是不是偶数
* @method static bool isOddNumbers(int $num) 判断一个数是不是奇数
*/
class Ints extends Facade
{
/**
* 获取当前Facade对应类名或者已经绑定的容器对象标识
* @access protected
* @return string
*/
protected static function getFacadeClass()
{
return helper::class;
}
}
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace DtApp\ThinkLibrary\facade;
use DtApp\ThinkLibrary\helper\Ints as helper;
use think\Facade;
/**
* 整数门面
* @see \DtApp\ThinkLibrary\helper\Ints
* @package DtApp\ThinkLibrary\Ints
* @package think\facade
* @mixin helper
*
* @method static bool isEvenNumbers(int $num) 判断一个数是不是偶数
* @method static bool isOddNumbers(int $num) 判断一个数是不是奇数
*/
class Ints extends Facade
{
/**
* 获取当前Facade对应类名或者已经绑定的容器对象标识
* @access protected
* @return string
*/
protected static function getFacadeClass()
{
return helper::class;
}
}

@ -1,56 +1,56 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace DtApp\ThinkLibrary\facade;
use DtApp\ThinkLibrary\helper\Pregs as helper;
use think\facade;
/**
* 验证门面
* @see \DtApp\ThinkLibrary\helper\Pregs
* @package DtApp\ThinkLibrary\Pregs
* @package think\facade
* @mixin helper
*
* @method static bool isIphone($mobile) 验证手机号码
* @method static bool isIphoneAll($mobile) 严谨验证手机号码
* @method static bool isTel($tel) 验证电话号码
* @method static bool isIdCard($mobile) 验证身份证号15位或18位数字
* @method static bool isDigit($digit) 验证是否是数字(这里小数点会认为是字符)
* @method static bool isNum($num) 验证是否是数字(可带小数点的数字)
* @method static bool isStr($str) 验证由数字、26个英文字母或者下划线组成的字符串
* @method static bool isPassword($str) 验证用户密码(以字母开头长度在6-18之间只能包含字符、数字和下划线)
* @method static bool isChinese($str) 验证汉字
* @method static bool isEmail($email) 验证Email地址
* @method static bool isLink($url) 验证网址URL
* @method static bool isQq($qq) 腾讯QQ号
* @method static bool isIp($ip) 验证IP地址
*/
class Pregs extends Facade
{
/**
* 获取当前Facade对应类名或者已经绑定的容器对象标识
* @access protected
* @return string
*/
protected static function getFacadeClass()
{
return helper::class;
}
}
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace DtApp\ThinkLibrary\facade;
use DtApp\ThinkLibrary\helper\Pregs as helper;
use think\facade;
/**
* 验证门面
* @see \DtApp\ThinkLibrary\helper\Pregs
* @package DtApp\ThinkLibrary\Pregs
* @package think\facade
* @mixin helper
*
* @method static bool isIphone($mobile) 验证手机号码
* @method static bool isIphoneAll($mobile) 严谨验证手机号码
* @method static bool isTel($tel) 验证电话号码
* @method static bool isIdCard($mobile) 验证身份证号15位或18位数字
* @method static bool isDigit($digit) 验证是否是数字(这里小数点会认为是字符)
* @method static bool isNum($num) 验证是否是数字(可带小数点的数字)
* @method static bool isStr($str) 验证由数字、26个英文字母或者下划线组成的字符串
* @method static bool isPassword($str) 验证用户密码(以字母开头长度在6-18之间只能包含字符、数字和下划线)
* @method static bool isChinese($str) 验证汉字
* @method static bool isEmail($email) 验证Email地址
* @method static bool isLink($url) 验证网址URL
* @method static bool isQq($qq) 腾讯QQ号
* @method static bool isIp($ip) 验证IP地址
*/
class Pregs extends Facade
{
/**
* 获取当前Facade对应类名或者已经绑定的容器对象标识
* @access protected
* @return string
*/
protected static function getFacadeClass()
{
return helper::class;
}
}

@ -1,45 +1,45 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace DtApp\ThinkLibrary\facade;
use DtApp\ThinkLibrary\helper\Randoms as helper;
use think\facade;
/**
* 随机门面
* @see \DtApp\ThinkLibrary\helper\Randoms
* @package DtApp\ThinkLibrary\Randoms
* @package think\facade
* @mixin helper
*
* @method static string generate(int $length = 6, int $type = 1) 生成随机
*/
class Randoms extends Facade
{
/**
* 获取当前Facade对应类名或者已经绑定的容器对象标识
* @access protected
* @return string
*/
protected static function getFacadeClass()
{
return helper::class;
}
}
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace DtApp\ThinkLibrary\facade;
use DtApp\ThinkLibrary\helper\Randoms as helper;
use think\facade;
/**
* 随机门面
* @see \DtApp\ThinkLibrary\helper\Randoms
* @package DtApp\ThinkLibrary\Randoms
* @package think\facade
* @mixin helper
*
* @method static string generate(int $length = 6, int $type = 1) 生成随机
*/
class Randoms extends Facade
{
/**
* 获取当前Facade对应类名或者已经绑定的容器对象标识
* @access protected
* @return string
*/
protected static function getFacadeClass()
{
return helper::class;
}
}

@ -1,59 +1,59 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace DtApp\ThinkLibrary\facade;
use DtApp\ThinkLibrary\helper\Requests as helper;
use think\Facade;
/**
* 请求门面
* @see \DtApp\ThinkLibrary\helper\Requests
* @package DtApp\ThinkLibrary\facade
* @package think\facade
* @mixin helper
*
* @method static array isEmpty(array $data, array $arr) array|bool 判断输入的参数
* @method static array isEmptyRet(array $data, array $arr) array 判断输入的参数为空就返回Json错误
* @method static bool isGet() 判断是否为GET方式
* @method static bool isPost() 判断是否为POST方式
* @method static bool isPut() 判断是否为PUT方式
* @method static bool isDelete() 判断是否为DELETE方式
* @method static bool isAjax() 判断是否为Ajax方式
* @method static bool isMobile() 判断是否为移动端访问
* @method static bool isWeiXin() 判断是否微信内置浏览器访问
* @method static bool isWeiXinMp() 判断是否为微信小程序访问
* @method static bool isAliPay() 判断是否支付宝内置浏览器访问
* @method static bool isQQ() 判断是否QQ内置浏览器访问
* @method static bool isQQBrowser() 判断是否QQ浏览器访问
* @method static string getDeviceType() 获取客户端类型
* @method static string getMobileType() 获取手机设备类型
* @method static string getWebsiteAddress() 获取域名地址
*/
class Requests extends Facade
{
/**
* 获取当前Facade对应类名或者已经绑定的容器对象标识
* @access protected
* @return string
*/
public static function getFacadeClass()
{
return helper::class;
}
}
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace DtApp\ThinkLibrary\facade;
use DtApp\ThinkLibrary\helper\Requests as helper;
use think\Facade;
/**
* 请求门面
* @see \DtApp\ThinkLibrary\helper\Requests
* @package DtApp\ThinkLibrary\facade
* @package think\facade
* @mixin helper
*
* @method static array isEmpty(array $data, array $arr) array|bool 判断输入的参数
* @method static array isEmptyRet(array $data, array $arr) array 判断输入的参数为空就返回Json错误
* @method static bool isGet() 判断是否为GET方式
* @method static bool isPost() 判断是否为POST方式
* @method static bool isPut() 判断是否为PUT方式
* @method static bool isDelete() 判断是否为DELETE方式
* @method static bool isAjax() 判断是否为Ajax方式
* @method static bool isMobile() 判断是否为移动端访问
* @method static bool isWeiXin() 判断是否微信内置浏览器访问
* @method static bool isWeiXinMp() 判断是否为微信小程序访问
* @method static bool isAliPay() 判断是否支付宝内置浏览器访问
* @method static bool isQQ() 判断是否QQ内置浏览器访问
* @method static bool isQQBrowser() 判断是否QQ浏览器访问
* @method static string getDeviceType() 获取客户端类型
* @method static string getMobileType() 获取手机设备类型
* @method static string getWebsiteAddress() 获取域名地址
*/
class Requests extends Facade
{
/**
* 获取当前Facade对应类名或者已经绑定的容器对象标识
* @access protected
* @return string
*/
public static function getFacadeClass()
{
return helper::class;
}
}

@ -1,45 +1,45 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace DtApp\ThinkLibrary\facade;
use DtApp\ThinkLibrary\helper\Returns as helper;
use think\Facade;
/**
* 返回门面
* @see \DtApp\ThinkLibrary\helper\Returns
* @package DtApp\ThinkLibrary\Returns
* @package think\facade
* @mixin helper
*
* @method static jsonSuccess(array $data = [], string $msg = 'success', int $code = 0, array $ext = []) 返回Json-成功
* @method static jsonError(string $msg = 'error', int $code = 1, array $data = [], array $ext = []) 返回Json-错误
*/
class Returns extends Facade
{
/**
* 获取当前Facade对应类名或者已经绑定的容器对象标识
* @access protected
* @return string
*/
public static function getFacadeClass()
{
return helper::class;
}
}
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace DtApp\ThinkLibrary\facade;
use DtApp\ThinkLibrary\helper\Returns as helper;
use think\Facade;
/**
* 返回门面
* @see \DtApp\ThinkLibrary\helper\Returns
* @package DtApp\ThinkLibrary\Returns
* @package think\facade
* @mixin helper
*
* @method static jsonSuccess(array $data = [], string $msg = 'success', int $code = 0, array $ext = []) 返回Json-成功
* @method static jsonError(string $msg = 'error', int $code = 1, array $data = [], array $ext = []) 返回Json-错误
*/
class Returns extends Facade
{
/**
* 获取当前Facade对应类名或者已经绑定的容器对象标识
* @access protected
* @return string
*/
public static function getFacadeClass()
{
return helper::class;
}
}

@ -1,50 +1,50 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace DtApp\ThinkLibrary\facade;
use DtApp\ThinkLibrary\helper\Strings as helper;
use think\facade;
/**
* 字符串门面
* @see \DtApp\ThinkLibrary\helper\Strings
* @package DtApp\ThinkLibrary\Strings
* @package think\facade
* @mixin helper
*
* @method static string extractBefore(string $str, int $start_num, int $end_num) 截取字符串前面n个字符
* @method static string extractRear(string $str, int $num) 截取字符串最后n个字符
* @method static string filter(string $str) 过滤字符串
* @method static bool exitContain(string $str, $nee = 3, $del = ',') bool 判断字符串是否包含某个字符
* @method static int len(string $str) int 统计字符串长度
* @method static string trimAll(string $str) 删除空格
* @method static string replace(string $search, string $replace, string $subject) 替换字符串
*/
class Strings extends Facade
{
/**
* 获取当前Facade对应类名或者已经绑定的容器对象标识
* @access protected
* @return string
*/
protected static function getFacadeClass()
{
return helper::class;
}
}
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace DtApp\ThinkLibrary\facade;
use DtApp\ThinkLibrary\helper\Strings as helper;
use think\facade;
/**
* 字符串门面
* @see \DtApp\ThinkLibrary\helper\Strings
* @package DtApp\ThinkLibrary\Strings
* @package think\facade
* @mixin helper
*
* @method static string extractBefore(string $str, int $start_num, int $end_num) 截取字符串前面n个字符
* @method static string extractRear(string $str, int $num) 截取字符串最后n个字符
* @method static string filter(string $str) 过滤字符串
* @method static bool exitContain(string $str, $nee = 3, $del = ',') bool 判断字符串是否包含某个字符
* @method static int len(string $str) int 统计字符串长度
* @method static string trimAll(string $str) 删除空格
* @method static string replace(string $search, string $replace, string $subject) 替换字符串
*/
class Strings extends Facade
{
/**
* 获取当前Facade对应类名或者已经绑定的容器对象标识
* @access protected
* @return string
*/
protected static function getFacadeClass()
{
return helper::class;
}
}

@ -1,52 +1,52 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace DtApp\ThinkLibrary\facade;
use DtApp\ThinkLibrary\helper\Times as helper;
use think\Facade;
/**
* 时间门面
* @see \DtApp\ThinkLibrary\helper\Times
* @package DtApp\ThinkLibrary\Times
* @package think\facade
* @mixin helper
*
* @method static string getData(string $format = "Y-m-d H:i:s") 当前时间
* @method static string getTime() 当前时间戳
* @method static string getUDate() 当前时间戳
* @method static string getTimeDifference(string $end_time, string $start_time) 计算两个时间差
* @method static string dateToTimestamp(string $date) 将指定日期转换为时间戳
* @method static string timestampToDate(int $time, string $format = "Y-m-d H:i:s") 将指定时间戳转换为日期
* @method static string dateRear(string $format = "Y-m-d H:i:s", int $mun = 10, int $time = 0) 在某个时间之前的时间
* @method static string dateBefore(string $format = "Y-m-d H:i:s", int $mun = 10, int $time = 0) 在某个时间之后的时间
* @method static bool checkIsBetweenTime(string $start, string $end) 判断当前的时分是否在指定的时间段内
*/
class Times extends Facade
{
/**
* 获取当前Facade对应类名或者已经绑定的容器对象标识
* @access protected
* @return string
*/
protected static function getFacadeClass()
{
return helper::class;
}
}
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace DtApp\ThinkLibrary\facade;
use DtApp\ThinkLibrary\helper\Times as helper;
use think\Facade;
/**
* 时间门面
* @see \DtApp\ThinkLibrary\helper\Times
* @package DtApp\ThinkLibrary\Times
* @package think\facade
* @mixin helper
*
* @method static string getData(string $format = "Y-m-d H:i:s") 当前时间
* @method static string getTime() 当前时间戳
* @method static string getUDate() 当前时间戳
* @method static string getTimeDifference(string $end_time, string $start_time) 计算两个时间差
* @method static string dateToTimestamp(string $date) 将指定日期转换为时间戳
* @method static string timestampToDate(int $time, string $format = "Y-m-d H:i:s") 将指定时间戳转换为日期
* @method static string dateRear(string $format = "Y-m-d H:i:s", int $mun = 10, int $time = 0) 在某个时间之前的时间
* @method static string dateBefore(string $format = "Y-m-d H:i:s", int $mun = 10, int $time = 0) 在某个时间之后的时间
* @method static bool checkIsBetweenTime(string $start, string $end) 判断当前的时分是否在指定的时间段内
*/
class Times extends Facade
{
/**
* 获取当前Facade对应类名或者已经绑定的容器对象标识
* @access protected
* @return string
*/
protected static function getFacadeClass()
{
return helper::class;
}
}

@ -1,46 +1,46 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace DtApp\ThinkLibrary\facade;
use DtApp\ThinkLibrary\helper\UnIqIds as helper;
use think\Facade;
/**
* 唯一ID门面
* @see \DtApp\ThinkLibrary\UnIqIds
* @package DtApp\ThinkLibrary\UnIqIds
* @package think\facade
* @mixin helper
*
* @method static string random($size = 10, $type = 1, $prefix = '') 获取随机字符串编码
* @method static string date($size = 16, $prefix = '') 唯一日期编码
* @method static string number($size = 12, $prefix = '') 唯一数字编码
*/
class UnIqIds extends Facade
{
/**
* 获取当前Facade对应类名或者已经绑定的容器对象标识
* @access protected
* @return string
*/
protected static function getFacadeClass()
{
return helper::class;
}
}
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace DtApp\ThinkLibrary\facade;
use DtApp\ThinkLibrary\helper\UnIqIds as helper;
use think\Facade;
/**
* 唯一ID门面
* @see \DtApp\ThinkLibrary\UnIqIds
* @package DtApp\ThinkLibrary\UnIqIds
* @package think\facade
* @mixin helper
*
* @method static string random($size = 10, $type = 1, $prefix = '') 获取随机字符串编码
* @method static string date($size = 16, $prefix = '') 唯一日期编码
* @method static string number($size = 12, $prefix = '') 唯一数字编码
*/
class UnIqIds extends Facade
{
/**
* 获取当前Facade对应类名或者已经绑定的容器对象标识
* @access protected
* @return string
*/
protected static function getFacadeClass()
{
return helper::class;
}
}

@ -1,49 +1,49 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace DtApp\ThinkLibrary\facade;
use DtApp\ThinkLibrary\helper\Urls as helper;
use think\Facade;
/**
* 网址门面
* @see \DtApp\ThinkLibrary\Urls
* @package DtApp\ThinkLibrary\Urls
* @package think\facade
* @mixin helper
*
* @method static string lenCode(string $url) 编码
* @method static string deCode(string $url) 解码
* @method static string toParams(array $data) 格式化参数格式化成url参数
* @method static bool isUrl(string $url) 判断是否为Url
* @method static string deleteProtocol(string $url) 删除协议
* @method static string retrieve(string $url) 获取URL文件格式
*/
class Urls extends Facade
{
/**
* 获取当前Facade对应类名或者已经绑定的容器对象标识
* @access protected
* @return string
*/
protected static function getFacadeClass()
{
return helper::class;
}
}
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace DtApp\ThinkLibrary\facade;
use DtApp\ThinkLibrary\helper\Urls as helper;
use think\Facade;
/**
* 网址门面
* @see \DtApp\ThinkLibrary\Urls
* @package DtApp\ThinkLibrary\Urls
* @package think\facade
* @mixin helper
*
* @method static string lenCode(string $url) 编码
* @method static string deCode(string $url) 解码
* @method static string toParams(array $data) 格式化参数格式化成url参数
* @method static bool isUrl(string $url) 判断是否为Url
* @method static string deleteProtocol(string $url) 删除协议
* @method static string retrieve(string $url) 获取URL文件格式
*/
class Urls extends Facade
{
/**
* 获取当前Facade对应类名或者已经绑定的容器对象标识
* @access protected
* @return string
*/
protected static function getFacadeClass()
{
return helper::class;
}
}

@ -1,45 +1,45 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace DtApp\ThinkLibrary\facade;
use DtApp\ThinkLibrary\helper\Xmls as helper;
use think\Facade;
/**
* XML门面
* @see \DtApp\ThinkLibrary\helper\Xmls
* @package DtApp\ThinkLibrary\Xmls
* @package think\facade
* @mixin helper
*
* @method static string toXml(array $values) 数组转换为xml
* @method static string toArray(string $xml) 将XML转为array
*/
class Xmls extends Facade
{
/**
* 获取当前Facade对应类名或者已经绑定的容器对象标识
* @access protected
* @return string
*/
protected static function getFacadeClass()
{
return helper::class;
}
}
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace DtApp\ThinkLibrary\facade;
use DtApp\ThinkLibrary\helper\Xmls as helper;
use think\Facade;
/**
* XML门面
* @see \DtApp\ThinkLibrary\helper\Xmls
* @package DtApp\ThinkLibrary\Xmls
* @package think\facade
* @mixin helper
*
* @method static string toXml(array $values) 数组转换为xml
* @method static string toArray(string $xml) 将XML转为array
*/
class Xmls extends Facade
{
/**
* 获取当前Facade对应类名或者已经绑定的容器对象标识
* @access protected
* @return string
*/
protected static function getFacadeClass()
{
return helper::class;
}
}

@ -1,187 +1,187 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace DtApp\ThinkLibrary\helper;
/**
* 数组管理类
* @mixin Arrays
* @package DtApp\ThinkLibrary\helper
*/
class Arrays
{
/**
* 数组随机返回一个下标
* @param $array
* @return mixed
*/
public function rand(array $array)
{
return array_rand($array);
}
/**
* 数组随机返回一个值
* @param $array
* @return mixed
*/
public function randValue(array $array)
{
return $array[array_rand($array)];
}
/**
* 分隔数组
* @param array $array 数组
* @param int $num 数量
* @return array
*/
public function split(array $array, $num = 5): array
{
$arrRet = array();
if (!isset($array) || empty($array)) {
return $arrRet;
}
$iCount = count($array) / $num;
if (!is_int($iCount)) {
$iCount = ceil($iCount);
} else {
++$iCount;
}
for ($i = 0; $i < $iCount; ++$i) {
$arrInfos = array_slice($array, $i * $num, $num);
if (empty($arrInfos)) {
continue;
}
$arrRet[] = $arrInfos;
unset($arrInfos);
}
return $arrRet;
}
/**
* 多维数组去重
* @param array $array
* @return array
*/
public function unique(array $array): array
{
$out = array();
foreach ($array as $key => $value) {
if (!in_array($value, $out)) {
$out[$key] = $value;
}
}
$out = array_values($out);
return $out;
}
/**
* 二维数组根据某个键排序
* @param array $arrays
* @param string $sort_key
* @param int $sort_order
* @param int $sort_type
* @return array
*/
public function sort(array $arrays, string $sort_key, $sort_order = SORT_ASC, $sort_type = SORT_NUMERIC): array
{
$key_arrays = array();
if (is_array($arrays)) {
foreach ($arrays as $array) {
if (is_array($array)) {
$key_arrays[] = $array[$sort_key];
} else {
return [];
}
}
} else {
return [];
}
array_multisort($key_arrays, $sort_order, $sort_type, $arrays);
return $arrays;
}
/**
* 数组删除空格
* @param array $arr
* @return array
*/
public function trimArray(array $arr)
{
if (!is_array($arr)) {
return $arr;
}
foreach ($arr as $key => $value) {
if (is_array($value)) {
$arr[$key] = $this->TrimArray($value);
} else {
$arr[$key] = $this->trimAll($value);
}
}
return $arr;
}
/**
* 字符串删除空格
* @param $str
* @return string|string[]
*/
private function trimAll($str)
{
$oldchar = array(" ", " ", "\t", "\n", "\r");
$newchar = array("", "", "", "", "");
return str_replace($oldchar, $newchar, $str);
}
/**
* 把json字符串或json对象转json数组
* @param $output
* @return array
*/
public function toArray($output): array
{
if (is_array($output)) {
return $output;
}
if (is_object($output)) {
$output = json_encode($output, JSON_UNESCAPED_UNICODE);
}
return json_decode($output, true);
}
/**
* @param $array
* @return array
*/
public function valChunk($array,$name): array
{
$result = array();
$ar2 = [];
foreach ($array as $key => $value) {
foreach ($array as $k => $val) {
if ($value["{$name}"] == $val["{$name}"]) {
$ar2[] = $val;
}
}
$result[$value["{$name}"]] = $ar2;
$ar2 = [];
}
return $result;
}
}
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace DtApp\ThinkLibrary\helper;
/**
* 数组管理类
* @mixin Arrays
* @package DtApp\ThinkLibrary\helper
*/
class Arrays
{
/**
* 数组随机返回一个下标
* @param $array
* @return mixed
*/
public function rand(array $array)
{
return array_rand($array);
}
/**
* 数组随机返回一个值
* @param $array
* @return mixed
*/
public function randValue(array $array)
{
return $array[array_rand($array)];
}
/**
* 分隔数组
* @param array $array 数组
* @param int $num 数量
* @return array
*/
public function split(array $array, $num = 5): array
{
$arrRet = array();
if (!isset($array) || empty($array)) {
return $arrRet;
}
$iCount = count($array) / $num;
if (!is_int($iCount)) {
$iCount = ceil($iCount);
} else {
++$iCount;
}
for ($i = 0; $i < $iCount; ++$i) {
$arrInfos = array_slice($array, $i * $num, $num);
if (empty($arrInfos)) {
continue;
}
$arrRet[] = $arrInfos;
unset($arrInfos);
}
return $arrRet;
}
/**
* 多维数组去重
* @param array $array
* @return array
*/
public function unique(array $array): array
{
$out = array();
foreach ($array as $key => $value) {
if (!in_array($value, $out)) {
$out[$key] = $value;
}
}
$out = array_values($out);
return $out;
}
/**
* 二维数组根据某个键排序
* @param array $arrays
* @param string $sort_key
* @param int $sort_order
* @param int $sort_type
* @return array
*/
public function sort(array $arrays, string $sort_key, $sort_order = SORT_ASC, $sort_type = SORT_NUMERIC): array
{
$key_arrays = array();
if (is_array($arrays)) {
foreach ($arrays as $array) {
if (is_array($array)) {
$key_arrays[] = $array[$sort_key];
} else {
return [];
}
}
} else {
return [];
}
array_multisort($key_arrays, $sort_order, $sort_type, $arrays);
return $arrays;
}
/**
* 数组删除空格
* @param array $arr
* @return array
*/
public function trimArray(array $arr)
{
if (!is_array($arr)) {
return $arr;
}
foreach ($arr as $key => $value) {
if (is_array($value)) {
$arr[$key] = $this->TrimArray($value);
} else {
$arr[$key] = $this->trimAll($value);
}
}
return $arr;
}
/**
* 字符串删除空格
* @param $str
* @return string|string[]
*/
private function trimAll($str)
{
$oldchar = array(" ", " ", "\t", "\n", "\r");
$newchar = array("", "", "", "", "");
return str_replace($oldchar, $newchar, $str);
}
/**
* 把json字符串或json对象转json数组
* @param $output
* @return array
*/
public function toArray($output): array
{
if (is_array($output)) {
return $output;
}
if (is_object($output)) {
$output = json_encode($output, JSON_UNESCAPED_UNICODE);
}
return json_decode($output, true);
}
/**
* @param $array
* @return array
*/
public function valChunk($array,$name): array
{
$result = array();
$ar2 = [];
foreach ($array as $key => $value) {
foreach ($array as $k => $val) {
if ($value["{$name}"] == $val["{$name}"]) {
$ar2[] = $val;
}
}
$result[$value["{$name}"]] = $ar2;
$ar2 = [];
}
return $result;
}
}

@ -1,38 +1,38 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace DtApp\ThinkLibrary\helper;
/**
* 日期管理类
* @mixin Dates
* @package DtApp\ThinkLibrary\helper
*/
class Dates
{
/**
* 当前日期
* @param string $format 格式
* @return false|string
*/
public function current(string $format = "Y-m-d")
{
date_default_timezone_set('Asia/Shanghai');
return date($format);
}
}
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace DtApp\ThinkLibrary\helper;
/**
* 日期管理类
* @mixin Dates
* @package DtApp\ThinkLibrary\helper
*/
class Dates
{
/**
* 当前日期
* @param string $format 格式
* @return false|string
*/
public function current(string $format = "Y-m-d")
{
date_default_timezone_set('Asia/Shanghai');
return date($format);
}
}

@ -1,82 +1,82 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace DtApp\ThinkLibrary\helper;
/**
* 小数管理类
* @mixin Decimals
* @package DtApp\ThinkLibrary\helper
*/
class Decimals
{
/**
* 直接取整,舍弃小数保留整数
* @param $num
* @return int
*/
public function intval($num): int
{
return (int)$num;
}
/**
* 四舍五入取整
* @param $num
* @param int $bl
* @return float
*/
public function round($num, $bl = 0): float
{
return round($num, $bl);
}
/**
* 有小数,就在整数的基础上加一
* @param $num
* @return false|float
*/
public function ceil($num)
{
return ceil($num);
}
/**
* 有小数,就取整数位
* @param $num
* @return false|float
*/
public function floor($num)
{
return floor($num);
}
/**
* 判断是不是小数
* @param $num
* @return bool
*/
public function judge($num): bool
{
if (is_int($num)) {
return false;
}
return true;
}
}
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace DtApp\ThinkLibrary\helper;
/**
* 小数管理类
* @mixin Decimals
* @package DtApp\ThinkLibrary\helper
*/
class Decimals
{
/**
* 直接取整,舍弃小数保留整数
* @param $num
* @return int
*/
public function intval($num): int
{
return (int)$num;
}
/**
* 四舍五入取整
* @param $num
* @param int $bl
* @return float
*/
public function round($num, $bl = 0): float
{
return round($num, $bl);
}
/**
* 有小数,就在整数的基础上加一
* @param $num
* @return false|float
*/
public function ceil($num)
{
return ceil($num);
}
/**
* 有小数,就取整数位
* @param $num
* @return false|float
*/
public function floor($num)
{
return floor($num);
}
/**
* 判断是不是小数
* @param $num
* @return bool
*/
public function judge($num): bool
{
if (is_int($num)) {
return false;
}
return true;
}
}

@ -1,185 +1,185 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace DtApp\ThinkLibrary\helper;
use DtApp\ThinkLibrary\exception\DtaException;
use think\Exception;
use ZipArchive;
/**
* 文件管理类
* @mixin Files
* @package DtApp\ThinkLibrary\helper
*/
class Files
{
/**
* 删除文件
* @param string $name 路径
* @return bool
* @throws DtaException
*/
public function delete(string $name): bool
{
if (empty($name)) {
throw new DtaException('请检查需要删除文件夹的名称');
}
return file_exists($name) && unlink($name);
}
/**
* 删除文件夹
* @param string $name 路径
* @return bool
* @throws DtaException
* @throws Exception
*/
public function deletes(string $name): bool
{
if (empty($name)) {
throw new DtaException('请检查需要删除文件夹的名称');
}
//先删除目录下的文件:
$dh = opendir($name);
while ($file = readdir($dh)) {
if ($file !== "." && $file !== "..") {
$fullpath = $name . "/" . $file;
if (!is_dir($fullpath)) {
unlink($fullpath);
} else {
$this->deletes($fullpath);
}
}
}
closedir($dh);
//删除当前文件夹:
if (rmdir($name)) {
return true;
}
return false;
}
/**
* 把文件夹里面的文件打包成zip文件
* @param string $name 路径
* @param string $suffix_name 需要打包的后缀名,默认.png
* @param string $file_name 文件名,默认全部名
* @return bool
* @throws DtaException
*/
public function folderZip(string $name, string $suffix_name = '.png', string $file_name = '*'): bool
{
if (empty($name)) {
throw new DtaException('请检查需要打包的路径名称');
}
$list = glob($name . "{$file_name}.{$suffix_name}");
$fileList = $list;
$zip = new ZipArchive();
// 打开压缩包
$zip->open($name, ZipArchive::CREATE);
//向压缩包中添加文件
foreach ($fileList as $file) {
$zip->addFile($file, basename($file));
}
//关闭压缩包
$zip->close();
return true;
}
/**
* 获取目录下的所有文件和目录
* @param string $path
* @return array
*/
public function getFiles(string $path): array
{
$files = [];
if (is_dir($path)) {
$path = dirname($path) . '/' . basename($path) . '/';
$file = dir($path);
while (false !== ($entry = $file->read())) {
if ($entry !== '.' && $entry !== '..') {
$cur = $path . $entry;
if (is_dir($cur)) {
$subPath = $cur . '/';
$this->getFiles($subPath);
}
$files[] = $cur;
}
}
$file->close();
return $files;
}
return [];
}
/**
* 删除目录下的文件
* @param string $path
* @return bool
*/
public function rmFiles(string $path): bool
{
$files = $this->getFiles($path);
if (!is_array($files)) {
return false;
}
if (empty($files)) {
return false;
}
foreach ($files as $item => $file) {
if (is_dir($file)) {
rmdir($file);
} elseif (is_file($file)) {
unlink($file);
}
}
return true;
}
/**
* 判断文件是否存在
* @param string $path
* @return bool
*/
public function judgeFile(string $path): bool
{
if (file_exists($path)) {
return true;
}
return false;
}
/**
* 判断目录是否存在
* @param string $path
* @return bool
*/
public function judgeContents(string $path): bool
{
if (is_dir($path)) {
return true;
}
return false;
}
}
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace DtApp\ThinkLibrary\helper;
use DtApp\ThinkLibrary\exception\DtaException;
use think\Exception;
use ZipArchive;
/**
* 文件管理类
* @mixin Files
* @package DtApp\ThinkLibrary\helper
*/
class Files
{
/**
* 删除文件
* @param string $name 路径
* @return bool
* @throws DtaException
*/
public function delete(string $name): bool
{
if (empty($name)) {
throw new DtaException('请检查需要删除文件夹的名称');
}
return file_exists($name) && unlink($name);
}
/**
* 删除文件夹
* @param string $name 路径
* @return bool
* @throws DtaException
* @throws Exception
*/
public function deletes(string $name): bool
{
if (empty($name)) {
throw new DtaException('请检查需要删除文件夹的名称');
}
//先删除目录下的文件:
$dh = opendir($name);
while ($file = readdir($dh)) {
if ($file !== "." && $file !== "..") {
$fullpath = $name . "/" . $file;
if (!is_dir($fullpath)) {
unlink($fullpath);
} else {
$this->deletes($fullpath);
}
}
}
closedir($dh);
//删除当前文件夹:
if (rmdir($name)) {
return true;
}
return false;
}
/**
* 把文件夹里面的文件打包成zip文件
* @param string $name 路径
* @param string $suffix_name 需要打包的后缀名,默认.png
* @param string $file_name 文件名,默认全部名
* @return bool
* @throws DtaException
*/
public function folderZip(string $name, string $suffix_name = '.png', string $file_name = '*'): bool
{
if (empty($name)) {
throw new DtaException('请检查需要打包的路径名称');
}
$list = glob($name . "{$file_name}.{$suffix_name}");
$fileList = $list;
$zip = new ZipArchive();
// 打开压缩包
$zip->open($name, ZipArchive::CREATE);
//向压缩包中添加文件
foreach ($fileList as $file) {
$zip->addFile($file, basename($file));
}
//关闭压缩包
$zip->close();
return true;
}
/**
* 获取目录下的所有文件和目录
* @param string $path
* @return array
*/
public function getFiles(string $path): array
{
$files = [];
if (is_dir($path)) {
$path = dirname($path) . '/' . basename($path) . '/';
$file = dir($path);
while (false !== ($entry = $file->read())) {
if ($entry !== '.' && $entry !== '..') {
$cur = $path . $entry;
if (is_dir($cur)) {
$subPath = $cur . '/';
$this->getFiles($subPath);
}
$files[] = $cur;
}
}
$file->close();
return $files;
}
return [];
}
/**
* 删除目录下的文件
* @param string $path
* @return bool
*/
public function rmFiles(string $path): bool
{
$files = $this->getFiles($path);
if (!is_array($files)) {
return false;
}
if (empty($files)) {
return false;
}
foreach ($files as $item => $file) {
if (is_dir($file)) {
rmdir($file);
} elseif (is_file($file)) {
unlink($file);
}
}
return true;
}
/**
* 判断文件是否存在
* @param string $path
* @return bool
*/
public function judgeFile(string $path): bool
{
if (file_exists($path)) {
return true;
}
return false;
}
/**
* 判断目录是否存在
* @param string $path
* @return bool
*/
public function judgeContents(string $path): bool
{
if (is_dir($path)) {
return true;
}
return false;
}
}

@ -1,47 +1,47 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace DtApp\ThinkLibrary\helper;
/**
* 整数管理类
* @mixin Ints
* @package DtApp\ThinkLibrary\helper
*/
class Ints
{
/**
* 判断一个数是不是偶数
* @param int $num
* @return bool
*/
public function isEvenNumbers(int $num): bool
{
return $num % 2 === 0;
}
/**
* 判断一个数是不是奇数
* @param int $num
* @return bool
*/
public function isOddNumbers(int $num): bool
{
return !($num % 2 === 0);
}
}
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace DtApp\ThinkLibrary\helper;
/**
* 整数管理类
* @mixin Ints
* @package DtApp\ThinkLibrary\helper
*/
class Ints
{
/**
* 判断一个数是不是偶数
* @param int $num
* @return bool
*/
public function isEvenNumbers(int $num): bool
{
return $num % 2 === 0;
}
/**
* 判断一个数是不是奇数
* @param int $num
* @return bool
*/
public function isOddNumbers(int $num): bool
{
return !($num % 2 === 0);
}
}

@ -1,213 +1,213 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace DtApp\ThinkLibrary\helper;
/**
* 验证管理类
* @mixin Pregs
* @package DtApp\ThinkLibrary\helper
*/
class Pregs
{
/**
* 验证手机号码
* @access public
* @param $mobile
* @return bool
*/
public function isIphone($mobile): bool
{
if (preg_match('/^[1]([3-9])[0-9]{9}$/', $mobile)) {
return true;
}
return false;
}
/**
* 严谨验证手机号码
* 移动134 135 136 137 138 139 147 150 151 152 157 158 159 178 182 183 184 187 188 198
* 联通130 131 132 145 155 156 166 171 175 176 185 186
* 电信133 149 153 173 177 180 181 189 199
* 虚拟运营商: 170 195
* @access public
* @param $mobile
* @return bool
*/
public function isIphoneAll($mobile): bool
{
if (preg_match('/^[1](([3][0-9])|([4][5-9])|([5][0-3,5-9])|([6][5,6])|([7][0-8])|([8][0-9])|([9][1,5,8-9]))[0-9]{8}$/', $mobile)) {
return true;
}
return false;
}
/**
* 验证电话号码
* @access public
* @param $tel
* @return bool
*/
public function isTel($tel): bool
{
if (preg_match("/^(\(\d{3,4}\)|\d{3,4}-)?\d{7,8}$/", $tel)) {
return true;
}
return false;
}
/**
* 验证身份证号15位或18位数字
* @access public
* @param int $id 身份证号码
* @return bool
*/
public function isIdCard($id): bool
{
if (preg_match("/^\d{15}|\d{18}$/", $id)) {
return true;
}
return false;
}
/**
* 验证是否是数字(这里小数点会认为是字符)
* @access public
* @param $digit
* @return bool
*/
public function isDigit($digit): bool
{
if (preg_match("/^\d*$/", $digit)) {
return true;
}
return false;
}
/**
* 验证是否是数字(可带小数点的数字)
* @access public
* @param $num
* @return bool
*/
public function isNum($num): bool
{
if (is_numeric($num)) {
return true;
}
return false;
}
/**
* 验证由数字、26个英文字母或者下划线组成的字符串
* @access public
* @param $str
* @return bool
*/
public function isStr($str): bool
{
if (preg_match("/^\w+$/", $str)) {
return true;
}
return false;
}
/**
* 验证用户密码(以字母开头长度在6-18之间只能包含字符、数字和下划线)
* @access public
* @param $str
* @return bool
*/
public function isPassword($str): bool
{
if (preg_match("/^[a-zA-Z]\w{5,17}$/", $str)) {
return true;
}
return false;
}
/**
* 验证汉字
* @access public
* @param $str
* @return bool
*/
public function isChinese($str): bool
{
if (preg_match("/^[\u4e00-\u9fa5],{0,}$/", $str)) {
return true;
}
return false;
}
/**
* 验证Email地址
* @access public
* @param $email
* @return bool
*/
public function isEmail($email): bool
{
if (preg_match("/^\w+[-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/", $email)) {
return true;
}
return false;
}
/**
* 验证网址URL
* @access public
* @param $url
* @return bool
*/
public function isLink($url): bool
{
if (preg_match("/http|https:\/\/[\w.]+[\w\/]*[\w.]*\??[\w=&\+\%]*/is", $url)) {
return true;
}
return false;
}
/**
* 腾讯QQ号
* @access public
* @param $qq
* @return bool
*/
public function isQq($qq): bool
{
if (preg_match("/^[1-9][0-9]{4,}$/", $qq)) {
return true;
}
return false;
}
/**
* 验证IP地址
* @access public
* @param $ip
* @return bool
*/
public function isIp($ip): bool
{
if (preg_match("/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/", $ip)) {
return true;
}
return false;
}
}
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace DtApp\ThinkLibrary\helper;
/**
* 验证管理类
* @mixin Pregs
* @package DtApp\ThinkLibrary\helper
*/
class Pregs
{
/**
* 验证手机号码
* @access public
* @param $mobile
* @return bool
*/
public function isIphone($mobile): bool
{
if (preg_match('/^[1]([3-9])[0-9]{9}$/', $mobile)) {
return true;
}
return false;
}
/**
* 严谨验证手机号码
* 移动134 135 136 137 138 139 147 150 151 152 157 158 159 178 182 183 184 187 188 198
* 联通130 131 132 145 155 156 166 171 175 176 185 186
* 电信133 149 153 173 177 180 181 189 199
* 虚拟运营商: 170 195
* @access public
* @param $mobile
* @return bool
*/
public function isIphoneAll($mobile): bool
{
if (preg_match('/^[1](([3][0-9])|([4][5-9])|([5][0-3,5-9])|([6][5,6])|([7][0-8])|([8][0-9])|([9][1,5,8-9]))[0-9]{8}$/', $mobile)) {
return true;
}
return false;
}
/**
* 验证电话号码
* @access public
* @param $tel
* @return bool
*/
public function isTel($tel): bool
{
if (preg_match("/^(\(\d{3,4}\)|\d{3,4}-)?\d{7,8}$/", $tel)) {
return true;
}
return false;
}
/**
* 验证身份证号15位或18位数字
* @access public
* @param int $id 身份证号码
* @return bool
*/
public function isIdCard($id): bool
{
if (preg_match("/^\d{15}|\d{18}$/", $id)) {
return true;
}
return false;
}
/**
* 验证是否是数字(这里小数点会认为是字符)
* @access public
* @param $digit
* @return bool
*/
public function isDigit($digit): bool
{
if (preg_match("/^\d*$/", $digit)) {
return true;
}
return false;
}
/**
* 验证是否是数字(可带小数点的数字)
* @access public
* @param $num
* @return bool
*/
public function isNum($num): bool
{
if (is_numeric($num)) {
return true;
}
return false;
}
/**
* 验证由数字、26个英文字母或者下划线组成的字符串
* @access public
* @param $str
* @return bool
*/
public function isStr($str): bool
{
if (preg_match("/^\w+$/", $str)) {
return true;
}
return false;
}
/**
* 验证用户密码(以字母开头长度在6-18之间只能包含字符、数字和下划线)
* @access public
* @param $str
* @return bool
*/
public function isPassword($str): bool
{
if (preg_match("/^[a-zA-Z]\w{5,17}$/", $str)) {
return true;
}
return false;
}
/**
* 验证汉字
* @access public
* @param $str
* @return bool
*/
public function isChinese($str): bool
{
if (preg_match("/^[\u4e00-\u9fa5],{0,}$/", $str)) {
return true;
}
return false;
}
/**
* 验证Email地址
* @access public
* @param $email
* @return bool
*/
public function isEmail($email): bool
{
if (preg_match("/^\w+[-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/", $email)) {
return true;
}
return false;
}
/**
* 验证网址URL
* @access public
* @param $url
* @return bool
*/
public function isLink($url): bool
{
if (preg_match("/http|https:\/\/[\w.]+[\w\/]*[\w.]*\??[\w=&\+\%]*/is", $url)) {
return true;
}
return false;
}
/**
* 腾讯QQ号
* @access public
* @param $qq
* @return bool
*/
public function isQq($qq): bool
{
if (preg_match("/^[1-9][0-9]{4,}$/", $qq)) {
return true;
}
return false;
}
/**
* 验证IP地址
* @access public
* @param $ip
* @return bool
*/
public function isIp($ip): bool
{
if (preg_match("/^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$/", $ip)) {
return true;
}
return false;
}
}

@ -1,93 +1,93 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace DtApp\ThinkLibrary\helper;
use Exception;
/**
* 随机管理类
* @mixin Randoms
* @package DtApp\ThinkLibrary\helper
*/
class Randoms
{
/**
* 生成随机
* @param int $length 长度
* @param int $type 类型1 纯数字2 纯小写字母3 纯大写字母4 数字和小写字母5 数字和大写字母6 大小写字母7 数字和大小写字母
* @return string
* @throws Exception
*/
public function generate(int $length = 6, int $type = 1): string
{
// 取字符集数组
$number = range(0, 9);
$lowerLetter = range('a', 'z');
$upperLetter = range('A', 'Z');
// 根据type合并字符集
if ($type === 1) {
$charset = $number;
} elseif ($type === 2) {
$charset = $lowerLetter;
} elseif ($type === 3) {
$charset = $upperLetter;
} elseif ($type === 4) {
$charset = array_merge($number, $lowerLetter);
} elseif ($type === 5) {
$charset = array_merge($number, $upperLetter);
} elseif ($type === 6) {
$charset = array_merge($lowerLetter, $upperLetter);
} elseif ($type === 7) {
$charset = array_merge($number, $lowerLetter, $upperLetter);
} else {
$charset = $number;
}
$str = '';
// 生成字符串
for ($i = 0; $i < $length; $i++) {
$str .= $charset[random_int(0, count($charset) - 1)];
// 验证规则
if ($type === 4 && strlen($str) >= 2) {
if (!preg_match('/\d+/', $str) || !preg_match('/[a-z]+/', $str)) {
$str = substr($str, 0, -1);
--$i;
}
}
if ($type === 5 && strlen($str) >= 2) {
if (!preg_match('/\d+/', $str) || !preg_match('/[A-Z]+/', $str)) {
$str = substr($str, 0, -1);
--$i;
}
}
if ($type === 6 && strlen($str) >= 2) {
if (!preg_match('/[a-z]+/', $str) || !preg_match('/[A-Z]+/', $str)) {
$str = substr($str, 0, -1);
--$i;
}
}
if ($type === 7 && strlen($str) >= 3) {
if (!preg_match('/\d+/', $str) || !preg_match('/[a-z]+/', $str) || !preg_match('/[A-Z]+/', $str)) {
$str = substr($str, 0, -2);
$i -= 2;
}
}
}
return $str;
}
}
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace DtApp\ThinkLibrary\helper;
use Exception;
/**
* 随机管理类
* @mixin Randoms
* @package DtApp\ThinkLibrary\helper
*/
class Randoms
{
/**
* 生成随机
* @param int $length 长度
* @param int $type 类型1 纯数字2 纯小写字母3 纯大写字母4 数字和小写字母5 数字和大写字母6 大小写字母7 数字和大小写字母
* @return string
* @throws Exception
*/
public function generate(int $length = 6, int $type = 1): string
{
// 取字符集数组
$number = range(0, 9);
$lowerLetter = range('a', 'z');
$upperLetter = range('A', 'Z');
// 根据type合并字符集
if ($type === 1) {
$charset = $number;
} elseif ($type === 2) {
$charset = $lowerLetter;
} elseif ($type === 3) {
$charset = $upperLetter;
} elseif ($type === 4) {
$charset = array_merge($number, $lowerLetter);
} elseif ($type === 5) {
$charset = array_merge($number, $upperLetter);
} elseif ($type === 6) {
$charset = array_merge($lowerLetter, $upperLetter);
} elseif ($type === 7) {
$charset = array_merge($number, $lowerLetter, $upperLetter);
} else {
$charset = $number;
}
$str = '';
// 生成字符串
for ($i = 0; $i < $length; $i++) {
$str .= $charset[random_int(0, count($charset) - 1)];
// 验证规则
if ($type === 4 && strlen($str) >= 2) {
if (!preg_match('/\d+/', $str) || !preg_match('/[a-z]+/', $str)) {
$str = substr($str, 0, -1);
--$i;
}
}
if ($type === 5 && strlen($str) >= 2) {
if (!preg_match('/\d+/', $str) || !preg_match('/[A-Z]+/', $str)) {
$str = substr($str, 0, -1);
--$i;
}
}
if ($type === 6 && strlen($str) >= 2) {
if (!preg_match('/[a-z]+/', $str) || !preg_match('/[A-Z]+/', $str)) {
$str = substr($str, 0, -1);
--$i;
}
}
if ($type === 7 && strlen($str) >= 3) {
if (!preg_match('/\d+/', $str) || !preg_match('/[a-z]+/', $str) || !preg_match('/[A-Z]+/', $str)) {
$str = substr($str, 0, -2);
$i -= 2;
}
}
}
return $str;
}
}

@ -1,228 +1,228 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace DtApp\ThinkLibrary\helper;
/**
* 请求管理类
* @mixin Requests
* @package DtApp\ThinkLibrary\helper
*/
class Requests
{
/**
* 判断输入的参数
* @param array $data
* @param array $arr
* @return array
*/
public function isEmpty(array $data, array $arr): array
{
foreach ($arr as $k => $v) {
if (empty($data[(string)$v] ?? '')) {
return [];
}
}
return $data;
}
/**
* 判断输入的参数为空就返回Json错误
* @param array $data
* @param array $arr
* @return array
*/
public function isEmptyRet(array $data, array $arr): array
{
foreach ($arr as $k => $v) {
if (empty($data[(string)$v] ?? '')) {
(new Returns)->jsonError('请检查参数', 102);
}
}
return $data;
}
/**
* 判断是否为GET方式
* @return bool
*/
public function isGet(): bool
{
return request()->isGet();
}
/**
* 判断是否为POST方式
* @return bool
*/
public function isPost(): bool
{
return request()->isPost();
}
/**
* 判断是否为PUT方式
* @return boolean
*/
public function isPut(): bool
{
return request()->isPut();
}
/**
* 判断是否为DELETE方式
* @return boolean
*/
public function isDelete(): bool
{
return request()->isDelete();
}
/**
* 判断是否为Ajax方式
* @return bool
*/
public function isAjax(): bool
{
return request()->isAjax();
}
/**
* 判断是否为移动端访问
* @return bool
*/
public function isMobile(): bool
{
// 如果有HTTP_X_WAP_PROFILE则一定是移动设备
if (isset($_SERVER['HTTP_X_WAP_PROFILE'])) {
return true;
}
//如果via信息含有wap则一定是移动设备,部分服务商会屏蔽该信息
//找不到为flase,否则为true
if (isset($_SERVER['HTTP_VIA'])) {
return stripos(request()->server('HTTP_VIA'), "wap") !== false;
}
//判断手机发送的客户端标志
if (isset($_SERVER['HTTP_USER_AGENT'])) {
$clientkeywords = [
'nokia', 'sony', 'ericsson', 'mot', 'samsung', 'htc', 'sgh', 'lg', 'sharp',
'sie-', 'philips', 'panasonic', 'alcatel', 'lenovo', 'iphone', 'ipod', 'blackberry', 'meizu',
'android', 'netfront', 'symbian', 'ucweb', 'windowsce', 'palm', 'operamini', 'operamobi',
'openwave', 'nexusone', 'cldc', 'midp', 'wap', 'mobile', 'alipay'
];
// 从HTTP_USER_AGENT中查找手机浏览器的关键字
if (preg_match("/(" . implode('|', $clientkeywords) . ")/i", strtolower(request()->server('HTTP_USER_AGENT')))) {
return true;
}
}
//协议法,因为有可能不准确,放到最后判断
// 如果只支持wml并且不支持html那一定是移动设备
// 如果支持wml和html但是wml在html之前则是移动设备
return isset($_SERVER['HTTP_ACCEPT']) && (strpos(request()->server('HTTP_ACCEPT'), 'vnd.wap.wml') !== false) && (strpos(request()->server('HTTP_ACCEPT'), 'text/html') === false || (strpos(request()->server('HTTP_ACCEPT'), 'vnd.wap.wml') < strpos(request()->server('HTTP_ACCEPT'), 'text/html')));
}
/**
* 判断是否微信内置浏览器访问
* @return bool
*/
public function isWeiXin(): bool
{
return strpos(request()->server('HTTP_USER_AGENT'), 'MicroMessenger') !== false;
}
/**
* 判断是否为微信小程序访问
* @return bool
*/
public function isWeiXinMp(): bool
{
return strpos(request()->server('HTTP_USER_AGENT'), 'miniProgram') !== false;
}
/**
* 判断是否支付宝内置浏览器访问
* @return bool
*/
public function isAliPay(): bool
{
return strpos(request()->server('HTTP_USER_AGENT'), 'Alipay') !== false;
}
/**
* 判断是否QQ内置浏览器访问
* @return bool
*/
public function isQQ(): bool
{
return (strpos(request()->server('HTTP_USER_AGENT'), 'QQ') !== false) && strpos(request()->server('HTTP_USER_AGENT'), '_SQ_') !== false;
}
/**
* 判断是否QQ浏览器访问
* @return bool
*/
public function isQQBrowser(): bool
{
if (strpos(request()->server('HTTP_USER_AGENT'), 'QQ') !== false) {
return !(strpos(request()->server('HTTP_USER_AGENT'), '_SQ_') !== false);
}
return false;
}
/**
* 获取客户端类型
* @return string
*/
public function getDeviceType()
{
$agent = strtolower(request()->server('HTTP_USER_AGENT'));
if (strpos($agent, 'iphone') || strpos($agent, 'ipad') || strpos($agent, 'android')) {
$type = 'mobile';
} else {
$type = 'computer';
}
return $type;
}
/**
* 获取手机设备类型
* @return string
*/
public function getMobileType()
{
$agent = strtolower(request()->server('HTTP_USER_AGENT'));
$type = 'other';
if (strpos($agent, 'iphone') || strpos($agent, 'ipad')) {
$type = 'ios';
}
if (strpos($agent, 'android')) {
$type = 'android';
}
return $type;
}
/**
* 获取域名地址
* @return string
*/
public function getWebsiteAddress(): string
{
$http_type = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https')) ? 'https://' : 'http://';
return $http_type . $_SERVER['HTTP_HOST'] . "/";
}
}
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace DtApp\ThinkLibrary\helper;
/**
* 请求管理类
* @mixin Requests
* @package DtApp\ThinkLibrary\helper
*/
class Requests
{
/**
* 判断输入的参数
* @param array $data
* @param array $arr
* @return array
*/
public function isEmpty(array $data, array $arr): array
{
foreach ($arr as $k => $v) {
if (empty($data[(string)$v] ?? '')) {
return [];
}
}
return $data;
}
/**
* 判断输入的参数为空就返回Json错误
* @param array $data
* @param array $arr
* @return array
*/
public function isEmptyRet(array $data, array $arr): array
{
foreach ($arr as $k => $v) {
if (empty($data[(string)$v] ?? '')) {
(new Returns)->jsonError('请检查参数', 102);
}
}
return $data;
}
/**
* 判断是否为GET方式
* @return bool
*/
public function isGet(): bool
{
return request()->isGet();
}
/**
* 判断是否为POST方式
* @return bool
*/
public function isPost(): bool
{
return request()->isPost();
}
/**
* 判断是否为PUT方式
* @return boolean
*/
public function isPut(): bool
{
return request()->isPut();
}
/**
* 判断是否为DELETE方式
* @return boolean
*/
public function isDelete(): bool
{
return request()->isDelete();
}
/**
* 判断是否为Ajax方式
* @return bool
*/
public function isAjax(): bool
{
return request()->isAjax();
}
/**
* 判断是否为移动端访问
* @return bool
*/
public function isMobile(): bool
{
// 如果有HTTP_X_WAP_PROFILE则一定是移动设备
if (isset($_SERVER['HTTP_X_WAP_PROFILE'])) {
return true;
}
//如果via信息含有wap则一定是移动设备,部分服务商会屏蔽该信息
//找不到为flase,否则为true
if (isset($_SERVER['HTTP_VIA'])) {
return stripos(request()->server('HTTP_VIA'), "wap") !== false;
}
//判断手机发送的客户端标志
if (isset($_SERVER['HTTP_USER_AGENT'])) {
$clientkeywords = [
'nokia', 'sony', 'ericsson', 'mot', 'samsung', 'htc', 'sgh', 'lg', 'sharp',
'sie-', 'philips', 'panasonic', 'alcatel', 'lenovo', 'iphone', 'ipod', 'blackberry', 'meizu',
'android', 'netfront', 'symbian', 'ucweb', 'windowsce', 'palm', 'operamini', 'operamobi',
'openwave', 'nexusone', 'cldc', 'midp', 'wap', 'mobile', 'alipay'
];
// 从HTTP_USER_AGENT中查找手机浏览器的关键字
if (preg_match("/(" . implode('|', $clientkeywords) . ")/i", strtolower(request()->server('HTTP_USER_AGENT')))) {
return true;
}
}
//协议法,因为有可能不准确,放到最后判断
// 如果只支持wml并且不支持html那一定是移动设备
// 如果支持wml和html但是wml在html之前则是移动设备
return isset($_SERVER['HTTP_ACCEPT']) && (strpos(request()->server('HTTP_ACCEPT'), 'vnd.wap.wml') !== false) && (strpos(request()->server('HTTP_ACCEPT'), 'text/html') === false || (strpos(request()->server('HTTP_ACCEPT'), 'vnd.wap.wml') < strpos(request()->server('HTTP_ACCEPT'), 'text/html')));
}
/**
* 判断是否微信内置浏览器访问
* @return bool
*/
public function isWeiXin(): bool
{
return strpos(request()->server('HTTP_USER_AGENT'), 'MicroMessenger') !== false;
}
/**
* 判断是否为微信小程序访问
* @return bool
*/
public function isWeiXinMp(): bool
{
return strpos(request()->server('HTTP_USER_AGENT'), 'miniProgram') !== false;
}
/**
* 判断是否支付宝内置浏览器访问
* @return bool
*/
public function isAliPay(): bool
{
return strpos(request()->server('HTTP_USER_AGENT'), 'Alipay') !== false;
}
/**
* 判断是否QQ内置浏览器访问
* @return bool
*/
public function isQQ(): bool
{
return (strpos(request()->server('HTTP_USER_AGENT'), 'QQ') !== false) && strpos(request()->server('HTTP_USER_AGENT'), '_SQ_') !== false;
}
/**
* 判断是否QQ浏览器访问
* @return bool
*/
public function isQQBrowser(): bool
{
if (strpos(request()->server('HTTP_USER_AGENT'), 'QQ') !== false) {
return !(strpos(request()->server('HTTP_USER_AGENT'), '_SQ_') !== false);
}
return false;
}
/**
* 获取客户端类型
* @return string
*/
public function getDeviceType()
{
$agent = strtolower(request()->server('HTTP_USER_AGENT'));
if (strpos($agent, 'iphone') || strpos($agent, 'ipad') || strpos($agent, 'android')) {
$type = 'mobile';
} else {
$type = 'computer';
}
return $type;
}
/**
* 获取手机设备类型
* @return string
*/
public function getMobileType()
{
$agent = strtolower(request()->server('HTTP_USER_AGENT'));
$type = 'other';
if (strpos($agent, 'iphone') || strpos($agent, 'ipad')) {
$type = 'ios';
}
if (strpos($agent, 'android')) {
$type = 'android';
}
return $type;
}
/**
* 获取域名地址
* @return string
*/
public function getWebsiteAddress(): string
{
$http_type = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https')) ? 'https://' : 'http://';
return $http_type . $_SERVER['HTTP_HOST'] . "/";
}
}

@ -1,87 +1,87 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace DtApp\ThinkLibrary\helper;
use think\exception\HttpResponseException;
/**
* 返回管理类
* @mixin Returns
* @package DtApp\ThinkLibrary\helper
*/
class Returns
{
public function __construct()
{
date_default_timezone_set('Asia/Shanghai');
header('Content-Type:application/json; charset=utf-8');
}
/**
* 返回Json-成功
* @param array $data 数据
* @param string $msg 描述
* @param int $code 状态
* @param array $ext 扩展字段
*/
public function jsonSuccess(array $data = [], string $msg = 'success', int $code = 0, array $ext = [])
{
if (!empty($ext) && is_array($ext)) {
throw new HttpResponseException(json(array_merge([
'code' => $code,
'msg' => $msg,
'time' => time(),
'data' => $data
], $ext)));
}
throw new HttpResponseException(json([
'code' => $code,
'msg' => $msg,
'time' => time(),
'data' => $data
]));
}
/**
* 返回Json-错误
* @param string $msg 描述
* @param int $code 状态码
* @param array $data 数据
* @param array $ext 扩展字段
*/
public function jsonError(string $msg = 'error', int $code = 1, array $data = [], array $ext = []): void
{
if (!empty($ext) && is_array($ext)) {
throw new HttpResponseException(json(array_merge([
'code' => $code,
'msg' => $msg,
'time' => time(),
'data' => $data
], $ext)));
}
throw new HttpResponseException(json([
'code' => $code,
'msg' => $msg,
'time' => time(),
'data' => $data
]));
}
}
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace DtApp\ThinkLibrary\helper;
use think\exception\HttpResponseException;
/**
* 返回管理类
* @mixin Returns
* @package DtApp\ThinkLibrary\helper
*/
class Returns
{
public function __construct()
{
date_default_timezone_set('Asia/Shanghai');
header('Content-Type:application/json; charset=utf-8');
}
/**
* 返回Json-成功
* @param array $data 数据
* @param string $msg 描述
* @param int $code 状态
* @param array $ext 扩展字段
*/
public function jsonSuccess(array $data = [], string $msg = 'success', int $code = 0, array $ext = [])
{
if (!empty($ext) && is_array($ext)) {
throw new HttpResponseException(json(array_merge([
'code' => $code,
'msg' => $msg,
'time' => time(),
'data' => $data
], $ext)));
}
throw new HttpResponseException(json([
'code' => $code,
'msg' => $msg,
'time' => time(),
'data' => $data
]));
}
/**
* 返回Json-错误
* @param string $msg 描述
* @param int $code 状态码
* @param array $data 数据
* @param array $ext 扩展字段
*/
public function jsonError(string $msg = 'error', int $code = 1, array $data = [], array $ext = []): void
{
if (!empty($ext) && is_array($ext)) {
throw new HttpResponseException(json(array_merge([
'code' => $code,
'msg' => $msg,
'time' => time(),
'data' => $data
], $ext)));
}
throw new HttpResponseException(json([
'code' => $code,
'msg' => $msg,
'time' => time(),
'data' => $data
]));
}
}

@ -1,124 +1,124 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace DtApp\ThinkLibrary\helper;
/**
* 字符串管理类
* @mixin Strings
* @package DtApp\ThinkLibrary\helper
*/
class Strings
{
/**
* 截取字符串前面n个字符
* @param string $str 字符串
* @param int $start_num 开始位置
* @param int $end_num 多少个
* @return string
*/
public function extractBefore(string $str, int $start_num, int $end_num): string
{
if (strlen($str) < $start_num + $end_num) {
return $str;
}
return substr($str, $start_num, $end_num);
}
/**
* 截取字符串最后n个字符
* 截取字符串最后n个字符
* @param string $str 字符串
* @param int $num 多少个
* @return string
*/
public function extractRear(string $str, int $num): string
{
if (strlen($str) <= $num) {
return $str;
}
return substr($str, -$num);
}
/**
* 过滤字符串
* @param string $str
* @return string
*/
public function filter(string $str): string
{
$str = str_replace(array('`', '·', '~', '!', '', '@', '#', '$', '¥', '%', '^', '……', '&', '*', '(', ')', '', '', '-', '_', '——', '+', '=', '|', '\\', '[', ']', '【', '】', '{', '}', ';', '', ':', '', '\'', '"', '“', '”', ',', '', '<', '>', '《', '》', '.', '。', '/', '、', '?', '', '╮', '(', ')', 'r', 'ぷ', '〆', 'ゞ', 'ヤ', 'ゼ', 'ǎ', 'ǎ', '〆', 'む', '§', '上门'), '', $str);
return trim($str);
}
/**
* 判断字符串是否包含某个字符
* @param $str
* @param int $nee
* @param string $del
* @return bool
*/
public function exitContain(string $str, $nee = 3, $del = ','): bool
{
if (strpos($str, $del) !== false) {
$var = explode($del, $str);
foreach ($var as $v) {
if ($v === $nee) {
return true;
}
}
return false;
}
return $str === $nee;
}
/**
* 统计字符串长度
* @param string $str 字符串
* @return int
*/
public function len(string $str): int
{
return strlen($str);
}
/**
* 字符串删除空格
* @param $str
* @return string|string[]
*/
public function trimAll($str): string
{
$oldchar = array(" ", " ", "\t", "\n", "\r");
$newchar = array("", "", "", "", "");
return str_replace($oldchar, $newchar, $str);
}
/**
* 替换字符串
* @param string $search
* @param string $replace
* @param string $subject
* @return string|string[]
*/
public function replace(string $search, string $replace, string $subject)
{
return str_replace($search, $replace, $subject);
}
}
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace DtApp\ThinkLibrary\helper;
/**
* 字符串管理类
* @mixin Strings
* @package DtApp\ThinkLibrary\helper
*/
class Strings
{
/**
* 截取字符串前面n个字符
* @param string $str 字符串
* @param int $start_num 开始位置
* @param int $end_num 多少个
* @return string
*/
public function extractBefore(string $str, int $start_num, int $end_num): string
{
if (strlen($str) < $start_num + $end_num) {
return $str;
}
return substr($str, $start_num, $end_num);
}
/**
* 截取字符串最后n个字符
* 截取字符串最后n个字符
* @param string $str 字符串
* @param int $num 多少个
* @return string
*/
public function extractRear(string $str, int $num): string
{
if (strlen($str) <= $num) {
return $str;
}
return substr($str, -$num);
}
/**
* 过滤字符串
* @param string $str
* @return string
*/
public function filter(string $str): string
{
$str = str_replace(array('`', '·', '~', '!', '', '@', '#', '$', '¥', '%', '^', '……', '&', '*', '(', ')', '', '', '-', '_', '——', '+', '=', '|', '\\', '[', ']', '【', '】', '{', '}', ';', '', ':', '', '\'', '"', '“', '”', ',', '', '<', '>', '《', '》', '.', '。', '/', '、', '?', '', '╮', '(', ')', 'r', 'ぷ', '〆', 'ゞ', 'ヤ', 'ゼ', 'ǎ', 'ǎ', '〆', 'む', '§', '上门'), '', $str);
return trim($str);
}
/**
* 判断字符串是否包含某个字符
* @param $str
* @param int $nee
* @param string $del
* @return bool
*/
public function exitContain(string $str, $nee = 3, $del = ','): bool
{
if (strpos($str, $del) !== false) {
$var = explode($del, $str);
foreach ($var as $v) {
if ($v === $nee) {
return true;
}
}
return false;
}
return $str === $nee;
}
/**
* 统计字符串长度
* @param string $str 字符串
* @return int
*/
public function len(string $str): int
{
return strlen($str);
}
/**
* 字符串删除空格
* @param $str
* @return string|string[]
*/
public function trimAll($str): string
{
$oldchar = array(" ", " ", "\t", "\n", "\r");
$newchar = array("", "", "", "", "");
return str_replace($oldchar, $newchar, $str);
}
/**
* 替换字符串
* @param string $search
* @param string $replace
* @param string $subject
* @return string|string[]
*/
public function replace(string $search, string $replace, string $subject)
{
return str_replace($search, $replace, $subject);
}
}

@ -1,150 +1,150 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace DtApp\ThinkLibrary\helper;
/**
* 时间管理类
* @mixin Times
* @package DtApp\ThinkLibrary\helper
*/
class Times
{
/**
* 当前时间
* @param string $format 格式
* @return false|string
*/
public function getData(string $format = "Y-m-d H:i:s")
{
date_default_timezone_set('Asia/Shanghai');
return date($format, time());
}
/**
* 当前时间戳
* @return false|string
*/
public function getTime()
{
date_default_timezone_set('Asia/Shanghai');
return time();
}
/**
* 毫秒时间
* @return false|string
*/
public function getUDate()
{
date_default_timezone_set('Asia/Shanghai');
$msec = 0;
list($msec, $sec) = explode(' ', microtime());
return (float)sprintf('%.0f', ((float)$msec + (float)$sec) * 1000);
}
/**
* 计算两个时间差
* @param string $end_time 结束时间
* @param string $start_time 开始时间
* @return false|int
*/
public function getTimeDifference(string $end_time, string $start_time)
{
date_default_timezone_set('Asia/Shanghai');
$end_time = strtotime($end_time);
$start_time = $start_time === '' ? time() : strtotime($start_time);
return $end_time - $start_time;
}
/**
* 将指定日期转换为时间戳
* @param string $date
* @return false|int
*/
public function dateToTimestamp(string $date)
{
date_default_timezone_set('Asia/Shanghai');
return strtotime($date);
}
/**
* 将指定时间戳转换为日期
* @param string $format
* @param int $time
* @return false|string
*/
public function timestampToDate(int $time, string $format = "Y-m-d H:i:s")
{
date_default_timezone_set('Asia/Shanghai');
return date($format, $time);
}
/**
* 在某个时间之前的时间
* @param string $format 格式
* @param int $mun 多少秒
* @param int $time
* @return false|string
*/
public function dateBefore(string $format = "Y-m-d H:i:s", int $mun = 60, int $time = 0)
{
date_default_timezone_set('Asia/Shanghai');
if (empty($time)) {
$time = time();
}
return date($format, $time - $mun);
}
/**
* 在某个时间之后的时间
* @param string $format 格式
* @param int $mun 多少秒
* @param int $time
* @return false|string
*/
public function dateRear(string $format = "Y-m-d H:i:s", int $mun = 60, int $time = 0)
{
date_default_timezone_set('Asia/Shanghai');
if (empty($time)) {
$time = time();
}
return date($format, $time + $mun);
}
/**
* 判断当前的时分是否在指定的时间段内
* @param string $start 开始时间
* @param string $end 结束时间
* @return bool true在范围内false:没在范围内
*/
public function checkIsBetweenTime(string $start, string $end)
{
date_default_timezone_set('Asia/Shanghai');
$date = date('H:i');
$curTime = strtotime($date);//当前时分
$assignTime1 = strtotime($start);//获得指定分钟时间戳00:00
$assignTime2 = strtotime($end);//获得指定分钟时间戳01:00
$result = false;
if ($curTime > $assignTime1 && $curTime < $assignTime2) {
$result = true;
}
return $result;
}
}
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace DtApp\ThinkLibrary\helper;
/**
* 时间管理类
* @mixin Times
* @package DtApp\ThinkLibrary\helper
*/
class Times
{
/**
* 当前时间
* @param string $format 格式
* @return false|string
*/
public function getData(string $format = "Y-m-d H:i:s")
{
date_default_timezone_set('Asia/Shanghai');
return date($format, time());
}
/**
* 当前时间戳
* @return false|string
*/
public function getTime()
{
date_default_timezone_set('Asia/Shanghai');
return time();
}
/**
* 毫秒时间
* @return false|string
*/
public function getUDate()
{
date_default_timezone_set('Asia/Shanghai');
$msec = 0;
list($msec, $sec) = explode(' ', microtime());
return (float)sprintf('%.0f', ((float)$msec + (float)$sec) * 1000);
}
/**
* 计算两个时间差
* @param string $end_time 结束时间
* @param string $start_time 开始时间
* @return false|int
*/
public function getTimeDifference(string $end_time, string $start_time)
{
date_default_timezone_set('Asia/Shanghai');
$end_time = strtotime($end_time);
$start_time = $start_time === '' ? time() : strtotime($start_time);
return $end_time - $start_time;
}
/**
* 将指定日期转换为时间戳
* @param string $date
* @return false|int
*/
public function dateToTimestamp(string $date)
{
date_default_timezone_set('Asia/Shanghai');
return strtotime($date);
}
/**
* 将指定时间戳转换为日期
* @param string $format
* @param int $time
* @return false|string
*/
public function timestampToDate(int $time, string $format = "Y-m-d H:i:s")
{
date_default_timezone_set('Asia/Shanghai');
return date($format, $time);
}
/**
* 在某个时间之前的时间
* @param string $format 格式
* @param int $mun 多少秒
* @param int $time
* @return false|string
*/
public function dateBefore(string $format = "Y-m-d H:i:s", int $mun = 60, int $time = 0)
{
date_default_timezone_set('Asia/Shanghai');
if (empty($time)) {
$time = time();
}
return date($format, $time - $mun);
}
/**
* 在某个时间之后的时间
* @param string $format 格式
* @param int $mun 多少秒
* @param int $time
* @return false|string
*/
public function dateRear(string $format = "Y-m-d H:i:s", int $mun = 60, int $time = 0)
{
date_default_timezone_set('Asia/Shanghai');
if (empty($time)) {
$time = time();
}
return date($format, $time + $mun);
}
/**
* 判断当前的时分是否在指定的时间段内
* @param string $start 开始时间
* @param string $end 结束时间
* @return bool true在范围内false:没在范围内
*/
public function checkIsBetweenTime(string $start, string $end)
{
date_default_timezone_set('Asia/Shanghai');
$date = date('H:i');
$curTime = strtotime($date);//当前时分
$assignTime1 = strtotime($start);//获得指定分钟时间戳00:00
$assignTime2 = strtotime($end);//获得指定分钟时间戳01:00
$result = false;
if ($curTime > $assignTime1 && $curTime < $assignTime2) {
$result = true;
}
return $result;
}
}

@ -1,98 +1,98 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace DtApp\ThinkLibrary\helper;
use Exception;
/**
* 唯一ID管理类
* @mixin UnIqIds
* @package DtApp\ThinkLibrary\helper
*/
class UnIqIds
{
/**
* 获取随机字符串编码
* @param integer $size 字符串长度
* @param integer $type 字符串类型(1纯数字,2纯字母,3数字字母)
* @param string $prefix 编码前缀
* @return string
* @throws Exception
*/
public function random($size = 10, $type = 1, $prefix = ''): string
{
$numbs = '0123456789';
$chars = 'abcdefghijklmnopqrstuvwxyz';
if ((int)$type === 1) {
$chars = $numbs;
}
if ((int)$type === 2) {
$chars = ($chars);
}
if ((int)$type === 3) {
$chars = "{$numbs}{$chars}";
}
$string = $prefix . $chars[random_int(1, strlen($chars) - 1)];
if (isset($chars)) {
while (strlen($string) < $size) {
$string .= $chars[random_int(0, strlen($chars) - 1)];
}
}
return $string;
}
/**
* 唯一日期编码
* @param integer $size
* @param string $prefix
* @return string
* @throws Exception
*/
public function date($size = 16, $prefix = ''): string
{
if ($size < 14) {
$size = 14;
}
$string = $prefix . date('Ymd') . (date('H') + date('i')) . date('s');
while (strlen($string) < $size) {
$string .= random_int(0, 9);
}
return $string;
}
/**
* 唯一数字编码
* @param integer $size
* @param string $prefix
* @return string
* @throws Exception
*/
public function number($size = 12, $prefix = ''): string
{
$time = time() . '';
if ($size < 10) {
$size = 10;
}
$string = $prefix . ($time[0] . $time[1]) . substr($time, 2) . random_int(0, 9);
while (strlen($string) < $size) {
$string .= random_int(0, 9);
}
return $string;
}
}
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace DtApp\ThinkLibrary\helper;
use Exception;
/**
* 唯一ID管理类
* @mixin UnIqIds
* @package DtApp\ThinkLibrary\helper
*/
class UnIqIds
{
/**
* 获取随机字符串编码
* @param integer $size 字符串长度
* @param integer $type 字符串类型(1纯数字,2纯字母,3数字字母)
* @param string $prefix 编码前缀
* @return string
* @throws Exception
*/
public function random($size = 10, $type = 1, $prefix = ''): string
{
$numbs = '0123456789';
$chars = 'abcdefghijklmnopqrstuvwxyz';
if ((int)$type === 1) {
$chars = $numbs;
}
if ((int)$type === 2) {
$chars = ($chars);
}
if ((int)$type === 3) {
$chars = "{$numbs}{$chars}";
}
$string = $prefix . $chars[random_int(1, strlen($chars) - 1)];
if (isset($chars)) {
while (strlen($string) < $size) {
$string .= $chars[random_int(0, strlen($chars) - 1)];
}
}
return $string;
}
/**
* 唯一日期编码
* @param integer $size
* @param string $prefix
* @return string
* @throws Exception
*/
public function date($size = 16, $prefix = ''): string
{
if ($size < 14) {
$size = 14;
}
$string = $prefix . date('Ymd') . (date('H') + date('i')) . date('s');
while (strlen($string) < $size) {
$string .= random_int(0, 9);
}
return $string;
}
/**
* 唯一数字编码
* @param integer $size
* @param string $prefix
* @return string
* @throws Exception
*/
public function number($size = 12, $prefix = ''): string
{
$time = time() . '';
if ($size < 10) {
$size = 10;
}
$string = $prefix . ($time[0] . $time[1]) . substr($time, 2) . random_int(0, 9);
while (strlen($string) < $size) {
$string .= random_int(0, 9);
}
return $string;
}
}

@ -1,116 +1,116 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace DtApp\ThinkLibrary\helper;
/**
* 网址管理类
* @mixin Urls
* @package DtApp\ThinkLibrary\helper
*/
class Urls
{
/**
* 编码
* @param string $url
* @return string
*/
public function lenCode(string $url): string
{
if (empty($url)) {
return '';
}
return urlencode($url);
}
/**
* 解码
* @param string $url
* @return string
*/
public function deCode(string $url): string
{
if (empty($url)) {
return '';
}
return urldecode($url);
}
/**
* 格式化参数格式化成url参数
* @param array $data
* @return string
*/
public function toParams(array $data): string
{
$buff = "";
foreach ($data as $k => $v) {
if ($k !== "sign" && $v !== "" && !is_array($v)) {
$buff .= $k . "=" . $v . "&";
}
}
$buff = trim($buff, "&");
return $buff;
}
/**
* 判断是否为Url
* @param string $url
* @return bool
*/
public function isUrl(string $url): bool
{
$pattern = "#(http|https)://(.*\.)?.*\..*#i";
if (preg_match($pattern, $url)) {
return true;
}
return false;
}
/**
* 删除协议
* @param string $url
* @return string
*/
public function deleteProtocol(string $url): string
{
if (empty($this->isUrl($url))) {
return $url;
}
if (strpos($url, 'https://') !== false) {
return str_replace("https://", "//", $url);
}
if (strpos($url, 'http://') !== false) {
return str_replace("http://", "//", $url);
}
return $url;
}
/**
* 获取URL文件格式
* @param string $url
* @return mixed|string
*/
public function retrieve(string $url)
{
$path = parse_url($url);
$str = explode('.', $path['path']);
return $str[1];
}
}
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace DtApp\ThinkLibrary\helper;
/**
* 网址管理类
* @mixin Urls
* @package DtApp\ThinkLibrary\helper
*/
class Urls
{
/**
* 编码
* @param string $url
* @return string
*/
public function lenCode(string $url): string
{
if (empty($url)) {
return '';
}
return urlencode($url);
}
/**
* 解码
* @param string $url
* @return string
*/
public function deCode(string $url): string
{
if (empty($url)) {
return '';
}
return urldecode($url);
}
/**
* 格式化参数格式化成url参数
* @param array $data
* @return string
*/
public function toParams(array $data): string
{
$buff = "";
foreach ($data as $k => $v) {
if ($k !== "sign" && $v !== "" && !is_array($v)) {
$buff .= $k . "=" . $v . "&";
}
}
$buff = trim($buff, "&");
return $buff;
}
/**
* 判断是否为Url
* @param string $url
* @return bool
*/
public function isUrl(string $url): bool
{
$pattern = "#(http|https)://(.*\.)?.*\..*#i";
if (preg_match($pattern, $url)) {
return true;
}
return false;
}
/**
* 删除协议
* @param string $url
* @return string
*/
public function deleteProtocol(string $url): string
{
if (empty($this->isUrl($url))) {
return $url;
}
if (strpos($url, 'https://') !== false) {
return str_replace("https://", "//", $url);
}
if (strpos($url, 'http://') !== false) {
return str_replace("http://", "//", $url);
}
return $url;
}
/**
* 获取URL文件格式
* @param string $url
* @return mixed|string
*/
public function retrieve(string $url)
{
$path = parse_url($url);
$str = explode('.', $path['path']);
return $str[1];
}
}

@ -1,78 +1,78 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary\helper;
use DtApp\ThinkLibrary\Helper;
use think\Validate;
class ValidateHelper extends Helper
{
/**
* 快捷输入并验证( 支持 规则 # 别名
*
* age.require => message // 最大值限定
* age.between:1,120 => message // 范围限定
* name.require => message // 必填内容
* name.default => 100 // 获取并设置默认值
* region.value => value // 固定字段数值内容
* 更多规则参照 ThinkPHP 官方的验证类
*
* @param array $rules 验证规则( 验证信息数组
* @param string $input 输入内容 ( post. 或 get. )
* @param callable|null $callable 异常处理操作
* @return array
*/
public function init(array $rules, $input = '', ?callable $callable = null): array
{
if (is_string($input)) {
$type = trim($input, '.') ?: 'request';
$input = $this->app->request->$type();
}
[$data, $rule, $info] = [[], [], []];
foreach ($rules as $name => $message) {
if (is_numeric($name)) {
[$name, $alias] = explode('#', $message . '#');
$data[$name] = $input[($alias ?: $name)] ?? null;
} elseif (strpos($name, '.') === false) {
$data[$name] = $message;
} elseif (preg_match('|^(.*?)\.(.*?)#(.*?)#?$|', $name . '#', $matches)) {
[, $_key, $_rule, $alias] = $matches;
if (in_array($_rule, ['value', 'default'])) {
if ($_rule === 'value') {
$data[$_key] = $message;
} elseif ($_rule === 'default') {
$data[$_key] = $input[($alias ?: $_key)] ?? $message;
}
} else {
$info[explode(':', $name)[0]] = $message;
$data[$_key] = $data[$_key] ?? ($input[($alias ?: $_key)] ?? null);
$rule[$_key] = isset($rule[$_key]) ? ($rule[$_key] . '|' . $_rule) : $_rule;
}
}
}
$validate = new Validate();
if ($validate->rule($rule)->message($info)->check($data)) {
return $data;
}
if (is_callable($callable)) {
return $callable($validate->getError());
}
$this->class->error($validate->getError());
}
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary\helper;
use DtApp\ThinkLibrary\Helper;
use think\Validate;
class ValidateHelper extends Helper
{
/**
* 快捷输入并验证( 支持 规则 # 别名
*
* age.require => message // 最大值限定
* age.between:1,120 => message // 范围限定
* name.require => message // 必填内容
* name.default => 100 // 获取并设置默认值
* region.value => value // 固定字段数值内容
* 更多规则参照 ThinkPHP 官方的验证类
*
* @param array $rules 验证规则( 验证信息数组
* @param string $input 输入内容 ( post. 或 get. )
* @param callable|null $callable 异常处理操作
* @return array
*/
public function init(array $rules, $input = '', ?callable $callable = null): array
{
if (is_string($input)) {
$type = trim($input, '.') ?: 'request';
$input = $this->app->request->$type();
}
[$data, $rule, $info] = [[], [], []];
foreach ($rules as $name => $message) {
if (is_numeric($name)) {
[$name, $alias] = explode('#', $message . '#');
$data[$name] = $input[($alias ?: $name)] ?? null;
} elseif (strpos($name, '.') === false) {
$data[$name] = $message;
} elseif (preg_match('|^(.*?)\.(.*?)#(.*?)#?$|', $name . '#', $matches)) {
[, $_key, $_rule, $alias] = $matches;
if (in_array($_rule, ['value', 'default'])) {
if ($_rule === 'value') {
$data[$_key] = $message;
} elseif ($_rule === 'default') {
$data[$_key] = $input[($alias ?: $_key)] ?? $message;
}
} else {
$info[explode(':', $name)[0]] = $message;
$data[$_key] = $data[$_key] ?? ($input[($alias ?: $_key)] ?? null);
$rule[$_key] = isset($rule[$_key]) ? ($rule[$_key] . '|' . $_rule) : $_rule;
}
}
}
$validate = new Validate();
if ($validate->rule($rule)->message($info)->check($data)) {
return $data;
}
if (is_callable($callable)) {
return $callable($validate->getError());
}
$this->class->error($validate->getError());
}
}

@ -1,69 +1,69 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace DtApp\ThinkLibrary\helper;
use DtApp\ThinkLibrary\exception\DtaException;
/**
* XML管理类
* @mixin Xmls
* @package DtApp\ThinkLibrary\helper
*/
class Xmls
{
/**
* 数组转换为xml
* @param array $values 数组
* @return string
* @throws DtaException
*/
public function toXml(array $values): string
{
if (!is_array($values) || count($values) <= 0) {
throw new DtaException('数组数据异常!');
}
$xml = "<xml>";
foreach ($values as $key => $val) {
if (is_array($val)) {
$xml .= "<" . $key . ">" . $this->toXml($val) . "</" . $key . ">";
} else if (is_numeric($val)) {
$xml .= "<" . $key . ">" . $val . "</" . $key . ">";
} else {
$xml .= "<" . $key . "><![CDATA[" . $val . "]]></" . $key . ">";
}
}
$xml .= "</xml>";
return $xml;
}
/**
* 将XML转为array
* @param string $xml
* @return mixed
* @throws DtaException
*/
public function toArray(string $xml)
{
if (!$xml) {
throw new DtaException('xml数据异常');
}
libxml_disable_entity_loader(true);
return json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
}
}
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace DtApp\ThinkLibrary\helper;
use DtApp\ThinkLibrary\exception\DtaException;
/**
* XML管理类
* @mixin Xmls
* @package DtApp\ThinkLibrary\helper
*/
class Xmls
{
/**
* 数组转换为xml
* @param array $values 数组
* @return string
* @throws DtaException
*/
public function toXml(array $values): string
{
if (!is_array($values) || count($values) <= 0) {
throw new DtaException('数组数据异常!');
}
$xml = "<xml>";
foreach ($values as $key => $val) {
if (is_array($val)) {
$xml .= "<" . $key . ">" . $this->toXml($val) . "</" . $key . ">";
} else if (is_numeric($val)) {
$xml .= "<" . $key . ">" . $val . "</" . $key . ">";
} else {
$xml .= "<" . $key . "><![CDATA[" . $val . "]]></" . $key . ">";
}
}
$xml .= "</xml>";
return $xml;
}
/**
* 将XML转为array
* @param string $xml
* @return mixed
* @throws DtaException
*/
public function toArray(string $xml)
{
if (!$xml) {
throw new DtaException('xml数据异常');
}
libxml_disable_entity_loader(true);
return json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
}
}

@ -1,57 +1,57 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary\service;
use DtApp\ThinkLibrary\Service;
use DtApp\ThinkLibrary\service\curl\HttpService;
/**
* 倍洽
* Class BeAryChatService
* @package DtApp\ThinkLibrary\service
*/
class BeAryChatService extends Service
{
/**
* 发送文本消息
* @param string $webhook
* @param string $content 消息内容
* @return bool 发送结果
*/
public function text(string $webhook, string $content): bool
{
return $this->sendMsg($webhook, [
'text' => $content
]);
}
/**
* 组装发送消息
* @param string $webhook
* @param array $data 消息内容数组
* @return bool 发送结果
*/
private function sendMsg(string $webhook, array $data): bool
{
$result = HttpService::instance()
->url($webhook)
->data($data)
->toArray();
return $result['code'] !== 0;
}
}
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary\service;
use DtApp\ThinkLibrary\Service;
use DtApp\ThinkLibrary\service\curl\HttpService;
/**
* 倍洽
* Class BeAryChatService
* @package DtApp\ThinkLibrary\service
*/
class BeAryChatService extends Service
{
/**
* 发送文本消息
* @param string $webhook
* @param string $content 消息内容
* @return bool 发送结果
*/
public function text(string $webhook, string $content): bool
{
return $this->sendMsg($webhook, [
'text' => $content
]);
}
/**
* 组装发送消息
* @param string $webhook
* @param array $data 消息内容数组
* @return bool 发送结果
*/
private function sendMsg(string $webhook, array $data): bool
{
$result = HttpService::instance()
->url($webhook)
->data($data)
->toArray();
return $result['code'] !== 0;
}
}

@ -1,98 +1,98 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary\service;
use DtApp\ThinkLibrary\exception\DtaException;
use DtApp\ThinkLibrary\Service;
use DtApp\ThinkLibrary\service\curl\HttpService;
use think\exception\HttpException;
/**
* 钉钉
* Class DingTalkService
* @package DtApp\ThinkLibrary\service
*/
class DingTalkService extends Service
{
/**
* 消息类型
* @var string
*/
private $msg_type = 'text';
/**
* @var
*/
private $access_token;
/**
* @var string
*/
private $oapi_url = "https://oapi.dingtalk.com/";
/**
* 配置access_token
* @param string $str
* @return $this
*/
public function accessToken(string $str): self
{
$this->access_token = $str;
return $this;
}
/**
* 发送文本消息
* @param string $content 消息内容
* @return bool 发送结果
* @throws DtaException
*/
public function text(string $content): bool
{
$this->msg_type = 'text';
return $this->sendMsg([
'text' => [
'content' => $content,
],
]);
}
/**
* 组装发送消息
* @param array $data 消息内容数组
* @return bool 发送结果
* @throws DtaException
*/
private function sendMsg(array $data): bool
{
if (empty($this->access_token)) {
throw new DtaException("请检查access_token");
}
if (empty($data['msgtype'])) {
$data['msgtype'] = $this->msg_type;
}
$result = HttpService::instance()
->url("{$this->oapi_url}robot/send?access_token=" . $this->access_token)
->data($data)
->post()
->toArray();
if ($result['errcode'] == 0) {
return $result['errmsg'];
}
throw new HttpException(404, json_encode($result, JSON_UNESCAPED_UNICODE));
}
}
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary\service;
use DtApp\ThinkLibrary\exception\DtaException;
use DtApp\ThinkLibrary\Service;
use DtApp\ThinkLibrary\service\curl\HttpService;
use think\exception\HttpException;
/**
* 钉钉
* Class DingTalkService
* @package DtApp\ThinkLibrary\service
*/
class DingTalkService extends Service
{
/**
* 消息类型
* @var string
*/
private $msg_type = 'text';
/**
* @var
*/
private $access_token;
/**
* @var string
*/
private $oapi_url = "https://oapi.dingtalk.com/";
/**
* 配置access_token
* @param string $str
* @return $this
*/
public function accessToken(string $str): self
{
$this->access_token = $str;
return $this;
}
/**
* 发送文本消息
* @param string $content 消息内容
* @return bool 发送结果
* @throws DtaException
*/
public function text(string $content): bool
{
$this->msg_type = 'text';
return $this->sendMsg([
'text' => [
'content' => $content,
],
]);
}
/**
* 组装发送消息
* @param array $data 消息内容数组
* @return bool 发送结果
* @throws DtaException
*/
private function sendMsg(array $data): bool
{
if (empty($this->access_token)) {
throw new DtaException("请检查access_token");
}
if (empty($data['msgtype'])) {
$data['msgtype'] = $this->msg_type;
}
$result = HttpService::instance()
->url("{$this->oapi_url}robot/send?access_token=" . $this->access_token)
->data($data)
->post()
->toArray();
if ($result['errcode'] == 0) {
return $result['errmsg'];
}
throw new HttpException(404, json_encode($result, JSON_UNESCAPED_UNICODE));
}
}

@ -1,180 +1,180 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary\service;
use DtApp\ThinkLibrary\Service;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
use think\Exception;
/**
* 表格服务
* Class ExcelService
* @package DtApp\ThinkLibrary\service
*/
class ExcelService extends Service
{
/**
* 头部
* @var array
*/
private $head = [];
/**
* 设置头部
* [
* [
* [
* 'index' => 1,
* 'value' => '标题'
* ],
* [
* 'index' => 2,
* 'value' => '名称'
* ]
* ],
* [
* [
* 'index' => 1,
* 'value' => '标题2'
* ],
* [
* 'index' => 2,
* 'value' => '名称2'
* ]
* ]
* ];
* @param array $head
* @return ExcelService
*/
public function setHead(array $head = []): ExcelService
{
$this->head = $head;
return $this;
}
/**
* 头部长度
* @var array
*/
private $head_length = 0;
/**
* 设置头部长度
* @param int $length
* @return ExcelService
*/
public function setHeadLength(int $length = 0): ExcelService
{
$this->head_length = $length;
return $this;
}
/**
* 内容
* @var array
*/
private $content = [];
/**
* 设置内容
* [
* [
* [
* 'index' => 1,
* 'value' => '标题'
* ],
* [
* 'index' => 2,
* 'value' => '名称'
* ]
* ],
* [
* [
* 'index' => 1,
* 'value' => '标题2'
* ],
* [
* 'index' => 2,
* 'value' => '名称2'
* ]
* ]
* ];
* @param array $content
* @return ExcelService
*/
public function setContent(array $content = []): ExcelService
{
$this->content = $content;
return $this;
}
/**
* 文件名
* @var string
*/
private $file_name = '';
/**
* 设置文件名(不需要后缀名)
* @param string $file_name
* @return $this
*/
public function setFileName(string $file_name = ''): self
{
$this->file_name = $file_name;
return $this;
}
/**
* 生成表格文件
* @return string
* @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
* @throws Exception
*/
public function generate(): string
{
// 生成表格
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
if (empty($this->head)) {
throw new Exception('头部内容未设置!');
}
if (empty($this->head_length)) {
throw new Exception('头部长度未设置!');
}
if (empty($this->file_name)) {
throw new Exception('文件保存路径未设置!');
}
//设置工作表标题名称
//设置单元格内容
foreach ($this->head as $key => $value) {
foreach ($value as $k => $v) {
$sheet->setCellValueByColumnAndRow($v['index'], $key + 1, $v['value']);
}
}
foreach ($this->content as $key => $value) {
foreach ($value as $k => $v) {
$sheet->setCellValueByColumnAndRow($v['index'], $key + $this->head_length, $v['value']);
}
}
$writer = new Xlsx($spreadsheet);
$writer->save("{$this->file_name}.xlsx");
return "{$this->file_name}.xlsx";
}
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary\service;
use DtApp\ThinkLibrary\Service;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
use think\Exception;
/**
* 表格服务
* Class ExcelService
* @package DtApp\ThinkLibrary\service
*/
class ExcelService extends Service
{
/**
* 头部
* @var array
*/
private $head = [];
/**
* 设置头部
* [
* [
* [
* 'index' => 1,
* 'value' => '标题'
* ],
* [
* 'index' => 2,
* 'value' => '名称'
* ]
* ],
* [
* [
* 'index' => 1,
* 'value' => '标题2'
* ],
* [
* 'index' => 2,
* 'value' => '名称2'
* ]
* ]
* ];
* @param array $head
* @return ExcelService
*/
public function setHead(array $head = []): ExcelService
{
$this->head = $head;
return $this;
}
/**
* 头部长度
* @var array
*/
private $head_length = 0;
/**
* 设置头部长度
* @param int $length
* @return ExcelService
*/
public function setHeadLength(int $length = 0): ExcelService
{
$this->head_length = $length;
return $this;
}
/**
* 内容
* @var array
*/
private $content = [];
/**
* 设置内容
* [
* [
* [
* 'index' => 1,
* 'value' => '标题'
* ],
* [
* 'index' => 2,
* 'value' => '名称'
* ]
* ],
* [
* [
* 'index' => 1,
* 'value' => '标题2'
* ],
* [
* 'index' => 2,
* 'value' => '名称2'
* ]
* ]
* ];
* @param array $content
* @return ExcelService
*/
public function setContent(array $content = []): ExcelService
{
$this->content = $content;
return $this;
}
/**
* 文件名
* @var string
*/
private $file_name = '';
/**
* 设置文件名(不需要后缀名)
* @param string $file_name
* @return $this
*/
public function setFileName(string $file_name = ''): self
{
$this->file_name = $file_name;
return $this;
}
/**
* 生成表格文件
* @return string
* @throws \PhpOffice\PhpSpreadsheet\Writer\Exception
* @throws Exception
*/
public function generate(): string
{
// 生成表格
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
if (empty($this->head)) {
throw new Exception('头部内容未设置!');
}
if (empty($this->head_length)) {
throw new Exception('头部长度未设置!');
}
if (empty($this->file_name)) {
throw new Exception('文件保存路径未设置!');
}
//设置工作表标题名称
//设置单元格内容
foreach ($this->head as $key => $value) {
foreach ($value as $k => $v) {
$sheet->setCellValueByColumnAndRow($v['index'], $key + 1, $v['value']);
}
}
foreach ($this->content as $key => $value) {
foreach ($value as $k => $v) {
$sheet->setCellValueByColumnAndRow($v['index'], $key + $this->head_length, $v['value']);
}
}
$writer = new Xlsx($spreadsheet);
$writer->save("{$this->file_name}.xlsx");
return "{$this->file_name}.xlsx";
}
}

@ -1,45 +1,45 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary\service\Ip;
class IpIpDistrictInfo
{
/**
* @var
*/
public $country_name , $region_name, $city_name , $district_name , $china_admin_code, $covering_radius,$longitude , $latitude = '';
/**
* IpIpDistrictInfo constructor.
* @param array $data
*/
public function __construct(array $data)
{
foreach ($data AS $field => $value) {
$this->{$field} = $value;
}
}
/**
* @param $name
* @return mixed
*/
public function __get($name)
{
return $this->{$name};
}
}
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary\service\Ip;
class IpIpDistrictInfo
{
/**
* @var
*/
public $country_name , $region_name, $city_name , $district_name , $china_admin_code, $covering_radius,$longitude , $latitude = '';
/**
* IpIpDistrictInfo constructor.
* @param array $data
*/
public function __construct(array $data)
{
foreach ($data AS $field => $value) {
$this->{$field} = $value;
}
}
/**
* @param $name
* @return mixed
*/
public function __get($name)
{
return $this->{$name};
}
}

@ -1,307 +1,307 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary\service\Ip;
use BadMethodCallException;
use Exception;
use InvalidArgumentException;
class IpIpReader
{
public const IPV4 = 1;
public const IPV6 = 2;
private $file;
private $fileSize = 0;
private $nodeCount = 0;
private $nodeOffset = 0;
private $meta = [];
private $database;
/**
* Reader constructor.
* @param $database
* @throws Exception
*/
public function __construct($database)
{
$this->database = $database;
$this->init();
}
/**
* @throws Exception
*/
private function init(): void
{
if (is_readable($this->database) === FALSE) {
throw new InvalidArgumentException("The IP Database file \"{$this->database}\" does not exist or is not readable.");
}
$this->file = @fopen($this->database, 'rb');
if ($this->file === FALSE) {
throw new InvalidArgumentException("IP Database File opening \"{$this->database}\".");
}
$this->fileSize = @filesize($this->database);
if ($this->fileSize === FALSE) {
throw new \UnexpectedValueException("Error determining the size of \"{$this->database}\".");
}
$metaLength = unpack('N', fread($this->file, 4))[1];
$text = fread($this->file, $metaLength);
$this->meta = json_decode($text, 1);
if (isset($this->meta['fields']) === FALSE || isset($this->meta['languages']) === FALSE) {
throw new Exception('IP Database metadata error.');
}
$fileSize = 4 + $metaLength + $this->meta['total_size'];
if ($fileSize !== $this->fileSize) {
throw new Exception('IP Database size error.');
}
$this->nodeCount = $this->meta['node_count'];
$this->nodeOffset = 4 + $metaLength;
}
/**
* @param $ip
* @param string $language
* @return array|NULL
*/
public function find($ip, $language): ?array
{
if (is_resource($this->file) === FALSE) {
throw new BadMethodCallException('IPIP DB closed.');
}
if (isset($this->meta['languages'][$language]) === FALSE) {
throw new InvalidArgumentException("language : {$language} not support.");
}
if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_IPV6) === FALSE) {
throw new InvalidArgumentException("The value \"$ip\" is not a valid IP address.");
}
if (strpos($ip, '.') !== FALSE && !$this->supportV4()) {
throw new InvalidArgumentException("The Database not support IPv4 address.");
}
if (strpos($ip, ':') !== FALSE && !$this->supportV6()) {
throw new InvalidArgumentException("The Database not support IPv6 address.");
}
try {
$node = $this->findNode($ip);
if ($node > 0) {
$data = $this->resolve($node);
$values = explode("\t", $data);
return array_slice($values, $this->meta['languages'][$language], count($this->meta['fields']));
}
} catch (Exception $e) {
return NULL;
}
return NULL;
}
/**
* @param $ip
* @param $language
* @return array|false|null
*/
public function findMap($ip, $language)
{
$array = $this->find($ip, $language);
if (NULL === $array) {
return NULL;
}
return array_combine($this->meta['fields'], $array);
}
/**
* @var int
*/
private $v4offset = 0;
/**
* @var array
*/
private $v6offsetCache = [];
/**
* @param $ip
* @return int
* @throws Exception
*/
private function findNode($ip): int
{
$binary = inet_pton($ip);
$bitCount = strlen($binary) * 8; // 32 | 128
$key = substr($binary, 0, 2);
$node = 0;
$index = 0;
if ($bitCount === 32) {
if ($this->v4offset === 0) {
for ($i = 0; $i < 96 && $node < $this->nodeCount; $i++) {
if ($i >= 80) {
$idx = 1;
} else {
$idx = 0;
}
$node = $this->readNode($node, $idx);
if ($node > $this->nodeCount) {
return 0;
}
}
$this->v4offset = $node;
} else {
$node = $this->v4offset;
}
} else {
if (isset($this->v6offsetCache[$key])) {
$index = 16;
$node = $this->v6offsetCache[$key];
}
}
for ($i = $index; $i < $bitCount; $i++) {
if ($node >= $this->nodeCount) {
break;
}
$node = $this->readNode($node, 1 & ((0xFF & ord($binary[$i >> 3])) >> 7 - ($i % 8)));
if ($i == 15) {
$this->v6offsetCache[$key] = $node;
}
}
if ($node === $this->nodeCount) {
return 0;
}
if ($node > $this->nodeCount) {
return $node;
}
throw new Exception("find node failed.");
}
/**
* @param $node
* @param $index
* @return mixed
* @throws Exception
*/
private function readNode($node, $index)
{
return unpack('N', $this->read($this->file, $node * 8 + $index * 4, 4))[1];
}
/**
* @param $node
* @return mixed
* @throws Exception
*/
private function resolve($node)
{
$resolved = $node - $this->nodeCount + $this->nodeCount * 8;
if ($resolved >= $this->fileSize) {
return NULL;
}
$bytes = $this->read($this->file, $resolved, 2);
$size = unpack('N', str_pad($bytes, 4, "\x00", STR_PAD_LEFT))[1];
$resolved += 2;
return $this->read($this->file, $resolved, $size);
}
/**
*
*/
public function close(): void
{
if (is_resource($this->file) === TRUE) {
fclose($this->file);
}
}
/**
* @param $stream
* @param $offset
* @param $length
* @return bool|string
* @throws Exception
*/
private function read($stream, $offset, $length)
{
if ($length > 0) {
if (fseek($stream, $offset + $this->nodeOffset) === 0) {
$value = fread($stream, $length);
if (strlen($value) === $length) {
return $value;
}
}
throw new Exception("The Database file read bad data.");
}
return '';
}
/**
* @return bool
*/
public function supportV6(): bool
{
return ($this->meta['ip_version'] & self::IPV6) === self::IPV6;
}
/**
* @return bool
*/
public function supportV4(): bool
{
return ($this->meta['ip_version'] & self::IPV4) === self::IPV4;
}
/**
* @return array
*/
public function getMeta()
{
return $this->meta;
}
/**
* @return int UTC Timestamp
*/
public function getBuildTime()
{
return $this->meta['build'];
}
}
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary\service\Ip;
use BadMethodCallException;
use Exception;
use InvalidArgumentException;
class IpIpReader
{
public const IPV4 = 1;
public const IPV6 = 2;
private $file;
private $fileSize = 0;
private $nodeCount = 0;
private $nodeOffset = 0;
private $meta = [];
private $database;
/**
* Reader constructor.
* @param $database
* @throws Exception
*/
public function __construct($database)
{
$this->database = $database;
$this->init();
}
/**
* @throws Exception
*/
private function init(): void
{
if (is_readable($this->database) === FALSE) {
throw new InvalidArgumentException("The IP Database file \"{$this->database}\" does not exist or is not readable.");
}
$this->file = @fopen($this->database, 'rb');
if ($this->file === FALSE) {
throw new InvalidArgumentException("IP Database File opening \"{$this->database}\".");
}
$this->fileSize = @filesize($this->database);
if ($this->fileSize === FALSE) {
throw new \UnexpectedValueException("Error determining the size of \"{$this->database}\".");
}
$metaLength = unpack('N', fread($this->file, 4))[1];
$text = fread($this->file, $metaLength);
$this->meta = json_decode($text, 1);
if (isset($this->meta['fields']) === FALSE || isset($this->meta['languages']) === FALSE) {
throw new Exception('IP Database metadata error.');
}
$fileSize = 4 + $metaLength + $this->meta['total_size'];
if ($fileSize !== $this->fileSize) {
throw new Exception('IP Database size error.');
}
$this->nodeCount = $this->meta['node_count'];
$this->nodeOffset = 4 + $metaLength;
}
/**
* @param $ip
* @param string $language
* @return array|NULL
*/
public function find($ip, $language): ?array
{
if (is_resource($this->file) === FALSE) {
throw new BadMethodCallException('IPIP DB closed.');
}
if (isset($this->meta['languages'][$language]) === FALSE) {
throw new InvalidArgumentException("language : {$language} not support.");
}
if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_IPV6) === FALSE) {
throw new InvalidArgumentException("The value \"$ip\" is not a valid IP address.");
}
if (strpos($ip, '.') !== FALSE && !$this->supportV4()) {
throw new InvalidArgumentException("The Database not support IPv4 address.");
}
if (strpos($ip, ':') !== FALSE && !$this->supportV6()) {
throw new InvalidArgumentException("The Database not support IPv6 address.");
}
try {
$node = $this->findNode($ip);
if ($node > 0) {
$data = $this->resolve($node);
$values = explode("\t", $data);
return array_slice($values, $this->meta['languages'][$language], count($this->meta['fields']));
}
} catch (Exception $e) {
return NULL;
}
return NULL;
}
/**
* @param $ip
* @param $language
* @return array|false|null
*/
public function findMap($ip, $language)
{
$array = $this->find($ip, $language);
if (NULL === $array) {
return NULL;
}
return array_combine($this->meta['fields'], $array);
}
/**
* @var int
*/
private $v4offset = 0;
/**
* @var array
*/
private $v6offsetCache = [];
/**
* @param $ip
* @return int
* @throws Exception
*/
private function findNode($ip): int
{
$binary = inet_pton($ip);
$bitCount = strlen($binary) * 8; // 32 | 128
$key = substr($binary, 0, 2);
$node = 0;
$index = 0;
if ($bitCount === 32) {
if ($this->v4offset === 0) {
for ($i = 0; $i < 96 && $node < $this->nodeCount; $i++) {
if ($i >= 80) {
$idx = 1;
} else {
$idx = 0;
}
$node = $this->readNode($node, $idx);
if ($node > $this->nodeCount) {
return 0;
}
}
$this->v4offset = $node;
} else {
$node = $this->v4offset;
}
} else {
if (isset($this->v6offsetCache[$key])) {
$index = 16;
$node = $this->v6offsetCache[$key];
}
}
for ($i = $index; $i < $bitCount; $i++) {
if ($node >= $this->nodeCount) {
break;
}
$node = $this->readNode($node, 1 & ((0xFF & ord($binary[$i >> 3])) >> 7 - ($i % 8)));
if ($i == 15) {
$this->v6offsetCache[$key] = $node;
}
}
if ($node === $this->nodeCount) {
return 0;
}
if ($node > $this->nodeCount) {
return $node;
}
throw new Exception("find node failed.");
}
/**
* @param $node
* @param $index
* @return mixed
* @throws Exception
*/
private function readNode($node, $index)
{
return unpack('N', $this->read($this->file, $node * 8 + $index * 4, 4))[1];
}
/**
* @param $node
* @return mixed
* @throws Exception
*/
private function resolve($node)
{
$resolved = $node - $this->nodeCount + $this->nodeCount * 8;
if ($resolved >= $this->fileSize) {
return NULL;
}
$bytes = $this->read($this->file, $resolved, 2);
$size = unpack('N', str_pad($bytes, 4, "\x00", STR_PAD_LEFT))[1];
$resolved += 2;
return $this->read($this->file, $resolved, $size);
}
/**
*
*/
public function close(): void
{
if (is_resource($this->file) === TRUE) {
fclose($this->file);
}
}
/**
* @param $stream
* @param $offset
* @param $length
* @return bool|string
* @throws Exception
*/
private function read($stream, $offset, $length)
{
if ($length > 0) {
if (fseek($stream, $offset + $this->nodeOffset) === 0) {
$value = fread($stream, $length);
if (strlen($value) === $length) {
return $value;
}
}
throw new Exception("The Database file read bad data.");
}
return '';
}
/**
* @return bool
*/
public function supportV6(): bool
{
return ($this->meta['ip_version'] & self::IPV6) === self::IPV6;
}
/**
* @return bool
*/
public function supportV4(): bool
{
return ($this->meta['ip_version'] & self::IPV4) === self::IPV4;
}
/**
* @return array
*/
public function getMeta()
{
return $this->meta;
}
/**
* @return int UTC Timestamp
*/
public function getBuildTime()
{
return $this->meta['build'];
}
}

@ -1,88 +1,88 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary\service\Ip;
use DtApp\ThinkLibrary\Service;
use Exception;
use think\App;
/**
* IP - IPIP
* Class IpIpService
* @package DtApp\ThinkLibrary\service\ip
*/
class IpIpService extends Service
{
/**
* @var IpIpReader|null
*/
public $reader;
/**
* IpIpService constructor.
* @param App $app
* @throws Exception
*/
public function __construct(App $app)
{
$this->reader = new IpIpReader(__DIR__ . '../bin/ipipfree.ipdb');
parent::__construct($app);
}
/**
* @param $ip
* @param $language
* @return array|NULL
*/
public function getFind(string $ip = '', string $language = 'CN')
{
if (empty($ip)) {
$ip = get_ip();
}
return $this->reader->find($ip, $language);
}
/**
* @param $ip
* @param $language
* @return array|false|null
*/
public function getFindMap(string $ip = '', string $language = 'CN')
{
if (empty($ip)) {
$ip = get_ip();
}
return $this->reader->findMap($ip, $language);
}
/**
* @param $ip
* @param $language
* @return IpIpDistrictInfo|null
*/
public function getFindInfo(string $ip = '', string $language = 'CN')
{
if (empty($ip)) {
$ip = get_ip();
}
$map = $this->getFindMap($ip, $language);
if (NULL === $map) {
return NUll;
}
return new IpIpDistrictInfo($map);
}
}
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary\service\Ip;
use DtApp\ThinkLibrary\Service;
use Exception;
use think\App;
/**
* IP - IPIP
* Class IpIpService
* @package DtApp\ThinkLibrary\service\ip
*/
class IpIpService extends Service
{
/**
* @var IpIpReader|null
*/
public $reader;
/**
* IpIpService constructor.
* @param App $app
* @throws Exception
*/
public function __construct(App $app)
{
$this->reader = new IpIpReader(__DIR__ . '../bin/ipipfree.ipdb');
parent::__construct($app);
}
/**
* @param $ip
* @param $language
* @return array|NULL
*/
public function getFind(string $ip = '', string $language = 'CN')
{
if (empty($ip)) {
$ip = get_ip();
}
return $this->reader->find($ip, $language);
}
/**
* @param $ip
* @param $language
* @return array|false|null
*/
public function getFindMap(string $ip = '', string $language = 'CN')
{
if (empty($ip)) {
$ip = get_ip();
}
return $this->reader->findMap($ip, $language);
}
/**
* @param $ip
* @param $language
* @return IpIpDistrictInfo|null
*/
public function getFindInfo(string $ip = '', string $language = 'CN')
{
if (empty($ip)) {
$ip = get_ip();
}
$map = $this->getFindMap($ip, $language);
if (NULL === $map) {
return NUll;
}
return new IpIpDistrictInfo($map);
}
}

@ -1,152 +1,152 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary\service\Ip;
use DtApp\ThinkLibrary\exception\DtaException;
use DtApp\ThinkLibrary\Service;
use DtApp\ThinkLibrary\service\curl\HttpService;
/**
* IP - 地图
* Class MapService
* @package DtApp\ThinkLibrary\service\ip
*/
class MapService extends Service
{
/**
* 开发密钥
* @var
*/
private $key;
/**
* 开发密钥
* @var
*/
private $ak;
/**
* 需要查询的IP
* @var
*/
private $ip;
/**
* 配置腾讯地图或高德地图Key
* @param $str
* @return $this
*/
public function key(string $str): self
{
$this->key = $str;
return $this;
}
/**
* 配置百度地图ak
* @param $str
* @return $this
*/
public function ak(string $str): self
{
$this->ak = $str;
return $this;
}
/**
* 查询指定IP
* @param string $str
* @return $this
*/
public function ip(string $str): self
{
$this->ip = $str;
return $this;
}
/**
* 腾讯地图
* https://lbs.qq.com/webservice_v1/guide-ip.html
* @param string $output
* @return array|bool|mixed|string
* @throws DtaException
*/
public function qq(string $output = 'JSON')
{
if (empty($this->key)) {
throw new DtaException('开发密钥不能为空');
}
if (empty($this->ip)) {
$this->ip = get_ip();
}
$url = "https://apis.map.qq.com/ws/location/v1/ip?key={$this->key}&output={$output}";
if (!empty($this->ip)) {
$url = "https://apis.map.qq.com/ws/location/v1/ip?key={$this->key}&ip={$this->ip}&output={$output}";
}
return HttpService::instance()
->url($url)
->toArray();
}
/**
* 百度地图
* http://lbsyun.baidu.com/index.php?title=webapi/ip-api
* @param string $coor
* @return array|bool|mixed|string
* @throws DtaException
*/
public function baidu(string $coor = 'bd09ll')
{
if (empty($this->ak)) {
throw new DtaException('开发者密钥不能为空');
}
if (empty($this->ip)) {
$this->ip = get_ip();
}
$url = "https://api.map.baidu.com/location/ip?ak={$this->ak}&coor={$coor}";
if (!empty($this->ip)) {
$url = "https://api.map.baidu.com/location/ip?ak={$this->ak}&ip={$this->ip}&coor={$coor}";
}
return HttpService::instance()
->url($url)
->toArray();
}
/**
* 高德地图
* https://lbs.amap.com/api/webservice/guide/api/ipconfig
* @param string $output
* @return array|bool|mixed|string
* @throws DtaException
*/
public function amap(string $output = 'JSON')
{
if (empty($this->key)) {
throw new DtaException('开发密钥不能为空');
}
if (empty($this->ip)) {
$this->ip = get_ip();
}
$url = "https://restapi.amap.com/v3/ip?parameters&key={$this->key}&output={$output}";
if (!empty($this->ip)) {
$url = "https://restapi.amap.com/v3/ip?key={$this->key}&ip={$this->ip}&output={$output}";
}
return HttpService::instance()
->url($url)
->toArray();
}
}
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary\service\Ip;
use DtApp\ThinkLibrary\exception\DtaException;
use DtApp\ThinkLibrary\Service;
use DtApp\ThinkLibrary\service\curl\HttpService;
/**
* IP - 地图
* Class MapService
* @package DtApp\ThinkLibrary\service\ip
*/
class MapService extends Service
{
/**
* 开发密钥
* @var
*/
private $key;
/**
* 开发密钥
* @var
*/
private $ak;
/**
* 需要查询的IP
* @var
*/
private $ip;
/**
* 配置腾讯地图或高德地图Key
* @param $str
* @return $this
*/
public function key(string $str): self
{
$this->key = $str;
return $this;
}
/**
* 配置百度地图ak
* @param $str
* @return $this
*/
public function ak(string $str): self
{
$this->ak = $str;
return $this;
}
/**
* 查询指定IP
* @param string $str
* @return $this
*/
public function ip(string $str): self
{
$this->ip = $str;
return $this;
}
/**
* 腾讯地图
* https://lbs.qq.com/webservice_v1/guide-ip.html
* @param string $output
* @return array|bool|mixed|string
* @throws DtaException
*/
public function qq(string $output = 'JSON')
{
if (empty($this->key)) {
throw new DtaException('开发密钥不能为空');
}
if (empty($this->ip)) {
$this->ip = get_ip();
}
$url = "https://apis.map.qq.com/ws/location/v1/ip?key={$this->key}&output={$output}";
if (!empty($this->ip)) {
$url = "https://apis.map.qq.com/ws/location/v1/ip?key={$this->key}&ip={$this->ip}&output={$output}";
}
return HttpService::instance()
->url($url)
->toArray();
}
/**
* 百度地图
* http://lbsyun.baidu.com/index.php?title=webapi/ip-api
* @param string $coor
* @return array|bool|mixed|string
* @throws DtaException
*/
public function baidu(string $coor = 'bd09ll')
{
if (empty($this->ak)) {
throw new DtaException('开发者密钥不能为空');
}
if (empty($this->ip)) {
$this->ip = get_ip();
}
$url = "https://api.map.baidu.com/location/ip?ak={$this->ak}&coor={$coor}";
if (!empty($this->ip)) {
$url = "https://api.map.baidu.com/location/ip?ak={$this->ak}&ip={$this->ip}&coor={$coor}";
}
return HttpService::instance()
->url($url)
->toArray();
}
/**
* 高德地图
* https://lbs.amap.com/api/webservice/guide/api/ipconfig
* @param string $output
* @return array|bool|mixed|string
* @throws DtaException
*/
public function amap(string $output = 'JSON')
{
if (empty($this->key)) {
throw new DtaException('开发密钥不能为空');
}
if (empty($this->ip)) {
$this->ip = get_ip();
}
$url = "https://restapi.amap.com/v3/ip?parameters&key={$this->key}&output={$output}";
if (!empty($this->ip)) {
$url = "https://restapi.amap.com/v3/ip?key={$this->key}&ip={$this->ip}&output={$output}";
}
return HttpService::instance()
->url($url)
->toArray();
}
}

@ -1,240 +1,240 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary\service\Ip;
use DtApp\ThinkLibrary\exception\DtaException;
use DtApp\ThinkLibrary\Service;
use DtApp\ThinkLibrary\service\curl\HttpService;
/**
* IP - 在线查询接口
* Class OnlineService
* @package DtApp\ThinkLibrary\service\ip
*/
class OnlineService extends Service
{
/**
* 需要查询的IP
* @var
*/
private $ip;
/**
* 查询指定IP
* @param string $str
* @return $this
*/
public function ip(string $str): self
{
$this->ip = $str;
return $this;
}
/**
* 哔哩哔哩ip查询接口
* @return array|bool|mixed|string
*/
public function biliBili()
{
$url = "https://api.bilibili.com/x/web-interface/zone";
return HttpService::instance()
->url($url)
->toArray();
}
/**
* batch
* @param string $lang 语言
* @return array|bool|mixed|string
*/
public function batch(string $lang = 'zh-CN')
{
$url = "http://ip-api.com/json/?lang={$lang}";
return HttpService::instance()
->url($url)
->toArray();
}
/**
* lookup
* @return array|bool|mixed|string
*/
public function lookup()
{
$url = "https://extreme-ip-lookup.com/json/";
return HttpService::instance()
->url($url)
->toArray();
}
/**
* 网易IP查询接口
* @return array|bool|mixed|string
*/
public function netEase()
{
$url = "https://ipservice.3g.163.com/ip";
return HttpService::instance()
->url($url)
->toArray();
}
/**
* 百度搜索
* @return bool|false|mixed|string|string[]
*/
public function baidu()
{
if (empty($this->ip)) {
$this->ip = get_ip();
}
$url = "https://sp0.baidu.com/8aQDcjqpAAV3otqbppnN2DJv/api.php?query={$this->ip}&co=&resource_id=6006&ie=utf8&oe=utf8&cb=json";
$res = HttpService::instance()
->url($url)
->toArray(false);
$res = str_replace("/**/json", "", $res);
$res = substr($res, 1);
$res = substr($res, 0, -2);
$res = json_decode($res, true);
return $res;
}
/**
* 太平洋
* @return bool|false|mixed|string
*/
public function pConLine()
{
$url = "http://whois.pconline.com.cn/ipJson.jsp?json=true";
if (!empty($this->ip)) {
$url = "http://whois.pconline.com.cn/ipJson.jsp?json=true&ip={$this->ip}";
}
$res = HttpService::instance()
->url($url)
->toArray(false);
preg_match('/{.+}/', $res, $res);
$res = iconv('gbk', 'utf-8', $res[0]);
$res = json_decode($res, true);
return $res;
}
/**
* 新浪
* @return bool|false|mixed|string|string[]
*/
public function siNa()
{
if (empty($this->ip)) {
$this->ip = get_ip();
}
$url = "http://ip.ws.126.net/ipquery?ip={$this->ip}";
$res = HttpService::instance()
->url($url)
->toArray(false);
$res = iconv('gbk', 'utf-8', $res);
$res = substr($res, strpos($res, "{"));
$res = substr($res, 0, -2);
$res = str_replace(array("city", "province"), array('"city"', '"province"'), $res);
$res = json_decode($res, true);
return $res;
}
/**
* 好搜
* @return bool|mixed|string
*/
public function so()
{
if (empty($this->ip)) {
$this->ip = get_ip();
}
$url = "https://open.onebox.so.com/dataApi?type=ip&src=onebox&tpl=0&num=1&query=ip&ip={$this->ip}&url=ip";
return HttpService::instance()
->url($url)
->toArray();
}
/**
* 搜狐
*/
public function soHu()
{
$url = "http://pv.sohu.com/cityjson?ie=utf-8";
$res = HttpService::instance()
->url($url)
->toArray(false);
$res = str_replace("var returnCitySN = ", "", $res);
$res = substr($res, 0, -1);
$res = json_decode($res, true);
return $res;
}
/**
* 淘宝
* @param string $ip IP地址
* @return bool|mixed|string
*/
public function taoBao(string $ip = '')
{
if (empty($this->ip)) {
$this->ip = get_ip();
}
$url = "http://ip.taobao.com/service/getIpInfo.php?ip={$this->ip}";
return HttpService::instance()
->url($url)
->toArray();
}
/**
* 阿里云
* @param string $appcode
* @return bool|mixed|string
* @throws DtaException
*/
public function aliYun(string $appcode = '')
{
if (empty($this->ip)) {
$this->ip = get_ip();
}
$host = "http://iploc.market.alicloudapi.com";
$path = "/v3/ip";
$method = "GET";
if (empty($appcode)) {
throw new DtaException('请检查阿里-阿里云配置信息 appcode');
}
$headers = array();
$headers[] = "Authorization:APPCODE " . $appcode;
$querys = "ip={$this->ip}";
$bodys = "";
$url = $host . $path . "?" . $querys;
$curl = curl_init();
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_FAILONERROR, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, false);
if (1 == strpos("$" . $host, "https://")) {
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
}
$content = curl_exec($curl);
curl_close($curl);
return json_decode($content, true);
}
}
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary\service\Ip;
use DtApp\ThinkLibrary\exception\DtaException;
use DtApp\ThinkLibrary\Service;
use DtApp\ThinkLibrary\service\curl\HttpService;
/**
* IP - 在线查询接口
* Class OnlineService
* @package DtApp\ThinkLibrary\service\ip
*/
class OnlineService extends Service
{
/**
* 需要查询的IP
* @var
*/
private $ip;
/**
* 查询指定IP
* @param string $str
* @return $this
*/
public function ip(string $str): self
{
$this->ip = $str;
return $this;
}
/**
* 哔哩哔哩ip查询接口
* @return array|bool|mixed|string
*/
public function biliBili()
{
$url = "https://api.bilibili.com/x/web-interface/zone";
return HttpService::instance()
->url($url)
->toArray();
}
/**
* batch
* @param string $lang 语言
* @return array|bool|mixed|string
*/
public function batch(string $lang = 'zh-CN')
{
$url = "http://ip-api.com/json/?lang={$lang}";
return HttpService::instance()
->url($url)
->toArray();
}
/**
* lookup
* @return array|bool|mixed|string
*/
public function lookup()
{
$url = "https://extreme-ip-lookup.com/json/";
return HttpService::instance()
->url($url)
->toArray();
}
/**
* 网易IP查询接口
* @return array|bool|mixed|string
*/
public function netEase()
{
$url = "https://ipservice.3g.163.com/ip";
return HttpService::instance()
->url($url)
->toArray();
}
/**
* 百度搜索
* @return bool|false|mixed|string|string[]
*/
public function baidu()
{
if (empty($this->ip)) {
$this->ip = get_ip();
}
$url = "https://sp0.baidu.com/8aQDcjqpAAV3otqbppnN2DJv/api.php?query={$this->ip}&co=&resource_id=6006&ie=utf8&oe=utf8&cb=json";
$res = HttpService::instance()
->url($url)
->toArray(false);
$res = str_replace("/**/json", "", $res);
$res = substr($res, 1);
$res = substr($res, 0, -2);
$res = json_decode($res, true);
return $res;
}
/**
* 太平洋
* @return bool|false|mixed|string
*/
public function pConLine()
{
$url = "http://whois.pconline.com.cn/ipJson.jsp?json=true";
if (!empty($this->ip)) {
$url = "http://whois.pconline.com.cn/ipJson.jsp?json=true&ip={$this->ip}";
}
$res = HttpService::instance()
->url($url)
->toArray(false);
preg_match('/{.+}/', $res, $res);
$res = iconv('gbk', 'utf-8', $res[0]);
$res = json_decode($res, true);
return $res;
}
/**
* 新浪
* @return bool|false|mixed|string|string[]
*/
public function siNa()
{
if (empty($this->ip)) {
$this->ip = get_ip();
}
$url = "http://ip.ws.126.net/ipquery?ip={$this->ip}";
$res = HttpService::instance()
->url($url)
->toArray(false);
$res = iconv('gbk', 'utf-8', $res);
$res = substr($res, strpos($res, "{"));
$res = substr($res, 0, -2);
$res = str_replace(array("city", "province"), array('"city"', '"province"'), $res);
$res = json_decode($res, true);
return $res;
}
/**
* 好搜
* @return bool|mixed|string
*/
public function so()
{
if (empty($this->ip)) {
$this->ip = get_ip();
}
$url = "https://open.onebox.so.com/dataApi?type=ip&src=onebox&tpl=0&num=1&query=ip&ip={$this->ip}&url=ip";
return HttpService::instance()
->url($url)
->toArray();
}
/**
* 搜狐
*/
public function soHu()
{
$url = "http://pv.sohu.com/cityjson?ie=utf-8";
$res = HttpService::instance()
->url($url)
->toArray(false);
$res = str_replace("var returnCitySN = ", "", $res);
$res = substr($res, 0, -1);
$res = json_decode($res, true);
return $res;
}
/**
* 淘宝
* @param string $ip IP地址
* @return bool|mixed|string
*/
public function taoBao(string $ip = '')
{
if (empty($this->ip)) {
$this->ip = get_ip();
}
$url = "http://ip.taobao.com/service/getIpInfo.php?ip={$this->ip}";
return HttpService::instance()
->url($url)
->toArray();
}
/**
* 阿里云
* @param string $appcode
* @return bool|mixed|string
* @throws DtaException
*/
public function aliYun(string $appcode = '')
{
if (empty($this->ip)) {
$this->ip = get_ip();
}
$host = "http://iploc.market.alicloudapi.com";
$path = "/v3/ip";
$method = "GET";
if (empty($appcode)) {
throw new DtaException('请检查阿里-阿里云配置信息 appcode');
}
$headers = array();
$headers[] = "Authorization:APPCODE " . $appcode;
$querys = "ip={$this->ip}";
$bodys = "";
$url = $host . $path . "?" . $querys;
$curl = curl_init();
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_FAILONERROR, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HEADER, false);
if (1 == strpos("$" . $host, "https://")) {
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
}
$content = curl_exec($curl);
curl_close($curl);
return json_decode($content, true);
}
}

@ -1,162 +1,162 @@
<?php
namespace DtApp\ThinkLibrary\service;
use DtApp\ThinkLibrary\Service;
use DtApp\ThinkLibrary\service\curl\HttpService;
use think\App;
use think\exception\HttpException;
/**
* 卡商网
* http://www.kashangwl.com/
* Class KaShAngWl
* @package DtApp\ThinkLibrary\service
*/
class KaShAngWl extends Service
{
/**
* 接口地址
* @var string
*/
private $api_url = 'http://www.kashangwl.com/api';
/**
* 商家编号、商家密钥
* @var
*/
private $customer_id, $customer_key;
/**
* 设置商家编号
* @param string $customer_id
* @return $this
*/
public function setCustomerId(string $customer_id): self
{
$this->customer_id = $customer_id;
return $this;
}
/**
* 设置商家密钥
* @param string $customer_key
* @return $this
*/
public function setCustomerKey(string $customer_key): self
{
$this->customer_key = $customer_key;
return $this;
}
/**
* 待请求的链接
* @var string
*/
private $method = '';
/**
* 设置接口
* @param $method
* @return KaShAngWl
*/
public function setMethod($method): self
{
$this->method = "{$this->api_url}/$method";
return $this;
}
/**
* 需要发送的的参数
* @var
*/
private $param;
/**
* 入参
* @param $param
* @return KaShAngWl
*/
public function param($param): self
{
$this->param = $param;
return $this;
}
/**
* 响应内容
* @var
*/
private $output;
/**
* 时间戳
* @var int
*/
private $time;
public function __construct(App $app)
{
$this->time = time();
parent::__construct($app);
}
/**
* @return array|mixed
*/
public function toArray()
{
//首先检测是否支持curl
if (!extension_loaded("curl")) {
throw new HttpException(404, '请开启curl模块');
}
$this->http();
// 正常
if (is_array($this->output)) {
return $this->output;
}
if (is_object($this->output)) {
$this->output = json_encode($this->output, JSON_UNESCAPED_UNICODE);
}
$this->output = json_decode($this->output, true);
return $this->output;
}
/**
* 网络请求
*/
private function http(): void
{
//生成签名
$sign = $this->createSign();
//组织参数
$this->param['customer_id'] = $this->customer_id;
$this->param['timestamp'] = $this->time;
$this->param['sign'] = $sign;
$result = HttpService::instance()
->url($this->method)
->data($this->param)
->post()
->toArray();
$this->output = $result;
}
/**
* 签名
* @return string
*/
private function createSign(): string
{
$sign = $this->customer_key;
$this->param['customer_id'] = $this->customer_id;
$this->param['timestamp'] = $this->time;
ksort($this->param);
foreach ($this->param as $key => $val) {
if ($key !== '' && $val !== '') {
$sign .= $key . $val;
}
}
$sign = strtolower(md5($sign));
return $sign;
}
<?php
namespace DtApp\ThinkLibrary\service;
use DtApp\ThinkLibrary\Service;
use DtApp\ThinkLibrary\service\curl\HttpService;
use think\App;
use think\exception\HttpException;
/**
* 卡商网
* http://www.kashangwl.com/
* Class KaShAngWl
* @package DtApp\ThinkLibrary\service
*/
class KaShAngWl extends Service
{
/**
* 接口地址
* @var string
*/
private $api_url = 'http://www.kashangwl.com/api';
/**
* 商家编号、商家密钥
* @var
*/
private $customer_id, $customer_key;
/**
* 设置商家编号
* @param string $customer_id
* @return $this
*/
public function setCustomerId(string $customer_id): self
{
$this->customer_id = $customer_id;
return $this;
}
/**
* 设置商家密钥
* @param string $customer_key
* @return $this
*/
public function setCustomerKey(string $customer_key): self
{
$this->customer_key = $customer_key;
return $this;
}
/**
* 待请求的链接
* @var string
*/
private $method = '';
/**
* 设置接口
* @param $method
* @return KaShAngWl
*/
public function setMethod($method): self
{
$this->method = "{$this->api_url}/$method";
return $this;
}
/**
* 需要发送的的参数
* @var
*/
private $param;
/**
* 入参
* @param $param
* @return KaShAngWl
*/
public function param($param): self
{
$this->param = $param;
return $this;
}
/**
* 响应内容
* @var
*/
private $output;
/**
* 时间戳
* @var int
*/
private $time;
public function __construct(App $app)
{
$this->time = time();
parent::__construct($app);
}
/**
* @return array|mixed
*/
public function toArray()
{
//首先检测是否支持curl
if (!extension_loaded("curl")) {
throw new HttpException(404, '请开启curl模块');
}
$this->http();
// 正常
if (is_array($this->output)) {
return $this->output;
}
if (is_object($this->output)) {
$this->output = json_encode($this->output, JSON_UNESCAPED_UNICODE);
}
$this->output = json_decode($this->output, true);
return $this->output;
}
/**
* 网络请求
*/
private function http(): void
{
//生成签名
$sign = $this->createSign();
//组织参数
$this->param['customer_id'] = $this->customer_id;
$this->param['timestamp'] = $this->time;
$this->param['sign'] = $sign;
$result = HttpService::instance()
->url($this->method)
->data($this->param)
->post()
->toArray();
$this->output = $result;
}
/**
* 签名
* @return string
*/
private function createSign(): string
{
$sign = $this->customer_key;
$this->param['customer_id'] = $this->customer_id;
$this->param['timestamp'] = $this->time;
ksort($this->param);
foreach ($this->param as $key => $val) {
if ($key !== '' && $val !== '') {
$sign .= $key . $val;
}
}
$sign = strtolower(md5($sign));
return $sign;
}
}

@ -1,452 +1,452 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary\service;
use DtApp\ThinkLibrary\exception\DtaException;
use DtApp\ThinkLibrary\Service;
use think\App;
/**
* 纯真数据库
* Class QqWryService
* @package DtApp\ThinkLibrary\service
*/
class QqWryService extends Service
{
/**
* QQWry.Dat文件指针
* @var resource
*/
private $fp;
/**
* 第一条IP记录的偏移地址
*
* @var int
*/
private $firstIp;
/**
* 最后一条IP记录的偏移地址
* @var int
*/
private $lastIp;
/**
* IP记录的总条数不包含版本信息记录
* @var int
*/
private $totalIp;
/**
* 不存在
* @var string
*/
private $unknown = '未知';
/**
* 构造函数,打开 QQWry.Dat 文件并初始化类中的信息
* @param App $app
*/
public function __construct(App $app)
{
$this->fp = 0;
if (($this->fp = fopen(__DIR__ . '/bin/qqwry.dat', 'rb')) !== false) {
$this->firstIp = $this->getLong();
$this->lastIp = $this->getLong();
$this->totalIp = ($this->lastIp - $this->firstIp) / 7;
}
parent::__construct($app);
}
/**
* 设置未知的返回字段
* @param string $unknown
* @return QqWryService
*/
public function setUnknown(string $unknown = '未知')
{
$this->unknown = $unknown;
return $this;
}
/**
* 获取省信息
* @param string $ip
* @return mixed
* @throws DtaException
*/
public function getProvince(string $ip = '')
{
return $this->getLocation($ip)['state'];
}
/**
* 获取城市信息
* @param string $ip
* @return mixed
* @throws DtaException
*/
public function getCity(string $ip = '')
{
return $this->getLocation($ip)['city'];
}
/**
* 获取地区信息
* @param string $ip
* @return mixed
* @throws DtaException
*/
public function getArea(string $ip = '')
{
return $this->getLocation($ip)['area'];
}
/**
* 获取运营商信息
* @param string $ip
* @return mixed
* @throws DtaException
*/
public function getExtend(string $ip = '')
{
return $this->getLocation($ip)['extend'];
}
/**
* 根据所给 IP 地址或域名返回所在地区信息
* @param string $ip
* @return mixed|null
* @throws DtaException
*/
public function getLocation(string $ip = '')
{
if (empty($ip)) {
$ip = get_ip();
}
if (strpos($ip, 'http://') === 0) {
$ip = substr($ip, 7);
$ip = gethostbyname($ip);
}
static $locationData = [];
if (!isset($locationData[$ip])) {
if (!$this->fp) {
// 如果数据文件没有被正确打开,则直接返回错误
throw new DtaException('数据库文件不存在!');
}
$location['ip'] = $ip; // 将输入的域名转化为IP地址
$ip = $this->packIp($location['ip']); // 将输入的IP地址转化为可比较的IP地址
// 不合法的IP地址会被转化为255.255.255.255
// 对分搜索
$l = 0; // 搜索的下边界
$u = $this->totalIp; // 搜索的上边界
$findip = $this->lastIp; // 如果没有找到就返回最后一条IP记录QQWry.Dat的版本信息
while ($l <= $u) { // 当上边界小于下边界时,查找失败
$i = floor(($l + $u) / 2); // 计算近似中间记录
fseek($this->fp, $this->firstIp + $i * 7);
$beginip = strrev(fread($this->fp, 4)); // 获取中间记录的开始IP地址
// strrev函数在这里的作用是将little-endian的压缩IP地址转化为big-endian的格式
// 以便用于比较,后面相同。
if ($ip < $beginip) { // 用户的IP小于中间记录的开始IP地址时
$u = $i - 1; // 将搜索的上边界修改为中间记录减一
} else {
fseek($this->fp, $this->getLong3());
$endip = strrev(fread($this->fp, 4)); // 获取中间记录的结束IP地址
if ($ip > $endip) { // 用户的IP大于中间记录的结束IP地址时
$l = $i + 1; // 将搜索的下边界修改为中间记录加一
} else { // 用户的IP在中间记录的IP范围内时
$findip = $this->firstIp + $i * 7;
break; // 则表示找到结果,退出循环
}
}
}
//获取查找到的IP地理位置信息
fseek($this->fp, $findip);
$location['beginip'] = long2ip($this->getLong()); // 用户IP所在范围的开始地址
$offset = $this->getLong3();
fseek($this->fp, $offset);
$location['endip'] = long2ip($this->getLong()); // 用户IP所在范围的结束地址
$byte = fread($this->fp, 1); // 标志字节
switch (ord($byte)) {
case 1: // 标志字节为1表示国家和区域信息都被同时重定向
$countryOffset = $this->getLong3(); // 重定向地址
fseek($this->fp, $countryOffset);
$byte = fread($this->fp, 1); // 标志字节
switch (ord($byte)) {
case 2: // 标志字节为2表示国家信息又被重定向
fseek($this->fp, $this->getLong3());
$location['all'] = $this->getString();
fseek($this->fp, $countryOffset + 4);
$location['extend'] = $this->getExtendString();
break;
default: // 否则,表示国家信息没有被重定向
$location['all'] = $this->getString($byte);
$location['extend'] = $this->getExtendString();
break;
}
break;
case 2: // 标志字节为2表示国家信息被重定向
fseek($this->fp, $this->getLong3());
$location['all'] = $this->getString();
fseek($this->fp, $offset + 8);
$location['extend'] = $this->getExtendString();
break;
default: // 否则,表示国家信息没有被重定向
$location['all'] = $this->getString($byte);
$location['extend'] = $this->getExtendString();
break;
}
// CZ88.NET表示没有有效信息
if (trim($location['all']) === 'CZ88.NET') {
$location['all'] = $this->unknown;
}
if (trim($location['extend']) === 'CZ88.NET') {
$location['extend'] = '';
}
$location['all'] = iconv("gb2312", "UTF-8//IGNORE", $location['all']);
$location['extend'] = iconv("gb2312", "UTF-8//IGNORE", $location['extend']);
$location['extend'] = $location['extend'] ?? '';
$parseData = $this->parseLocation($location['all']);
$location['state'] = $parseData[0];
$location['city'] = $parseData[1];
$location['area'] = $parseData[2];
// 全部地址
$res['location_all'] = $location['all'];
// 运营商
$res['isp']['name'] = $location['extend'];
// IP
$res['ip']['ipv4'] = $location['ip'];
$res['ip']['beginip'] = $location['beginip'];
$res['ip']['endip'] = $location['endip'];
$res['ip']['trueip'] = ip2long($location['ip']);
$res['ip']['ipv6'] = $this->getNormalizedIP($location['ip']);
$getAdCodeLatLng = $this->getNameAdCodeLatLng($location['state'], $location['city'], $location['area']);
// 省份
$res['province'] = $getAdCodeLatLng['province'];
// 城市
$res['city'] = $getAdCodeLatLng['city'];
// 地区
$res['district'] = $getAdCodeLatLng['district'];
$locationData[$ip] = $location;
}
return $res;
}
/**
* 解析省市区县
* @param $location
* @return array
* @example '江苏省苏州市吴江市' , '江苏省苏州市吴中区' , '江苏省苏州市昆山市' , '黑龙江省鸡西市' , '广西桂林市' , '陕西省西安市户县' , '河南省开封市通许县' ,'内蒙古呼伦贝尔市海拉尔区','甘肃省白银市平川区','孟加拉','上海市' , '北京市朝阳区' ,'美国' ,'香港' , 俄罗斯' ,'IANA'
*/
private function parseLocation($location)
{
$state = $city = $area = $this->unknown;
if (preg_match('/^(.+省)?(新疆|内蒙古|宁夏|西藏|广西|香港|澳门)?(.+市)?(.+市)?(.+(县|区))?/', $location, $preg)) {
if (count($preg) == 4) { //匹配 "浙江省杭州市"
$state = $preg[1] ? $preg[1] : ($preg[2] ? $preg[2] : $preg[3]);
$city = $preg[3];
} else if (count($preg) == 7) { //匹配 "浙江省杭州市江干区"
$state = $preg[1] ? $preg[1] : ($preg[2] ? $preg[2] : $preg[3]);
$city = $preg[3];
$area = $preg[5];
} else if (count($preg) == 3) { //匹配 "香港"
$state = $preg[1] ? $preg[1] : $preg[2];
$city = $state;
} else if (count($preg) == 2) { //匹配 "浙江省"
$state = $preg[1] ? $preg[1] : $this->unknown;
}
}
return [$state, $city, $area];
}
/**
* 返回读取的长整型数
* @return mixed
*/
private function getLong()
{
//将读取的little-endian编码的4个字节转化为长整型数
$result = unpack('Vlong', fread($this->fp, 4));
return $result['long'];
}
/**
* 返回读取的3个字节的长整型数
* @return mixed
*/
private function getLong3()
{
//将读取的little-endian编码的3个字节转化为长整型数
$result = unpack('Vlong', fread($this->fp, 3) . chr(0));
return $result['long'];
}
/**
* 返回压缩后可进行比较的IP地址
* @param $ip
* @return false|string
*/
private function packIp($ip)
{
// 将IP地址转化为长整型数如果在PHP5中IP地址错误则返回False
// 这时intval将Flase转化为整数-1之后压缩成big-endian编码的字符串
return pack('N', intval(ip2long($ip)));
}
/**
* 返回读取的字符串
*
* @access private
* @param string $data
* @return string
*/
private function getString($data = "")
{
$char = fread($this->fp, 1);
while (ord($char) > 0) { // 字符串按照C格式保存以\0结束
$data .= $char; // 将读取的字符连接到给定字符串之后
$char = fread($this->fp, 1);
}
return $data;
}
/**
* 返回地区信息
* @return string
*/
private function getExtendString()
{
$byte = fread($this->fp, 1); // 标志字节
switch (ord($byte)) {
case 0: // 没有区域信息
$area = "";
break;
case 1:
case 2: // 标志字节为1或2表示区域信息被重定向
fseek($this->fp, $this->getLong3());
$area = $this->getString();
break;
default: // 否则,表示区域信息没有被重定向
$area = $this->getString($byte);
break;
}
return $area;
}
/**
* 析构函数,用于在页面执行结束后自动关闭打开的文件。
*/
public function __destruct()
{
if ($this->fp) {
fclose($this->fp);
}
$this->fp = 0;
}
/**
* ipv4转换ipv6
* @param $ip
* @return bool|false|string|string[]|null
*/
protected function getNormalizedIP($ip)
{
if (!is_string($ip)) {
return '';
}
if (preg_match('%^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$%', $ip, $match)) {
$IPParts = array();
for ($i = 1; $i <= 4; $i++) {
$IPPart = (int)$match[$i];
if ($IPPart > 255) {
return '';
}
$IPParts[$i] = str_pad(decHex($IPPart), 2, '0', STR_PAD_LEFT);
}
return '0000:0000:0000:0000:0000:ffff:' . $IPParts[1] . $IPParts[2] . ':' . $IPParts[3] . $IPParts[4];
}
return '';
}
/**
* 解析CODE
* @param $province_name
* @param $city_name
* @param $district_name
* @return array
*/
private function getNameAdCodeLatLng($province_name, $city_name, $district_name)
{
// 名称
$province['name'] = $province_name;
$city['name'] = $city_name;
$district['name'] = $district_name;
// adcode
$province['adcode'] = '';
$city['adcode'] = '';
$district['adcode'] = '';
// lat
$province['lat'] = '';
$city['lat'] = '';
$district['lat'] = '';
// lng
$province['lng'] = '';
$city['lng'] = '';
$district['lng'] = '';
if (!empty($province_name)) {
$json_province = json_decode(file_get_contents(__DIR__ . '/bin/province.json'), true);
foreach ($json_province['rows'] as $key => $value) {
if ($value['name'] == $province_name) {
$province['name'] = $value['name'];
$province['adcode'] = $value['adcode'];
$province['lat'] = $value['lat'];
$province['lng'] = $value['lng'];
}
}
}
if (!empty($city_name)) {
$json_city = json_decode(file_get_contents(__DIR__ . '/bin/city.json'), true);
foreach ($json_city['rows'] as $key => $value) {
if ($value['name'] == $city_name) {
$city['name'] = $value['name'];
$city['adcode'] = $value['adcode'];
$city['lat'] = $value['lat'];
$city['lng'] = $value['lng'];
}
}
}
if (!empty($district_name)) {
$json_district = json_decode(file_get_contents(__DIR__ . '/bin/district.json'), true);
foreach ($json_district['rows'] as $key => $value) {
if ($value['name'] == $district_name) {
$district['name'] = $value['name'];
$district['adcode'] = $value['adcode'];
$district['lat'] = $value['lat'];
$district['lng'] = $value['lng'];
}
}
}
return [
'province' => $province,
'city' => $city,
'district' => $district
];
}
}
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary\service;
use DtApp\ThinkLibrary\exception\DtaException;
use DtApp\ThinkLibrary\Service;
use think\App;
/**
* 纯真数据库
* Class QqWryService
* @package DtApp\ThinkLibrary\service
*/
class QqWryService extends Service
{
/**
* QQWry.Dat文件指针
* @var resource
*/
private $fp;
/**
* 第一条IP记录的偏移地址
*
* @var int
*/
private $firstIp;
/**
* 最后一条IP记录的偏移地址
* @var int
*/
private $lastIp;
/**
* IP记录的总条数不包含版本信息记录
* @var int
*/
private $totalIp;
/**
* 不存在
* @var string
*/
private $unknown = '未知';
/**
* 构造函数,打开 QQWry.Dat 文件并初始化类中的信息
* @param App $app
*/
public function __construct(App $app)
{
$this->fp = 0;
if (($this->fp = fopen(__DIR__ . '/bin/qqwry.dat', 'rb')) !== false) {
$this->firstIp = $this->getLong();
$this->lastIp = $this->getLong();
$this->totalIp = ($this->lastIp - $this->firstIp) / 7;
}
parent::__construct($app);
}
/**
* 设置未知的返回字段
* @param string $unknown
* @return QqWryService
*/
public function setUnknown(string $unknown = '未知')
{
$this->unknown = $unknown;
return $this;
}
/**
* 获取省信息
* @param string $ip
* @return mixed
* @throws DtaException
*/
public function getProvince(string $ip = '')
{
return $this->getLocation($ip)['state'];
}
/**
* 获取城市信息
* @param string $ip
* @return mixed
* @throws DtaException
*/
public function getCity(string $ip = '')
{
return $this->getLocation($ip)['city'];
}
/**
* 获取地区信息
* @param string $ip
* @return mixed
* @throws DtaException
*/
public function getArea(string $ip = '')
{
return $this->getLocation($ip)['area'];
}
/**
* 获取运营商信息
* @param string $ip
* @return mixed
* @throws DtaException
*/
public function getExtend(string $ip = '')
{
return $this->getLocation($ip)['extend'];
}
/**
* 根据所给 IP 地址或域名返回所在地区信息
* @param string $ip
* @return mixed|null
* @throws DtaException
*/
public function getLocation(string $ip = '')
{
if (empty($ip)) {
$ip = get_ip();
}
if (strpos($ip, 'http://') === 0) {
$ip = substr($ip, 7);
$ip = gethostbyname($ip);
}
static $locationData = [];
if (!isset($locationData[$ip])) {
if (!$this->fp) {
// 如果数据文件没有被正确打开,则直接返回错误
throw new DtaException('数据库文件不存在!');
}
$location['ip'] = $ip; // 将输入的域名转化为IP地址
$ip = $this->packIp($location['ip']); // 将输入的IP地址转化为可比较的IP地址
// 不合法的IP地址会被转化为255.255.255.255
// 对分搜索
$l = 0; // 搜索的下边界
$u = $this->totalIp; // 搜索的上边界
$findip = $this->lastIp; // 如果没有找到就返回最后一条IP记录QQWry.Dat的版本信息
while ($l <= $u) { // 当上边界小于下边界时,查找失败
$i = floor(($l + $u) / 2); // 计算近似中间记录
fseek($this->fp, $this->firstIp + $i * 7);
$beginip = strrev(fread($this->fp, 4)); // 获取中间记录的开始IP地址
// strrev函数在这里的作用是将little-endian的压缩IP地址转化为big-endian的格式
// 以便用于比较,后面相同。
if ($ip < $beginip) { // 用户的IP小于中间记录的开始IP地址时
$u = $i - 1; // 将搜索的上边界修改为中间记录减一
} else {
fseek($this->fp, $this->getLong3());
$endip = strrev(fread($this->fp, 4)); // 获取中间记录的结束IP地址
if ($ip > $endip) { // 用户的IP大于中间记录的结束IP地址时
$l = $i + 1; // 将搜索的下边界修改为中间记录加一
} else { // 用户的IP在中间记录的IP范围内时
$findip = $this->firstIp + $i * 7;
break; // 则表示找到结果,退出循环
}
}
}
//获取查找到的IP地理位置信息
fseek($this->fp, $findip);
$location['beginip'] = long2ip($this->getLong()); // 用户IP所在范围的开始地址
$offset = $this->getLong3();
fseek($this->fp, $offset);
$location['endip'] = long2ip($this->getLong()); // 用户IP所在范围的结束地址
$byte = fread($this->fp, 1); // 标志字节
switch (ord($byte)) {
case 1: // 标志字节为1表示国家和区域信息都被同时重定向
$countryOffset = $this->getLong3(); // 重定向地址
fseek($this->fp, $countryOffset);
$byte = fread($this->fp, 1); // 标志字节
switch (ord($byte)) {
case 2: // 标志字节为2表示国家信息又被重定向
fseek($this->fp, $this->getLong3());
$location['all'] = $this->getString();
fseek($this->fp, $countryOffset + 4);
$location['extend'] = $this->getExtendString();
break;
default: // 否则,表示国家信息没有被重定向
$location['all'] = $this->getString($byte);
$location['extend'] = $this->getExtendString();
break;
}
break;
case 2: // 标志字节为2表示国家信息被重定向
fseek($this->fp, $this->getLong3());
$location['all'] = $this->getString();
fseek($this->fp, $offset + 8);
$location['extend'] = $this->getExtendString();
break;
default: // 否则,表示国家信息没有被重定向
$location['all'] = $this->getString($byte);
$location['extend'] = $this->getExtendString();
break;
}
// CZ88.NET表示没有有效信息
if (trim($location['all']) === 'CZ88.NET') {
$location['all'] = $this->unknown;
}
if (trim($location['extend']) === 'CZ88.NET') {
$location['extend'] = '';
}
$location['all'] = iconv("gb2312", "UTF-8//IGNORE", $location['all']);
$location['extend'] = iconv("gb2312", "UTF-8//IGNORE", $location['extend']);
$location['extend'] = $location['extend'] ?? '';
$parseData = $this->parseLocation($location['all']);
$location['state'] = $parseData[0];
$location['city'] = $parseData[1];
$location['area'] = $parseData[2];
// 全部地址
$res['location_all'] = $location['all'];
// 运营商
$res['isp']['name'] = $location['extend'];
// IP
$res['ip']['ipv4'] = $location['ip'];
$res['ip']['beginip'] = $location['beginip'];
$res['ip']['endip'] = $location['endip'];
$res['ip']['trueip'] = ip2long($location['ip']);
$res['ip']['ipv6'] = $this->getNormalizedIP($location['ip']);
$getAdCodeLatLng = $this->getNameAdCodeLatLng($location['state'], $location['city'], $location['area']);
// 省份
$res['province'] = $getAdCodeLatLng['province'];
// 城市
$res['city'] = $getAdCodeLatLng['city'];
// 地区
$res['district'] = $getAdCodeLatLng['district'];
$locationData[$ip] = $location;
}
return $res;
}
/**
* 解析省市区县
* @param $location
* @return array
* @example '江苏省苏州市吴江市' , '江苏省苏州市吴中区' , '江苏省苏州市昆山市' , '黑龙江省鸡西市' , '广西桂林市' , '陕西省西安市户县' , '河南省开封市通许县' ,'内蒙古呼伦贝尔市海拉尔区','甘肃省白银市平川区','孟加拉','上海市' , '北京市朝阳区' ,'美国' ,'香港' , 俄罗斯' ,'IANA'
*/
private function parseLocation($location)
{
$state = $city = $area = $this->unknown;
if (preg_match('/^(.+省)?(新疆|内蒙古|宁夏|西藏|广西|香港|澳门)?(.+市)?(.+市)?(.+(县|区))?/', $location, $preg)) {
if (count($preg) == 4) { //匹配 "浙江省杭州市"
$state = $preg[1] ? $preg[1] : ($preg[2] ? $preg[2] : $preg[3]);
$city = $preg[3];
} else if (count($preg) == 7) { //匹配 "浙江省杭州市江干区"
$state = $preg[1] ? $preg[1] : ($preg[2] ? $preg[2] : $preg[3]);
$city = $preg[3];
$area = $preg[5];
} else if (count($preg) == 3) { //匹配 "香港"
$state = $preg[1] ? $preg[1] : $preg[2];
$city = $state;
} else if (count($preg) == 2) { //匹配 "浙江省"
$state = $preg[1] ? $preg[1] : $this->unknown;
}
}
return [$state, $city, $area];
}
/**
* 返回读取的长整型数
* @return mixed
*/
private function getLong()
{
//将读取的little-endian编码的4个字节转化为长整型数
$result = unpack('Vlong', fread($this->fp, 4));
return $result['long'];
}
/**
* 返回读取的3个字节的长整型数
* @return mixed
*/
private function getLong3()
{
//将读取的little-endian编码的3个字节转化为长整型数
$result = unpack('Vlong', fread($this->fp, 3) . chr(0));
return $result['long'];
}
/**
* 返回压缩后可进行比较的IP地址
* @param $ip
* @return false|string
*/
private function packIp($ip)
{
// 将IP地址转化为长整型数如果在PHP5中IP地址错误则返回False
// 这时intval将Flase转化为整数-1之后压缩成big-endian编码的字符串
return pack('N', intval(ip2long($ip)));
}
/**
* 返回读取的字符串
*
* @access private
* @param string $data
* @return string
*/
private function getString($data = "")
{
$char = fread($this->fp, 1);
while (ord($char) > 0) { // 字符串按照C格式保存以\0结束
$data .= $char; // 将读取的字符连接到给定字符串之后
$char = fread($this->fp, 1);
}
return $data;
}
/**
* 返回地区信息
* @return string
*/
private function getExtendString()
{
$byte = fread($this->fp, 1); // 标志字节
switch (ord($byte)) {
case 0: // 没有区域信息
$area = "";
break;
case 1:
case 2: // 标志字节为1或2表示区域信息被重定向
fseek($this->fp, $this->getLong3());
$area = $this->getString();
break;
default: // 否则,表示区域信息没有被重定向
$area = $this->getString($byte);
break;
}
return $area;
}
/**
* 析构函数,用于在页面执行结束后自动关闭打开的文件。
*/
public function __destruct()
{
if ($this->fp) {
fclose($this->fp);
}
$this->fp = 0;
}
/**
* ipv4转换ipv6
* @param $ip
* @return bool|false|string|string[]|null
*/
protected function getNormalizedIP($ip)
{
if (!is_string($ip)) {
return '';
}
if (preg_match('%^(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$%', $ip, $match)) {
$IPParts = array();
for ($i = 1; $i <= 4; $i++) {
$IPPart = (int)$match[$i];
if ($IPPart > 255) {
return '';
}
$IPParts[$i] = str_pad(decHex($IPPart), 2, '0', STR_PAD_LEFT);
}
return '0000:0000:0000:0000:0000:ffff:' . $IPParts[1] . $IPParts[2] . ':' . $IPParts[3] . $IPParts[4];
}
return '';
}
/**
* 解析CODE
* @param $province_name
* @param $city_name
* @param $district_name
* @return array
*/
private function getNameAdCodeLatLng($province_name, $city_name, $district_name)
{
// 名称
$province['name'] = $province_name;
$city['name'] = $city_name;
$district['name'] = $district_name;
// adcode
$province['adcode'] = '';
$city['adcode'] = '';
$district['adcode'] = '';
// lat
$province['lat'] = '';
$city['lat'] = '';
$district['lat'] = '';
// lng
$province['lng'] = '';
$city['lng'] = '';
$district['lng'] = '';
if (!empty($province_name)) {
$json_province = json_decode(file_get_contents(__DIR__ . '/bin/province.json'), true);
foreach ($json_province['rows'] as $key => $value) {
if ($value['name'] == $province_name) {
$province['name'] = $value['name'];
$province['adcode'] = $value['adcode'];
$province['lat'] = $value['lat'];
$province['lng'] = $value['lng'];
}
}
}
if (!empty($city_name)) {
$json_city = json_decode(file_get_contents(__DIR__ . '/bin/city.json'), true);
foreach ($json_city['rows'] as $key => $value) {
if ($value['name'] == $city_name) {
$city['name'] = $value['name'];
$city['adcode'] = $value['adcode'];
$city['lat'] = $value['lat'];
$city['lng'] = $value['lng'];
}
}
}
if (!empty($district_name)) {
$json_district = json_decode(file_get_contents(__DIR__ . '/bin/district.json'), true);
foreach ($json_district['rows'] as $key => $value) {
if ($value['name'] == $district_name) {
$district['name'] = $value['name'];
$district['adcode'] = $value['adcode'];
$district['lat'] = $value['lat'];
$district['lng'] = $value['lng'];
}
}
}
return [
'province' => $province,
'city' => $city,
'district' => $district
];
}
}

@ -1,52 +1,52 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary\service;
use DtApp\ThinkLibrary\Service;
/**
* 路由服务
* Class RouteService
* @package DtApp\ThinkLibrary\service
*/
class RouteService extends Service
{
/**
* 跳转到某地址
* @param string $url
* @param int $status
* @param bool $parameter
*/
public function redirect(string $url = '', int $status = 302, bool $parameter = false): void
{
if (empty($url)) {
$url = request()->scheme() . "://" . request()->host();
}
$param = http_build_query(request()->param());
if ($status === 301) {
header('HTTP/1.1 301 Moved Permanently');
}
if (empty($parameter)) {
header("Location: {$url}");
} elseif (empty($parameter) === false && empty($param) === true) {
header("Location: {$url}");
} else {
header("Location: {$url}?{$param}");
}
exit;
}
}
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary\service;
use DtApp\ThinkLibrary\Service;
/**
* 路由服务
* Class RouteService
* @package DtApp\ThinkLibrary\service
*/
class RouteService extends Service
{
/**
* 跳转到某地址
* @param string $url
* @param int $status
* @param bool $parameter
*/
public function redirect(string $url = '', int $status = 302, bool $parameter = false): void
{
if (empty($url)) {
$url = request()->scheme() . "://" . request()->host();
}
$param = http_build_query(request()->param());
if ($status === 301) {
header('HTTP/1.1 301 Moved Permanently');
}
if (empty($parameter)) {
header("Location: {$url}");
} elseif (empty($parameter) === false && empty($param) === true) {
header("Location: {$url}");
} else {
header("Location: {$url}?{$param}");
}
exit;
}
}

@ -1,159 +1,159 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary\service;
use DtApp\ThinkLibrary\Service;
/**
* 本地存储
* Class StorageService
* @package DtApp\ThinkLibrary\service
*/
class StorageService extends Service
{
/**
* @var string
*/
private $path = '', $remotely = '';
/**
* 文件夹
* @param string $path
* @return $this
*/
public function path(string $path): self
{
$this->path = $path;
return $this;
}
/**
* 需要保存的远程文件
* @param string $remotely
* @return $this
*/
public function remotely(string $remotely): self
{
$this->remotely = $remotely;
return $this;
}
/**
* 获取配置信息
* @return $this
*/
private function getConfig(): self
{
$this->path = config('dtapp.storage.path');
return $this;
}
/**
* 保存文件
* @param string $name 保存的文件名
* @return array
*/
public function save(string $name): array
{
if (empty($this->path)) {
$this->getConfig();
}
// 判断文件夹是否存在
is_dir($this->path) || mkdir($concurrentDirectory = $this->path, 0777, true) || is_dir($concurrentDirectory);
$return_content = $this->http_get_data($this->remotely);
$fp = @fopen("{$this->path}{$name}", "a"); //将文件绑定到流
fwrite($fp, $return_content); //写入文件
return [
'file_name' => $name,
'path' => $this->path,
'remotely' => $this->remotely,
'save_path' => "{$this->path}{$name}",
'size' => $this->bytes($name)
];
}
/**
* 下载
* @param $url
* @return false|string
*/
private function http_get_data($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_URL, $url);
ob_start();
curl_exec($ch);
$return_content = ob_get_clean();
$return_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
return $return_content;
}
/**
* 删除文件
* @param string $name
* @return bool
*/
public function delete(string $name)
{
if (empty($this->path)) {
$this->getConfig();
}
if (file_exists($name)) {
if (unlink($name)) {
return true;
}
}
return false;
}
/**
* 统计文件大小
* @param string $name
* @return string
*/
public function bytes(string $name)
{
if (empty($this->path)) {
$this->getConfig();
}
$bytes = filesize($this->path . $name);
if ($bytes >= 1073741824) {
$bytes = round($bytes / 1073741824 * 100) / 100 . 'GB';
} elseif ($bytes >= 1048576) {
$bytes = round($bytes / 1048576 * 100) / 100 . 'MB';
} elseif ($bytes >= 1024) {
$bytes = round($bytes / 1024 * 100) / 100 . 'KB';
} else {
$bytes .= 'Bytes';
}
return $bytes;
}
/**
* 获取文件路径
* @return string
*/
public function getPath(): string
{
if (empty($this->path)) {
$this->getConfig();
}
return $this->path;
}
}
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary\service;
use DtApp\ThinkLibrary\Service;
/**
* 本地存储
* Class StorageService
* @package DtApp\ThinkLibrary\service
*/
class StorageService extends Service
{
/**
* @var string
*/
private $path = '', $remotely = '';
/**
* 文件夹
* @param string $path
* @return $this
*/
public function path(string $path): self
{
$this->path = $path;
return $this;
}
/**
* 需要保存的远程文件
* @param string $remotely
* @return $this
*/
public function remotely(string $remotely): self
{
$this->remotely = $remotely;
return $this;
}
/**
* 获取配置信息
* @return $this
*/
private function getConfig(): self
{
$this->path = config('dtapp.storage.path');
return $this;
}
/**
* 保存文件
* @param string $name 保存的文件名
* @return array
*/
public function save(string $name): array
{
if (empty($this->path)) {
$this->getConfig();
}
// 判断文件夹是否存在
is_dir($this->path) || mkdir($concurrentDirectory = $this->path, 0777, true) || is_dir($concurrentDirectory);
$return_content = $this->http_get_data($this->remotely);
$fp = @fopen("{$this->path}{$name}", "a"); //将文件绑定到流
fwrite($fp, $return_content); //写入文件
return [
'file_name' => $name,
'path' => $this->path,
'remotely' => $this->remotely,
'save_path' => "{$this->path}{$name}",
'size' => $this->bytes($name)
];
}
/**
* 下载
* @param $url
* @return false|string
*/
private function http_get_data($url)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_URL, $url);
ob_start();
curl_exec($ch);
$return_content = ob_get_clean();
$return_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
return $return_content;
}
/**
* 删除文件
* @param string $name
* @return bool
*/
public function delete(string $name)
{
if (empty($this->path)) {
$this->getConfig();
}
if (file_exists($name)) {
if (unlink($name)) {
return true;
}
}
return false;
}
/**
* 统计文件大小
* @param string $name
* @return string
*/
public function bytes(string $name)
{
if (empty($this->path)) {
$this->getConfig();
}
$bytes = filesize($this->path . $name);
if ($bytes >= 1073741824) {
$bytes = round($bytes / 1073741824 * 100) / 100 . 'GB';
} elseif ($bytes >= 1048576) {
$bytes = round($bytes / 1048576 * 100) / 100 . 'MB';
} elseif ($bytes >= 1024) {
$bytes = round($bytes / 1024 * 100) / 100 . 'KB';
} else {
$bytes .= 'Bytes';
}
return $bytes;
}
/**
* 获取文件路径
* @return string
*/
public function getPath(): string
{
if (empty($this->path)) {
$this->getConfig();
}
return $this->path;
}
}

@ -1,165 +1,165 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary\service;
use DtApp\ThinkLibrary\Service;
use Exception;
/**
* 系统服务
* Class SystemService
* @package DtApp\ThinkLibrary\service
*/
class SystemService extends Service
{
/**
* 生成最短URL地址
* @param string $url 路由地址
* @param array $vars PATH 变量
* @param boolean|string $suffix 后缀
* @param boolean|string $domain 域名
* @param boolean|string $fillSuffix 补上后缀
* @return string
*/
public function uri($url = '', array $vars = [], $suffix = true, $domain = false, $fillSuffix = false): string
{
$default_app = config('app.default_app', 'index');
$default_action = config('route.default_action', 'index');
$default_controller = config('route.default_controller', 'Index');
$url_html_suffix = config('route.url_html_suffix', 'html');
$pathinfo_depr = config('route.pathinfo_depr', '/');
$url_common_param = config('route.url_common_param', true);
if (empty($url)) {
$url = "{$default_app}/{$default_action}/{$default_controller}";
}
if (empty($suffix) && !empty($fillSuffix)) {
if (empty($url_common_param)) {
$location = $this->app->route->buildUrl($url, $vars)->suffix($suffix)->domain($domain)->build();
} else {
$location = $this->app->route->buildUrl($url, [])->suffix($suffix)->domain($domain)->build();
}
if (empty($vars)) {
$location = substr($location . ($pathinfo_depr) . $this->arr_to_str($vars, $pathinfo_depr), 0, -1) . ".{$url_html_suffix}";
} else {
$location .= ($pathinfo_depr) . $this->arr_to_str($vars, $pathinfo_depr) . ".{$url_html_suffix}";
}
} else {
$location = $this->app->route->buildUrl($url, $vars)->suffix($suffix)->domain($domain)->build();
}
return $location;
}
/**
* 二维数组转化为字符串,中间用,隔开
* @param $arr
* @param string $glue
* @return false|string
*/
private function arr_to_str($arr, $glue = "/")
{
$t = '';
foreach ($arr as $k => $v) {
$t .= $k . $glue . $v . $glue;
}
// 利用字符串截取函数消除最后一个
return substr($t, 0, -1);
}
/**
* @var array
*/
private $result = [];
/**
* 第一个mac地址
* @var
*/
private $macAddr;
/**
* 获取电脑MAC地址
* @return mixed
*/
public function mac()
{
switch (strtolower(PHP_OS)) {
case "solaris":
case "aix":
case 'unix':
break;
case "linux":
$this->getLinux();
break;
default:
$this->getWindows();
break;
}
$tem = array();
foreach ($this->result as $val) {
if (preg_match("/[0-9a-f][0-9a-f][:-]" . "[0-9a-f][0-9a-f][:-]" . "[0-9a-f][0-9a-f][:-]" . "[0-9a-f][0-9a-f][:-]" . "[0-9a-f][0-9a-f][:-]" . "[0-9a-f][0-9a-f]/i", $val, $tem)) {
$this->macAddr = $tem[0];//多个网卡时会返回第一个网卡的mac地址一般够用。
break;
//$this->macAddrs[] = $temp_array[0];//返回所有的mac地址
}
}
unset($temp_array);
return $this->macAddr;
}
/**
* Linux系统
* @return array
*/
private function getLinux(): array
{
@exec("ifconfig -a", $this->result);
return $this->result;
}
/**
* Windows系统
*/
private function getWindows(): void
{
@exec("ipconfig /all", $this->result);
if ($this->result) {
return;
}
$ipconfig = $_SERVER["WINDIR"] . "\system32\ipconfig.exe";
if (is_file($ipconfig)) {
@exec($ipconfig . " /all", $this->result);
return;
}
@exec($_SERVER["WINDIR"] . "\system\ipconfig.exe /all", $this->result);
}
/**
* 获取Linux服务器IP
* @return string
*/
public function linuxIp()
{
try {
$ip_cmd = "ifconfig eth0 | sed -n '/inet addr/p' | awk '{print $2}' | awk -F ':' '{print $2}'";
return trim(exec($ip_cmd));
} catch (Exception $e) {
return "0.0.0.0";
}
}
}
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary\service;
use DtApp\ThinkLibrary\Service;
use Exception;
/**
* 系统服务
* Class SystemService
* @package DtApp\ThinkLibrary\service
*/
class SystemService extends Service
{
/**
* 生成最短URL地址
* @param string $url 路由地址
* @param array $vars PATH 变量
* @param boolean|string $suffix 后缀
* @param boolean|string $domain 域名
* @param boolean|string $fillSuffix 补上后缀
* @return string
*/
public function uri($url = '', array $vars = [], $suffix = true, $domain = false, $fillSuffix = false): string
{
$default_app = config('app.default_app', 'index');
$default_action = config('route.default_action', 'index');
$default_controller = config('route.default_controller', 'Index');
$url_html_suffix = config('route.url_html_suffix', 'html');
$pathinfo_depr = config('route.pathinfo_depr', '/');
$url_common_param = config('route.url_common_param', true);
if (empty($url)) {
$url = "{$default_app}/{$default_action}/{$default_controller}";
}
if (empty($suffix) && !empty($fillSuffix)) {
if (empty($url_common_param)) {
$location = $this->app->route->buildUrl($url, $vars)->suffix($suffix)->domain($domain)->build();
} else {
$location = $this->app->route->buildUrl($url, [])->suffix($suffix)->domain($domain)->build();
}
if (empty($vars)) {
$location = substr($location . ($pathinfo_depr) . $this->arr_to_str($vars, $pathinfo_depr), 0, -1) . ".{$url_html_suffix}";
} else {
$location .= ($pathinfo_depr) . $this->arr_to_str($vars, $pathinfo_depr) . ".{$url_html_suffix}";
}
} else {
$location = $this->app->route->buildUrl($url, $vars)->suffix($suffix)->domain($domain)->build();
}
return $location;
}
/**
* 二维数组转化为字符串,中间用,隔开
* @param $arr
* @param string $glue
* @return false|string
*/
private function arr_to_str($arr, $glue = "/")
{
$t = '';
foreach ($arr as $k => $v) {
$t .= $k . $glue . $v . $glue;
}
// 利用字符串截取函数消除最后一个
return substr($t, 0, -1);
}
/**
* @var array
*/
private $result = [];
/**
* 第一个mac地址
* @var
*/
private $macAddr;
/**
* 获取电脑MAC地址
* @return mixed
*/
public function mac()
{
switch (strtolower(PHP_OS)) {
case "solaris":
case "aix":
case 'unix':
break;
case "linux":
$this->getLinux();
break;
default:
$this->getWindows();
break;
}
$tem = array();
foreach ($this->result as $val) {
if (preg_match("/[0-9a-f][0-9a-f][:-]" . "[0-9a-f][0-9a-f][:-]" . "[0-9a-f][0-9a-f][:-]" . "[0-9a-f][0-9a-f][:-]" . "[0-9a-f][0-9a-f][:-]" . "[0-9a-f][0-9a-f]/i", $val, $tem)) {
$this->macAddr = $tem[0];//多个网卡时会返回第一个网卡的mac地址一般够用。
break;
//$this->macAddrs[] = $temp_array[0];//返回所有的mac地址
}
}
unset($temp_array);
return $this->macAddr;
}
/**
* Linux系统
* @return array
*/
private function getLinux(): array
{
@exec("ifconfig -a", $this->result);
return $this->result;
}
/**
* Windows系统
*/
private function getWindows(): void
{
@exec("ipconfig /all", $this->result);
if ($this->result) {
return;
}
$ipconfig = $_SERVER["WINDIR"] . "\system32\ipconfig.exe";
if (is_file($ipconfig)) {
@exec($ipconfig . " /all", $this->result);
return;
}
@exec($_SERVER["WINDIR"] . "\system\ipconfig.exe /all", $this->result);
}
/**
* 获取Linux服务器IP
* @return string
*/
public function linuxIp()
{
try {
$ip_cmd = "ifconfig eth0 | sed -n '/inet addr/p' | awk '{print $2}' | awk -F ':' '{print $2}'";
return trim(exec($ip_cmd));
} catch (Exception $e) {
return "0.0.0.0";
}
}
}

@ -1,58 +1,58 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary\service;
use DtApp\ThinkLibrary\Service;
use DtApp\ThinkLibrary\service\curl\HttpService;
/**
* WorkTile
* Class WorkKileService
* @package DtApp\ThinkLibrary\service
*/
class WorkKileService extends Service
{
/**
* 发送文本消息
* @param string $webhook
* @param string $user 发送对象
* @param string $content 消息内容
* @return bool 发送结果
*/
public function text(string $webhook, string $user, string $content): bool
{
return $this->sendMsg($webhook, [
'user' => $user,
'text' => $content
]);
}
/**
* 组装发送消息
* @param string $webhook
* @param array $data 消息内容数组
* @return bool 发送结果
*/
private function sendMsg(string $webhook, array $data): bool
{
$result = HttpService::instance()
->url($webhook)
->data($data)
->toArray();
return $result['code'] === 200;
}
}
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary\service;
use DtApp\ThinkLibrary\Service;
use DtApp\ThinkLibrary\service\curl\HttpService;
/**
* WorkTile
* Class WorkKileService
* @package DtApp\ThinkLibrary\service
*/
class WorkKileService extends Service
{
/**
* 发送文本消息
* @param string $webhook
* @param string $user 发送对象
* @param string $content 消息内容
* @return bool 发送结果
*/
public function text(string $webhook, string $user, string $content): bool
{
return $this->sendMsg($webhook, [
'user' => $user,
'text' => $content
]);
}
/**
* 组装发送消息
* @param string $webhook
* @param array $data 消息内容数组
* @return bool 发送结果
*/
private function sendMsg(string $webhook, array $data): bool
{
$result = HttpService::instance()
->url($webhook)
->data($data)
->toArray();
return $result['code'] === 200;
}
}

@ -1,91 +1,91 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary\service\aliyun;
use DtApp\ThinkLibrary\Service;
use OSS\Core\OssException;
use OSS\OssClient;
/**
* 阿里云对象存储
* https://www.aliyun.com/product/oss
* Class OssService
* @package DtApp\ThinkLibrary\service\aliyun
*/
class OssService extends Service
{
/**
* @var
*/
private $accessKeyId, $accessKeySecret, $endpoint, $bucket;
/**
* @param string $accessKeyId
* @return $this
*/
public function accessKeyId(string $accessKeyId)
{
$this->accessKeyId = $accessKeyId;
return $this;
}
/**
* @param string $accessKeySecret
* @return $this
*/
public function accessKeySecret(string $accessKeySecret)
{
$this->accessKeySecret = $accessKeySecret;
return $this;
}
/**
* @param string $endpoint
* @return $this
*/
public function endpoint(string $endpoint): self
{
$this->endpoint = $endpoint;
return $this;
}
/**
* @param string $bucket
* @return $this
*/
public function bucket(string $bucket): self
{
$this->bucket = $bucket;
return $this;
}
/**
* @param string $object
* @param string $filePath
* @return bool
*/
public function upload(string $object, string $filePath): bool
{
try {
$ossClient = new OssClient($this->accessKeyId, $this->accessKeySecret, $this->endpoint);
$ossClient->uploadFile($this->bucket, $object, $filePath);
return true;
} catch (OssException $e) {
return false;
}
}
}
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary\service\aliyun;
use DtApp\ThinkLibrary\Service;
use OSS\Core\OssException;
use OSS\OssClient;
/**
* 阿里云对象存储
* https://www.aliyun.com/product/oss
* Class OssService
* @package DtApp\ThinkLibrary\service\aliyun
*/
class OssService extends Service
{
/**
* @var
*/
private $accessKeyId, $accessKeySecret, $endpoint, $bucket;
/**
* @param string $accessKeyId
* @return $this
*/
public function accessKeyId(string $accessKeyId)
{
$this->accessKeyId = $accessKeyId;
return $this;
}
/**
* @param string $accessKeySecret
* @return $this
*/
public function accessKeySecret(string $accessKeySecret)
{
$this->accessKeySecret = $accessKeySecret;
return $this;
}
/**
* @param string $endpoint
* @return $this
*/
public function endpoint(string $endpoint): self
{
$this->endpoint = $endpoint;
return $this;
}
/**
* @param string $bucket
* @return $this
*/
public function bucket(string $bucket): self
{
$this->bucket = $bucket;
return $this;
}
/**
* @param string $object
* @param string $filePath
* @return bool
*/
public function upload(string $object, string $filePath): bool
{
try {
$ossClient = new OssClient($this->accessKeyId, $this->accessKeySecret, $this->endpoint);
$ossClient->uploadFile($this->bucket, $object, $filePath);
return true;
} catch (OssException $e) {
return false;
}
}
}

@ -1,112 +1,112 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary\service\amap;
use DtApp\ThinkLibrary\Service;
use DtApp\ThinkLibrary\service\curl\HttpService;
/**
* 高德地图
* https://lbs.amap.com/api/webservice/summary
* Class AmApService
* @package DtApp\ThinkLibrary\service\amap
*/
class AmApService extends Service
{
/**
* @var string
*/
private $url = "https://restapi.amap.com/v3/";
/**
* @var string
*/
private $key = "";
/**
* @var string
*/
private $output = "JSON";
/**
* @param string $key
* @return $this
*/
public function key(string $key): self
{
$this->key = $key;
return $this;
}
/**
* 天气查询
* https://lbs.amap.com/api/webservice/guide/api/weatherinfo
* @param string $city
* @param string $extensions
* @return array|bool|mixed|string
*/
public function weather($city = "110101", $extensions = "base")
{
$data = http_build_query([
"city" => $city,
"extensions" => $extensions,
"key" => $this->key,
"output" => $this->output,
]);
return HttpService::instance()
->url("{$this->url}weather/weatherInfo?{$data}")
->toArray();
}
/**
* 地理编码
* https://lbs.amap.com/api/webservice/guide/api/georegeo#geo
* @param $address
* @param string $city
* @return array|bool|mixed|string
*/
public function gCoderGeo($address, $city = '')
{
$data = http_build_query([
"city" => $city,
"address" => $address,
"key" => $this->key,
"output" => $this->output,
]);
return HttpService::instance()
->url("{$this->url}geocode/geo?{$data}")
->toArray();
}
/**
* 逆地理编码
* https://lbs.amap.com/api/webservice/guide/api/georegeo#regeo
* @param $location
* @return array|bool|mixed|string
*/
public function gCoderReGeo($location)
{
$data = http_build_query([
"location" => $location,
"key" => $this->key,
"output" => $this->output,
]);
return HttpService::instance()
->url("{$this->url}geocode/regeo?{$data}")
->toArray();
}
}
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary\service\amap;
use DtApp\ThinkLibrary\Service;
use DtApp\ThinkLibrary\service\curl\HttpService;
/**
* 高德地图
* https://lbs.amap.com/api/webservice/summary
* Class AmApService
* @package DtApp\ThinkLibrary\service\amap
*/
class AmApService extends Service
{
/**
* @var string
*/
private $url = "https://restapi.amap.com/v3/";
/**
* @var string
*/
private $key = "";
/**
* @var string
*/
private $output = "JSON";
/**
* @param string $key
* @return $this
*/
public function key(string $key): self
{
$this->key = $key;
return $this;
}
/**
* 天气查询
* https://lbs.amap.com/api/webservice/guide/api/weatherinfo
* @param string $city
* @param string $extensions
* @return array|bool|mixed|string
*/
public function weather($city = "110101", $extensions = "base")
{
$data = http_build_query([
"city" => $city,
"extensions" => $extensions,
"key" => $this->key,
"output" => $this->output,
]);
return HttpService::instance()
->url("{$this->url}weather/weatherInfo?{$data}")
->toArray();
}
/**
* 地理编码
* https://lbs.amap.com/api/webservice/guide/api/georegeo#geo
* @param $address
* @param string $city
* @return array|bool|mixed|string
*/
public function gCoderGeo($address, $city = '')
{
$data = http_build_query([
"city" => $city,
"address" => $address,
"key" => $this->key,
"output" => $this->output,
]);
return HttpService::instance()
->url("{$this->url}geocode/geo?{$data}")
->toArray();
}
/**
* 逆地理编码
* https://lbs.amap.com/api/webservice/guide/api/georegeo#regeo
* @param $location
* @return array|bool|mixed|string
*/
public function gCoderReGeo($location)
{
$data = http_build_query([
"location" => $location,
"key" => $this->key,
"output" => $this->output,
]);
return HttpService::instance()
->url("{$this->url}geocode/regeo?{$data}")
->toArray();
}
}

@ -1,97 +1,97 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary\service\baidu;
use BaiduBce\Services\Bos\BosClient;
use DtApp\ThinkLibrary\Service;
use Exception;
/**
* 百度云对象存储
* https://cloud.baidu.com/product/bos.html
* Class BosService
* @package DtApp\ThinkLibrary\service\baidu
*/
class BosService extends Service
{
/**
* @var
*/
private $accessKeyId, $secretAccessKey, $endpoint, $bucket;
/**
* @param string $accessKeyId
* @return $this
*/
public function accessKeyId(string $accessKeyId)
{
$this->accessKeyId = $accessKeyId;
return $this;
}
/**
* @param string $secretAccessKey
* @return $this
*/
public function secretAccessKey(string $secretAccessKey)
{
$this->secretAccessKey = $secretAccessKey;
return $this;
}
/**
* @param string $endpoint
* @return $this
*/
public function endpoint(string $endpoint)
{
$this->endpoint = $endpoint;
return $this;
}
/**
* @param string $bucket
* @return $this
*/
public function bucket(string $bucket)
{
$this->bucket = $bucket;
return $this;
}
/**
* @param string $object
* @param string $filePath
* @return bool
* @throws Exception
*/
public function upload(string $object, string $filePath): bool
{
// 设置BosClient的Access Key ID、Secret Access Key和ENDPOINT
$BOS_TEST_CONFIG = array(
'credentials' => array(
'accessKeyId' => $this->accessKeyId,
'secretAccessKey' => $this->secretAccessKey,
),
'endpoint' => $this->endpoint,
);
$client = new BosClient($BOS_TEST_CONFIG);
// 从文件中直接上传Object
$client->putObjectFromFile($this->bucket, $object, $filePath);
return true;
}
}
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary\service\baidu;
use BaiduBce\Services\Bos\BosClient;
use DtApp\ThinkLibrary\Service;
use Exception;
/**
* 百度云对象存储
* https://cloud.baidu.com/product/bos.html
* Class BosService
* @package DtApp\ThinkLibrary\service\baidu
*/
class BosService extends Service
{
/**
* @var
*/
private $accessKeyId, $secretAccessKey, $endpoint, $bucket;
/**
* @param string $accessKeyId
* @return $this
*/
public function accessKeyId(string $accessKeyId)
{
$this->accessKeyId = $accessKeyId;
return $this;
}
/**
* @param string $secretAccessKey
* @return $this
*/
public function secretAccessKey(string $secretAccessKey)
{
$this->secretAccessKey = $secretAccessKey;
return $this;
}
/**
* @param string $endpoint
* @return $this
*/
public function endpoint(string $endpoint)
{
$this->endpoint = $endpoint;
return $this;
}
/**
* @param string $bucket
* @return $this
*/
public function bucket(string $bucket)
{
$this->bucket = $bucket;
return $this;
}
/**
* @param string $object
* @param string $filePath
* @return bool
* @throws Exception
*/
public function upload(string $object, string $filePath): bool
{
// 设置BosClient的Access Key ID、Secret Access Key和ENDPOINT
$BOS_TEST_CONFIG = array(
'credentials' => array(
'accessKeyId' => $this->accessKeyId,
'secretAccessKey' => $this->secretAccessKey,
),
'endpoint' => $this->endpoint,
);
$client = new BosClient($BOS_TEST_CONFIG);
// 从文件中直接上传Object
$client->putObjectFromFile($this->bucket, $object, $filePath);
return true;
}
}

@ -1,106 +1,106 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary\service\baidu;
use DtApp\ThinkLibrary\exception\DtaException;
use DtApp\ThinkLibrary\Service;
use DtApp\ThinkLibrary\service\curl\HttpService;
/**
* 百度地图
* http://lbsyun.baidu.com/index.php?title=webapi
* Class LbsYunService
* @package DtApp\ThinkLibrary\service\baidu
*/
class LbsYunService extends Service
{
/**
* @var string
*/
private $ak = "";
/**
* @var string
*/
private $output = "json";
/**
* @param string $ak
* @return $this
*/
public function ak(string $ak): self
{
$this->ak = $ak;
return $this;
}
/**
* 国内天气查询
* http://lbsyun.baidu.com/index.php?title=webapi/weather
* @param int $district_id
* @param string $coordtype
* @param string $location
* @return array|bool|mixed|string
* @throws DtaException
*/
public function weather($district_id = 110100, string $coordtype = "bd09ll", string $location = "")
{
if (empty($this->ak)) {
throw new DtaException('请检查ak参数');
}
$data = http_build_query([
"district_id" => $district_id,
"coordtype" => $coordtype,
"ak" => $this->ak,
"location" => $location,
"data_type" => 'all',
"output" => $this->output,
]);
return HttpService::instance()
->url("http://api.map.baidu.com/weather/v1/?{$data}")
->toArray();
}
/**
* 国外天气查询
* http://lbsyun.baidu.com/index.php?title=webapi/weather-abroad
* @param int $district_id
* @param string $coordtype
* @param string $location
* @param string $language
* @return array|bool|mixed|string
* @throws DtaException
*/
public function weatherAbroad($district_id = 110100, string $coordtype = "bd09ll", string $location = "", string $language = "cn")
{
if (empty($this->ak)) {
throw new DtaException('请检查ak参数');
}
$data = http_build_query([
"district_id" => $district_id,
"coordtype" => $coordtype,
"ak" => $this->ak,
"location" => $location,
"data_type" => 'all',
"language" => $language,
"output" => $this->output,
]);
return HttpService::instance()
->url("http://api.map.baidu.com/weather_abroad/v1/?{$data}")
->toArray();
}
}
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary\service\baidu;
use DtApp\ThinkLibrary\exception\DtaException;
use DtApp\ThinkLibrary\Service;
use DtApp\ThinkLibrary\service\curl\HttpService;
/**
* 百度地图
* http://lbsyun.baidu.com/index.php?title=webapi
* Class LbsYunService
* @package DtApp\ThinkLibrary\service\baidu
*/
class LbsYunService extends Service
{
/**
* @var string
*/
private $ak = "";
/**
* @var string
*/
private $output = "json";
/**
* @param string $ak
* @return $this
*/
public function ak(string $ak): self
{
$this->ak = $ak;
return $this;
}
/**
* 国内天气查询
* http://lbsyun.baidu.com/index.php?title=webapi/weather
* @param int $district_id
* @param string $coordtype
* @param string $location
* @return array|bool|mixed|string
* @throws DtaException
*/
public function weather($district_id = 110100, string $coordtype = "bd09ll", string $location = "")
{
if (empty($this->ak)) {
throw new DtaException('请检查ak参数');
}
$data = http_build_query([
"district_id" => $district_id,
"coordtype" => $coordtype,
"ak" => $this->ak,
"location" => $location,
"data_type" => 'all',
"output" => $this->output,
]);
return HttpService::instance()
->url("http://api.map.baidu.com/weather/v1/?{$data}")
->toArray();
}
/**
* 国外天气查询
* http://lbsyun.baidu.com/index.php?title=webapi/weather-abroad
* @param int $district_id
* @param string $coordtype
* @param string $location
* @param string $language
* @return array|bool|mixed|string
* @throws DtaException
*/
public function weatherAbroad($district_id = 110100, string $coordtype = "bd09ll", string $location = "", string $language = "cn")
{
if (empty($this->ak)) {
throw new DtaException('请检查ak参数');
}
$data = http_build_query([
"district_id" => $district_id,
"coordtype" => $coordtype,
"ak" => $this->ak,
"location" => $location,
"data_type" => 'all',
"language" => $language,
"output" => $this->output,
]);
return HttpService::instance()
->url("http://api.map.baidu.com/weather_abroad/v1/?{$data}")
->toArray();
}
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

@ -1,311 +1,311 @@
{
"rows": [
{
"adcode": "360000",
"people_count_2010": 43976312,
"lat": 28.676493,
"lng": 115.892151,
"name": "江西省",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "410000",
"people_count_2010": 96486884,
"lat": 34.757975,
"lng": 113.665412,
"name": "河南省",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "510000",
"people_count_2010": 85974759,
"lat": 30.659462,
"lng": 104.065735,
"name": "四川省",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "500000",
"people_count_2010": 28458101,
"lat": 29.533155,
"lng": 106.504962,
"name": "重庆市",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "540000",
"people_count_2010": 2554907,
"lat": 29.660361,
"lng": 91.132212,
"name": "西藏自治区",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "520000",
"people_count_2010": 25119376,
"lat": 26.578343,
"lng": 106.713478,
"name": "贵州省",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "210000",
"people_count_2010": 43149614,
"lat": 41.796767,
"lng": 123.429096,
"name": "辽宁省",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "650000",
"people_count_2010": 29070614,
"lat": 43.792818,
"lng": 87.617733,
"name": "新疆维吾尔自治区",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "370000",
"people_count_2010": 94646230,
"lat": 36.675807,
"lng": 117.000923,
"name": "山东省",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "310000",
"people_count_2010": 21135161,
"lat": 31.231706,
"lng": 121.472644,
"name": "上海市",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "820000",
"people_count_2010": null,
"lat": 22.198951,
"lng": 113.54909,
"name": "澳門特別行政區",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "140000",
"people_count_2010": 34364492,
"lat": 37.857014,
"lng": 112.549248,
"name": "山西省",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "330000",
"people_count_2010": 53807755,
"lat": 30.287459,
"lng": 120.153576,
"name": "浙江省",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "460000",
"people_count_2010": 42028870,
"lat": 20.031971,
"lng": 110.33119,
"name": "海南省",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "350000",
"people_count_2010": 39026582,
"lat": 26.075302,
"lng": 119.306239,
"name": "福建省",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "630000",
"people_count_2010": 5619543,
"lat": 36.623178,
"lng": 101.778916,
"name": "青海省",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "640000",
"people_count_2010": 6466366,
"lat": 38.46637,
"lng": 106.278179,
"name": "宁夏回族自治区",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "420000",
"people_count_2010": 62160766,
"lat": 30.584355,
"lng": 114.298572,
"name": "湖北省",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "620000",
"people_count_2010": 27957557,
"lat": 36.058039,
"lng": 103.823557,
"name": "甘肃省",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "340000",
"people_count_2010": 57217014,
"lat": 31.86119,
"lng": 117.283042,
"name": "安徽省",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "710000",
"people_count_2010": null,
"lat": 25.044332,
"lng": 121.509062,
"name": "台湾省",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "610000",
"people_count_2010": 35876998,
"lat": 34.263161,
"lng": 108.948024,
"name": "陕西省",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "450000",
"people_count_2010": 47082115,
"lat": 22.82402,
"lng": 108.320004,
"name": "广西壮族自治区",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "120000",
"people_count_2010": 15298136,
"lat": 39.125596,
"lng": 117.190182,
"name": "天津市",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "530000",
"people_count_2010": 72840959,
"lat": 25.040609,
"lng": 102.712251,
"name": "云南省",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "230000",
"people_count_2010": 40734477,
"lat": 45.756967,
"lng": 126.642464,
"name": "黑龙江省",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "440000",
"people_count_2010": 107131199,
"lat": 23.125178,
"lng": 113.280637,
"name": "广东省",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "430000",
"people_count_2010": 67158313,
"lat": 28.19409,
"lng": 112.982279,
"name": "湖南省",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "130000",
"people_count_2010": 106816280,
"lat": 38.045474,
"lng": 114.502461,
"name": "河北省",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "150000",
"people_count_2010": 26353789,
"lat": 40.818311,
"lng": 111.670801,
"name": "内蒙古自治区",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "220000",
"people_count_2010": 26423220,
"lat": 43.886841,
"lng": 125.3245,
"name": "吉林省",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "320000",
"people_count_2010": 79104628,
"lat": 32.041544,
"lng": 118.767413,
"name": "江苏省",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "110000",
"people_count_2010": 18934592,
"lat": 39.904989,
"lng": 116.405285,
"name": "北京市",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "810000",
"people_count_2010": null,
"lat": 22.320048,
"lng": 114.173355,
"name": "香港特別行政區",
"level": "province",
"parent": "中华人民共和国"
}
],
"total": 34
}
{
"rows": [
{
"adcode": "360000",
"people_count_2010": 43976312,
"lat": 28.676493,
"lng": 115.892151,
"name": "江西省",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "410000",
"people_count_2010": 96486884,
"lat": 34.757975,
"lng": 113.665412,
"name": "河南省",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "510000",
"people_count_2010": 85974759,
"lat": 30.659462,
"lng": 104.065735,
"name": "四川省",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "500000",
"people_count_2010": 28458101,
"lat": 29.533155,
"lng": 106.504962,
"name": "重庆市",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "540000",
"people_count_2010": 2554907,
"lat": 29.660361,
"lng": 91.132212,
"name": "西藏自治区",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "520000",
"people_count_2010": 25119376,
"lat": 26.578343,
"lng": 106.713478,
"name": "贵州省",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "210000",
"people_count_2010": 43149614,
"lat": 41.796767,
"lng": 123.429096,
"name": "辽宁省",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "650000",
"people_count_2010": 29070614,
"lat": 43.792818,
"lng": 87.617733,
"name": "新疆维吾尔自治区",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "370000",
"people_count_2010": 94646230,
"lat": 36.675807,
"lng": 117.000923,
"name": "山东省",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "310000",
"people_count_2010": 21135161,
"lat": 31.231706,
"lng": 121.472644,
"name": "上海市",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "820000",
"people_count_2010": null,
"lat": 22.198951,
"lng": 113.54909,
"name": "澳門特別行政區",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "140000",
"people_count_2010": 34364492,
"lat": 37.857014,
"lng": 112.549248,
"name": "山西省",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "330000",
"people_count_2010": 53807755,
"lat": 30.287459,
"lng": 120.153576,
"name": "浙江省",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "460000",
"people_count_2010": 42028870,
"lat": 20.031971,
"lng": 110.33119,
"name": "海南省",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "350000",
"people_count_2010": 39026582,
"lat": 26.075302,
"lng": 119.306239,
"name": "福建省",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "630000",
"people_count_2010": 5619543,
"lat": 36.623178,
"lng": 101.778916,
"name": "青海省",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "640000",
"people_count_2010": 6466366,
"lat": 38.46637,
"lng": 106.278179,
"name": "宁夏回族自治区",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "420000",
"people_count_2010": 62160766,
"lat": 30.584355,
"lng": 114.298572,
"name": "湖北省",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "620000",
"people_count_2010": 27957557,
"lat": 36.058039,
"lng": 103.823557,
"name": "甘肃省",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "340000",
"people_count_2010": 57217014,
"lat": 31.86119,
"lng": 117.283042,
"name": "安徽省",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "710000",
"people_count_2010": null,
"lat": 25.044332,
"lng": 121.509062,
"name": "台湾省",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "610000",
"people_count_2010": 35876998,
"lat": 34.263161,
"lng": 108.948024,
"name": "陕西省",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "450000",
"people_count_2010": 47082115,
"lat": 22.82402,
"lng": 108.320004,
"name": "广西壮族自治区",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "120000",
"people_count_2010": 15298136,
"lat": 39.125596,
"lng": 117.190182,
"name": "天津市",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "530000",
"people_count_2010": 72840959,
"lat": 25.040609,
"lng": 102.712251,
"name": "云南省",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "230000",
"people_count_2010": 40734477,
"lat": 45.756967,
"lng": 126.642464,
"name": "黑龙江省",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "440000",
"people_count_2010": 107131199,
"lat": 23.125178,
"lng": 113.280637,
"name": "广东省",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "430000",
"people_count_2010": 67158313,
"lat": 28.19409,
"lng": 112.982279,
"name": "湖南省",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "130000",
"people_count_2010": 106816280,
"lat": 38.045474,
"lng": 114.502461,
"name": "河北省",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "150000",
"people_count_2010": 26353789,
"lat": 40.818311,
"lng": 111.670801,
"name": "内蒙古自治区",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "220000",
"people_count_2010": 26423220,
"lat": 43.886841,
"lng": 125.3245,
"name": "吉林省",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "320000",
"people_count_2010": 79104628,
"lat": 32.041544,
"lng": 118.767413,
"name": "江苏省",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "110000",
"people_count_2010": 18934592,
"lat": 39.904989,
"lng": 116.405285,
"name": "北京市",
"level": "province",
"parent": "中华人民共和国"
},
{
"adcode": "810000",
"people_count_2010": null,
"lat": 22.320048,
"lng": 114.173355,
"name": "香港特別行政區",
"level": "province",
"parent": "中华人民共和国"
}
],
"total": 34
}

@ -1,460 +1,460 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary\service\bt;
use DtApp\ThinkLibrary\exception\DtaException;
use DtApp\ThinkLibrary\facade\Files;
use DtApp\ThinkLibrary\Service;
use DtApp\ThinkLibrary\service\curl\BtService;
/**
* 宝塔Api
* https://www.bt.cn/
* Class ApiService
* @package DtApp\ThinkLibrary\service\bt
*/
class ApiService extends Service
{
/**
* @var string
*/
private $url = '';
/**
* @var int
*/
private $page = 1;
/**
* @var int
*/
private $limit = 15;
/**
* @var string
*/
private $order = 'id desc';
/**
* @var array
*/
private $where = [];
/**
* @var
*/
private $contents, $backtrack, $key, $panel;
/**
* @param string $key
* @return $this
*/
public function key(string $key): self
{
$this->key = $key;
return $this;
}
/**
* @param string $panel
* @return $this
*/
public function panel(string $panel)
{
$this->panel = $panel;
return $this;
}
/**
* 获取配置信息
* @return $this
*/
private function getConfig(): self
{
$this->key = config('dtapp.bt.key');
$this->panel = config('dtapp.bt.panel');
return $this;
}
/**
* 获取监控信息
* @param string $type 类型 GetCpuIo = CPU信息/内存 GetDiskIo = 磁盘IO GetNetWorkIo = 网络IO
* @param int $start_time 开始时间
* @param int $end_time 结束时间
* @return mixed
*/
public function getCpuIoInfo($type = 'GetCpuIo', $start_time = 0, $end_time = 0)
{
if (empty($start_time)) {
$start_time = strtotime(date('Y-m-d'));
}
if (empty($end_time)) {
$end_time = time();
}
$this->url = "/ajax?action={$type}&start={$start_time}&end={$end_time}";
return $this;
}
/**
* 获取网站列表
* @return mixed
*/
public function getSites()
{
$this->url = "crontab?action=GetDataList";
$this->where['type'] = 'sites';
return $this;
}
/**
* 获取数据库列表
* @return mixed
*/
public function getDatabases()
{
$this->url = 'data?action=getData';
$this->where['tojs'] = 'database.get_list';
$this->where['table'] = 'databases';
$this->where['limit'] = $this->limit;
$this->where['p'] = $this->page;
$this->where['order'] = $this->order;
return $this;
}
/**
* 获取防火墙
* @return mixed
*/
public function getFirewalls()
{
$this->url = 'data?action=getData';
$this->where['tojs'] = 'firewall.get_list';
$this->where['table'] = 'firewall';
$this->where['limit'] = $this->limit;
$this->where['p'] = $this->page;
$this->where['order'] = $this->order;
return $this;
}
/**
* 获取面板日志
* @return mixed
*/
public function getLogs()
{
$this->url = 'data?action=getData';
$this->where['tojs'] = 'firewall.get_log_list';
$this->where['table'] = 'logs';
$this->where['limit'] = $this->limit;
$this->where['p'] = $this->page;
$this->where['order'] = $this->order;
return $this;
}
/**
* 获取消息通道
* @return mixed
*/
public function getNews()
{
$this->url = 'config?action=get_settings';
return $this;
}
/**
* 获取网站列表
* @return mixed
*/
public function getCronTabs()
{
$this->url = 'data?action=getData';
$this->where['tojs'] = 'site.get_list';
$this->where['table'] = 'sites';
$this->where['limit'] = $this->limit;
$this->where['p'] = $this->page;
$this->where['order'] = $this->order;
return $this;
}
/**
* 获取网站分类
* @return mixed
*/
public function getTypes()
{
$this->url = 'site?action=get_site_types';
return $this;
}
/**
* 获取软件列表
* @return mixed
*/
public function getSoFts()
{
$this->url = 'plugin?action=get_soft_list';
$this->where['p'] = $this->page;
$this->where['tojs'] = 'soft.get_list';
return $this;
}
/**
* 获取硬盘信息
* @return mixed
*/
public function getDiskInfo()
{
$this->url = 'system?action=GetDiskInfo';
return $this;
}
/**
* 获取信息系统
* @return mixed
*/
public function getSystemTotal()
{
$this->url = 'system?action=GetSystemTotal';
return $this;
}
/**
* 获取用户信息
* @return mixed
*/
public function getUserInfo()
{
$this->url = 'ssl?action=GetUserInfo';
return $this;
}
/**
* 获取网络信息
* @return mixed
*/
public function getNetWork()
{
$this->url = 'system?action=GetNetWork';
return $this;
}
/**
* 获取插件信息
* @return mixed
*/
public function getPlugin()
{
$this->url = 'plugin?action=get_index_list';
return $this;
}
/**
* 获取软件信息
* @return mixed
*/
public function getSoft()
{
$this->url = 'plugin?action=get_soft_list';
return $this;
}
/**
* 获取更新信息
* @return mixed
*/
public function getUpdatePanel()
{
$this->url = 'ajax?action=UpdatePanel';
return $this;
}
/**
* 当前页码
* @param int $is
* @return $this
*/
public function page(int $is = 1): self
{
$this->page = $is;
return $this;
}
/**
* 返回数量
* @param int $is
* @return $this
*/
public function limit(int $is = 15): self
{
$this->limit = $is;
return $this;
}
/**
* 排序
* @param string $ss
* @return $this
*/
public function order(string $ss = 'id desc'): self
{
$this->order = $ss;
return $this;
}
/**
* 查询条件
* @param array $array
* @return ApiService
*/
public function where($array = []): ApiService
{
$this->where = $array;
return $this;
}
/**
* 获取数据和总数
* @return $this
*/
private function getDataWithOrderOpt(): self
{
$this->backtrack['data'] = $this->contents['data'];
$this->backtrack['orderOpt'] = $this->contents['orderOpt'];
return $this;
}
/**
* 获取数据和总数
* @return $this
*/
private function getDataWithCount(): self
{
if (empty($this->contents['data'])) {
$this->contents['data'] = [];
}
if (!is_array($this->contents['data'])) {
$this->contents['data'] = [];
}
$this->backtrack['data'] = $this->contents;
if (empty($this->contents['page'])) {
$this->contents['page'] = 0;
}
$this->backtrack['count'] = $this->getCountData($this->contents['page']);
return $this;
}
/**
* 获取数据
* @return $this
*/
private function getData()
{
$this->backtrack['data'] = $this->contents;
return $this;
}
/**
* 发起网络请求
* @return $this
* @throws DtaException
*/
private function getHttp(): self
{
//请求面板接口
$this->contents = $this->HttpPostCookie($this->url, $this->where);
return $this;
}
/**
* 返回Array
* @return array|mixed
* @throws DtaException
*/
public function toArray()
{
$this->getHttp();
if ($this->where['type'] === 'sites') {
$this->getDataWithOrderOpt();
} else {
$this->getDataWithCount();
}
if (empty($this->backtrack)) {
return [];
}
if (is_array($this->backtrack)) {
return $this->backtrack;
}
return json_decode($this->backtrack, true);
}
/**
* 发起POST请求
* @param string $url 网址
* @param array $data 数据
* @param bool $is_json 是否返回Json格式
* @return bool|mixed|string
* @throws DtaException
*/
protected function HttpPostCookie(string $url, array $data = [], bool $is_json = true)
{
if (empty($this->panel)) {
$this->getConfig();
}
if (empty($this->panel)) {
throw new DtaException('请检查panel参数');
}
//定义cookie保存位置
$file = app()->getRootPath() . 'runtime/dtapp/bt/cookie/';
$cookie_file = $file . md5($this->panel) . '.cookie';
if (empty(Files::judgeContents($file)) && !mkdir($file, 0777, true) && !is_dir($file)) {
throw new \RuntimeException(sprintf('Directory "%s" was not created', $file));
}
if (!file_exists($cookie_file)) {
$fp = fopen($cookie_file, 'wb+');
fclose($fp);
}
if (empty($this->key)) {
$this->getConfig();
}
if (empty($this->key)) {
throw new DtaException('请检查key参数');
}
return BtService::instance()
->panel($this->panel)
->key($this->key)
->url($url)
->cookie($cookie_file)
->data($data)
->toArray($is_json);
}
/**
* 获取总数
* @param string $str
* @return false|int|string
*/
protected function getCountData(string $str)
{
$start = strpos($str, "共");
$end = strpos($str, "条数据");
$count = substr($str, $start + 3, $end - $start - 3);
if (empty($count)) {
return 0;
}
return $count;
}
}
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary\service\bt;
use DtApp\ThinkLibrary\exception\DtaException;
use DtApp\ThinkLibrary\facade\Files;
use DtApp\ThinkLibrary\Service;
use DtApp\ThinkLibrary\service\curl\BtService;
/**
* 宝塔Api
* https://www.bt.cn/
* Class ApiService
* @package DtApp\ThinkLibrary\service\bt
*/
class ApiService extends Service
{
/**
* @var string
*/
private $url = '';
/**
* @var int
*/
private $page = 1;
/**
* @var int
*/
private $limit = 15;
/**
* @var string
*/
private $order = 'id desc';
/**
* @var array
*/
private $where = [];
/**
* @var
*/
private $contents, $backtrack, $key, $panel;
/**
* @param string $key
* @return $this
*/
public function key(string $key): self
{
$this->key = $key;
return $this;
}
/**
* @param string $panel
* @return $this
*/
public function panel(string $panel)
{
$this->panel = $panel;
return $this;
}
/**
* 获取配置信息
* @return $this
*/
private function getConfig(): self
{
$this->key = config('dtapp.bt.key');
$this->panel = config('dtapp.bt.panel');
return $this;
}
/**
* 获取监控信息
* @param string $type 类型 GetCpuIo = CPU信息/内存 GetDiskIo = 磁盘IO GetNetWorkIo = 网络IO
* @param int $start_time 开始时间
* @param int $end_time 结束时间
* @return mixed
*/
public function getCpuIoInfo($type = 'GetCpuIo', $start_time = 0, $end_time = 0)
{
if (empty($start_time)) {
$start_time = strtotime(date('Y-m-d'));
}
if (empty($end_time)) {
$end_time = time();
}
$this->url = "/ajax?action={$type}&start={$start_time}&end={$end_time}";
return $this;
}
/**
* 获取网站列表
* @return mixed
*/
public function getSites()
{
$this->url = "crontab?action=GetDataList";
$this->where['type'] = 'sites';
return $this;
}
/**
* 获取数据库列表
* @return mixed
*/
public function getDatabases()
{
$this->url = 'data?action=getData';
$this->where['tojs'] = 'database.get_list';
$this->where['table'] = 'databases';
$this->where['limit'] = $this->limit;
$this->where['p'] = $this->page;
$this->where['order'] = $this->order;
return $this;
}
/**
* 获取防火墙
* @return mixed
*/
public function getFirewalls()
{
$this->url = 'data?action=getData';
$this->where['tojs'] = 'firewall.get_list';
$this->where['table'] = 'firewall';
$this->where['limit'] = $this->limit;
$this->where['p'] = $this->page;
$this->where['order'] = $this->order;
return $this;
}
/**
* 获取面板日志
* @return mixed
*/
public function getLogs()
{
$this->url = 'data?action=getData';
$this->where['tojs'] = 'firewall.get_log_list';
$this->where['table'] = 'logs';
$this->where['limit'] = $this->limit;
$this->where['p'] = $this->page;
$this->where['order'] = $this->order;
return $this;
}
/**
* 获取消息通道
* @return mixed
*/
public function getNews()
{
$this->url = 'config?action=get_settings';
return $this;
}
/**
* 获取网站列表
* @return mixed
*/
public function getCronTabs()
{
$this->url = 'data?action=getData';
$this->where['tojs'] = 'site.get_list';
$this->where['table'] = 'sites';
$this->where['limit'] = $this->limit;
$this->where['p'] = $this->page;
$this->where['order'] = $this->order;
return $this;
}
/**
* 获取网站分类
* @return mixed
*/
public function getTypes()
{
$this->url = 'site?action=get_site_types';
return $this;
}
/**
* 获取软件列表
* @return mixed
*/
public function getSoFts()
{
$this->url = 'plugin?action=get_soft_list';
$this->where['p'] = $this->page;
$this->where['tojs'] = 'soft.get_list';
return $this;
}
/**
* 获取硬盘信息
* @return mixed
*/
public function getDiskInfo()
{
$this->url = 'system?action=GetDiskInfo';
return $this;
}
/**
* 获取信息系统
* @return mixed
*/
public function getSystemTotal()
{
$this->url = 'system?action=GetSystemTotal';
return $this;
}
/**
* 获取用户信息
* @return mixed
*/
public function getUserInfo()
{
$this->url = 'ssl?action=GetUserInfo';
return $this;
}
/**
* 获取网络信息
* @return mixed
*/
public function getNetWork()
{
$this->url = 'system?action=GetNetWork';
return $this;
}
/**
* 获取插件信息
* @return mixed
*/
public function getPlugin()
{
$this->url = 'plugin?action=get_index_list';
return $this;
}
/**
* 获取软件信息
* @return mixed
*/
public function getSoft()
{
$this->url = 'plugin?action=get_soft_list';
return $this;
}
/**
* 获取更新信息
* @return mixed
*/
public function getUpdatePanel()
{
$this->url = 'ajax?action=UpdatePanel';
return $this;
}
/**
* 当前页码
* @param int $is
* @return $this
*/
public function page(int $is = 1): self
{
$this->page = $is;
return $this;
}
/**
* 返回数量
* @param int $is
* @return $this
*/
public function limit(int $is = 15): self
{
$this->limit = $is;
return $this;
}
/**
* 排序
* @param string $ss
* @return $this
*/
public function order(string $ss = 'id desc'): self
{
$this->order = $ss;
return $this;
}
/**
* 查询条件
* @param array $array
* @return ApiService
*/
public function where($array = []): ApiService
{
$this->where = $array;
return $this;
}
/**
* 获取数据和总数
* @return $this
*/
private function getDataWithOrderOpt(): self
{
$this->backtrack['data'] = $this->contents['data'];
$this->backtrack['orderOpt'] = $this->contents['orderOpt'];
return $this;
}
/**
* 获取数据和总数
* @return $this
*/
private function getDataWithCount(): self
{
if (empty($this->contents['data'])) {
$this->contents['data'] = [];
}
if (!is_array($this->contents['data'])) {
$this->contents['data'] = [];
}
$this->backtrack['data'] = $this->contents;
if (empty($this->contents['page'])) {
$this->contents['page'] = 0;
}
$this->backtrack['count'] = $this->getCountData($this->contents['page']);
return $this;
}
/**
* 获取数据
* @return $this
*/
private function getData()
{
$this->backtrack['data'] = $this->contents;
return $this;
}
/**
* 发起网络请求
* @return $this
* @throws DtaException
*/
private function getHttp(): self
{
//请求面板接口
$this->contents = $this->HttpPostCookie($this->url, $this->where);
return $this;
}
/**
* 返回Array
* @return array|mixed
* @throws DtaException
*/
public function toArray()
{
$this->getHttp();
if ($this->where['type'] === 'sites') {
$this->getDataWithOrderOpt();
} else {
$this->getDataWithCount();
}
if (empty($this->backtrack)) {
return [];
}
if (is_array($this->backtrack)) {
return $this->backtrack;
}
return json_decode($this->backtrack, true);
}
/**
* 发起POST请求
* @param string $url 网址
* @param array $data 数据
* @param bool $is_json 是否返回Json格式
* @return bool|mixed|string
* @throws DtaException
*/
protected function HttpPostCookie(string $url, array $data = [], bool $is_json = true)
{
if (empty($this->panel)) {
$this->getConfig();
}
if (empty($this->panel)) {
throw new DtaException('请检查panel参数');
}
//定义cookie保存位置
$file = app()->getRootPath() . 'runtime/dtapp/bt/cookie/';
$cookie_file = $file . md5($this->panel) . '.cookie';
if (empty(Files::judgeContents($file)) && !mkdir($file, 0777, true) && !is_dir($file)) {
throw new \RuntimeException(sprintf('Directory "%s" was not created', $file));
}
if (!file_exists($cookie_file)) {
$fp = fopen($cookie_file, 'wb+');
fclose($fp);
}
if (empty($this->key)) {
$this->getConfig();
}
if (empty($this->key)) {
throw new DtaException('请检查key参数');
}
return BtService::instance()
->panel($this->panel)
->key($this->key)
->url($url)
->cookie($cookie_file)
->data($data)
->toArray($is_json);
}
/**
* 获取总数
* @param string $str
* @return false|int|string
*/
protected function getCountData(string $str)
{
$start = strpos($str, "共");
$end = strpos($str, "条数据");
$count = substr($str, $start + 3, $end - $start - 3);
if (empty($count)) {
return 0;
}
return $count;
}
}

@ -1,70 +1,70 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary\service\crypt;
use DtApp\ThinkLibrary\Service;
class AesService extends Service
{
/**
* @var
*/
private $key, $iv;
/**
* @param $str
* @return $this
*/
public function key($str): self
{
$this->key = $str;
return $this;
}
/**
* @param $str
* @return $this
*/
public function iv($str)
{
$this->iv = $str;
return $this;
}
/**
* 加密
* @param $data
* @return string
*/
public function encrypt($data)
{
if (!empty(is_array($data))) {
$data = json_encode($data, JSON_UNESCAPED_UNICODE);
}
return urlencode(base64_encode(openssl_encrypt($data, 'AES-128-CBC', $this->key, 1, $this->iv)));
}
/**
* 解密
* @param $data
* @return false|string
*/
public function decrypt($data)
{
return openssl_decrypt(base64_decode(urldecode($data)), "AES-128-CBC", $this->key, true, $this->iv);
}
}
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary\service\crypt;
use DtApp\ThinkLibrary\Service;
class AesService extends Service
{
/**
* @var
*/
private $key, $iv;
/**
* @param $str
* @return $this
*/
public function key($str): self
{
$this->key = $str;
return $this;
}
/**
* @param $str
* @return $this
*/
public function iv($str)
{
$this->iv = $str;
return $this;
}
/**
* 加密
* @param $data
* @return string
*/
public function encrypt($data)
{
if (!empty(is_array($data))) {
$data = json_encode($data, JSON_UNESCAPED_UNICODE);
}
return urlencode(base64_encode(openssl_encrypt($data, 'AES-128-CBC', $this->key, 1, $this->iv)));
}
/**
* 解密
* @param $data
* @return false|string
*/
public function decrypt($data)
{
return openssl_decrypt(base64_decode(urldecode($data)), "AES-128-CBC", $this->key, true, $this->iv);
}
}

@ -1,169 +1,169 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary\service\curl;
use DtApp\ThinkLibrary\Service;
use think\exception\HttpException;
/**
* 宝塔网络请求接口
* https://www.bt.cn/
* Class BtService
* @package DtApp\ThinkLibrary\service\curl
*/
class BtService extends Service
{
/**
* @var
*/
private $url, $key, $panel, $output, $cookie;
/**
* @var array
*/
private $data = [];
/**
* @var int
*/
private $timeout = 60;
/**
* 配置宝塔密钥
* @param string $str
* @return $this
*/
public function key(string $str): self
{
$this->key = $str;
return $this;
}
/**
* 配置宝塔网址
* @param string $str
* @return $this
*/
public function panel(string $str): self
{
$this->panel = $str;
return $this;
}
/**
* 配置网址
* @param string $str
* @return $this
*/
public function url(string $str): self
{
$this->url = $str;
return $this;
}
/**
* 认证内容
* @param string $str
* @return $this
*/
public function cookie(string $str): self
{
$this->cookie = $str;
return $this;
}
/**
* 超时默认60s
* @param int $int
* @return $this
*/
public function timeout(int $int): self
{
$this->timeout = $int;
return $this;
}
/**
* 数据
* @param array $array
* @return $this
*/
public function data(array $array): self
{
$this->data = $array;
return $this;
}
/**
* 返回数组数据
* @param bool $is
* @return array|bool|mixed|string
*/
public function toArray(bool $is = true)
{
if (empty($this->cookie)) {
throw new HttpException(404, '请检查cookie内容');
}
if (!extension_loaded("curl")) {
throw new HttpException(404, '请开启curl模块');
}
$this->http();
if (empty($is)) {
return $this->output;
}
if (is_array($this->output)) {
return $this->output;
}
return json_decode($this->output, true);
}
/**
* 发起请求
* @return $this
*/
private function http(): self
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->panel . $this->url);
curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, array_merge($this->getKeyData(), $this->data));
curl_setopt($ch, CURLOPT_COOKIEJAR, $this->cookie);
curl_setopt($ch, CURLOPT_COOKIEFILE, $this->cookie);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$output = curl_exec($ch);
curl_close($ch);
$this->output = $output;
return $this;
}
/**
* 构造带有签名的关联数组
* @return array
*/
private function getKeyData(): array
{
$time = time();
return array(
'request_token' => md5($time . '' . md5($this->key)),
'request_time' => $time
);
}
}
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary\service\curl;
use DtApp\ThinkLibrary\Service;
use think\exception\HttpException;
/**
* 宝塔网络请求接口
* https://www.bt.cn/
* Class BtService
* @package DtApp\ThinkLibrary\service\curl
*/
class BtService extends Service
{
/**
* @var
*/
private $url, $key, $panel, $output, $cookie;
/**
* @var array
*/
private $data = [];
/**
* @var int
*/
private $timeout = 60;
/**
* 配置宝塔密钥
* @param string $str
* @return $this
*/
public function key(string $str): self
{
$this->key = $str;
return $this;
}
/**
* 配置宝塔网址
* @param string $str
* @return $this
*/
public function panel(string $str): self
{
$this->panel = $str;
return $this;
}
/**
* 配置网址
* @param string $str
* @return $this
*/
public function url(string $str): self
{
$this->url = $str;
return $this;
}
/**
* 认证内容
* @param string $str
* @return $this
*/
public function cookie(string $str): self
{
$this->cookie = $str;
return $this;
}
/**
* 超时默认60s
* @param int $int
* @return $this
*/
public function timeout(int $int): self
{
$this->timeout = $int;
return $this;
}
/**
* 数据
* @param array $array
* @return $this
*/
public function data(array $array): self
{
$this->data = $array;
return $this;
}
/**
* 返回数组数据
* @param bool $is
* @return array|bool|mixed|string
*/
public function toArray(bool $is = true)
{
if (empty($this->cookie)) {
throw new HttpException(404, '请检查cookie内容');
}
if (!extension_loaded("curl")) {
throw new HttpException(404, '请开启curl模块');
}
$this->http();
if (empty($is)) {
return $this->output;
}
if (is_array($this->output)) {
return $this->output;
}
return json_decode($this->output, true);
}
/**
* 发起请求
* @return $this
*/
private function http(): self
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->panel . $this->url);
curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, array_merge($this->getKeyData(), $this->data));
curl_setopt($ch, CURLOPT_COOKIEJAR, $this->cookie);
curl_setopt($ch, CURLOPT_COOKIEFILE, $this->cookie);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$output = curl_exec($ch);
curl_close($ch);
$this->output = $output;
return $this;
}
/**
* 构造带有签名的关联数组
* @return array
*/
private function getKeyData(): array
{
$time = time();
return array(
'request_token' => md5($time . '' . md5($this->key)),
'request_time' => $time
);
}
}

@ -1,297 +1,297 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary\service\curl;
use DtApp\ThinkLibrary\Service;
use think\exception\HttpException;
/**
* 通用网络请求
* Class HttpService
* @package DtApp\ThinkLibrary\service\curl
*/
class HttpService extends Service
{
/**
* @var
*/
private $url, $data, $cert, $output;
/**
* @var int
*/
private $timeout = 60;
/**
* @var string
*/
private $method = 'GET';
/**
* @var string
*/
private $headers = 'application/json;charset=utf-8';
/**
* 配置网络请求接口
* @param string $str
* @return $this
*/
public function url(string $str): self
{
$this->url = $str;
return $this;
}
/**
* 需要请求的数据
* @param $str
* @return $this
*/
public function data($str): self
{
if (is_array($str)) {
$this->data = json_encode($str, JSON_UNESCAPED_UNICODE);
} else {
$this->data = $str;
}
return $this;
}
/**
* 请求头
* @param $str
* @return $this
*/
public function headers(string $str): self
{
$this->headers = $str;
return $this;
}
/**
* 超时默认60s
* @param int $int
* @return $this
*/
public function timeout(int $int): self
{
$this->timeout = $int;
return $this;
}
/**
* 证书
* @param string $sslCertPath
* @param string $sslKeyPath
* @return $this
*/
public function cert(string $sslCertPath, string $sslKeyPath): self
{
$this->cert = [
'key' => $sslKeyPath,
'cert' => $sslCertPath,
];
return $this;
}
/**
* GET请求方式
* @return $this
*/
public function get(): self
{
$this->method = 'GET';
return $this;
}
/**
* POST请求方式
* @return $this
*/
public function post(): self
{
$this->method = 'POST';
return $this;
}
/**
* XML请求方式
* @return $this
*/
public function xml(): self
{
$this->method = 'XML';
return $this;
}
/**
* XML请求方式
* @return $this
*/
public function file(): self
{
$this->method = 'FILE';
return $this;
}
/**
* 返回数组数据
* @param bool $is
* @return array|bool|mixed|string
*/
public function toArray(bool $is = true)
{
//首先检测是否支持curl
if (!extension_loaded("curl")) {
throw new HttpException(404, '请开启curl模块');
}
if ($this->method === 'GET') {
$this->httpGet();
} else if ($this->method === 'POST') {
$this->httpPost();
} else if ($this->method === 'XML') {
$this->httpXml();
} else if ($this->method === 'FILE') {
$this->httpFile();
} else {
throw new HttpException(404, '请求方式异常');
}
if (empty($is)) {
return $this->output;
}
if (is_array($this->output)) {
return $this->output;
}
return json_decode($this->output, true);
}
/**
* 发送GET请求
* @return bool|mixed|string
*/
private function httpGet()
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $this->url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
if (!empty($this->data)) {
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $this->data);
}
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
$output = curl_exec($curl);
curl_close($curl);
$this->output = $output;
return $this;
}
/**
* 发送Post请求
* @return array|bool|mixed|string
*/
private function httpPost()
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: ' . $this->headers));
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 跳过证书检查
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // 从证书中检查SSL加密算法是否存在
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $this->data);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
$content = curl_exec($ch);
curl_close($ch);
$this->output = $content;
return $this;
}
/**
* 发送Xml数据
* @return string
*/
private function httpXml()
{
//初始一个curl会话
$ch = curl_init();
//设置超时
curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout);
curl_setopt($ch, CURLOPT_URL, $this->url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); //严格校验
//设置header
curl_setopt($ch, CURLOPT_HEADER, FALSE);
//要求结果为字符串且输出到屏幕上
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
//post提交方式
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $this->data);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20);
curl_setopt($ch, CURLOPT_TIMEOUT, 40);
set_time_limit(0);
if (!empty($this->headers)) {
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: ' . $this->headers));
}
//运行curl
$data = curl_exec($ch);
curl_close($ch);
$this->output = $data;
return $this;
}
/**
* 上传图片
* @return false|string
*/
private function httpFile()
{
//初始一个curl会话
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->url);
//设置超时
curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout);
if (empty($this->cert)) {
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSLCERTTYPE, 'PEM');
curl_setopt($ch, CURLOPT_SSLKEYTYPE, 'PEM');
curl_setopt($ch, CURLOPT_SSLCERT, $this->cert['cert']);
curl_setopt($ch, CURLOPT_SSLKEY, $this->cert['key']);
} else if (strpos($this->url, 'https') === 0) {
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 信任任何证书
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); // 检查证书中是否设置域名
}
if (!empty($this->headers)) {
curl_setopt($ch, CURLOPT_HTTPHEADER, array('content-type: ' . $this->headers));
}
curl_setopt($ch, CURLOPT_HEADER, true); // 是否需要响应 header
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); // 获得响应结果里的:头大小
$response_body = substr($output, $header_size);
curl_close($ch);
$this->output = $response_body;
return $this;
}
}
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary\service\curl;
use DtApp\ThinkLibrary\Service;
use think\exception\HttpException;
/**
* 通用网络请求
* Class HttpService
* @package DtApp\ThinkLibrary\service\curl
*/
class HttpService extends Service
{
/**
* @var
*/
private $url, $data, $cert, $output;
/**
* @var int
*/
private $timeout = 60;
/**
* @var string
*/
private $method = 'GET';
/**
* @var string
*/
private $headers = 'application/json;charset=utf-8';
/**
* 配置网络请求接口
* @param string $str
* @return $this
*/
public function url(string $str): self
{
$this->url = $str;
return $this;
}
/**
* 需要请求的数据
* @param $str
* @return $this
*/
public function data($str): self
{
if (is_array($str)) {
$this->data = json_encode($str, JSON_UNESCAPED_UNICODE);
} else {
$this->data = $str;
}
return $this;
}
/**
* 请求头
* @param $str
* @return $this
*/
public function headers(string $str): self
{
$this->headers = $str;
return $this;
}
/**
* 超时默认60s
* @param int $int
* @return $this
*/
public function timeout(int $int): self
{
$this->timeout = $int;
return $this;
}
/**
* 证书
* @param string $sslCertPath
* @param string $sslKeyPath
* @return $this
*/
public function cert(string $sslCertPath, string $sslKeyPath): self
{
$this->cert = [
'key' => $sslKeyPath,
'cert' => $sslCertPath,
];
return $this;
}
/**
* GET请求方式
* @return $this
*/
public function get(): self
{
$this->method = 'GET';
return $this;
}
/**
* POST请求方式
* @return $this
*/
public function post(): self
{
$this->method = 'POST';
return $this;
}
/**
* XML请求方式
* @return $this
*/
public function xml(): self
{
$this->method = 'XML';
return $this;
}
/**
* XML请求方式
* @return $this
*/
public function file(): self
{
$this->method = 'FILE';
return $this;
}
/**
* 返回数组数据
* @param bool $is
* @return array|bool|mixed|string
*/
public function toArray(bool $is = true)
{
//首先检测是否支持curl
if (!extension_loaded("curl")) {
throw new HttpException(404, '请开启curl模块');
}
if ($this->method === 'GET') {
$this->httpGet();
} else if ($this->method === 'POST') {
$this->httpPost();
} else if ($this->method === 'XML') {
$this->httpXml();
} else if ($this->method === 'FILE') {
$this->httpFile();
} else {
throw new HttpException(404, '请求方式异常');
}
if (empty($is)) {
return $this->output;
}
if (is_array($this->output)) {
return $this->output;
}
return json_decode($this->output, true);
}
/**
* 发送GET请求
* @return bool|mixed|string
*/
private function httpGet()
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $this->url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
if (!empty($this->data)) {
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $this->data);
}
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
$output = curl_exec($curl);
curl_close($curl);
$this->output = $output;
return $this;
}
/**
* 发送Post请求
* @return array|bool|mixed|string
*/
private function httpPost()
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: ' . $this->headers));
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 跳过证书检查
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // 从证书中检查SSL加密算法是否存在
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $this->data);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
$content = curl_exec($ch);
curl_close($ch);
$this->output = $content;
return $this;
}
/**
* 发送Xml数据
* @return string
*/
private function httpXml()
{
//初始一个curl会话
$ch = curl_init();
//设置超时
curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout);
curl_setopt($ch, CURLOPT_URL, $this->url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); //严格校验
//设置header
curl_setopt($ch, CURLOPT_HEADER, FALSE);
//要求结果为字符串且输出到屏幕上
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
//post提交方式
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $this->data);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20);
curl_setopt($ch, CURLOPT_TIMEOUT, 40);
set_time_limit(0);
if (!empty($this->headers)) {
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: ' . $this->headers));
}
//运行curl
$data = curl_exec($ch);
curl_close($ch);
$this->output = $data;
return $this;
}
/**
* 上传图片
* @return false|string
*/
private function httpFile()
{
//初始一个curl会话
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $this->url);
//设置超时
curl_setopt($ch, CURLOPT_TIMEOUT, $this->timeout);
if (empty($this->cert)) {
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSLCERTTYPE, 'PEM');
curl_setopt($ch, CURLOPT_SSLKEYTYPE, 'PEM');
curl_setopt($ch, CURLOPT_SSLCERT, $this->cert['cert']);
curl_setopt($ch, CURLOPT_SSLKEY, $this->cert['key']);
} else if (strpos($this->url, 'https') === 0) {
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 信任任何证书
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2); // 检查证书中是否设置域名
}
if (!empty($this->headers)) {
curl_setopt($ch, CURLOPT_HTTPHEADER, array('content-type: ' . $this->headers));
}
curl_setopt($ch, CURLOPT_HEADER, true); // 是否需要响应 header
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($ch);
$header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); // 获得响应结果里的:头大小
$response_body = substr($output, $header_size);
curl_close($ch);
$this->output = $response_body;
return $this;
}
}

@ -1,231 +1,231 @@
<?php
namespace DtApp\ThinkLibrary\service\decent;
use DtApp\ThinkLibrary\exception\DtaException;
use DtApp\ThinkLibrary\facade\Xmls;
use DtApp\ThinkLibrary\Service;
use think\exception\HttpException;
/**
* 缴费平台
* Class EJiAoFei
* @package DtApp\ThinkLibrary\service\decent
*/
class EJiAoFei extends Service
{
/**
* 待请求的链接
* @var string
*/
private $api, $method = '';
/**
* 由鼎信商务提供
* @var
*/
private $userid, $pwd, $key = '';
/**
* 需要发送的的参数
* @var
*/
private $param;
/**
* 响应内容
* @var
*/
private $output;
/**
* ip:端口
* @param string $api
* @return $this
*/
public function api(string $api): self
{
$this->api = $api;
return $this;
}
/**
* 由鼎信商务提供
* @param string $userid
* @return $this
*/
public function userid(string $userid): self
{
$this->userid = $userid;
return $this;
}
/**
* 由鼎信商务提供
* @param string $pwd
* @return $this
*/
public function pwd(string $pwd): self
{
$this->pwd = $pwd;
return $this;
}
/**
* 由鼎信商务提供
* @param string $key
* @return $this
*/
public function key(string $key): self
{
$this->key = $key;
return $this;
}
/**
* 话费充值
* @param string $orderid 用户提交的订单号 用户提交的订单号最长32位用户保证其唯一性
* @param int $face 充值面值 以元为单位包含10、20、30、50、100、200、300、500 移动联通电信
* @param string $account 手机号码 需要充值的手机号码
* @param int $amount 购买数量 只能为1
* @return $this
*/
public function chongZhi(string $orderid, int $face, string $account, int $amount = 1): self
{
$this->method = 'chongzhi_jkorders';
$this->param = "userid={$this->userid}&pwd={$this->pwd}&orderid={$orderid}&face={$face}&account={$account}&amount={$amount}";
return $this;
}
/**
* 通用查询
* @param string $orderid 用户提交的订单号 用户提交的订单号最长32位用户保证其唯一性
* @return $this
*/
public function query(string $orderid): self
{
$this->method = 'query_jkorders';
$this->param = "userid={$this->userid}&pwd={$this->pwd}&orderid={$orderid}";
return $this;
}
/**
* 用户余额查询
* @return $this
*/
public function money(): self
{
$this->method = 'money_jkuser';
$this->param = "userid={$this->userid}&pwd={$this->pwd}";
return $this;
}
/**
* 腾讯充值
* @param string $orderid 用户提交的订单号 用户提交的订单号最长32位用户保证其唯一性
* @param string $account QQ号 需要充值的QQ号
* @param int $productid 产品id 可以通过queryTXproduct查询
* @param int $amount 购买数量
* @param string $ip 充值QQ号ip 可以为空
* @param string $times 时间戳 格式yyyyMMddhhmmss
* @return $this
*/
public function txchongzhi(string $orderid, string $account, int $productid, int $amount, string $ip, string $times): self
{
$this->method = 'txchongzhi';
$this->param = "userid={$this->userid}&pwd={$this->pwd}&orderid={$orderid}&account={$account}&productid={$productid}&amount={$amount}&ip={$ip}&times={$times}";
return $this;
}
/**
* 可充值腾讯产品查询
* @return $this
*/
public function queryTXproduct(): self
{
$this->method = 'queryTXproduct';
$this->param = "userid={$this->userid}&pwd={$this->pwd}";
return $this;
}
/**
* 流量充值
* @param string $orderid 用户提交的订单号 用户提交的订单号最长32位用户保证其唯一性
* @param string $account 充值手机号 需要充值的手机号
* @param int $gprs 充值流量值 单位MB具体流量值请咨询商务
* @param int $area 充值流量范围 0 全国流量1 省内流量
* @param int $effecttime 生效日期 0 即时生效1次日生效2 次月生效
* @param int $validity 流量有效期 传入月数0为当月有效
* @param string $times 时间戳 格式yyyyMMddhhmmss
* @return $this
*/
public function gprsChongzhiAdvance(string $orderid, string $account, int $gprs, int $area, int $effecttime, int $validity, string $times): self
{
$this->method = 'gprsChongzhiAdvance';
$this->param = "userid={$this->userid}&pwd={$this->pwd}&orderid={$orderid}&account={$account}&gprs={$gprs}&area={$area}&effecttime={$effecttime}&validity={$validity}&times={$times}";
return $this;
}
/**
* 会员订单成本价查询
* @param string $orderid 用户订单号 用户提交订单号
* @return $this
*/
public function checkCost(string $orderid): self
{
$this->method = 'checkCost';
$this->param = "userid={$this->userid}&pwd={$this->pwd}&orderid={$orderid}";
return $this;
}
/**
* @throws DtaException
*/
public function toArray()
{
//首先检测是否支持curl
if (!extension_loaded("curl")) {
throw new HttpException(404, '请开启curl模块');
}
if (empty($this->api)) {
throw new DtaException('请检查api参数');
}
$this->http();
// 正常
if (is_array($this->output)) {
return $this->output;
}
if (is_object($this->output)) {
$this->output = json_encode($this->output, JSON_UNESCAPED_UNICODE);
}
$this->output = json_decode($this->output, true);
return $this->output;
}
/**
* 网络请求
*/
private function http(): void
{
//生成签名
$sign = $this->createSign();
//组织参数
$this->param .= '&userkey=' . $sign;
$url = "http://" . $this->api . "/" . $this->method . ".do?{$this->param}";
$result = file_get_contents($url);
$result = Xmls::toArray($result);
$this->output = $result;
}
/**
* 签名
* @return string
*/
private function createSign(): string
{
$sign = str_replace(array("&", "="), array("", ""), $this->param);
$sign .= $this->key;
$sign = strtoupper(md5($sign));
return $sign;
}
<?php
namespace DtApp\ThinkLibrary\service\decent;
use DtApp\ThinkLibrary\exception\DtaException;
use DtApp\ThinkLibrary\facade\Xmls;
use DtApp\ThinkLibrary\Service;
use think\exception\HttpException;
/**
* 缴费平台
* Class EJiAoFei
* @package DtApp\ThinkLibrary\service\decent
*/
class EJiAoFei extends Service
{
/**
* 待请求的链接
* @var string
*/
private $api, $method = '';
/**
* 由鼎信商务提供
* @var
*/
private $userid, $pwd, $key = '';
/**
* 需要发送的的参数
* @var
*/
private $param;
/**
* 响应内容
* @var
*/
private $output;
/**
* ip:端口
* @param string $api
* @return $this
*/
public function api(string $api): self
{
$this->api = $api;
return $this;
}
/**
* 由鼎信商务提供
* @param string $userid
* @return $this
*/
public function userid(string $userid): self
{
$this->userid = $userid;
return $this;
}
/**
* 由鼎信商务提供
* @param string $pwd
* @return $this
*/
public function pwd(string $pwd): self
{
$this->pwd = $pwd;
return $this;
}
/**
* 由鼎信商务提供
* @param string $key
* @return $this
*/
public function key(string $key): self
{
$this->key = $key;
return $this;
}
/**
* 话费充值
* @param string $orderid 用户提交的订单号 用户提交的订单号最长32位用户保证其唯一性
* @param int $face 充值面值 以元为单位包含10、20、30、50、100、200、300、500 移动联通电信
* @param string $account 手机号码 需要充值的手机号码
* @param int $amount 购买数量 只能为1
* @return $this
*/
public function chongZhi(string $orderid, int $face, string $account, int $amount = 1): self
{
$this->method = 'chongzhi_jkorders';
$this->param = "userid={$this->userid}&pwd={$this->pwd}&orderid={$orderid}&face={$face}&account={$account}&amount={$amount}";
return $this;
}
/**
* 通用查询
* @param string $orderid 用户提交的订单号 用户提交的订单号最长32位用户保证其唯一性
* @return $this
*/
public function query(string $orderid): self
{
$this->method = 'query_jkorders';
$this->param = "userid={$this->userid}&pwd={$this->pwd}&orderid={$orderid}";
return $this;
}
/**
* 用户余额查询
* @return $this
*/
public function money(): self
{
$this->method = 'money_jkuser';
$this->param = "userid={$this->userid}&pwd={$this->pwd}";
return $this;
}
/**
* 腾讯充值
* @param string $orderid 用户提交的订单号 用户提交的订单号最长32位用户保证其唯一性
* @param string $account QQ号 需要充值的QQ号
* @param int $productid 产品id 可以通过queryTXproduct查询
* @param int $amount 购买数量
* @param string $ip 充值QQ号ip 可以为空
* @param string $times 时间戳 格式yyyyMMddhhmmss
* @return $this
*/
public function txchongzhi(string $orderid, string $account, int $productid, int $amount, string $ip, string $times): self
{
$this->method = 'txchongzhi';
$this->param = "userid={$this->userid}&pwd={$this->pwd}&orderid={$orderid}&account={$account}&productid={$productid}&amount={$amount}&ip={$ip}&times={$times}";
return $this;
}
/**
* 可充值腾讯产品查询
* @return $this
*/
public function queryTXproduct(): self
{
$this->method = 'queryTXproduct';
$this->param = "userid={$this->userid}&pwd={$this->pwd}";
return $this;
}
/**
* 流量充值
* @param string $orderid 用户提交的订单号 用户提交的订单号最长32位用户保证其唯一性
* @param string $account 充值手机号 需要充值的手机号
* @param int $gprs 充值流量值 单位MB具体流量值请咨询商务
* @param int $area 充值流量范围 0 全国流量1 省内流量
* @param int $effecttime 生效日期 0 即时生效1次日生效2 次月生效
* @param int $validity 流量有效期 传入月数0为当月有效
* @param string $times 时间戳 格式yyyyMMddhhmmss
* @return $this
*/
public function gprsChongzhiAdvance(string $orderid, string $account, int $gprs, int $area, int $effecttime, int $validity, string $times): self
{
$this->method = 'gprsChongzhiAdvance';
$this->param = "userid={$this->userid}&pwd={$this->pwd}&orderid={$orderid}&account={$account}&gprs={$gprs}&area={$area}&effecttime={$effecttime}&validity={$validity}&times={$times}";
return $this;
}
/**
* 会员订单成本价查询
* @param string $orderid 用户订单号 用户提交订单号
* @return $this
*/
public function checkCost(string $orderid): self
{
$this->method = 'checkCost';
$this->param = "userid={$this->userid}&pwd={$this->pwd}&orderid={$orderid}";
return $this;
}
/**
* @throws DtaException
*/
public function toArray()
{
//首先检测是否支持curl
if (!extension_loaded("curl")) {
throw new HttpException(404, '请开启curl模块');
}
if (empty($this->api)) {
throw new DtaException('请检查api参数');
}
$this->http();
// 正常
if (is_array($this->output)) {
return $this->output;
}
if (is_object($this->output)) {
$this->output = json_encode($this->output, JSON_UNESCAPED_UNICODE);
}
$this->output = json_decode($this->output, true);
return $this->output;
}
/**
* 网络请求
*/
private function http(): void
{
//生成签名
$sign = $this->createSign();
//组织参数
$this->param .= '&userkey=' . $sign;
$url = "http://" . $this->api . "/" . $this->method . ".do?{$this->param}";
$result = file_get_contents($url);
$result = Xmls::toArray($result);
$this->output = $result;
}
/**
* 签名
* @return string
*/
private function createSign(): string
{
$sign = str_replace(array("&", "="), array("", ""), $this->param);
$sign .= $this->key;
$sign = strtoupper(md5($sign));
return $sign;
}
}

@ -1,108 +1,108 @@
<?php
namespace DtApp\ThinkLibrary\service\dingdanxia;
use DtApp\ThinkLibrary\exception\DtaException;
use DtApp\ThinkLibrary\Service;
use DtApp\ThinkLibrary\service\curl\HttpService;
use think\exception\HttpException;
/**
* 订单侠开放平台
* Class DingDanXiaService
* @package DtApp\ThinkLibrary\service\dingdanxia
*/
class DingDanXiaService extends Service
{
/**
* 接口秘钥
* @var string
*/
private $app_key;
/**
* API接口
* @var string
*/
private $method;
/**
* 需要发送的的参数
* @var
*/
private $param;
/**
* 响应内容
* @var
*/
private $output;
/**
* 接口秘钥,请登录后台获取
* @param string $appKey
* @return $this
*/
public function appKey(string $appKey): self
{
$this->app_key = $appKey;
return $this;
}
/**
* 自定义接口
* @param string $method
* @return $this
*/
public function setMethod($method = ''): self
{
$this->method = $method;
return $this;
}
/**
* 请求参数
* @param array $param
* @return $this
*/
public function param(array $param): self
{
$this->param = $param;
return $this;
}
/**
* 获取配置信息
* @return $this
*/
private function getConfig(): self
{
$this->app_key = config('dtapp.dingdanxia.app_key');
return $this;
}
/**
* 返回Array
* @return array|mixed
* @throws DtaException
*/
public function toArray()
{
//首先检测是否支持curl
if (!extension_loaded("curl")) {
throw new HttpException(404, '请开启curl模块');
}
if (empty($this->app_key)) {
$this->getConfig();
}
if (empty($this->method)) {
throw new DtaException('请检查接口');
}
$this->output = HttpService::instance()
->url($this->method)
->data($this->param)
->post()
->toArray();
return $this->output;
}
<?php
namespace DtApp\ThinkLibrary\service\dingdanxia;
use DtApp\ThinkLibrary\exception\DtaException;
use DtApp\ThinkLibrary\Service;
use DtApp\ThinkLibrary\service\curl\HttpService;
use think\exception\HttpException;
/**
* 订单侠开放平台
* Class DingDanXiaService
* @package DtApp\ThinkLibrary\service\dingdanxia
*/
class DingDanXiaService extends Service
{
/**
* 接口秘钥
* @var string
*/
private $app_key;
/**
* API接口
* @var string
*/
private $method;
/**
* 需要发送的的参数
* @var
*/
private $param;
/**
* 响应内容
* @var
*/
private $output;
/**
* 接口秘钥,请登录后台获取
* @param string $appKey
* @return $this
*/
public function appKey(string $appKey): self
{
$this->app_key = $appKey;
return $this;
}
/**
* 自定义接口
* @param string $method
* @return $this
*/
public function setMethod($method = ''): self
{
$this->method = $method;
return $this;
}
/**
* 请求参数
* @param array $param
* @return $this
*/
public function param(array $param): self
{
$this->param = $param;
return $this;
}
/**
* 获取配置信息
* @return $this
*/
private function getConfig(): self
{
$this->app_key = config('dtapp.dingdanxia.app_key');
return $this;
}
/**
* 返回Array
* @return array|mixed
* @throws DtaException
*/
public function toArray()
{
//首先检测是否支持curl
if (!extension_loaded("curl")) {
throw new HttpException(404, '请开启curl模块');
}
if (empty($this->app_key)) {
$this->getConfig();
}
if (empty($this->method)) {
throw new DtaException('请检查接口');
}
$this->output = HttpService::instance()
->url($this->method)
->data($this->param)
->post()
->toArray();
return $this->output;
}
}

File diff suppressed because it is too large Load Diff

@ -1,99 +1,99 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary\service\huaweicloud;
use DtApp\ThinkLibrary\Service;
use Obs\ObsClient;
/**
* 华为云对象存储
* https://www.huaweicloud.com/product/obs.html
* Class ObsService
* @package DtApp\ThinkLibrary\service\huaweicloud
*/
class ObsService extends Service
{
/**
* @var
*/
private $key, $secret, $endpoint, $bucket;
/**
* @param string $key
* @return $this
*/
public function key(string $key): self
{
$this->key = $key;
return $this;
}
/**
* @param string $secret
* @return $this
*/
public function secret(string $secret): self
{
$this->secret = $secret;
return $this;
}
/**
* @param string $endpoint
* @return $this
*/
public function endpoint(string $endpoint): self
{
$this->endpoint = $endpoint;
return $this;
}
/**
* @param string $bucket
* @return $this
*/
public function bucket(string $bucket): self
{
$this->bucket = $bucket;
return $this;
}
/**
* @param string $object
* @param string $filePath
* @return bool
*/
public function upload(string $object, string $filePath): bool
{
// 创建ObsClient实例
$obsClient = new ObsClient([
'key' => $this->key,
'secret' => $this->secret,
'endpoint' => $this->endpoint
]);
$resp = $obsClient->putObject([
'Bucket' => $this->bucket,
'Key' => $object,
'SourceFile' => $filePath // localfile为待上传的本地文件路径需要指定到具体的文件名
]);
if (isset($resp['RequestId'])) {
return true;
}
return false;
}
}
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary\service\huaweicloud;
use DtApp\ThinkLibrary\Service;
use Obs\ObsClient;
/**
* 华为云对象存储
* https://www.huaweicloud.com/product/obs.html
* Class ObsService
* @package DtApp\ThinkLibrary\service\huaweicloud
*/
class ObsService extends Service
{
/**
* @var
*/
private $key, $secret, $endpoint, $bucket;
/**
* @param string $key
* @return $this
*/
public function key(string $key): self
{
$this->key = $key;
return $this;
}
/**
* @param string $secret
* @return $this
*/
public function secret(string $secret): self
{
$this->secret = $secret;
return $this;
}
/**
* @param string $endpoint
* @return $this
*/
public function endpoint(string $endpoint): self
{
$this->endpoint = $endpoint;
return $this;
}
/**
* @param string $bucket
* @return $this
*/
public function bucket(string $bucket): self
{
$this->bucket = $bucket;
return $this;
}
/**
* @param string $object
* @param string $filePath
* @return bool
*/
public function upload(string $object, string $filePath): bool
{
// 创建ObsClient实例
$obsClient = new ObsClient([
'key' => $this->key,
'secret' => $this->secret,
'endpoint' => $this->endpoint
]);
$resp = $obsClient->putObject([
'Bucket' => $this->bucket,
'Key' => $object,
'SourceFile' => $filePath // localfile为待上传的本地文件路径需要指定到具体的文件名
]);
if (isset($resp['RequestId'])) {
return true;
}
return false;
}
}

File diff suppressed because it is too large Load Diff

@ -1,120 +1,120 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary\service\jdcloud;
use DtApp\ThinkLibrary\Service;
use DtApp\ThinkLibrary\service\curl\HttpService;
/**
* 京东万象
* https://wx.jdcloud.com/
* Class VientianeService
* @package DtApp\ThinkLibrary\service\jdcloud
*/
class VientianeService extends Service
{
/**
* @var
*/
private $url, $param, $app_key;
/**
* 您申请的appkey
* @param string $appKey
* @return $this
*/
public function appKey(string $appKey): self
{
$this->app_key = $appKey;
return $this;
}
/**
* 组参
* @param array $param
* @return $this
*/
public function param(array $param): self
{
$this->param = $param;
return $this;
}
/**
* 空气质量实时数据
* https://wx.jdcloud.com/market/datas/26/1656
* @return array|bool|mixed|string
*/
public function pm25Cities()
{
$this->url = "https://way.jd.com/pm25/cities";
return $this->http();
}
/**
* 中国和世界天气预报
* https://wx.jdcloud.com/market/datas/26/10610
*/
public function heFreeWeather()
{
$this->url = "https://way.jd.com/he/freeweather";
return $this->http();
}
/**
* 全国天气预报
* https://wx.jdcloud.com/market/datas/26/11065
*/
public function jiSuApiWeather()
{
$this->url = "https://way.jd.com/jisuapi/weather";
return $this->http();
}
/**
* 菜谱大全
* https://wx.jdcloud.com/market/datas/26/11072
*/
public function jiSuApiSearch()
{
$this->url = "https://way.jd.com/jisuapi/search";
return $this->http();
}
/**
* IP商圈字典
* https://wx.jdcloud.com/market/datas/26/13432
*/
public function rtBaSiaIpAreaDict()
{
$this->url = "https://way.jd.com/RTBAsia/ip_area_dict";
return $this->http();
}
/**
* 请求
* @return array|bool|mixed|string
*/
private function http()
{
$this->param['appkey'] = $this->app_key;
$this->param = http_build_query($this->param);
return HttpService::instance()
->url("{$this->url}?{$this->param}")
->toArray();
}
}
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary\service\jdcloud;
use DtApp\ThinkLibrary\Service;
use DtApp\ThinkLibrary\service\curl\HttpService;
/**
* 京东万象
* https://wx.jdcloud.com/
* Class VientianeService
* @package DtApp\ThinkLibrary\service\jdcloud
*/
class VientianeService extends Service
{
/**
* @var
*/
private $url, $param, $app_key;
/**
* 您申请的appkey
* @param string $appKey
* @return $this
*/
public function appKey(string $appKey): self
{
$this->app_key = $appKey;
return $this;
}
/**
* 组参
* @param array $param
* @return $this
*/
public function param(array $param): self
{
$this->param = $param;
return $this;
}
/**
* 空气质量实时数据
* https://wx.jdcloud.com/market/datas/26/1656
* @return array|bool|mixed|string
*/
public function pm25Cities()
{
$this->url = "https://way.jd.com/pm25/cities";
return $this->http();
}
/**
* 中国和世界天气预报
* https://wx.jdcloud.com/market/datas/26/10610
*/
public function heFreeWeather()
{
$this->url = "https://way.jd.com/he/freeweather";
return $this->http();
}
/**
* 全国天气预报
* https://wx.jdcloud.com/market/datas/26/11065
*/
public function jiSuApiWeather()
{
$this->url = "https://way.jd.com/jisuapi/weather";
return $this->http();
}
/**
* 菜谱大全
* https://wx.jdcloud.com/market/datas/26/11072
*/
public function jiSuApiSearch()
{
$this->url = "https://way.jd.com/jisuapi/search";
return $this->http();
}
/**
* IP商圈字典
* https://wx.jdcloud.com/market/datas/26/13432
*/
public function rtBaSiaIpAreaDict()
{
$this->url = "https://way.jd.com/RTBAsia/ip_area_dict";
return $this->http();
}
/**
* 请求
* @return array|bool|mixed|string
*/
private function http()
{
$this->param['appkey'] = $this->app_key;
$this->param = http_build_query($this->param);
return HttpService::instance()
->url("{$this->url}?{$this->param}")
->toArray();
}
}

@ -1,112 +1,112 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary\service\ksyun;
use DtApp\ThinkLibrary\Service;
use Ks3Client;
use Ks3ServiceException;
/**
* 金山云对象存储
* https://www.ksyun.com/nv/product/KS3.html
* Class Ks3Service
* @package DtApp\ThinkLibrary\service\ksyun
*/
class Ks3Service extends Service
{
/**
* @var
*/
private $accessKeyID, $accessKeySecret, $endpoint, $bucket;
/**
* @param string $accessKeyID
* @return $this
*/
public function accessKeyID(string $accessKeyID)
{
$this->accessKeyID = $accessKeyID;
return $this;
}
/**
* @param string $accessKeySecret
* @return $this
*/
public function accessKeySecret(string $accessKeySecret)
{
$this->accessKeySecret = $accessKeySecret;
return $this;
}
/**
* @param string $endpoint
* @return $this
*/
public function endpoint(string $endpoint): self
{
$this->endpoint = $endpoint;
return $this;
}
/**
* @param string $bucket
* @return $this
*/
public function bucket(string $bucket): self
{
$this->bucket = $bucket;
return $this;
}
/**
* @param string $object
* @param string $filePath
* @return bool
*/
public function upload(string $object, string $filePath): ?bool
{
require_once(__DIR__ . "/bin/Ks3Client.class.php");
$client = new Ks3Client($this->accessKeyID, $this->accessKeySecret, $this->endpoint);
$content = fopen($filePath, 'rb');
$args = [
"Bucket" => $this->bucket,
"Key" => $object,
"Content" => [
//要上传的内容
"content" => $content,//可以是文件路径或者resource,如果文件大于2G请提供文件路径
"seek_position" => 0//跳过文件开头?个字节
],
"ACL" => "public-read",//可以设置访问权限,合法值,private、public-read
"ObjectMeta" => [
//设置object的元数据,可以设置"Cache-Control","Content-Disposition","Content-Encoding","Content-Length","Content-MD5","Content-Type","Expires"。当设置了Content-Length时最后上传的为从seek_position开始向后Content-Length个字节的内容。当设置了Content-MD5时系统会在服务端进行md5校验。
"Content-Type" => "binay/ocet-stream"
//"Content-Length"=>4
],
"UserMeta" => [
//可以设置object的用户元数据需要以x-kss-meta-开头
"x-kss-meta-test" => "test"
]
];
try {
$client->putObjectByFile($args);
return true;
} catch (Ks3ServiceException $e) {
return false;
}
}
}
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary\service\ksyun;
use DtApp\ThinkLibrary\Service;
use Ks3Client;
use Ks3ServiceException;
/**
* 金山云对象存储
* https://www.ksyun.com/nv/product/KS3.html
* Class Ks3Service
* @package DtApp\ThinkLibrary\service\ksyun
*/
class Ks3Service extends Service
{
/**
* @var
*/
private $accessKeyID, $accessKeySecret, $endpoint, $bucket;
/**
* @param string $accessKeyID
* @return $this
*/
public function accessKeyID(string $accessKeyID)
{
$this->accessKeyID = $accessKeyID;
return $this;
}
/**
* @param string $accessKeySecret
* @return $this
*/
public function accessKeySecret(string $accessKeySecret)
{
$this->accessKeySecret = $accessKeySecret;
return $this;
}
/**
* @param string $endpoint
* @return $this
*/
public function endpoint(string $endpoint): self
{
$this->endpoint = $endpoint;
return $this;
}
/**
* @param string $bucket
* @return $this
*/
public function bucket(string $bucket): self
{
$this->bucket = $bucket;
return $this;
}
/**
* @param string $object
* @param string $filePath
* @return bool
*/
public function upload(string $object, string $filePath): ?bool
{
require_once(__DIR__ . "/bin/Ks3Client.class.php");
$client = new Ks3Client($this->accessKeyID, $this->accessKeySecret, $this->endpoint);
$content = fopen($filePath, 'rb');
$args = [
"Bucket" => $this->bucket,
"Key" => $object,
"Content" => [
//要上传的内容
"content" => $content,//可以是文件路径或者resource,如果文件大于2G请提供文件路径
"seek_position" => 0//跳过文件开头?个字节
],
"ACL" => "public-read",//可以设置访问权限,合法值,private、public-read
"ObjectMeta" => [
//设置object的元数据,可以设置"Cache-Control","Content-Disposition","Content-Encoding","Content-Length","Content-MD5","Content-Type","Expires"。当设置了Content-Length时最后上传的为从seek_position开始向后Content-Length个字节的内容。当设置了Content-MD5时系统会在服务端进行md5校验。
"Content-Type" => "binay/ocet-stream"
//"Content-Length"=>4
],
"UserMeta" => [
//可以设置object的用户元数据需要以x-kss-meta-开头
"x-kss-meta-test" => "test"
]
];
try {
$client->putObjectByFile($args);
return true;
} catch (Ks3ServiceException $e) {
return false;
}
}
}

@ -1,129 +1,129 @@
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary\service\kuaishou;
use DtApp\ThinkLibrary\facade\Pregs;
use DtApp\ThinkLibrary\Service;
use GuzzleHttp\Client;
use GuzzleHttp\Cookie\CookieJar;
use GuzzleHttp\Psr7\Stream;
/**
* 快手-视频去水印
* Class WatermarkService
* @package DtApp\ThinkLibrary\service\kuaishou
*/
class WatermarkService extends Service
{
/**
* @var
*/
private $url, $contents, $backtrack;
/**
* 设置网址
* @param $url
* @return $this
*/
public function setUrl($url): self
{
if (Pregs::isLink($url)) {
$this->url = $url;
} else {
preg_match_all('#\bhttps?://[^,\s()<>]+(?:\([\w\d]+\)|([^,[:punct:]\s]|/))#', $url, $match);
$this->url = $match[0][0];
}
return $this;
}
/**
* 获取接口全部信息
* @return WatermarkService
* @throws \GuzzleHttp\Exception\GuzzleException
*/
private function getApi(): self
{
$this->contents = $this->getContents($this->url);
return $this;
}
/**
* 获取全部信息
* @return $this
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function getAll(): self
{
$this->getApi();
$data = [
'video_src' => $this->contents['video_src'],
'cover_image' => $this->contents['cover_image'],
];
$this->backtrack = $data;
return $this;
}
/**
* 返回Array
* @return array|mixed
*/
public function toArray()
{
if (empty($this->backtrack)) {
return [];
}
if (is_array($this->backtrack)) {
return $this->backtrack;
}
return json_decode($this->backtrack, true);
}
/**
* 获取
* @param $url
* @return array
* @throws \GuzzleHttp\Exception\GuzzleException
*/
private function getContents($url): array
{
$headers = [
'Connection' => 'keep-alive',
'User-Agent' => 'Mozilla/5.0 (iPhone; CPU iPhone OS 12_1_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/16D57 Version/12.0 Safari/604.1'
];
$client = new Client(['timeout' => 2, 'headers' => $headers, 'http_errors' => false,]);
$data['headers'] = $headers;
$data['verify'] = __DIR__ . DIRECTORY_SEPARATOR . 'cacert.pem';
$jar = new CookieJar();
$data['cookies'] = $jar;
$response = $client->request('GET', $url, $data);
$body = $response->getBody();
if ($body instanceof Stream) {
$body = $body->getContents();
}
$result = htmlspecialchars_decode($body);
$pattern = '#"srcNoMark":"(.*?)"#';
preg_match($pattern, $result, $match);
$data['video_src'] = $match[1];
$pattern = '#"poster":"(.*?)"#';
preg_match($pattern, $result, $match);
if (!empty($match[1])) {
$data['cover_image'] = $match[1];
return $data;
}
return [];
}
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary\service\kuaishou;
use DtApp\ThinkLibrary\facade\Pregs;
use DtApp\ThinkLibrary\Service;
use GuzzleHttp\Client;
use GuzzleHttp\Cookie\CookieJar;
use GuzzleHttp\Psr7\Stream;
/**
* 快手-视频去水印
* Class WatermarkService
* @package DtApp\ThinkLibrary\service\kuaishou
*/
class WatermarkService extends Service
{
/**
* @var
*/
private $url, $contents, $backtrack;
/**
* 设置网址
* @param $url
* @return $this
*/
public function setUrl($url): self
{
if (Pregs::isLink($url)) {
$this->url = $url;
} else {
preg_match_all('#\bhttps?://[^,\s()<>]+(?:\([\w\d]+\)|([^,[:punct:]\s]|/))#', $url, $match);
$this->url = $match[0][0];
}
return $this;
}
/**
* 获取接口全部信息
* @return WatermarkService
* @throws \GuzzleHttp\Exception\GuzzleException
*/
private function getApi(): self
{
$this->contents = $this->getContents($this->url);
return $this;
}
/**
* 获取全部信息
* @return $this
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function getAll(): self
{
$this->getApi();
$data = [
'video_src' => $this->contents['video_src'],
'cover_image' => $this->contents['cover_image'],
];
$this->backtrack = $data;
return $this;
}
/**
* 返回Array
* @return array|mixed
*/
public function toArray()
{
if (empty($this->backtrack)) {
return [];
}
if (is_array($this->backtrack)) {
return $this->backtrack;
}
return json_decode($this->backtrack, true);
}
/**
* 获取
* @param $url
* @return array
* @throws \GuzzleHttp\Exception\GuzzleException
*/
private function getContents($url): array
{
$headers = [
'Connection' => 'keep-alive',
'User-Agent' => 'Mozilla/5.0 (iPhone; CPU iPhone OS 12_1_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/16D57 Version/12.0 Safari/604.1'
];
$client = new Client(['timeout' => 2, 'headers' => $headers, 'http_errors' => false,]);
$data['headers'] = $headers;
$data['verify'] = __DIR__ . DIRECTORY_SEPARATOR . 'cacert.pem';
$jar = new CookieJar();
$data['cookies'] = $jar;
$response = $client->request('GET', $url, $data);
$body = $response->getBody();
if ($body instanceof Stream) {
$body = $body->getContents();
}
$result = htmlspecialchars_decode($body);
$pattern = '#"srcNoMark":"(.*?)"#';
preg_match($pattern, $result, $match);
$data['video_src'] = $match[1];
$pattern = '#"poster":"(.*?)"#';
preg_match($pattern, $result, $match);
if (!empty($match[1])) {
$data['cover_image'] = $match[1];
return $data;
}
return [];
}
}

File diff suppressed because it is too large Load Diff

@ -1,24 +1,24 @@
<?php
/**
* 示例接口名称pdd.ad.api.advertiser.open.account
*/
require_once dirname(__FILE__).'/Config.php';
require_once dirname(__FILE__)."/../vendor/autoload.php";
use Com\Pdd\Pop\Sdk\PopHttpClient;
use Com\Pdd\Pop\Sdk\Api\Request\PddAdApiAdvertiserOpenAccountRequest;
$client = new PopHttpClient(Config::$clientId, Config::$clientSecret);
$request = new PddAdApiAdvertiserOpenAccountRequest();
try{
$response = $client->syncInvoke($request);
} catch(Com\Pdd\Pop\Sdk\PopHttpException $e){
echo $e->getMessage();
exit;
}
$content = $response->getContent();
if(isset($content['error_response'])){
echo "异常返回";
}
<?php
/**
* 示例接口名称pdd.ad.api.advertiser.open.account
*/
require_once dirname(__FILE__).'/Config.php';
require_once dirname(__FILE__)."/../vendor/autoload.php";
use Com\Pdd\Pop\Sdk\PopHttpClient;
use Com\Pdd\Pop\Sdk\Api\Request\PddAdApiAdvertiserOpenAccountRequest;
$client = new PopHttpClient(Config::$clientId, Config::$clientSecret);
$request = new PddAdApiAdvertiserOpenAccountRequest();
try{
$response = $client->syncInvoke($request);
} catch(Com\Pdd\Pop\Sdk\PopHttpException $e){
echo $e->getMessage();
exit;
}
$content = $response->getContent();
if(isset($content['error_response'])){
echo "异常返回";
}
echo json_encode($content,JSON_UNESCAPED_UNICODE);

@ -1,24 +1,24 @@
<?php
/**
* 示例接口名称pdd.ad.api.advertiser.query.account.balance
*/
require_once dirname(__FILE__).'/Config.php';
require_once dirname(__FILE__)."/../vendor/autoload.php";
use Com\Pdd\Pop\Sdk\PopHttpClient;
use Com\Pdd\Pop\Sdk\Api\Request\PddAdApiAdvertiserQueryAccountBalanceRequest;
$client = new PopHttpClient(Config::$clientId, Config::$clientSecret);
$request = new PddAdApiAdvertiserQueryAccountBalanceRequest();
try{
$response = $client->syncInvoke($request);
} catch(Com\Pdd\Pop\Sdk\PopHttpException $e){
echo $e->getMessage();
exit;
}
$content = $response->getContent();
if(isset($content['error_response'])){
echo "异常返回";
}
<?php
/**
* 示例接口名称pdd.ad.api.advertiser.query.account.balance
*/
require_once dirname(__FILE__).'/Config.php';
require_once dirname(__FILE__)."/../vendor/autoload.php";
use Com\Pdd\Pop\Sdk\PopHttpClient;
use Com\Pdd\Pop\Sdk\Api\Request\PddAdApiAdvertiserQueryAccountBalanceRequest;
$client = new PopHttpClient(Config::$clientId, Config::$clientSecret);
$request = new PddAdApiAdvertiserQueryAccountBalanceRequest();
try{
$response = $client->syncInvoke($request);
} catch(Com\Pdd\Pop\Sdk\PopHttpException $e){
echo $e->getMessage();
exit;
}
$content = $response->getContent();
if(isset($content['error_response'])){
echo "异常返回";
}
echo json_encode($content,JSON_UNESCAPED_UNICODE);

@ -1,24 +1,24 @@
<?php
/**
* 示例接口名称pdd.ad.api.advertiser.query.account.info
*/
require_once dirname(__FILE__).'/Config.php';
require_once dirname(__FILE__)."/../vendor/autoload.php";
use Com\Pdd\Pop\Sdk\PopHttpClient;
use Com\Pdd\Pop\Sdk\Api\Request\PddAdApiAdvertiserQueryAccountInfoRequest;
$client = new PopHttpClient(Config::$clientId, Config::$clientSecret);
$request = new PddAdApiAdvertiserQueryAccountInfoRequest();
try{
$response = $client->syncInvoke($request);
} catch(Com\Pdd\Pop\Sdk\PopHttpException $e){
echo $e->getMessage();
exit;
}
$content = $response->getContent();
if(isset($content['error_response'])){
echo "异常返回";
}
<?php
/**
* 示例接口名称pdd.ad.api.advertiser.query.account.info
*/
require_once dirname(__FILE__).'/Config.php';
require_once dirname(__FILE__)."/../vendor/autoload.php";
use Com\Pdd\Pop\Sdk\PopHttpClient;
use Com\Pdd\Pop\Sdk\Api\Request\PddAdApiAdvertiserQueryAccountInfoRequest;
$client = new PopHttpClient(Config::$clientId, Config::$clientSecret);
$request = new PddAdApiAdvertiserQueryAccountInfoRequest();
try{
$response = $client->syncInvoke($request);
} catch(Com\Pdd\Pop\Sdk\PopHttpException $e){
echo $e->getMessage();
exit;
}
$content = $response->getContent();
if(isset($content['error_response'])){
echo "异常返回";
}
echo json_encode($content,JSON_UNESCAPED_UNICODE);

@ -1,24 +1,24 @@
<?php
/**
* 示例接口名称pdd.ad.api.advertiser.query.detail
*/
require_once dirname(__FILE__).'/Config.php';
require_once dirname(__FILE__)."/../vendor/autoload.php";
use Com\Pdd\Pop\Sdk\PopHttpClient;
use Com\Pdd\Pop\Sdk\Api\Request\PddAdApiAdvertiserQueryDetailRequest;
$client = new PopHttpClient(Config::$clientId, Config::$clientSecret);
$request = new PddAdApiAdvertiserQueryDetailRequest();
try{
$response = $client->syncInvoke($request);
} catch(Com\Pdd\Pop\Sdk\PopHttpException $e){
echo $e->getMessage();
exit;
}
$content = $response->getContent();
if(isset($content['error_response'])){
echo "异常返回";
}
<?php
/**
* 示例接口名称pdd.ad.api.advertiser.query.detail
*/
require_once dirname(__FILE__).'/Config.php';
require_once dirname(__FILE__)."/../vendor/autoload.php";
use Com\Pdd\Pop\Sdk\PopHttpClient;
use Com\Pdd\Pop\Sdk\Api\Request\PddAdApiAdvertiserQueryDetailRequest;
$client = new PopHttpClient(Config::$clientId, Config::$clientSecret);
$request = new PddAdApiAdvertiserQueryDetailRequest();
try{
$response = $client->syncInvoke($request);
} catch(Com\Pdd\Pop\Sdk\PopHttpException $e){
echo $e->getMessage();
exit;
}
$content = $response->getContent();
if(isset($content['error_response'])){
echo "异常返回";
}
echo json_encode($content,JSON_UNESCAPED_UNICODE);

@ -1,25 +1,25 @@
<?php
/**
* 示例接口名称pdd.ad.api.goods.query.gallery.images
*/
require_once dirname(__FILE__).'/Config.php';
require_once dirname(__FILE__)."/../vendor/autoload.php";
use Com\Pdd\Pop\Sdk\PopHttpClient;
use Com\Pdd\Pop\Sdk\Api\Request\PddAdApiGoodsQueryGalleryImagesRequest;
$client = new PopHttpClient(Config::$clientId, Config::$clientSecret);
$request = new PddAdApiGoodsQueryGalleryImagesRequest();
$request->setGoodsId(1);
try{
$response = $client->syncInvoke($request);
} catch(Com\Pdd\Pop\Sdk\PopHttpException $e){
echo $e->getMessage();
exit;
}
$content = $response->getContent();
if(isset($content['error_response'])){
echo "异常返回";
}
<?php
/**
* 示例接口名称pdd.ad.api.goods.query.gallery.images
*/
require_once dirname(__FILE__).'/Config.php';
require_once dirname(__FILE__)."/../vendor/autoload.php";
use Com\Pdd\Pop\Sdk\PopHttpClient;
use Com\Pdd\Pop\Sdk\Api\Request\PddAdApiGoodsQueryGalleryImagesRequest;
$client = new PopHttpClient(Config::$clientId, Config::$clientSecret);
$request = new PddAdApiGoodsQueryGalleryImagesRequest();
$request->setGoodsId(1);
try{
$response = $client->syncInvoke($request);
} catch(Com\Pdd\Pop\Sdk\PopHttpException $e){
echo $e->getMessage();
exit;
}
$content = $response->getContent();
if(isset($content['error_response'])){
echo "异常返回";
}
echo json_encode($content,JSON_UNESCAPED_UNICODE);

@ -1,25 +1,25 @@
<?php
/**
* 示例接口名称pdd.ad.api.goods.query.long.images
*/
require_once dirname(__FILE__).'/Config.php';
require_once dirname(__FILE__)."/../vendor/autoload.php";
use Com\Pdd\Pop\Sdk\PopHttpClient;
use Com\Pdd\Pop\Sdk\Api\Request\PddAdApiGoodsQueryLongImagesRequest;
$client = new PopHttpClient(Config::$clientId, Config::$clientSecret);
$request = new PddAdApiGoodsQueryLongImagesRequest();
$request->setGoodsId(1);
try{
$response = $client->syncInvoke($request);
} catch(Com\Pdd\Pop\Sdk\PopHttpException $e){
echo $e->getMessage();
exit;
}
$content = $response->getContent();
if(isset($content['error_response'])){
echo "异常返回";
}
<?php
/**
* 示例接口名称pdd.ad.api.goods.query.long.images
*/
require_once dirname(__FILE__).'/Config.php';
require_once dirname(__FILE__)."/../vendor/autoload.php";
use Com\Pdd\Pop\Sdk\PopHttpClient;
use Com\Pdd\Pop\Sdk\Api\Request\PddAdApiGoodsQueryLongImagesRequest;
$client = new PopHttpClient(Config::$clientId, Config::$clientSecret);
$request = new PddAdApiGoodsQueryLongImagesRequest();
$request->setGoodsId(1);
try{
$response = $client->syncInvoke($request);
} catch(Com\Pdd\Pop\Sdk\PopHttpException $e){
echo $e->getMessage();
exit;
}
$content = $response->getContent();
if(isset($content['error_response'])){
echo "异常返回";
}
echo json_encode($content,JSON_UNESCAPED_UNICODE);

@ -1,28 +1,28 @@
<?php
/**
* 示例接口名称pdd.ad.api.goods.query.page
*/
require_once dirname(__FILE__).'/Config.php';
require_once dirname(__FILE__)."/../vendor/autoload.php";
use Com\Pdd\Pop\Sdk\PopHttpClient;
use Com\Pdd\Pop\Sdk\Api\Request\PddAdApiGoodsQueryPageRequest;
$client = new PopHttpClient(Config::$clientId, Config::$clientSecret);
$request = new PddAdApiGoodsQueryPageRequest();
$request->setGoodsName('str');
$request->setPageNumber(1);
$request->setPageSize(1);
$request->setPlanId(1);
try{
$response = $client->syncInvoke($request);
} catch(Com\Pdd\Pop\Sdk\PopHttpException $e){
echo $e->getMessage();
exit;
}
$content = $response->getContent();
if(isset($content['error_response'])){
echo "异常返回";
}
<?php
/**
* 示例接口名称pdd.ad.api.goods.query.page
*/
require_once dirname(__FILE__).'/Config.php';
require_once dirname(__FILE__)."/../vendor/autoload.php";
use Com\Pdd\Pop\Sdk\PopHttpClient;
use Com\Pdd\Pop\Sdk\Api\Request\PddAdApiGoodsQueryPageRequest;
$client = new PopHttpClient(Config::$clientId, Config::$clientSecret);
$request = new PddAdApiGoodsQueryPageRequest();
$request->setGoodsName('str');
$request->setPageNumber(1);
$request->setPageSize(1);
$request->setPlanId(1);
try{
$response = $client->syncInvoke($request);
} catch(Com\Pdd\Pop\Sdk\PopHttpException $e){
echo $e->getMessage();
exit;
}
$content = $response->getContent();
if(isset($content['error_response'])){
echo "异常返回";
}
echo json_encode($content,JSON_UNESCAPED_UNICODE);

@ -1,26 +1,26 @@
<?php
/**
* 示例接口名称pdd.ad.api.keyword.create
*/
require_once dirname(__FILE__).'/Config.php';
require_once dirname(__FILE__)."/../vendor/autoload.php";
use Com\Pdd\Pop\Sdk\PopHttpClient;
use Com\Pdd\Pop\Sdk\Api\Request\PddAdApiKeywordCreateRequest;
$client = new PopHttpClient(Config::$clientId, Config::$clientSecret);
$request = new PddAdApiKeywordCreateRequest();
$request->setAdId(1);
$request->setKeywordList();
try{
$response = $client->syncInvoke($request);
} catch(Com\Pdd\Pop\Sdk\PopHttpException $e){
echo $e->getMessage();
exit;
}
$content = $response->getContent();
if(isset($content['error_response'])){
echo "异常返回";
}
<?php
/**
* 示例接口名称pdd.ad.api.keyword.create
*/
require_once dirname(__FILE__).'/Config.php';
require_once dirname(__FILE__)."/../vendor/autoload.php";
use Com\Pdd\Pop\Sdk\PopHttpClient;
use Com\Pdd\Pop\Sdk\Api\Request\PddAdApiKeywordCreateRequest;
$client = new PopHttpClient(Config::$clientId, Config::$clientSecret);
$request = new PddAdApiKeywordCreateRequest();
$request->setAdId(1);
$request->setKeywordList();
try{
$response = $client->syncInvoke($request);
} catch(Com\Pdd\Pop\Sdk\PopHttpException $e){
echo $e->getMessage();
exit;
}
$content = $response->getContent();
if(isset($content['error_response'])){
echo "异常返回";
}
echo json_encode($content,JSON_UNESCAPED_UNICODE);

@ -1,26 +1,26 @@
<?php
/**
* 示例接口名称pdd.ad.api.keyword.delete
*/
require_once dirname(__FILE__).'/Config.php';
require_once dirname(__FILE__)."/../vendor/autoload.php";
use Com\Pdd\Pop\Sdk\PopHttpClient;
use Com\Pdd\Pop\Sdk\Api\Request\PddAdApiKeywordDeleteRequest;
$client = new PopHttpClient(Config::$clientId, Config::$clientSecret);
$request = new PddAdApiKeywordDeleteRequest();
$request->setAdId(1);
$request->setKeywordIds(array(1));
try{
$response = $client->syncInvoke($request);
} catch(Com\Pdd\Pop\Sdk\PopHttpException $e){
echo $e->getMessage();
exit;
}
$content = $response->getContent();
if(isset($content['error_response'])){
echo "异常返回";
}
<?php
/**
* 示例接口名称pdd.ad.api.keyword.delete
*/
require_once dirname(__FILE__).'/Config.php';
require_once dirname(__FILE__)."/../vendor/autoload.php";
use Com\Pdd\Pop\Sdk\PopHttpClient;
use Com\Pdd\Pop\Sdk\Api\Request\PddAdApiKeywordDeleteRequest;
$client = new PopHttpClient(Config::$clientId, Config::$clientSecret);
$request = new PddAdApiKeywordDeleteRequest();
$request->setAdId(1);
$request->setKeywordIds(array(1));
try{
$response = $client->syncInvoke($request);
} catch(Com\Pdd\Pop\Sdk\PopHttpException $e){
echo $e->getMessage();
exit;
}
$content = $response->getContent();
if(isset($content['error_response'])){
echo "异常返回";
}
echo json_encode($content,JSON_UNESCAPED_UNICODE);

@ -1,29 +1,29 @@
<?php
/**
* 示例接口名称pdd.ad.api.keyword.query.list
*/
require_once dirname(__FILE__).'/Config.php';
require_once dirname(__FILE__)."/../vendor/autoload.php";
use Com\Pdd\Pop\Sdk\PopHttpClient;
use Com\Pdd\Pop\Sdk\Api\Request\PddAdApiKeywordQueryListRequest;
$client = new PopHttpClient(Config::$clientId, Config::$clientSecret);
$request = new PddAdApiKeywordQueryListRequest();
$request->setAdId(1);
$request->setBeginDate('str');
$request->setEndDate('str');
$request->setOrderBy(1);
$request->setSortBy(1);
try{
$response = $client->syncInvoke($request);
} catch(Com\Pdd\Pop\Sdk\PopHttpException $e){
echo $e->getMessage();
exit;
}
$content = $response->getContent();
if(isset($content['error_response'])){
echo "异常返回";
}
<?php
/**
* 示例接口名称pdd.ad.api.keyword.query.list
*/
require_once dirname(__FILE__).'/Config.php';
require_once dirname(__FILE__)."/../vendor/autoload.php";
use Com\Pdd\Pop\Sdk\PopHttpClient;
use Com\Pdd\Pop\Sdk\Api\Request\PddAdApiKeywordQueryListRequest;
$client = new PopHttpClient(Config::$clientId, Config::$clientSecret);
$request = new PddAdApiKeywordQueryListRequest();
$request->setAdId(1);
$request->setBeginDate('str');
$request->setEndDate('str');
$request->setOrderBy(1);
$request->setSortBy(1);
try{
$response = $client->syncInvoke($request);
} catch(Com\Pdd\Pop\Sdk\PopHttpException $e){
echo $e->getMessage();
exit;
}
$content = $response->getContent();
if(isset($content['error_response'])){
echo "异常返回";
}
echo json_encode($content,JSON_UNESCAPED_UNICODE);

@ -1,25 +1,25 @@
<?php
/**
* 示例接口名称pdd.ad.api.keyword.recommend.get
*/
require_once dirname(__FILE__).'/Config.php';
require_once dirname(__FILE__)."/../vendor/autoload.php";
use Com\Pdd\Pop\Sdk\PopHttpClient;
use Com\Pdd\Pop\Sdk\Api\Request\PddAdApiKeywordRecommendGetRequest;
$client = new PopHttpClient(Config::$clientId, Config::$clientSecret);
$request = new PddAdApiKeywordRecommendGetRequest();
$request->setGoodsId(1);
try{
$response = $client->syncInvoke($request);
} catch(Com\Pdd\Pop\Sdk\PopHttpException $e){
echo $e->getMessage();
exit;
}
$content = $response->getContent();
if(isset($content['error_response'])){
echo "异常返回";
}
<?php
/**
* 示例接口名称pdd.ad.api.keyword.recommend.get
*/
require_once dirname(__FILE__).'/Config.php';
require_once dirname(__FILE__)."/../vendor/autoload.php";
use Com\Pdd\Pop\Sdk\PopHttpClient;
use Com\Pdd\Pop\Sdk\Api\Request\PddAdApiKeywordRecommendGetRequest;
$client = new PopHttpClient(Config::$clientId, Config::$clientSecret);
$request = new PddAdApiKeywordRecommendGetRequest();
$request->setGoodsId(1);
try{
$response = $client->syncInvoke($request);
} catch(Com\Pdd\Pop\Sdk\PopHttpException $e){
echo $e->getMessage();
exit;
}
$content = $response->getContent();
if(isset($content['error_response'])){
echo "异常返回";
}
echo json_encode($content,JSON_UNESCAPED_UNICODE);

@ -1,26 +1,26 @@
<?php
/**
* 示例接口名称pdd.ad.api.keyword.relevance.get
*/
require_once dirname(__FILE__).'/Config.php';
require_once dirname(__FILE__)."/../vendor/autoload.php";
use Com\Pdd\Pop\Sdk\PopHttpClient;
use Com\Pdd\Pop\Sdk\Api\Request\PddAdApiKeywordRelevanceGetRequest;
$client = new PopHttpClient(Config::$clientId, Config::$clientSecret);
$request = new PddAdApiKeywordRelevanceGetRequest();
$request->setGoodsId(1);
$request->setWords(array('str'));
try{
$response = $client->syncInvoke($request);
} catch(Com\Pdd\Pop\Sdk\PopHttpException $e){
echo $e->getMessage();
exit;
}
$content = $response->getContent();
if(isset($content['error_response'])){
echo "异常返回";
}
<?php
/**
* 示例接口名称pdd.ad.api.keyword.relevance.get
*/
require_once dirname(__FILE__).'/Config.php';
require_once dirname(__FILE__)."/../vendor/autoload.php";
use Com\Pdd\Pop\Sdk\PopHttpClient;
use Com\Pdd\Pop\Sdk\Api\Request\PddAdApiKeywordRelevanceGetRequest;
$client = new PopHttpClient(Config::$clientId, Config::$clientSecret);
$request = new PddAdApiKeywordRelevanceGetRequest();
$request->setGoodsId(1);
$request->setWords(array('str'));
try{
$response = $client->syncInvoke($request);
} catch(Com\Pdd\Pop\Sdk\PopHttpException $e){
echo $e->getMessage();
exit;
}
$content = $response->getContent();
if(isset($content['error_response'])){
echo "异常返回";
}
echo json_encode($content,JSON_UNESCAPED_UNICODE);

@ -1,26 +1,26 @@
<?php
/**
* 示例接口名称pdd.ad.api.keyword.update
*/
require_once dirname(__FILE__).'/Config.php';
require_once dirname(__FILE__)."/../vendor/autoload.php";
use Com\Pdd\Pop\Sdk\PopHttpClient;
use Com\Pdd\Pop\Sdk\Api\Request\PddAdApiKeywordUpdateRequest;
$client = new PopHttpClient(Config::$clientId, Config::$clientSecret);
$request = new PddAdApiKeywordUpdateRequest();
$request->setAdId(1);
$request->setKeywords();
try{
$response = $client->syncInvoke($request);
} catch(Com\Pdd\Pop\Sdk\PopHttpException $e){
echo $e->getMessage();
exit;
}
$content = $response->getContent();
if(isset($content['error_response'])){
echo "异常返回";
}
<?php
/**
* 示例接口名称pdd.ad.api.keyword.update
*/
require_once dirname(__FILE__).'/Config.php';
require_once dirname(__FILE__)."/../vendor/autoload.php";
use Com\Pdd\Pop\Sdk\PopHttpClient;
use Com\Pdd\Pop\Sdk\Api\Request\PddAdApiKeywordUpdateRequest;
$client = new PopHttpClient(Config::$clientId, Config::$clientSecret);
$request = new PddAdApiKeywordUpdateRequest();
$request->setAdId(1);
$request->setKeywords();
try{
$response = $client->syncInvoke($request);
} catch(Com\Pdd\Pop\Sdk\PopHttpException $e){
echo $e->getMessage();
exit;
}
$content = $response->getContent();
if(isset($content['error_response'])){
echo "异常返回";
}
echo json_encode($content,JSON_UNESCAPED_UNICODE);

@ -1,28 +1,28 @@
<?php
/**
* 示例接口名称pdd.ad.api.plan.create
*/
require_once dirname(__FILE__).'/Config.php';
require_once dirname(__FILE__)."/../vendor/autoload.php";
use Com\Pdd\Pop\Sdk\PopHttpClient;
use Com\Pdd\Pop\Sdk\Api\Request\PddAdApiPlanCreateRequest;
$client = new PopHttpClient(Config::$clientId, Config::$clientSecret);
$request = new PddAdApiPlanCreateRequest();
$request->setAdPlanCreateMessage();
$request->setAdUnitCreateComplexMessageList();
$request->setPlanStrategy(1);
$request->setScenesType(1);
try{
$response = $client->syncInvoke($request);
} catch(Com\Pdd\Pop\Sdk\PopHttpException $e){
echo $e->getMessage();
exit;
}
$content = $response->getContent();
if(isset($content['error_response'])){
echo "异常返回";
}
<?php
/**
* 示例接口名称pdd.ad.api.plan.create
*/
require_once dirname(__FILE__).'/Config.php';
require_once dirname(__FILE__)."/../vendor/autoload.php";
use Com\Pdd\Pop\Sdk\PopHttpClient;
use Com\Pdd\Pop\Sdk\Api\Request\PddAdApiPlanCreateRequest;
$client = new PopHttpClient(Config::$clientId, Config::$clientSecret);
$request = new PddAdApiPlanCreateRequest();
$request->setAdPlanCreateMessage();
$request->setAdUnitCreateComplexMessageList();
$request->setPlanStrategy(1);
$request->setScenesType(1);
try{
$response = $client->syncInvoke($request);
} catch(Com\Pdd\Pop\Sdk\PopHttpException $e){
echo $e->getMessage();
exit;
}
$content = $response->getContent();
if(isset($content['error_response'])){
echo "异常返回";
}
echo json_encode($content,JSON_UNESCAPED_UNICODE);

@ -1,26 +1,26 @@
<?php
/**
* 示例接口名称pdd.ad.api.plan.delete
*/
require_once dirname(__FILE__).'/Config.php';
require_once dirname(__FILE__)."/../vendor/autoload.php";
use Com\Pdd\Pop\Sdk\PopHttpClient;
use Com\Pdd\Pop\Sdk\Api\Request\PddAdApiPlanDeleteRequest;
$client = new PopHttpClient(Config::$clientId, Config::$clientSecret);
$request = new PddAdApiPlanDeleteRequest();
$request->setPlanId(1);
$request->setScenesType(1);
try{
$response = $client->syncInvoke($request);
} catch(Com\Pdd\Pop\Sdk\PopHttpException $e){
echo $e->getMessage();
exit;
}
$content = $response->getContent();
if(isset($content['error_response'])){
echo "异常返回";
}
<?php
/**
* 示例接口名称pdd.ad.api.plan.delete
*/
require_once dirname(__FILE__).'/Config.php';
require_once dirname(__FILE__)."/../vendor/autoload.php";
use Com\Pdd\Pop\Sdk\PopHttpClient;
use Com\Pdd\Pop\Sdk\Api\Request\PddAdApiPlanDeleteRequest;
$client = new PopHttpClient(Config::$clientId, Config::$clientSecret);
$request = new PddAdApiPlanDeleteRequest();
$request->setPlanId(1);
$request->setScenesType(1);
try{
$response = $client->syncInvoke($request);
} catch(Com\Pdd\Pop\Sdk\PopHttpException $e){
echo $e->getMessage();
exit;
}
$content = $response->getContent();
if(isset($content['error_response'])){
echo "异常返回";
}
echo json_encode($content,JSON_UNESCAPED_UNICODE);

@ -1,26 +1,26 @@
<?php
/**
* 示例接口名称pdd.ad.api.plan.query.can.create.ad.plan
*/
require_once dirname(__FILE__).'/Config.php';
require_once dirname(__FILE__)."/../vendor/autoload.php";
use Com\Pdd\Pop\Sdk\PopHttpClient;
use Com\Pdd\Pop\Sdk\Api\Request\PddAdApiPlanQueryCanCreateAdPlanRequest;
$client = new PopHttpClient(Config::$clientId, Config::$clientSecret);
$request = new PddAdApiPlanQueryCanCreateAdPlanRequest();
$request->setPlanName('str');
$request->setScenesType(1);
try{
$response = $client->syncInvoke($request);
} catch(Com\Pdd\Pop\Sdk\PopHttpException $e){
echo $e->getMessage();
exit;
}
$content = $response->getContent();
if(isset($content['error_response'])){
echo "异常返回";
}
<?php
/**
* 示例接口名称pdd.ad.api.plan.query.can.create.ad.plan
*/
require_once dirname(__FILE__).'/Config.php';
require_once dirname(__FILE__)."/../vendor/autoload.php";
use Com\Pdd\Pop\Sdk\PopHttpClient;
use Com\Pdd\Pop\Sdk\Api\Request\PddAdApiPlanQueryCanCreateAdPlanRequest;
$client = new PopHttpClient(Config::$clientId, Config::$clientSecret);
$request = new PddAdApiPlanQueryCanCreateAdPlanRequest();
$request->setPlanName('str');
$request->setScenesType(1);
try{
$response = $client->syncInvoke($request);
} catch(Com\Pdd\Pop\Sdk\PopHttpException $e){
echo $e->getMessage();
exit;
}
$content = $response->getContent();
if(isset($content['error_response'])){
echo "异常返回";
}
echo json_encode($content,JSON_UNESCAPED_UNICODE);

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save