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

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

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

@ -1,72 +1,72 @@
{ {
"name": "dtapps/think-library", "name": "dtapps/think-library",
"description": "ThinkPhP扩展包", "description": "ThinkPhP扩展包",
"keywords": [ "keywords": [
"dtapps", "dtapps",
"think-library", "think-library",
"think", "think",
"thinkphp", "thinkphp",
"library" "library"
], ],
"time": "2020-04-13", "time": "2020-04-13",
"type": "library", "type": "library",
"license": "MIT", "license": "MIT",
"authors": [ "authors": [
{ {
"name": "Chaim", "name": "Chaim",
"email": "li.gc@icoud.com", "email": "li.gc@icoud.com",
"homepage": "https://api.dtapp.net" "homepage": "https://api.dtapp.net"
} }
], ],
"homepage": "https://www.dtapp.net", "homepage": "https://www.dtapp.net",
"require": { "require": {
"php": ">=7.1", "php": ">=7.1",
"ext-gd": "*", "ext-gd": "*",
"ext-libxml": "*", "ext-libxml": "*",
"ext-json": "*", "ext-json": "*",
"ext-simplexml": "*", "ext-simplexml": "*",
"ext-zip": "*", "ext-zip": "*",
"ext-openssl": "*", "ext-openssl": "*",
"ext-iconv": "*", "ext-iconv": "*",
"ext-curl": "*", "ext-curl": "*",
"ext-dom": "*", "ext-dom": "*",
"topthink/framework": "^6.0.0", "topthink/framework": "^6.0.0",
"topthink/think-orm": "^2.0", "topthink/think-orm": "^2.0",
"aliyuncs/oss-sdk-php": "^2.3", "aliyuncs/oss-sdk-php": "^2.3",
"obs/esdk-obs-php": "^3.19", "obs/esdk-obs-php": "^3.19",
"baidubce/bce-sdk-php": "^0.8.22", "baidubce/bce-sdk-php": "^0.8.22",
"qcloud/cos-sdk-v5": "^2.0", "qcloud/cos-sdk-v5": "^2.0",
"qiniu/php-sdk": "^7.2", "qiniu/php-sdk": "^7.2",
"upyun/sdk": "^3.4", "upyun/sdk": "^3.4",
"phpoffice/phpspreadsheet": "1.17.1", "phpoffice/phpspreadsheet": "1.17.1",
"alibabacloud/dysmsapi-20170525": "^1.0" "alibabacloud/dysmsapi-20170525": "^1.0"
}, },
"require-dev": { "require-dev": {
"symfony/var-dumper": "^4.2" "symfony/var-dumper": "^4.2"
}, },
"autoload": { "autoload": {
"files": [ "files": [
"src/common.php", "src/common.php",
"src/service/taobao/bin/TopSdk.php" "src/service/taobao/bin/TopSdk.php"
], ],
"psr-4": { "psr-4": {
"DtApp\\ThinkLibrary\\": "src" "DtApp\\ThinkLibrary\\": "src"
} }
}, },
"extra": { "extra": {
"think": { "think": {
"services": [ "services": [
"DtApp\\ThinkLibrary\\Library" "DtApp\\ThinkLibrary\\Library"
], ],
"config": { "config": {
"dtapp": "src/config.php" "dtapp": "src/config.php"
} }
} }
}, },
"repositories": { "repositories": {
"packagist": { "packagist": {
"type": "composer", "type": "composer",
"url": "https://mirrors.aliyun.com/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 <?php
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0 // | ThinkLibrary 6.0 for ThinkPhP 6.0
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ] // | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary // | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org ) // | 开源协议 ( https://mit-license.org )
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary // | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary // | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library // | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary; namespace DtApp\ThinkLibrary;
use DtApp\ThinkLibrary\helper\ValidateHelper; use DtApp\ThinkLibrary\helper\ValidateHelper;
use stdClass; use stdClass;
use think\App; use think\App;
use think\exception\HttpResponseException; use think\exception\HttpResponseException;
use think\Request; use think\Request;
/** /**
* 标准Api控制器基类 * 标准Api控制器基类
* Class ApiController * Class ApiController
* @package DtApp\ThinkLibrary * @package DtApp\ThinkLibrary
*/ */
abstract class ApiController extends stdClass abstract class ApiController extends stdClass
{ {
/** /**
* 应用容器 * 应用容器
* @var App * @var App
*/ */
public $app; public $app;
/** /**
* 请求对象 * 请求对象
* @var Request * @var Request
*/ */
public $request; public $request;
/** /**
* 解密后数据 * 解密后数据
* @var * @var
*/ */
private $aes_decrypt_data; private $aes_decrypt_data;
/** /**
* 加密相关的东西 * 加密相关的东西
* @var string * @var string
*/ */
private $aes_md5, $aes_md5_iv = ''; private $aes_md5, $aes_md5_iv = '';
/** /**
* ApiController constructor. * ApiController constructor.
* @param App $app * @param App $app
*/ */
public function __construct(App $app) public function __construct(App $app)
{ {
$this->app = $app; $this->app = $app;
$this->request = $app->request; $this->request = $app->request;
$this->app->bind('DtApp\ThinkLibrary\ApiController', $this); $this->app->bind('DtApp\ThinkLibrary\ApiController', $this);
if (in_array($this->request->action(), get_class_methods(__CLASS__))) { if (in_array($this->request->action(), get_class_methods(__CLASS__))) {
$this->error('Access without permission.'); $this->error('Access without permission.');
} }
$this->initialize(); $this->initialize();
} }
/** /**
* 控制器初始化 * 控制器初始化
*/ */
protected function initialize() protected function initialize()
{ {
} }
/** /**
* 返回失败的操作 * 返回失败的操作
* @param mixed $msg 消息内容 * @param mixed $msg 消息内容
* @param mixed $data 返回数据 * @param mixed $data 返回数据
* @param integer $code 返回代码 * @param integer $code 返回代码
*/ */
public function error($msg = 'error', $code = 1, $data = []): void public function error($msg = 'error', $code = 1, $data = []): void
{ {
throw new HttpResponseException(json([ throw new HttpResponseException(json([
'code' => $code, 'code' => $code,
'msg' => $msg, 'msg' => $msg,
'timestamp' => time(), 'timestamp' => time(),
'data' => $data, 'data' => $data,
])); ]));
} }
/** /**
* 返回成功的操作 * 返回成功的操作
* @param mixed $msg 消息内容 * @param mixed $msg 消息内容
* @param mixed $data 返回数据 * @param mixed $data 返回数据
* @param integer $code 返回代码 * @param integer $code 返回代码
*/ */
public function success($data = [], $msg = 'success', $code = 0): void public function success($data = [], $msg = 'success', $code = 0): void
{ {
throw new HttpResponseException(json([ throw new HttpResponseException(json([
'code' => $code, 'code' => $code,
'msg' => $msg, 'msg' => $msg,
'timestamp' => time(), 'timestamp' => time(),
'data' => $data, 'data' => $data,
])); ]));
} }
/** /**
* key * key
* @param string $name 参数名 * @param string $name 参数名
* @return $this * @return $this
*/ */
public function setAesMd5($name = 'sniff_h5'): self public function setAesMd5($name = 'sniff_h5'): self
{ {
$value = config("dtapp.md5.{$name}"); $value = config("dtapp.md5.{$name}");
$this->aes_md5 = $value; $this->aes_md5 = $value;
return $this; return $this;
} }
/** /**
* iv * iv
* @return $this * @return $this
*/ */
private function setAesMd5Iv(): self private function setAesMd5Iv(): self
{ {
$value = config("dtapp.md5.bcw"); $value = config("dtapp.md5.bcw");
$this->aes_md5_iv = $value; $this->aes_md5_iv = $value;
return $this; return $this;
} }
/** /**
* 返回成功的操作 * 返回成功的操作
* @param mixed $data 返回数据 * @param mixed $data 返回数据
* @param mixed $msg 消息内容 * @param mixed $msg 消息内容
* @param integer $code 返回代码 * @param integer $code 返回代码
*/ */
public function aesSuccess($data = [], $msg = 'success', $code = 0) public function aesSuccess($data = [], $msg = 'success', $code = 0)
{ {
$timestamp = time(); $timestamp = time();
throw new HttpResponseException(json([ throw new HttpResponseException(json([
'code' => $code, 'code' => $code,
'msg' => $msg, 'msg' => $msg,
'timestamp' => $timestamp, 'timestamp' => $timestamp,
'data' => [ 'data' => [
'aes' => $this->encrypt($data, $timestamp) 'aes' => $this->encrypt($data, $timestamp)
], ],
])); ]));
} }
/** /**
* URL重定向 * URL重定向
* @param string $url 跳转链接 * @param string $url 跳转链接
* @param integer $code 跳转代码 * @param integer $code 跳转代码
*/ */
public function redirect($url, $code = 301): void public function redirect($url, $code = 301): void
{ {
throw new HttpResponseException(redirect($url, $code)); throw new HttpResponseException(redirect($url, $code));
} }
/** /**
* @param array $rules * @param array $rules
* @param string $type * @param string $type
* @return mixed * @return mixed
*/ */
protected function _vali(array $rules, $type = '') protected function _vali(array $rules, $type = '')
{ {
return ValidateHelper::instance() return ValidateHelper::instance()
->init($rules, $type); ->init($rules, $type);
} }
/** /**
* 获取解密后的数据 * 获取解密后的数据
* @param string $name * @param string $name
* @param null $default * @param null $default
* @return mixed * @return mixed
*/ */
public function getAesDecryptData(string $name = '', $default = null) public function getAesDecryptData(string $name = '', $default = null)
{ {
if (empty($name)) { if (empty($name)) {
return $this->aes_decrypt_data; return $this->aes_decrypt_data;
} }
return $this->aes_decrypt_data[$name] ?? $default; return $this->aes_decrypt_data[$name] ?? $default;
} }
/** /**
* 验证接口签名 * 验证接口签名
*/ */
public function _judgeSign() public function _judgeSign()
{ {
// 加密的数据参数 // 加密的数据参数
$aes = $this->request->post('aes', ''); $aes = $this->request->post('aes', '');
if (empty($aes)) { if (empty($aes)) {
$this->error('数据未签名!', 104); $this->error('数据未签名!', 104);
} }
// 获取时间数据 // 获取时间数据
$timestamp = $this->request->get('timestamp', 0); $timestamp = $this->request->get('timestamp', 0);
// 判断是否有时间 // 判断是否有时间
if (empty($timestamp)) { if (empty($timestamp)) {
$this->error('数据异常!', 105); $this->error('数据异常!', 105);
} }
// 解密 // 解密
$aes_decode = $this->decrypt($aes, $timestamp); $aes_decode = $this->decrypt($aes, $timestamp);
if (empty($aes_decode)) { if (empty($aes_decode)) {
$this->error('解密失败', 106); $this->error('解密失败', 106);
} }
$data = json_decode($aes_decode, true); $data = json_decode($aes_decode, true);
// 判断是不是小于服务器时间 // 判断是不是小于服务器时间
$before = strtotime('-2minute'); $before = strtotime('-2minute');
$rear = strtotime('+2minute'); $rear = strtotime('+2minute');
if ($timestamp <= $rear && $timestamp >= $before) { if ($timestamp <= $rear && $timestamp >= $before) {
$this->aes_decrypt_data = $data; $this->aes_decrypt_data = $data;
} else { } else {
$this->error('已超时,请重新尝试!'); $this->error('已超时,请重新尝试!');
} }
} }
/** /**
* 加密 * 加密
* @param $data * @param $data
* @param int $timestamp * @param int $timestamp
* @return bool|string * @return bool|string
*/ */
private function encrypt($data, int $timestamp) private function encrypt($data, int $timestamp)
{ {
if (empty($this->aes_md5)) { if (empty($this->aes_md5)) {
$this->setAesMd5(); $this->setAesMd5();
} }
if (empty($this->aes_md5_iv)) { if (empty($this->aes_md5_iv)) {
$this->setAesMd5Iv(); $this->setAesMd5Iv();
} }
if (!empty(is_array($data))) { if (!empty(is_array($data))) {
$data = json_encode($data); $data = json_encode($data);
} }
return urlencode(base64_encode(openssl_encrypt($data, 'AES-128-CBC', $this->aes_md5, 1, $this->aes_md5_iv . $timestamp))); return urlencode(base64_encode(openssl_encrypt($data, 'AES-128-CBC', $this->aes_md5, 1, $this->aes_md5_iv . $timestamp)));
} }
/** /**
* 解密 * 解密
* @param string $data * @param string $data
* @param int $timestamp * @param int $timestamp
* @return bool|false|string * @return bool|false|string
*/ */
private function decrypt(string $data, int $timestamp) private function decrypt(string $data, int $timestamp)
{ {
if (empty($this->aes_md5)) { if (empty($this->aes_md5)) {
$this->setAesMd5(); $this->setAesMd5();
} }
if (empty($this->aes_md5_iv)) { if (empty($this->aes_md5_iv)) {
$this->setAesMd5Iv(); $this->setAesMd5Iv();
} }
return openssl_decrypt(base64_decode(urldecode($data)), "AES-128-CBC", $this->aes_md5, true, $this->aes_md5_iv . $timestamp); return openssl_decrypt(base64_decode(urldecode($data)), "AES-128-CBC", $this->aes_md5, true, $this->aes_md5_iv . $timestamp);
} }
} }

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

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

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

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

334
src/cache/Mysql.php vendored

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

@ -1,106 +1,106 @@
<?php <?php
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0 // | ThinkLibrary 6.0 for ThinkPhP 6.0
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ] // | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary // | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org ) // | 开源协议 ( https://mit-license.org )
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
// | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary // | gitee 仓库地址 https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 https://github.com/GC0202/ThinkLibrary // | github 仓库地址 https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 https://packagist.org/packages/liguangchun/think-library // | Packagist 地址 https://packagist.org/packages/liguangchun/think-library
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace DtApp\ThinkLibrary\service\baidu; namespace DtApp\ThinkLibrary\service\baidu;
use DtApp\ThinkLibrary\exception\DtaException; use DtApp\ThinkLibrary\exception\DtaException;
use DtApp\ThinkLibrary\Service; use DtApp\ThinkLibrary\Service;
use DtApp\ThinkLibrary\service\curl\HttpService; use DtApp\ThinkLibrary\service\curl\HttpService;
/** /**
* 百度地图 * 百度地图
* http://lbsyun.baidu.com/index.php?title=webapi * http://lbsyun.baidu.com/index.php?title=webapi
* Class LbsYunService * Class LbsYunService
* @package DtApp\ThinkLibrary\service\baidu * @package DtApp\ThinkLibrary\service\baidu
*/ */
class LbsYunService extends Service class LbsYunService extends Service
{ {
/** /**
* @var string * @var string
*/ */
private $ak = ""; private $ak = "";
/** /**
* @var string * @var string
*/ */
private $output = "json"; private $output = "json";
/** /**
* @param string $ak * @param string $ak
* @return $this * @return $this
*/ */
public function ak(string $ak): self public function ak(string $ak): self
{ {
$this->ak = $ak; $this->ak = $ak;
return $this; return $this;
} }
/** /**
* 国内天气查询 * 国内天气查询
* http://lbsyun.baidu.com/index.php?title=webapi/weather * http://lbsyun.baidu.com/index.php?title=webapi/weather
* @param int $district_id * @param int $district_id
* @param string $coordtype * @param string $coordtype
* @param string $location * @param string $location
* @return array|bool|mixed|string * @return array|bool|mixed|string
* @throws DtaException * @throws DtaException
*/ */
public function weather($district_id = 110100, string $coordtype = "bd09ll", string $location = "") public function weather($district_id = 110100, string $coordtype = "bd09ll", string $location = "")
{ {
if (empty($this->ak)) { if (empty($this->ak)) {
throw new DtaException('请检查ak参数'); throw new DtaException('请检查ak参数');
} }
$data = http_build_query([ $data = http_build_query([
"district_id" => $district_id, "district_id" => $district_id,
"coordtype" => $coordtype, "coordtype" => $coordtype,
"ak" => $this->ak, "ak" => $this->ak,
"location" => $location, "location" => $location,
"data_type" => 'all', "data_type" => 'all',
"output" => $this->output, "output" => $this->output,
]); ]);
return HttpService::instance() return HttpService::instance()
->url("http://api.map.baidu.com/weather/v1/?{$data}") ->url("http://api.map.baidu.com/weather/v1/?{$data}")
->toArray(); ->toArray();
} }
/** /**
* 国外天气查询 * 国外天气查询
* http://lbsyun.baidu.com/index.php?title=webapi/weather-abroad * http://lbsyun.baidu.com/index.php?title=webapi/weather-abroad
* @param int $district_id * @param int $district_id
* @param string $coordtype * @param string $coordtype
* @param string $location * @param string $location
* @param string $language * @param string $language
* @return array|bool|mixed|string * @return array|bool|mixed|string
* @throws DtaException * @throws DtaException
*/ */
public function weatherAbroad($district_id = 110100, string $coordtype = "bd09ll", string $location = "", string $language = "cn") public function weatherAbroad($district_id = 110100, string $coordtype = "bd09ll", string $location = "", string $language = "cn")
{ {
if (empty($this->ak)) { if (empty($this->ak)) {
throw new DtaException('请检查ak参数'); throw new DtaException('请检查ak参数');
} }
$data = http_build_query([ $data = http_build_query([
"district_id" => $district_id, "district_id" => $district_id,
"coordtype" => $coordtype, "coordtype" => $coordtype,
"ak" => $this->ak, "ak" => $this->ak,
"location" => $location, "location" => $location,
"data_type" => 'all', "data_type" => 'all',
"language" => $language, "language" => $language,
"output" => $this->output, "output" => $this->output,
]); ]);
return HttpService::instance() return HttpService::instance()
->url("http://api.map.baidu.com/weather_abroad/v1/?{$data}") ->url("http://api.map.baidu.com/weather_abroad/v1/?{$data}")
->toArray(); ->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": [ "rows": [
{ {
"adcode": "360000", "adcode": "360000",
"people_count_2010": 43976312, "people_count_2010": 43976312,
"lat": 28.676493, "lat": 28.676493,
"lng": 115.892151, "lng": 115.892151,
"name": "江西省", "name": "江西省",
"level": "province", "level": "province",
"parent": "中华人民共和国" "parent": "中华人民共和国"
}, },
{ {
"adcode": "410000", "adcode": "410000",
"people_count_2010": 96486884, "people_count_2010": 96486884,
"lat": 34.757975, "lat": 34.757975,
"lng": 113.665412, "lng": 113.665412,
"name": "河南省", "name": "河南省",
"level": "province", "level": "province",
"parent": "中华人民共和国" "parent": "中华人民共和国"
}, },
{ {
"adcode": "510000", "adcode": "510000",
"people_count_2010": 85974759, "people_count_2010": 85974759,
"lat": 30.659462, "lat": 30.659462,
"lng": 104.065735, "lng": 104.065735,
"name": "四川省", "name": "四川省",
"level": "province", "level": "province",
"parent": "中华人民共和国" "parent": "中华人民共和国"
}, },
{ {
"adcode": "500000", "adcode": "500000",
"people_count_2010": 28458101, "people_count_2010": 28458101,
"lat": 29.533155, "lat": 29.533155,
"lng": 106.504962, "lng": 106.504962,
"name": "重庆市", "name": "重庆市",
"level": "province", "level": "province",
"parent": "中华人民共和国" "parent": "中华人民共和国"
}, },
{ {
"adcode": "540000", "adcode": "540000",
"people_count_2010": 2554907, "people_count_2010": 2554907,
"lat": 29.660361, "lat": 29.660361,
"lng": 91.132212, "lng": 91.132212,
"name": "西藏自治区", "name": "西藏自治区",
"level": "province", "level": "province",
"parent": "中华人民共和国" "parent": "中华人民共和国"
}, },
{ {
"adcode": "520000", "adcode": "520000",
"people_count_2010": 25119376, "people_count_2010": 25119376,
"lat": 26.578343, "lat": 26.578343,
"lng": 106.713478, "lng": 106.713478,
"name": "贵州省", "name": "贵州省",
"level": "province", "level": "province",
"parent": "中华人民共和国" "parent": "中华人民共和国"
}, },
{ {
"adcode": "210000", "adcode": "210000",
"people_count_2010": 43149614, "people_count_2010": 43149614,
"lat": 41.796767, "lat": 41.796767,
"lng": 123.429096, "lng": 123.429096,
"name": "辽宁省", "name": "辽宁省",
"level": "province", "level": "province",
"parent": "中华人民共和国" "parent": "中华人民共和国"
}, },
{ {
"adcode": "650000", "adcode": "650000",
"people_count_2010": 29070614, "people_count_2010": 29070614,
"lat": 43.792818, "lat": 43.792818,
"lng": 87.617733, "lng": 87.617733,
"name": "新疆维吾尔自治区", "name": "新疆维吾尔自治区",
"level": "province", "level": "province",
"parent": "中华人民共和国" "parent": "中华人民共和国"
}, },
{ {
"adcode": "370000", "adcode": "370000",
"people_count_2010": 94646230, "people_count_2010": 94646230,
"lat": 36.675807, "lat": 36.675807,
"lng": 117.000923, "lng": 117.000923,
"name": "山东省", "name": "山东省",
"level": "province", "level": "province",
"parent": "中华人民共和国" "parent": "中华人民共和国"
}, },
{ {
"adcode": "310000", "adcode": "310000",
"people_count_2010": 21135161, "people_count_2010": 21135161,
"lat": 31.231706, "lat": 31.231706,
"lng": 121.472644, "lng": 121.472644,
"name": "上海市", "name": "上海市",
"level": "province", "level": "province",
"parent": "中华人民共和国" "parent": "中华人民共和国"
}, },
{ {
"adcode": "820000", "adcode": "820000",
"people_count_2010": null, "people_count_2010": null,
"lat": 22.198951, "lat": 22.198951,
"lng": 113.54909, "lng": 113.54909,
"name": "澳門特別行政區", "name": "澳門特別行政區",
"level": "province", "level": "province",
"parent": "中华人民共和国" "parent": "中华人民共和国"
}, },
{ {
"adcode": "140000", "adcode": "140000",
"people_count_2010": 34364492, "people_count_2010": 34364492,
"lat": 37.857014, "lat": 37.857014,
"lng": 112.549248, "lng": 112.549248,
"name": "山西省", "name": "山西省",
"level": "province", "level": "province",
"parent": "中华人民共和国" "parent": "中华人民共和国"
}, },
{ {
"adcode": "330000", "adcode": "330000",
"people_count_2010": 53807755, "people_count_2010": 53807755,
"lat": 30.287459, "lat": 30.287459,
"lng": 120.153576, "lng": 120.153576,
"name": "浙江省", "name": "浙江省",
"level": "province", "level": "province",
"parent": "中华人民共和国" "parent": "中华人民共和国"
}, },
{ {
"adcode": "460000", "adcode": "460000",
"people_count_2010": 42028870, "people_count_2010": 42028870,
"lat": 20.031971, "lat": 20.031971,
"lng": 110.33119, "lng": 110.33119,
"name": "海南省", "name": "海南省",
"level": "province", "level": "province",
"parent": "中华人民共和国" "parent": "中华人民共和国"
}, },
{ {
"adcode": "350000", "adcode": "350000",
"people_count_2010": 39026582, "people_count_2010": 39026582,
"lat": 26.075302, "lat": 26.075302,
"lng": 119.306239, "lng": 119.306239,
"name": "福建省", "name": "福建省",
"level": "province", "level": "province",
"parent": "中华人民共和国" "parent": "中华人民共和国"
}, },
{ {
"adcode": "630000", "adcode": "630000",
"people_count_2010": 5619543, "people_count_2010": 5619543,
"lat": 36.623178, "lat": 36.623178,
"lng": 101.778916, "lng": 101.778916,
"name": "青海省", "name": "青海省",
"level": "province", "level": "province",
"parent": "中华人民共和国" "parent": "中华人民共和国"
}, },
{ {
"adcode": "640000", "adcode": "640000",
"people_count_2010": 6466366, "people_count_2010": 6466366,
"lat": 38.46637, "lat": 38.46637,
"lng": 106.278179, "lng": 106.278179,
"name": "宁夏回族自治区", "name": "宁夏回族自治区",
"level": "province", "level": "province",
"parent": "中华人民共和国" "parent": "中华人民共和国"
}, },
{ {
"adcode": "420000", "adcode": "420000",
"people_count_2010": 62160766, "people_count_2010": 62160766,
"lat": 30.584355, "lat": 30.584355,
"lng": 114.298572, "lng": 114.298572,
"name": "湖北省", "name": "湖北省",
"level": "province", "level": "province",
"parent": "中华人民共和国" "parent": "中华人民共和国"
}, },
{ {
"adcode": "620000", "adcode": "620000",
"people_count_2010": 27957557, "people_count_2010": 27957557,
"lat": 36.058039, "lat": 36.058039,
"lng": 103.823557, "lng": 103.823557,
"name": "甘肃省", "name": "甘肃省",
"level": "province", "level": "province",
"parent": "中华人民共和国" "parent": "中华人民共和国"
}, },
{ {
"adcode": "340000", "adcode": "340000",
"people_count_2010": 57217014, "people_count_2010": 57217014,
"lat": 31.86119, "lat": 31.86119,
"lng": 117.283042, "lng": 117.283042,
"name": "安徽省", "name": "安徽省",
"level": "province", "level": "province",
"parent": "中华人民共和国" "parent": "中华人民共和国"
}, },
{ {
"adcode": "710000", "adcode": "710000",
"people_count_2010": null, "people_count_2010": null,
"lat": 25.044332, "lat": 25.044332,
"lng": 121.509062, "lng": 121.509062,
"name": "台湾省", "name": "台湾省",
"level": "province", "level": "province",
"parent": "中华人民共和国" "parent": "中华人民共和国"
}, },
{ {
"adcode": "610000", "adcode": "610000",
"people_count_2010": 35876998, "people_count_2010": 35876998,
"lat": 34.263161, "lat": 34.263161,
"lng": 108.948024, "lng": 108.948024,
"name": "陕西省", "name": "陕西省",
"level": "province", "level": "province",
"parent": "中华人民共和国" "parent": "中华人民共和国"
}, },
{ {
"adcode": "450000", "adcode": "450000",
"people_count_2010": 47082115, "people_count_2010": 47082115,
"lat": 22.82402, "lat": 22.82402,
"lng": 108.320004, "lng": 108.320004,
"name": "广西壮族自治区", "name": "广西壮族自治区",
"level": "province", "level": "province",
"parent": "中华人民共和国" "parent": "中华人民共和国"
}, },
{ {
"adcode": "120000", "adcode": "120000",
"people_count_2010": 15298136, "people_count_2010": 15298136,
"lat": 39.125596, "lat": 39.125596,
"lng": 117.190182, "lng": 117.190182,
"name": "天津市", "name": "天津市",
"level": "province", "level": "province",
"parent": "中华人民共和国" "parent": "中华人民共和国"
}, },
{ {
"adcode": "530000", "adcode": "530000",
"people_count_2010": 72840959, "people_count_2010": 72840959,
"lat": 25.040609, "lat": 25.040609,
"lng": 102.712251, "lng": 102.712251,
"name": "云南省", "name": "云南省",
"level": "province", "level": "province",
"parent": "中华人民共和国" "parent": "中华人民共和国"
}, },
{ {
"adcode": "230000", "adcode": "230000",
"people_count_2010": 40734477, "people_count_2010": 40734477,
"lat": 45.756967, "lat": 45.756967,
"lng": 126.642464, "lng": 126.642464,
"name": "黑龙江省", "name": "黑龙江省",
"level": "province", "level": "province",
"parent": "中华人民共和国" "parent": "中华人民共和国"
}, },
{ {
"adcode": "440000", "adcode": "440000",
"people_count_2010": 107131199, "people_count_2010": 107131199,
"lat": 23.125178, "lat": 23.125178,
"lng": 113.280637, "lng": 113.280637,
"name": "广东省", "name": "广东省",
"level": "province", "level": "province",
"parent": "中华人民共和国" "parent": "中华人民共和国"
}, },
{ {
"adcode": "430000", "adcode": "430000",
"people_count_2010": 67158313, "people_count_2010": 67158313,
"lat": 28.19409, "lat": 28.19409,
"lng": 112.982279, "lng": 112.982279,
"name": "湖南省", "name": "湖南省",
"level": "province", "level": "province",
"parent": "中华人民共和国" "parent": "中华人民共和国"
}, },
{ {
"adcode": "130000", "adcode": "130000",
"people_count_2010": 106816280, "people_count_2010": 106816280,
"lat": 38.045474, "lat": 38.045474,
"lng": 114.502461, "lng": 114.502461,
"name": "河北省", "name": "河北省",
"level": "province", "level": "province",
"parent": "中华人民共和国" "parent": "中华人民共和国"
}, },
{ {
"adcode": "150000", "adcode": "150000",
"people_count_2010": 26353789, "people_count_2010": 26353789,
"lat": 40.818311, "lat": 40.818311,
"lng": 111.670801, "lng": 111.670801,
"name": "内蒙古自治区", "name": "内蒙古自治区",
"level": "province", "level": "province",
"parent": "中华人民共和国" "parent": "中华人民共和国"
}, },
{ {
"adcode": "220000", "adcode": "220000",
"people_count_2010": 26423220, "people_count_2010": 26423220,
"lat": 43.886841, "lat": 43.886841,
"lng": 125.3245, "lng": 125.3245,
"name": "吉林省", "name": "吉林省",
"level": "province", "level": "province",
"parent": "中华人民共和国" "parent": "中华人民共和国"
}, },
{ {
"adcode": "320000", "adcode": "320000",
"people_count_2010": 79104628, "people_count_2010": 79104628,
"lat": 32.041544, "lat": 32.041544,
"lng": 118.767413, "lng": 118.767413,
"name": "江苏省", "name": "江苏省",
"level": "province", "level": "province",
"parent": "中华人民共和国" "parent": "中华人民共和国"
}, },
{ {
"adcode": "110000", "adcode": "110000",
"people_count_2010": 18934592, "people_count_2010": 18934592,
"lat": 39.904989, "lat": 39.904989,
"lng": 116.405285, "lng": 116.405285,
"name": "北京市", "name": "北京市",
"level": "province", "level": "province",
"parent": "中华人民共和国" "parent": "中华人民共和国"
}, },
{ {
"adcode": "810000", "adcode": "810000",
"people_count_2010": null, "people_count_2010": null,
"lat": 22.320048, "lat": 22.320048,
"lng": 114.173355, "lng": 114.173355,
"name": "香港特別行政區", "name": "香港特別行政區",
"level": "province", "level": "province",
"parent": "中华人民共和国" "parent": "中华人民共和国"
} }
], ],
"total": 34 "total": 34
} }

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

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

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

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

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

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

File diff suppressed because it is too large Load Diff

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

File diff suppressed because it is too large Load Diff

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

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

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

File diff suppressed because it is too large Load Diff

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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