From 4fa69e69980f90e86e28165fa9bc1a4502a8e853 Mon Sep 17 00:00:00 2001 From: Chaim Date: Tue, 19 May 2020 17:44:51 +0800 Subject: [PATCH] =?UTF-8?q?-=20=E5=A2=9E=E5=8A=A0=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=E7=9A=84?= =?UTF-8?q?=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/config.php | 7 +++++++ src/service/Jd/UnionService.php | 15 +++++++++++++-- src/service/PinDuoDuo/JinBaoService.php | 17 +++++++++++++---- src/service/TaoBao/TbkService.php | 15 +++++++++++++-- src/service/bt/ApiService.php | 20 ++++++++++++++++++-- 5 files changed, 64 insertions(+), 10 deletions(-) diff --git a/src/config.php b/src/config.php index d0de386..d007adc 100644 --- a/src/config.php +++ b/src/config.php @@ -42,5 +42,12 @@ return [ // 联盟分配给应用的secretkey 'secret_key' => '', ] + ], + // 宝塔 + 'bt' => [ + // 密钥 + 'key' => '', + // 网址 + 'panel' => '', ] ]; diff --git a/src/service/Jd/UnionService.php b/src/service/Jd/UnionService.php index 6ddba0a..ad65aa9 100644 --- a/src/service/Jd/UnionService.php +++ b/src/service/Jd/UnionService.php @@ -149,6 +149,17 @@ class UnionService extends Service $this->output = $result; } + /** + * 获取配置信息 + * @return $this + */ + private function getConfig() + { + $this->app_key = config('dtapp.jd.union.app_key'); + $this->secret_key = config('dtapp.jd.union.secret_key'); + return $this; + } + /** * 网站/APP获取推广链接接口 * https://union.jd.com/openplatform/api/10421 @@ -314,7 +325,7 @@ class UnionService extends Service { //首先检测是否支持curl if (!extension_loaded("curl")) throw new CurlException('请开启curl模块!', E_USER_DEPRECATED); - $this->app_key = empty($this->app_key) ? config('dtapp.jd.union.app_key') : $this->app_key; + if (empty($this->app_key)) $this->getConfig(); if (empty($this->app_key)) throw new JdException('请检查app_key参数'); if (empty($this->method)) throw new JdException('请检查method参数'); $this->params['method'] = $this->method; @@ -337,7 +348,7 @@ class UnionService extends Service */ private function createSign() { - $this->secret_key = empty($this->secret_key) ? config('dtapp.jd.union.secret_key') : $this->secret_key; + if (empty($this->secret_key)) $this->getConfig(); if (empty($this->secret_key)) throw new JdException('请检查secret_key参数'); $sign = $this->secret_key; diff --git a/src/service/PinDuoDuo/JinBaoService.php b/src/service/PinDuoDuo/JinBaoService.php index 828b417..a6d86a7 100644 --- a/src/service/PinDuoDuo/JinBaoService.php +++ b/src/service/PinDuoDuo/JinBaoService.php @@ -142,6 +142,17 @@ class JinBaoService extends Service return $this; } + /** + * 获取配置信息 + * @return $this + */ + private function getConfig() + { + $this->client_id = config('dtapp.pinduoduo.jinbao.client_id'); + $this->client_secret = config('dtapp.pinduoduo.jinbao.client_secret'); + return $this; + } + /** * 获取商品信息 - 多多进宝商品查询 * https://jinbao.pinduoduo.com/third-party/api-detail?apiName=pdd.ddk.goods.search @@ -404,10 +415,8 @@ class JinBaoService extends Service { //首先检测是否支持curl if (!extension_loaded("curl")) throw new CurlException('请开启curl模块!', E_USER_DEPRECATED); - $this->client_id = empty($this->client_id) ? config('dtapp.pinduoduo.jinbao.client_id') : $this->client_id; - $this->client_secret = empty($this->client_secret) ? config('dtapp.pinduoduo.jinbao.client_secret') : $this->client_secret; + if (empty($this->client_id)) $this->getConfig(); if (empty($this->client_id)) throw new PinDouDouException('请检查client_id参数'); - if (empty($this->client_secret)) throw new PinDouDouException('请检查client_secret参数'); $this->param['type'] = $this->type; $this->param['client_id'] = $this->client_id; $this->param['timestamp'] = time(); @@ -438,7 +447,7 @@ class JinBaoService extends Service */ private function createSign() { - $this->client_secret = empty($this->client_secret) ? config('dtapp.pinduoduo.jinbao.client_secret') : $this->client_secret; + if (empty($this->client_secret)) $this->getConfig(); if (empty($this->client_secret)) throw new PinDouDouException('请检查client_secret参数'); $sign = $this->client_secret; diff --git a/src/service/TaoBao/TbkService.php b/src/service/TaoBao/TbkService.php index a99ce28..bd8dbcb 100644 --- a/src/service/TaoBao/TbkService.php +++ b/src/service/TaoBao/TbkService.php @@ -135,6 +135,17 @@ class TbkService extends Service return $this; } + /** + * 获取配置信息 + * @return $this + */ + private function getConfig() + { + $this->app_key = config('dtapp.taobao.tbk.app_key'); + $this->app_secret = config('dtapp.taobao.tbk.app_secret'); + return $this; + } + /** * 订单查询 - 淘宝客-推广者-所有订单查询 * https://open.taobao.com/api.htm?spm=a2e0r.13193907.0.0.210524ad2gvyOW&docId=40173&docType=2 @@ -458,7 +469,7 @@ class TbkService extends Service //首先检测是否支持curl if (!extension_loaded("curl")) throw new CurlException('请开启curl模块!', E_USER_DEPRECATED); $this->format = "json"; - $this->app_key = empty($this->app_key) ? config('dtapp.taobao.tbk.app_key') : $this->app_key; + if (empty($this->app_key)) $this->getConfig(); if (empty($this->app_key)) throw new TaoBaoException('请检查app_key参数'); if (empty($this->method)) throw new TaoBaoException('请检查method参数'); $this->param['app_key'] = $this->app_key; @@ -514,7 +525,7 @@ class TbkService extends Service */ private function createSign() { - $this->app_secret = empty($this->app_secret) ? config('dtapp.taobao.tbk.app_secret') : $this->app_secret; + if (empty($this->app_secret)) $this->getConfig(); if (empty($this->app_secret)) throw new TaoBaoException('请检查app_secret参数'); $sign = $this->app_secret; diff --git a/src/service/bt/ApiService.php b/src/service/bt/ApiService.php index 8623a86..206be93 100644 --- a/src/service/bt/ApiService.php +++ b/src/service/bt/ApiService.php @@ -16,6 +16,7 @@ namespace DtApp\ThinkLibrary\service\bt; +use DtApp\ThinkLibrary\exception\BtException; use DtApp\ThinkLibrary\exception\CurlException; use DtApp\ThinkLibrary\Service; use DtApp\ThinkLibrary\service\Curl\BtService; @@ -49,6 +50,17 @@ class ApiService extends Service return $this; } + /** + * 获取配置信息 + * @return $this + */ + private function getConfig() + { + $this->key = config('dtapp.bt.key'); + $this->panel = config('dtapp.bt.panel'); + return $this; + } + /** * 获取监控信息 * @param string $type 类型 GetCpuIo = CPU信息/内存 GetDiskIo = 磁盘IO GetNetWorkIo = 网络IO @@ -317,7 +329,7 @@ class ApiService extends Service /** * 发起网络请求 * @return $this - * @throws CurlException + * @throws CurlException|BtException */ private function getHttp() { @@ -365,10 +377,12 @@ class ApiService extends Service * @param array $data 数据 * @param bool $is_json 是否返回Json格式 * @return bool|mixed|string - * @throws CurlException + * @throws CurlException|BtException */ protected function HttpPostCookie(string $url, array $data = [], bool $is_json = true) { + if (empty($this->panel)) $this->getConfig(); + if (empty($this->panel)) throw new BtException('请检查panel参数'); //定义cookie保存位置 $file = app()->getRootPath() . 'runtime/dtapp/bt/cookie/'; $cookie_file = $file . md5($this->panel) . '.cookie'; @@ -377,6 +391,8 @@ class ApiService extends Service $fp = fopen($cookie_file, 'w+'); fclose($fp); } + if (empty($this->key)) $this->getConfig(); + if (empty($this->key)) throw new BtException('请检查key参数'); return BtService::instance() ->panel($this->panel) ->key($this->key)