前言
Joe主题有写好的壁纸模版,直接启用即可。刚开始博主感觉分类太多了,有些分类也不是自己喜欢的。就没有启用,最近有时间研究了一下代码。改造了一下,只留下自己感兴趣的分类。
核心代码
主要是core/route.php文件内的两个函数,调用了360的壁纸接口,原版如下
/* 获取壁纸分类 已测试 √ */
function _getWallpaperType($self)
{
$self->response->setStatus(200);
$json = _curl("http://cdn.apc.360.cn/index.php?c=WallPaper&a=getAllCategoriesV2&from=360chrome");
$res = json_decode($json, TRUE);
if ($res['errno'] == 0) {
$self->response->throwJson([
"code" => 1,
"data" => $res['data']
]);
} else {
$self->response->throwJson([
"code" => 0,
"data" => null
]);
}
}
/* 获取壁纸列表 已测试 √ */
function _getWallpaperList($self)
{
$self->response->setStatus(200);
$cid = $self->request->cid;
$start = $self->request->start;
$count = $self->request->count;
$json = _curl("http://wallpaper.apc.360.cn/index.php?c=WallPaper&a=getAppsByCategory&cid={$cid}&start={$start}&count={$count}&from=360chrome");
$res = json_decode($json, TRUE);
if ($res['errno'] == 0) {
$self->response->throwJson([
"code" => 1,
"data" => $res['data'],
"total" => $res['total']
]);
} else {
$self->response->throwJson([
"code" => 0,
"data" => null
]);
}
}
优化
主要优化 _getWallpaperType 函数,去掉不想要的分类
/* 获取壁纸分类 已测试 √ */
function _getWallpaperType($self)
{
$self->response->setStatus(200);
$json = _curl("http://cdn.apc.360.cn/index.php?c=WallPaper&a=getAllCategoriesV2&from=360chrome");
$res = json_decode($json, TRUE);
//$file=dirname(__FILE__).'/debug.log';
//保留喜欢的分类
$ilike = ['6', '12', '13', '22'];
$re_arr = array();
foreach ($res['data'] as $key => $value) {
if (in_array($value['id'], $ilike, true)){
//file_put_contents($file, $value['name']."\n",FILE_APPEND);
array_push($re_arr, $value);
}
}
if ($res['errno'] == 0) {
$self->response->throwJson([
"code" => 1,
"data" => $re_arr
]);
} else {
$self->response->throwJson([
"code" => 0,
"data" => null
]);
}
}
效果
首页美女发现是固定的,又懒得翻页。加了个随机,每次刷新都是不同的。
/* 获取壁纸列表 已测试 √ */
function _getWallpaperList($self)
{
$self->response->setStatus(200);
$cid = $self->request->cid;
//前50页随机显示图片
if (($cid == 6)&&($self->request->start < 2400)) {
$start = $self->request->start + rand(1,4800);
}else {
$start = $self->request->start;
}
$count = $self->request->count;
//$file=dirname(__FILE__).'/debug.log';
//file_put_contents($file, $cid."|".$start."|".$count."\n",FILE_APPEND);
$json = _curl("http://wallpaper.apc.360.cn/index.php?c=WallPaper&a=getAppsByCategory&cid={$cid}&start={$start}&count={$count}&from=360chrome");
$res = json_decode($json, TRUE);
if ($res['errno'] == 0) {
$self->response->throwJson([
"code" => 1,
"data" => $res['data'],
"total" => $res['total']
]);
} else {
$self->response->throwJson([
"code" => 0,
"data" => null
]);
}
}
评论 (0)