Joe主题壁纸页面模板代码改造

行云流水
2022-08-07 / 9 评论 / 690 阅读 / 正在检测是否收录...

前言

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
        ]);
    }
}

评论 (9)

取消
只有登录/注册用户才可评论
  1. 头像
    llll
    中国广东省 · Windows 10 · Google Chrome
    沙发

    喜欢这篇文章,作者666,文章真棒!

    回复
  2. 头像
    MJJ
    中国辽宁省 · Windows 10 · Google Chrome
    板凳

    无法下载 有办法解决吗
    手机端 电脑端没实验

    回复
    1. 头像
      行云流水 作者
      中国江苏省 · MacOS · Google Chrome
      @ MJJ

      什么无法下载?

      回复
      1. 头像
        MJJ
        中国辽宁省 · Windows X64 · QQ Browser
        @ 行云流水

        图片无法下载唉
        壁纸图片表情

        回复
  3. 头像
    MJJ
    中国辽宁省 · Windows 10 · Google Chrome
    地毯

    表情表情学习到了,感谢博主

    回复
  4. 头像
    usmr76@163.com
    中国陕西省 · Windows 10 · Google Chrome
    第4楼

    支持博主,一定多分享

    回复
  5. 头像
    .
    中国辽宁省 · Windows XP · Google Chrome
    第5楼

    喜欢这篇文章,作者666,文章真棒!

    回复
  6. 头像
    Joinliu
    中国四川省 · Android · Google Chrome
    第6楼

    受益匪浅,感谢博主。

    回复
  7. 头像
    Joinliu
    · Windows 10 · Google Chrome
    第7楼

    喜欢这篇文章,作者666,文章真棒!

    回复
  8. 头像
    chenmo
    · Windows 10 · Google Chrome
    第8楼

    这个不错,那我也去弄一个。表情

    回复