|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Xmly\API; |
|
4
|
|
|
|
|
5
|
|
|
use Xmly\Auth; |
|
6
|
|
|
use Xmly\Config; |
|
7
|
|
|
use Xmly\Http\Client; |
|
8
|
|
|
use Xmly\Http\Error; |
|
9
|
|
|
use Xmly\Util; |
|
10
|
|
|
|
|
11
|
|
|
final class AodManager |
|
12
|
|
|
{ |
|
13
|
|
|
private $auth; |
|
14
|
|
|
private $config; |
|
15
|
|
|
|
|
16
|
4 |
|
public function __construct(Auth $auth, Config $config = null) |
|
17
|
|
|
{ |
|
18
|
4 |
|
$this->auth = $auth; |
|
19
|
4 |
|
if ($config == null) { |
|
20
|
4 |
|
$this->config = new Config(); |
|
21
|
|
|
} else { |
|
22
|
4 |
|
$this->config = $config; |
|
23
|
|
|
} |
|
24
|
4 |
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* 点播-免费内容-获取分类列表 |
|
28
|
|
|
* |
|
29
|
|
|
* @param array $body 请求参数 |
|
30
|
|
|
* @param string $serverAuthStaticKey |
|
31
|
|
|
* @return array |
|
32
|
|
|
* |
|
33
|
|
|
* @link https://open.ximalaya.com/doc/detailApi?categoryId=10&articleId=6#%E5%88%86%E7%B1%BB%E5%88%97%E8%A1%A8 |
|
34
|
|
|
*/ |
|
35
|
1 |
|
public function getCategoriesList($body, $serverAuthStaticKey = null) |
|
36
|
|
|
{ |
|
37
|
1 |
|
$scheme = "http://"; |
|
38
|
1 |
|
if ($this->config->useHTTPS === true) { |
|
39
|
1 |
|
$scheme = "https://"; |
|
40
|
|
|
} |
|
41
|
1 |
|
$sigURL = $this->auth->signatureURL($body, $serverAuthStaticKey); |
|
42
|
1 |
|
$url = $scheme . Config::API_HOST . '/categories/list?' . $sigURL; |
|
43
|
1 |
|
return $this->get($url); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* 点播-免费内容-获取标签列表 |
|
48
|
|
|
* |
|
49
|
|
|
* @param array $body 请求参数 |
|
50
|
|
|
* @param string $serverAuthStaticKey |
|
51
|
|
|
* @return array |
|
52
|
|
|
* |
|
53
|
|
|
* @link https://open.ximalaya.com/doc/detailApi?categoryId=10&articleId=6#%E6%A0%87%E7%AD%BE%E5%88%97%E8%A1%A8 |
|
54
|
|
|
*/ |
|
55
|
1 |
|
public function getTagsList($body, $serverAuthStaticKey = null) |
|
56
|
|
|
{ |
|
57
|
1 |
|
$scheme = "http://"; |
|
58
|
1 |
|
if ($this->config->useHTTPS === true) { |
|
59
|
1 |
|
$scheme = "https://"; |
|
60
|
|
|
} |
|
61
|
1 |
|
$sigURL = $this->auth->signatureURL($body, $serverAuthStaticKey); |
|
62
|
1 |
|
$url = $scheme . Config::API_HOST . '/v2/tags/list?' . $sigURL; |
|
63
|
1 |
|
return $this->get($url); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* 点播-免费内容-获取专辑列表 |
|
68
|
|
|
* |
|
69
|
|
|
* @param array $body 请求参数 |
|
70
|
|
|
* @param string $serverAuthStaticKey |
|
71
|
|
|
* @return array |
|
72
|
|
|
* |
|
73
|
|
|
* @link https://open.ximalaya.com/doc/detailApi?categoryId=10&articleId=6#%E4%B8%93%E8%BE%91%E5%88%97%E8%A1%A8 |
|
74
|
|
|
*/ |
|
75
|
1 |
|
public function getAlbumsList($body, $serverAuthStaticKey = null) |
|
76
|
|
|
{ |
|
77
|
1 |
|
$scheme = "http://"; |
|
78
|
1 |
|
if ($this->config->useHTTPS === true) { |
|
79
|
1 |
|
$scheme = "https://"; |
|
80
|
|
|
} |
|
81
|
1 |
|
$sigURL = $this->auth->signatureURL($body, $serverAuthStaticKey); |
|
82
|
1 |
|
$url = $scheme . Config::API_HOST . '/v2/albums/list?' . $sigURL; |
|
83
|
1 |
|
return $this->get($url); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* 点播-主播-获取主播分类列表 |
|
88
|
|
|
* |
|
89
|
|
|
* @param array $body 请求参数 |
|
90
|
|
|
* @param string $serverAuthStaticKey |
|
91
|
|
|
* @return array |
|
92
|
|
|
* |
|
93
|
|
|
* @link https://open.ximalaya.com/doc/detailApi?categoryId=10&articleId=61#%E8%8E%B7%E5%8F%96%E4%B8%BB%E6%92%AD%E5%88%86%E7%B1%BB%E5%88%97%E8%A1%A8 |
|
94
|
|
|
*/ |
|
95
|
1 |
|
public function getAnnouncersCategories($body, $serverAuthStaticKey = null) |
|
96
|
|
|
{ |
|
97
|
1 |
|
$scheme = "http://"; |
|
98
|
1 |
|
if ($this->config->useHTTPS === true) { |
|
99
|
1 |
|
$scheme = "https://"; |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
1 |
|
$sigURL = $this->auth->signatureURL($body, $serverAuthStaticKey); |
|
103
|
1 |
|
$url = $scheme . Config::API_HOST . '/announcers/categories?' . $sigURL; |
|
104
|
1 |
|
return $this->get($url); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
/** |
|
108
|
|
|
* Get 请求方法 |
|
109
|
|
|
* |
|
110
|
|
|
* @param string $url 完整的带 sig 的请求 url |
|
111
|
|
|
* @return array |
|
112
|
|
|
*/ |
|
113
|
4 |
|
private function get($url) |
|
114
|
|
|
{ |
|
115
|
4 |
|
$headers = array(); |
|
116
|
4 |
|
$headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8'; |
|
117
|
4 |
|
$ret = Client::get($url, $headers); |
|
118
|
4 |
|
if (!$ret->ok()) { |
|
119
|
1 |
|
Util::writeErrLog($url, $ret->body, $ret->statusCode, $ret->duration, $ret->error); |
|
120
|
1 |
|
return array(null, new Error($url, $ret)); |
|
121
|
|
|
} |
|
122
|
4 |
|
if ($this->config->enableLogs === true) { |
|
123
|
4 |
|
Util::writeInfoLog($url, $ret->body, $ret->statusCode, $ret->duration); |
|
124
|
|
|
} |
|
125
|
4 |
|
return array($ret->json(), null); |
|
126
|
|
|
} |
|
127
|
|
|
} |
|
128
|
|
|
|