eliza209
 1 <?php
 2 
 3 define(\'WALLPAPER_PATH\',\'C:/xxx/xxx\'); //本地目录
 4 
 5 class BingPicture{
 6     
 7     private $content = "";
 8     private $imgurl = "";
 9     
10     public function __construct() {
11         $this->_getWallpaperUrl();
12     }
13     
14     //获取壁纸
15     public function _getWallpaperUrl(){
16         if (!function_exists(\'file_get_contents\')) 
17             return false;
18         
19         $this->content=file_get_contents(\'https://cn.bing.com/HPImageArchive.aspx?idx=0&n=1\');
20         
21         if (preg_match("/<url>(.+?)<\/url>/ies", $this->content, $matches)) {
22             $this->imgurl=\'https://cn.bing.com\'.$matches[1];
23         }
24     }
25     
26     //获取壁纸信息
27     public function getWallpaperInfo(){
28         if (preg_match("/<copyright>(.+?)<\/copyright>/ies", $this->content, $matches)) {
29             $imgcopyright=$matches[1];
30         }
31         
32         if($imgcopyright){
33             return $imgcopyright;
34         }
35     }
36     
37     //保存壁纸    
38     public function saveWallpaper() {
39         
40         if(!file_exists(WALLPAPER_PATH)){
41             mkdir(WALLPAPER_PATH, 0777);
42         }
43         
44         $url = $this->imgurl;
45         $pic = \'Bing\'.date("Ymd").\'.jpg\';
46         $file = WALLPAPER_PATH.\'/\'.$pic;
47         
48     if ($url == "")
49         return false;
50             
51         if(file_exists($file))
52                 return true;
53 
54     ob_start ();
55     readfile ( $url );
56     $img = ob_get_contents ();
57     ob_end_clean ();
58     $size = strlen ( $img );
59         
60         $fp2 = @fopen ( WALLPAPER_PATH . DIRECTORY_SEPARATOR . $pic, "a" );
61         fwrite ( $fp2, $img );
62         fclose ( $fp2 );
63     }
64     
65 }

以及创建任务计划定时执行脚本

 1 @echo off
 2 
 3 rem 定时获取并保存Bing壁纸脚本
 4 
 5 cd /d F:
 6 
 7 rem php.exe所在目录
 8 set PHP_PATH=F:\xxx
 9 
10 rem 脚本所在目录
11 start %PHP_PATH% -q F:\xxxx\xxx.php
12 
13 exit

 

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2021-12-09
  • 2022-12-23
  • 2022-12-23
  • 2021-11-23
  • 2022-12-23
  • 2022-01-02
  • 2022-02-01
猜你喜欢
  • 2021-10-01
  • 2021-11-03
  • 2021-07-08
  • 2021-08-21
  • 2021-12-24
  • 2021-12-24
  • 2022-12-23
相关资源
相似解决方案