Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
hwp committed Jul 6, 2020
1 parent cbf68c0 commit f17e2e0
Show file tree
Hide file tree
Showing 12 changed files with 84 additions and 54 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ $config = [
'apikey' => ''
];

$client = new \HaodankuSdk\HaodankuFatory($config);
$client = new \HaoDanKuSdk\HaodankuFatory($config);
$result = $client->top->lists();

if ($result == false) {
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand All @@ -15,7 +15,7 @@
"classmap": [
],
"psr-4": {
"HaodankuSdk\\": "src"
"HaoDanKuSdk\\": "src"
}
},
"repositories": {
Expand Down
4 changes: 2 additions & 2 deletions src/Api/Content.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php


namespace HaodankuSdk\Api;
namespace HaoDanKuSdk\Api;


use HaodankuSdk\GateWay;
use HaoDanKuSdk\GateWay;

class Content extends GateWay
{
Expand Down
4 changes: 2 additions & 2 deletions src/Api/Good.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php


namespace HaodankuSdk\Api;
namespace HaoDanKuSdk\Api;


use HaodankuSdk\GateWay;
use HaoDanKuSdk\GateWay;

class Good extends GateWay
{
Expand Down
14 changes: 7 additions & 7 deletions src/Api/Search.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php


namespace HaodankuSdk\Api;
namespace HaoDanKuSdk\Api;


use HaodankuSdk\GateWay;
use HaodankuSdk\HaodankuException;
use HaoDanKuSdk\GateWay;
use HaoDanKuSdk\HaoDanKuException;

class Search extends GateWay
{
Expand All @@ -15,12 +15,12 @@ class Search extends GateWay
* @link https://www.haodanku.com/api/detail/show/19.html
* @param array $params
* @return bool|mixed
* @throws HaodankuException
* @throws HaoDanKuException
*/
public function superSearch(array $params = [])
{
if (!isset($params['keyword'])) {
throw new HaodankuException("keyword不能为空哦");
throw new HaoDanKuException("keyword不能为空哦");
}
$params['keyword'] = urlencode(urlencode($params['keyword']));
if (!isset($params['back'])) {
Expand All @@ -40,12 +40,12 @@ public function superSearch(array $params = [])
* @link https://www.haodanku.com/api/detail/show/5.html
* @param array $params
* @return bool|mixed
* @throws HaodankuException
* @throws HaoDanKuException
*/
public function getByKeyword(array $params = [])
{
if (!isset($params['keyword'])) {
throw new HaodankuException("keyword不能为空哦");
throw new HaoDanKuException("keyword不能为空哦");
}
$params['keyword'] = urlencode(urlencode($params['keyword']));
if (!isset($params['back'])) {
Expand Down
4 changes: 2 additions & 2 deletions src/Api/Shop.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php


namespace HaodankuSdk\Api;
namespace HaoDanKuSdk\Api;


use HaodankuSdk\GateWay;
use HaoDanKuSdk\GateWay;

class Shop extends GateWay
{
Expand Down
10 changes: 5 additions & 5 deletions src/Api/Subject.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php


namespace HaodankuSdk\Api;
namespace HaoDanKuSdk\Api;


use HaodankuSdk\GateWay;
use HaodankuSdk\HaodankuException;
use HaoDanKuSdk\GateWay;
use HaoDanKuSdk\HaoDanKuException;

class Subject extends GateWay
{
Expand Down Expand Up @@ -38,12 +38,12 @@ public function lists(array $params = [])
* @link https://www.haodanku.com/api/detail/show/11.html
* @param array $params
* @return bool|mixed
* @throws HaodankuException
* @throws HaoDanKuException
*/
public function items(array $params = [])
{
if (!isset($params['id'])) {
throw new HaodankuException('id不能为空');
throw new HaoDanKuException('id不能为空');
}
return $this->send('get_subject_item', $params);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Api/Top.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php


namespace HaodankuSdk\Api;
namespace HaoDanKuSdk\Api;


use HaodankuSdk\GateWay;
use HaoDanKuSdk\GateWay;

class Top extends GateWay
{
Expand Down
27 changes: 21 additions & 6 deletions src/GateWay.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
<?php


namespace HaodankuSdk;
namespace HaoDanKuSdk;


use yumufeng\curl\Curl;

/**
* Class GateWay
* @package HaoDanKuSdk
*/
class GateWay
{
protected $baseUrl = 'http://v2.api.haodanku.com/';

protected $fatory = '';
protected $factory = '';

/**
* 参数
Expand All @@ -20,12 +24,23 @@ class GateWay
'apikey' => ''
];

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);
Expand All @@ -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;
}
}
Expand Down
11 changes: 11 additions & 0 deletions src/HaoDanKuException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
namespace HaoDanKuSdk;

/**
* Class HaoDanKuSdkException
* @package HaoDanKuSdk
*/
class HaoDanKuException extends \Exception
{

}
40 changes: 27 additions & 13 deletions src/HaodankuFatory.php → src/HaoDanKuFactory.php
Original file line number Diff line number Diff line change
@@ -1,45 +1,53 @@
<?php

namespace HaoDanKuSdk;

namespace HaodankuSdk;

use HaodankuSdk\Api\Content;
use HaodankuSdk\Api\Good;
use HaodankuSdk\Api\Search;
use HaodankuSdk\Api\Shop;
use HaodankuSdk\Api\Subject;
use HaodankuSdk\Api\Top;
use HaoDanKuSdk\Api\Content;
use HaoDanKuSdk\Api\Good;
use HaoDanKuSdk\Api\Search;
use HaoDanKuSdk\Api\Shop;
use HaoDanKuSdk\Api\Subject;
use HaoDanKuSdk\Api\Top;

/**
* Class HaodankuFatory
* @package HaodankuSdk
* Class HaoDanKuFactory
* @package HaoDanKuSdk
* @property Good good
* @property Top top
* @property Content content
* @property Search search
* @property Shop shop
* @property Subject subject
*/
class HaodankuFatory
class HaoDanKuFactory
{
private $config;
private $error;

/**
* HaoDanKuFactory constructor.
* @param null $config
* @throws HaoDanKuException
*/
public function __construct($config = null)
{
if (empty($config)) {
throw new HaodankuException('no config');
throw new HaoDanKuException('no config');
}
$this->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;
Expand All @@ -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;
Expand Down
10 changes: 0 additions & 10 deletions src/HaodankuException.php

This file was deleted.

0 comments on commit f17e2e0

Please sign in to comment.