ListData.php
3.25 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
<?php
namespace LibModels\Wap\Guang;
use Api\Sign;
use Api\Yohobuy;
use Plugin\Cache;
/**
* 逛首页列表相关的数据模型
*
* @name ListData
* @package LibModels/Wap/Guang
* @copyright yoho.inc
* @version 1.0 (2015-10-10 9:54:07)
* @author fei.hong <fei.hong@yoho.cn>
*/
class ListData
{
const URI_CATEGORY = 'guang/api/v1/category/get';
const URI_ARTICLELIST = 'guang/api/v2/article/getList';
const URI_AUTHOR = 'guang/service/v1/author/';
/**
* 逛分类
*
* 备注: id (0:最新,1:话题,2:搭配,3:潮人,4:潮品,5:小贴士)
*
* @return array
*/
public static function category()
{
$param = Yohobuy::param();
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(Yohobuy::SERVICE_URL . self::URI_CATEGORY, $param, 3600); // 有缓存1小时
}
/**
* 逛内容列表
*
* @param string $gender "1,3"表示男, "2,3"表示女, "1,2,3"表示所有
* @param int $sortId 分类ID
* @param int $uid 用户ID
* @param string $udid 客户端唯一标识
* @param int $page 分页第几页, 默认第1页
* @param string $tag 标签
* @param int $authorId 作者ID
* @return array
*/
public static function article($gender, $sortId, $uid = 0, $udid = '', $page = 1, $tag = null, $authorId = null)
{
$param = Yohobuy::param();
$param['gender'] = $gender;
$param['page'] = $page;
$param['uid'] = $uid;
$param['udid'] = $udid;
if (isset($sortId)) {
$param['sort_id'] = $sortId;
}
if (!empty($tag)) {
$param['tag'] = $tag;
}
if (isset($authorId) && is_numeric($authorId)) {
$param['author_id'] = $authorId;
}
$param['client_secret'] = Sign::getSign($param);
return Yohobuy::get(Yohobuy::SERVICE_URL . self::URI_ARTICLELIST, $param);
}
/**
* 根据分类进行分组的逛内容列表
*
* @param array $category 分类
* @param string $gender "1,3"表示男, "2,3"表示女
* @param int $uid 用户ID
* @param string $udid 客户端唯一标识
* @param int $page 分页第几页, 默认第1页
* @return array
*/
public static function articleGroup($category, $gender, $uid = 0, $udid, $page = 1)
{
$urlList = array();
$param = array();
foreach ($category as $value) {
$param = Yohobuy::param();
$param['gender'] = $gender;
$param['page'] = $page;
$param['sort_id'] = $value['id'];
$param['uid'] = $uid;
$param['udid'] = $udid;
$param['client_secret'] = Sign::getSign($param);
$urlList[$value['id']] = Yohobuy::httpBuildQuery(Yohobuy::SERVICE_URL . self::URI_ARTICLELIST, $param);
}
return Yohobuy::getMulti($urlList);
}
/**
* 获取作者信息
*
* @param int $id 作者ID
* @return array
*/
public static function author($id)
{
$result = array();
if (is_numeric($id)) {
$result = Yohobuy::yarClient(Yohobuy::SERVICE_URL . self::URI_AUTHOR, 'getAuthor', array($id), 3600); // 缓存1小时
}
return $result;
}
}