diff --git a/README.md b/README.md index 2fcb61c..4b6abbf 100644 --- a/README.md +++ b/README.md @@ -19,13 +19,13 @@ - Github仓库地址:https://github.com/GC0202/ThinkLibrary - 码云仓库地址:https://gitee.com/liguangchun/ThinkLibrary -- gitlab:https://gitlab.com/liguangchun/thinklibrary -- 阿里云仓库地址:https://github.com/GC0202/ThinkLibrary -- CODING:https://liguangchun-01.coding.net/p/ThinkLibrary/d/ThinkLibrary/git -- CODING:https://aizhineng.coding.net/p/ThinkLibrary/d/ThinkLibrary/git -- 腾讯云:https://liguangchundt.coding.net/p/ThinkLibrary/d/ThinkLibrary/git -- 微信:https://git.weixin.qq.com/liguangchun/ThinkLibrary -- 华为云:https://codehub-cn-south-1.devcloud.huaweicloud.com/composer00001/ThinkLibrary.git +- gitlab仓库地址:https://gitlab.com/liguangchun/thinklibrary +- 阿里云仓库地址:https://code.aliyun.com/liguancghun/ThinkLibrary +- CODING仓库地址:https://liguangchun-01.coding.net/p/ThinkLibrary/d/ThinkLibrary/git +- CODING仓库地址:https://aizhineng.coding.net/p/ThinkLibrary/d/ThinkLibrary/git +- 腾讯云仓库地址:https://liguangchundt.coding.net/p/ThinkLibrary/d/ThinkLibrary/git +- 微信仓库地址:https://git.weixin.qq.com/liguangchun/ThinkLibrary +- 华为云仓库地址:https://codehub-cn-south-1.devcloud.huaweicloud.com/composer00001/ThinkLibrary.git ### 开发版 ```text @@ -49,42 +49,90 @@ composer update liguangchun/think-library -vvv composer remove liguangchun/think-library -vvv ``` +## 获取电脑Mac地址服务使用示例 + +```php + +use DtApp\ThinkLibrary\service\MacService; + +dump(MacService::instance() +->get()); + +``` + +## 百度地图服务使用示例 + +```php + +use DtApp\ThinkLibrary\exception\CurlException; +use DtApp\ThinkLibrary\service\baidu\LbsYunService; + +try { + // 获取天气信息 + dump(LbsYunService::instance() + ->ak("") + ->weather()); +} catch (CurlException $e) { + dump($e->getMessage()); +} + +``` + +## 高德地图服务使用示例 + +```php + +use DtApp\ThinkLibrary\exception\CurlException; +use DtApp\ThinkLibrary\service\amap\AmApService; + +try { + // 获取天气信息 + dump(AmApService::instance() + ->key("") + ->weather()); +} catch (CurlException $e) { + dump($e->getMessage()); +} + + +``` + ## 抖音服务使用示例 -```text +```php -use DtApp\ThinkLibrary\service\douyin\DouYinException; +use DtApp\ThinkLibrary\exception\DouYinException; use DtApp\ThinkLibrary\service\douyin\WatermarkService; try { // 方法一 网址 - var_dump(WatermarkService::instance()->url('https://v.douyin.com/vPGAdM/')->getAll()->toArray()); + dump(WatermarkService::instance()->url('https://v.douyin.com/vPGAdM/')->getAll()->toArray()); // 方法一 粘贴 - var_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/'); - var_dump($dy->getAll()->toArray()); + dump($dy->getAll()->toArray()); // 方法二 粘贴 $dy = WatermarkService::instance()->url('#在抖音,记录美好生活#2020茂名加油,广州加油,武汉加油!中国加油,众志成城!#航拍 #茂名#武汉 #广州 #旅拍 @抖音小助手 https://v.douyin.com/vPafcr/ 复制此链接,打开【抖音短视频】,直接观看视频!'); - var_dump($dy->getAll()->toArray()); + dump($dy->getAll()->toArray()); // 获取全部信息 - var_dump(WatermarkService::instance()->url('https://v.douyin.com/vPGAdM/')->getAll()->toArray()); + dump(WatermarkService::instance()->url('https://v.douyin.com/vPGAdM/')->getAll()->toArray()); // 获取原全部信息 - var_dump(WatermarkService::instance()->url('https://v.douyin.com/vPGAdM/')->getApi()->toArray()); + dump(WatermarkService::instance()->url('https://v.douyin.com/vPGAdM/')->getApi()->toArray()); // 获取视频信息 - var_dump(WatermarkService::instance()->url('https://v.douyin.com/vPGAdM/')->getVideoInfo()->toArray()); + dump(WatermarkService::instance()->url('https://v.douyin.com/vPGAdM/')->getVideoInfo()->toArray()); // 获取音频信息 - var_dump(WatermarkService::instance()->url('https://v.douyin.com/vPGAdM/')->getMusicInfo()->toArray()); + dump(WatermarkService::instance()->url('https://v.douyin.com/vPGAdM/')->getMusicInfo()->toArray()); // 获取分享信息 - var_dump(WatermarkService::instance()->url('https://v.douyin.com/vPGAdM/')->getShareInfo()->toArray()); + dump(WatermarkService::instance()->url('https://v.douyin.com/vPGAdM/')->getShareInfo()->toArray()); // 获取作者信息 - var_dump(WatermarkService::instance()->url('https://v.douyin.com/vPGAdM/')->getAuthorInfo()->toArray()); + dump(WatermarkService::instance()->url('https://v.douyin.com/vPGAdM/')->getAuthorInfo()->toArray()); // 返回数组数据方法 - var_dump(WatermarkService::instance()->url('https://v.douyin.com/vPGAdM/')->getAll()->toArray()); + dump(WatermarkService::instance()->url('https://v.douyin.com/vPGAdM/')->getAll()->toArray()); // 返回Object数据方法 - var_dump(WatermarkService::instance()->url('https://v.douyin.com/vPGAdM/')->getAll()->toObject()); + dump(WatermarkService::instance()->url('https://v.douyin.com/vPGAdM/')->getAll()->toObject()); } catch (DouYinException $e) { // 错误提示 - var_dump($e->getMessage()); + dump($e->getMessage()); } ``` diff --git a/src/Library.php b/src/Library.php index afd5230..cca301e 100644 --- a/src/Library.php +++ b/src/Library.php @@ -28,9 +28,7 @@ class Library extends \think\Service */ public function register() { - // 加载语言包 - $this->app->lang->load(__DIR__ . '/lang/zh-cn.php', 'zh-cn'); - $this->app->lang->load(__DIR__ . '/lang/en-us.php', 'en-us'); + } /** diff --git a/src/config.php b/src/config.php index d007adc..744807e 100644 --- a/src/config.php +++ b/src/config.php @@ -49,5 +49,16 @@ return [ 'key' => '', // 网址 'panel' => '', + ], + // 百度 + 'baidu' => [ + // 地图 + 'lbs' => [ + 'ak' => '' + ] + ], + // 高德地图 + 'amap' => [ + 'key' => '' ] ]; diff --git a/src/exception/AliException.php b/src/exception/AliException.php new file mode 100644 index 0000000..b6457a3 --- /dev/null +++ b/src/exception/AliException.php @@ -0,0 +1,32 @@ +getMessage(); + } +} diff --git a/src/exception/BaiduException.php b/src/exception/BaiduException.php new file mode 100644 index 0000000..cf5334e --- /dev/null +++ b/src/exception/BaiduException.php @@ -0,0 +1,32 @@ +getMessage(); + } +} diff --git a/src/lang/en-us.php b/src/lang/en-us.php deleted file mode 100644 index 9932a63..0000000 --- a/src/lang/en-us.php +++ /dev/null @@ -1,31 +0,0 @@ - 'Sorry, no permission to access the operation.', - 'think_library_not_login' => 'Sorry, requiring login to obtain view permission.', - 'think_library_delete_success' => 'Data deletion completed.', - 'think_library_delete_error' => 'Sorry, data deletion failed, please try again later.', - 'think_library_form_success' => 'Data saving completed.', - 'think_library_form_error' => 'Sorry, data saving failed, please try again later.', - 'think_library_save_success' => 'Data update completed.', - 'think_library_save_error' => 'Sorry, data update failed, please try again later.', - 'think_library_sort_success' => 'Modification of list sort completed.', - 'think_library_sort_error' => 'Sorry, modification of list sort failed, please try again later.', - 'think_library_page_html' => 'Total %s records, display %s per page, total %s page current display %s page.', - 'think_library_csrf_error' => 'Form token validation failed, please refresh and try again later.', - 'think_library_queue_exist' => 'Task has been created, please wait for processing to complete.', -]; diff --git a/src/lang/zh-cn.php b/src/lang/zh-cn.php deleted file mode 100644 index 3ce365f..0000000 --- a/src/lang/zh-cn.php +++ /dev/null @@ -1,31 +0,0 @@ - '抱歉,没有访问该操作的权限!', - 'think_library_not_login' => '抱歉,需要登录获取访问权限!', - 'think_library_delete_success' => '恭喜, 数据删除成功!', - 'think_library_delete_error' => '抱歉,数据删除失败, 请稍候再试!', - 'think_library_form_success' => '恭喜, 数据保存成功!', - 'think_library_form_error' => '抱歉,数据保存失败, 请稍候再试!', - 'think_library_save_success' => '恭喜,数据更新成功!', - 'think_library_save_error' => '抱歉,数据更新失败, 请稍候再试!', - 'think_library_sort_success' => '恭喜,列表排序成功!', - 'think_library_sort_error' => '抱歉,列表排序失败,请稍候再试!', - 'think_library_page_html' => '共 %s 条记录,每页显示 %s 条,共 %s 页当前显示第 %s 页。', - 'think_library_csrf_error' => '表单令牌验证失败,请刷新页面再试!', - 'think_library_queue_exist' => '任务已创建,请等待处理完成!', -]; diff --git a/src/service/MacService.php b/src/service/MacService.php index 979d743..4d14cb6 100644 --- a/src/service/MacService.php +++ b/src/service/MacService.php @@ -25,13 +25,7 @@ use DtApp\ThinkLibrary\Service; */ class MacService extends Service { - private $result = array(); - - /** - * 所有mac地址 - * @var array - */ - private $macAddrs = array(); + private $result = []; /** * 第一个mac地址 diff --git a/src/service/amap/AmApService.php b/src/service/amap/AmApService.php index 870e570..969155a 100644 --- a/src/service/amap/AmApService.php +++ b/src/service/amap/AmApService.php @@ -16,6 +16,7 @@ namespace DtApp\ThinkLibrary\service\amap; +use DtApp\ThinkLibrary\exception\AliException; use DtApp\ThinkLibrary\exception\CurlException; use DtApp\ThinkLibrary\Service; use DtApp\ThinkLibrary\service\Curl\HttpService; @@ -40,6 +41,16 @@ class AmApService extends Service return $this; } + /** + * 获取配置信息 + * @return $this + */ + private function getConfig() + { + $this->key = config('dtapp.amap.key'); + return $this; + } + /** * 天气查询 * https://lbs.amap.com/api/webservice/guide/api/weatherinfo @@ -47,9 +58,12 @@ class AmApService extends Service * @param string $extensions * @return array|bool|mixed|string * @throws CurlException + * @throws AliException */ public function weather($city = "110101", $extensions = "base") { + if (empty($this->key)) $this->getConfig(); + if (empty($this->key)) throw new AliException('请检查key参数'); $data = http_build_query([ "city" => $city, "extensions" => $extensions, diff --git a/src/service/baidu/LbsYunService.php b/src/service/baidu/LbsYunService.php index dc3cc41..da9ac03 100644 --- a/src/service/baidu/LbsYunService.php +++ b/src/service/baidu/LbsYunService.php @@ -16,6 +16,7 @@ namespace DtApp\ThinkLibrary\service\baidu; +use DtApp\ThinkLibrary\exception\BaiduException; use DtApp\ThinkLibrary\exception\CurlException; use DtApp\ThinkLibrary\Service; use DtApp\ThinkLibrary\service\Curl\HttpService; @@ -40,6 +41,16 @@ class LbsYunService extends Service return $this; } + /** + * 获取配置信息 + * @return $this + */ + private function getConfig() + { + $this->ak = config('dtapp.baidu.lbs.ak'); + return $this; + } + /** * 国内天气查询 * http://lbsyun.baidu.com/index.php?title=webapi/weather @@ -47,10 +58,12 @@ class LbsYunService extends Service * @param string $coordtype * @param string $location * @return array|bool|mixed|string - * @throws CurlException + * @throws CurlException|BaiduException */ public function weather($district_id = 110100, string $coordtype = "bd09ll", string $location = "") { + if (empty($this->ak)) $this->getConfig(); + if (empty($this->ak)) throw new BaiduException('请检查ak参数'); $data = http_build_query([ "district_id" => $district_id, "coordtype" => $coordtype, @@ -73,9 +86,12 @@ class LbsYunService extends Service * @param string $language * @return array|bool|mixed|string * @throws CurlException + * @throws BaiduException */ public function weatherAbroad($district_id = 110100, string $coordtype = "bd09ll", string $location = "", string $language = "cn") { + if (empty($this->ak)) $this->getConfig(); + if (empty($this->ak)) throw new BaiduException('请检查ak参数'); $data = http_build_query([ "district_id" => $district_id, "coordtype" => $coordtype,