前言
Joe主题有写好的壁纸模版,直接启用即可。刚开始博主感觉分类太多了,有些分类也不是自己喜欢的。就没有启用,最近有时间研究了一下代码。改造了一下,只留下自己感兴趣的分类。
核心代码
/* 获取壁纸分类 已测试 √ */
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
]);
}
}
优化
/* 获取壁纸分类 已测试 √ */
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
]);
}
}
这篇文章写的真不错,真详细,点个赞。
喜欢这篇文章,作者666,文章真棒!
无法下载 有办法解决吗
手机端 电脑端没实验
什么无法下载?
图片无法下载唉
壁纸图片
学习到了,感谢博主
支持博主,一定多分享
喜欢这篇文章,作者666,文章真棒!
受益匪浅,感谢博主。
喜欢这篇文章,作者666,文章真棒!
这个不错,那我也去弄一个。