From f17e2e007d91ffdc85b285276d59090e7dd6861e Mon Sep 17 00:00:00 2001 From: hwp Date: Mon, 6 Jul 2020 21:52:01 +0800 Subject: [PATCH] init --- README.md | 2 +- composer.json | 8 ++-- src/Api/Content.php | 4 +- src/Api/Good.php | 4 +- src/Api/Search.php | 14 +++---- src/Api/Shop.php | 4 +- src/Api/Subject.php | 10 ++--- src/Api/Top.php | 4 +- src/GateWay.php | 27 ++++++++++--- src/HaoDanKuException.php | 11 +++++ ...HaodankuFatory.php => HaoDanKuFactory.php} | 40 +++++++++++++------ src/HaodankuException.php | 10 ----- 12 files changed, 84 insertions(+), 54 deletions(-) create mode 100644 src/HaoDanKuException.php rename src/{HaodankuFatory.php => HaoDanKuFactory.php} (61%) delete mode 100644 src/HaodankuException.php diff --git a/README.md b/README.md index 5979649..dc2ce1f 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ $config = [ 'apikey' => '' ]; -$client = new \HaodankuSdk\HaodankuFatory($config); +$client = new \HaoDanKuSdk\HaodankuFatory($config); $result = $client->top->lists(); if ($result == false) { diff --git a/composer.json b/composer.json index e134aed..da0c310 100644 --- a/composer.json +++ b/composer.json @@ -1,10 +1,10 @@ { - "name": "yumufeng/haodanku-sdk", + "name": "fightingPie/haodanku-union-sdk", "license": "MIT", "authors": [ { - "name": "yumufeng", - "email": "admin@yumufeng.com" + "name": "fightingPie", + "email": "hwppai314@gmail.com" } ], "require": { @@ -15,7 +15,7 @@ "classmap": [ ], "psr-4": { - "HaodankuSdk\\": "src" + "HaoDanKuSdk\\": "src" } }, "repositories": { diff --git a/src/Api/Content.php b/src/Api/Content.php index 6a3f1c2..20088b6 100644 --- a/src/Api/Content.php +++ b/src/Api/Content.php @@ -1,10 +1,10 @@ send('get_subject_item', $params); } diff --git a/src/Api/Top.php b/src/Api/Top.php index da43822..b62e718 100644 --- a/src/Api/Top.php +++ b/src/Api/Top.php @@ -1,10 +1,10 @@ '' ]; - public function __construct($config, HaodankuFatory $fatory) + /** + * GateWay constructor. + * @param $config + * @param HaoDanKuFactory $factory + */ + public function __construct($config, HaoDanKuFactory $factory) { - $this->fatory = $fatory; + $this->factory = $factory; $this->params = array_merge($this->params, $config); } + /** + * @param $method + * @param array $params + * @param bool $isPost + * @return bool|mixed + */ public function send($method, array $params, $isPost = false) { $sysParams = array_merge($this->params, $params); @@ -39,12 +54,12 @@ public function send($method, array $params, $isPost = false) } $info = json_decode($resp, true); if ($info['code'] == 0) { - $this->fatory->setError($info['msg']); + $this->factory->setError($info['msg']); return false; } return $info; } catch (\Exception $exception) { - $this->fatory->setError($exception->getMessage()); + $this->factory->setError($exception->getMessage()); return false; } } diff --git a/src/HaoDanKuException.php b/src/HaoDanKuException.php new file mode 100644 index 0000000..302b92d --- /dev/null +++ b/src/HaoDanKuException.php @@ -0,0 +1,11 @@ +config = $config; } + /** + * @param $api + * @return bool + * @throws \Exception + */ public function __get($api) { try { $classname = __NAMESPACE__ . "\\Api\\" . ucfirst($api); if (!class_exists($classname)) { throw new \Exception('api undefined'); - return false; } $new = new $classname($this->config, $this); return $new; @@ -48,11 +56,17 @@ public function __get($api) } } + /** + * @param $message + */ public function setError($message) { $this->error = $message; } + /** + * @return mixed + */ public function getError() { return $this->error; diff --git a/src/HaodankuException.php b/src/HaodankuException.php deleted file mode 100644 index 14ccf5e..0000000 --- a/src/HaodankuException.php +++ /dev/null @@ -1,10 +0,0 @@ -