'; return $rand_text; } /* ==================================================================================================== * 下载指定id的图片 * ==================================================================================================== */ function getCoverDownloadImageById($id) { $url = 'http://napi.uc.cn/3/classes/article/objects/' . $id . '?wmFeed=international_wallpaper&product=prod&q='; $str = $this->curl_get_contents($url); $a = json_decode($str, true); if (empty($a)) { echo "没有数据需要处理!"; return; } if ('' == $a['img']) { return; } $ext = substr($a['img'], strrpos($a['img'], '.')); if ('.jpg' != $ext && '.jpeg' != $ext && '.png' != $ext && '.bmp' != $ext && '.gif' != $ext) { $ext = '.jpg'; } $image_dir = PHP_EOL . date('Y') . DIRECTORY_SEPARATOR; $image_file = date('md') . $id . $ext; $down_image_file = dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'image' . $image_dir . $image_file; echo "准备下载: " . $down_image_file . PHP_EOL; // 如果文件已经存在就不在下载了 if (file_exists($down_image_file)) { echo PHP_EOL . "文件已存在,不重复下载: " . $down_image_file . PHP_EOL; return array('exists', $image_file); } // 如果目录不存在就创建目录 if (!is_dir(dirname($down_image_file))) { mkdir(dirname($down_image_file), 0777, true); } // 保存文件 file_put_contents($down_image_file, file_get_contents($a['img'])); // 检查文件是否下载成功 if (filesize($down_image_file) == 0 || !file_exists($down_image_file)) { return array('not download', $image_file); } echo "下载完成: " . $down_image_file . PHP_EOL; return array('download', $image_file); } /* ==================================================================================================== * 下载单张图片 * ==================================================================================================== */ function downloadSinglePhoto($url, $dest_dir) { $ext = substr($url, strrpos($url, '.')); if ('.jpg' != $ext && '.jpeg' != $ext && '.png' != $ext && '.bmp' != $ext && '.gif' != $ext) { $ext = '.jpg'; } $image_dir = PHP_EOL . date('Y') . DIRECTORY_SEPARATOR; $image_file = date('md') . '__TEMP__' . $ext; $down_image_file = $dest_dir . 'image' . $image_dir . $image_file; // 保存文件 file_put_contents($down_image_file, file_get_contents($url)); // 检查文件是否下载成功 if (filesize($down_image_file) == 0 || !file_exists($down_image_file)) { return false; } return $down_image_file; } /* ==================================================================================================== * 获取待处理数据 * ==================================================================================================== */ function getWallpaperList($page) { echo "==> 第" . $page . "页数据:" . PHP_EOL; // 获取json数据 $url = 'http://napi.uc.cn/3/classes/article/where/wmFeed="international_wallpaper"&product="prod"&include=["poster","user"]["keys"]="zol2","title","post_type","content","img","brief","id","author","read","value"]&need=0&order=createdAt desc&page=' . $page . '&pageSize=10&q='; $str = $this->curl_get_contents($url); $a = json_decode($str, true); if (empty($a)) { echo "没有数据需要处理!"; return; }
Copyright © 2025