InfoData.php
8.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
<?php
namespace LibModels\Web\Guang;
use Api\Yohobuy;
use Api\Sign;
class InfoData
{
/**
* 获取接口地址
* @return string
*/
public static function getUrl($type)
{
//作者信息
if ($type == 'author') {
return Yohobuy::SERVICE_URL.'guang/service/v1/author/getAuthor';
}
//文章评论列表
elseif($type == 'commentList') {
return Yohobuy::SERVICE_URL.'guang/api/v1/comments/getList';
}
//热门标签
elseif ($type == 'getTagTop') {
return Yohobuy::SERVICE_URL.'guang/api/v2/article/getTagTop';
}
//精彩推荐
elseif ($type == 'getArticleByViewsNum') {
return Yohobuy::SERVICE_URL.'guang/api/v2/article/getArticleByViewsNum';
}
elseif ($type == 'getBrand'){
return Yohobuy::SERVICE_URL.'guang/service/v2/article/getBrand';
}
//相关文章
elseif ($type == 'getOtherArticle') {
return Yohobuy::SERVICE_URL.'guang/service/v2/article/getOtherArticle';
}
//文章标题等相关信息
elseif ($type == 'getArticle') {
return Yohobuy::SERVICE_URL.'guang/service/v2/article/getArticle';
}
//文章详情
elseif ($type == 'getArticleContent') {
return Yohobuy::SERVICE_URL.'guang/service/v2/article/getArticleContent';
}
//基本信息
elseif ($type == 'getArticleBaseInfo') {
return Yohobuy::SERVICE_URL.'guang/api/v1/article/getArticleBaseInfo';
}
//添加评论
elseif ($type == 'addComment') {
return Yohobuy::SERVICE_URL.'guang/api/v1/comments/add';
}
//点赞
elseif ($type == 'setPraise') {
return Yohobuy::SERVICE_URL.'guang/api/v2/praise/setPraise';
}
//取消赞
elseif ($type == 'cancelPraise') {
return Yohobuy::SERVICE_URL.'guang/api/v2/praise/cancel';
}
//收藏
elseif ($type == 'setFavorite') {
return Yohobuy::SERVICE_URL.'guang/api/v1/favorite/setFavorite';
}
//取消收藏
elseif ($type == 'cancelFavorite') {
return Yohobuy::SERVICE_URL.'guang/api/v1/favorite/cancelFavorite';
}
}
/**
* 调用接口
* @param string $url
* @param array $param
* @param bool $onlyUrl true:返回请求地址; false:返回接口数据
* @return mixed
*/
public static function webApi($url, $param, $onlyUrl = false)
{
$param += Yohobuy::param();
$param['client_type'] = 'web';
$param['private_key'] = Yohobuy::$privateKeyList['web'];
$param['client_secret'] = Sign::getSign($param);
if ($onlyUrl) {
return Yohobuy::httpBuildQuery($url, $param);
}
return Yohobuy::get($url, $param);
}
/**
* 根据文章id获取文章信息
* @param $id
* @param $onlyUrl
* @return mixed
*/
public static function getArticleInfo($id, $onlyUrl = false)
{
$param['article_id'] = intval($id);
return self::webApi(self::getUrl('getArticle'), $param, $onlyUrl);
}
/**
* 组建根据文章id查询作者信息的url
* @param $authorId
* @param bool $onlyUrl
* @return mixed
*/
public static function author($authorId, $onlyUrl = false)
{
$param['author_id'] = intval($authorId);
return self::webApi(self::getUrl('author'), $param, $onlyUrl);
}
/**
* 热门标签
* @param int $page
* @param int $limit
* @param bool $onlyUrl
* @return string
*/
public static function tagTop($page = 1,$limit = 10, $onlyUrl = false)
{
$param['page'] = intval($page);
$param['limit'] = intval($limit);
return self::webApi(self::getUrl('getTagTop'), $param, $onlyUrl);
}
/**
* 组建根据文章id查询评论列表
* @param $articleId
* @param $page
* @param $limit
* @param $onlyUrl
* @return string
*/
public static function comment($articleId, $page = 1, $limit = 10, $onlyUrl = false)
{
$param['article_id'] = intval($articleId);
$param['page'] = intval($page);
$param['limit'] = intval($limit);
return self::webApi(self::getUrl('commentList'), $param, $onlyUrl);
}
/**
* 文章详细内容
* @param $articleId
* @param bool $onlyUrl
* @return mixed
*/
public static function articleContent($articleId, $onlyUrl = false)
{
$param['article_id'] = intval($articleId);
return self::webApi(self::getUrl('getArticleContent'), $param, $onlyUrl);
}
/**
* 判断用户是否收藏文章地址
* @param $articleId
* @param $uid
* @param $udid
* @param bool $onlyUrl
* @return mixed
*/
public static function baseInfo($articleId, $uid, $udid, $onlyUrl = false)
{
$param['id'] = intval($articleId);
$param['uid'] = $uid;
$param['udid'] = $udid;
return self::webApi(self::getUrl('getArticleBaseInfo'), $param, $onlyUrl);
}
/**
* 文章相关品牌
* @param $articleId
* @param bool $onlyUrl
* @return mixed
*/
public static function relateBrand($articleId, $onlyUrl = false)
{
$param['article_id'] = intval($articleId);
return self::webApi(self::getUrl('getBrand'), $param, $onlyUrl);
}
/**
* 相关文章列表
* @param $articleId
* @param $tag
* @param int $limit
* @param bool $onlyUrl
* @return mixed
*/
public static function relateList($articleId, $tag, $limit = 3, $onlyUrl = false)
{
$param['article_id'] = intval($articleId);
$param['tags'] = $tag;
$param['limit'] = intval($limit);
return self::webApi(self::getUrl('getOtherArticle'), $param, $onlyUrl);
}
/**
* 精彩推荐(48小时内浏览最多的文章)
*
* @param string $gender
* @param int $page
* @param int $limit
* @param bool $onlyUrl
* @return mixed
*/
public static function recommend($gender, $page = 1, $limit = 10, $onlyUrl = false)
{
$param['gender'] = $gender;
$param['page'] = intval($page);
$param['limit'] = intval($limit);
return self::webApi(self::getUrl('getArticleByViewsNum'), $param, $onlyUrl);
}
/**
* 添加文章评论
* @param $id 文章id
* @param $uid 用户id
* @param $content 评论内容
* @return mixed
*/
public static function addComment($id, $uid, $content)
{
$param['article_id'] = intval($id);
$param['uid'] = $uid;
$param['content'] = $content;
return self::webApi(self::getUrl('addComment'), $param);
}
/**
* 点赞
* @param $id
* @param $udid
* @return mixed
*/
public static function setPraise($id, $udid)
{
$param['article_id'] = intval($id);
$param['udid'] = $udid;
return self::webApi(self::getUrl('setPraise'), $param);
}
/**
* 取消赞
* @param $id
* @param $udid
* @return mixed
*/
public static function cancelPraise($id, $udid)
{
$param['article_id'] = intval($id);
$param['udid'] = $udid;
return self::webApi(self::getUrl('cancelPraise'), $param);
}
/**
* 收藏文章
* @param $id
* @param $uid
* @return mixed
*/
public static function setFavorite($id, $uid)
{
$param['article_id'] = intval($id);
$param['uid'] = $uid;
return self::webApi(self::getUrl('setFavorite'), $param);
}
/**
* 取消文章收藏
* @param $id
* @param $uid
* @return mixed
*/
public static function cancelFavorite($id, $uid)
{
$param['article_id'] = intval($id);
$param['uid'] = $uid;
return self::webApi(self::getUrl('cancelFavorite'), $param);
}
}