目 录CONTENT

文章目录

必应每日一图API搭建

米尔嘉
2023-04-04 / 0 评论 / 0 点赞 / 430 阅读 / 1,176 字 / 正在检测是否收录...
温馨提示:
本文最后更新于 2023-07-04,若内容或图片失效,请留言反馈。部分素材来自网络,若不小心影响到您的利益,请联系我们删除。

必应的api

https://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1

访问一下,返回的是一个json

{
  "images":[
    {
      "startdate":"20230401",
      "fullstartdate":"202304011600",
      "enddate":"20230402",
      "url":"/th?id=OHR.JavaBromo_ZH-CN2744043733_1920x1080.jpg&rf=LaDigue_1920x1080.jpg&pid=hp",
      "urlbase":"/th?id=OHR.JavaBromo_ZH-CN2744043733",
      "copyright":"爪哇岛东部的婆罗摩火山,印度尼西亚 (© Bento Fotography/Getty Images)",
      "copyrightlink":"https://www.bing.com/search?q=%E5%A9%86%E7%BD%97%E6%91%A9%E7%81%AB%E5%B1%B1&form=hpcapt&mkt=zh-cn",
      "title":"这座缥缈的山在哪里?",
      "quiz":"/search?q=Bing+homepage+quiz&filters=WQOskey:%22HPQuiz_20230401_JavaBromo%22&FORM=HPQUIZ",
      "wp":true,
      "hsh":"285b1fc1eb78d0f282cacf8dc80588f2",
      "drk":1,"top":1,"bot":1,"hs":[]}],
      "tooltips":
        {
          "loading":"正在加载...",
          "previous":"上一个图像",
          "next":"下一个图像",
          "walle":"此图片不能下载用作壁纸。",
          "walls":"下载今日美图。仅限用作桌面壁纸。"
        }
}

bing文件夹下index.php 必应每日一图php

index.php

<?php
//设置头为图片
@header("Content-Type:image/png");
//获取返回json,并解析成数组
$data = json_decode(get_curl("https://www.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1"),true);
//将图片转换成文件流
echo get_curl('https://www.bing.com'.$data['images'][0]['url']);


/**
 * curl最完整封装
 * @param  String  $url     要请求的连接,支持https
 * @param  integer $post    post参数
 * @param  integer $referer url来源
 * @param  integer $cookie  cookie
 * @param  integer $header  是否显示响应头
 * @param  integer $ua      自定义ua头
 * @param  integer $nobody  是否显示响应体
 * @return String           响应的结果
 */
function get_curl($url, $post = 0, $referer = 0, $cookie = 0, $header = 0, $ua = 0, $nobody = 0)
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    $httpheader[] = "Accept:*/*";
    $httpheader[] = "Accept-Encoding:gzip,deflate,sdch";
    $httpheader[] = "Accept-Language:zh-CN,zh;q=0.8";
    $httpheader[] = "Connection:close";
    curl_setopt($ch, CURLOPT_HTTPHEADER, $httpheader);
    if ($post) {
        curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
    }
    if ($header) {
        curl_setopt($ch, CURLOPT_HEADER, true);
    }
    if ($cookie) {
        curl_setopt($ch, CURLOPT_COOKIE, $cookie);
    }
    if ($referer) {
        curl_setopt($ch, CURLOPT_REFERER, $referer);
    }
    if ($ua) {
        curl_setopt($ch, CURLOPT_USERAGENT, $ua);
    } else {
        curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Linux; U; Android 4.0.4; es-mx; HTC_One_X Build/IMM76D) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0");
    }
    if ($nobody) {
        curl_setopt($ch, CURLOPT_NOBODY, 1);
    }
    curl_setopt($ch, CURLOPT_ENCODING, "gzip");
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    $ret = curl_exec($ch);
    curl_close($ch);
    return $ret;
}
?>

每日一图

<!-- html -->
<img src="https://api.minterjia.com/bing/" alt="">

<!-- markdown -->
![随机图片](https://api.minterjia.com/bing/)

随机图片API源码

api 文件夹

random.php 随机图片php

images 图片文件夹

random.php

<?php
header('Cache-Control:no-cache,must-revalidate');
header('Pragma:no-cache');
header("Expires:0");
header("Access-Control-Allow-Origin:*");
//处理请求输出数据
//这将得到一个文件夹中的所有gif,jpg和png图片的数组
$rand=rand(0,1);
if($rand){
    $localurl="images/*.{gif,jpg,png,webp}";
}else{
    $localurl="images/*.{gif,jpg,png,webp}";
}
$img_array=glob($localurl,GLOB_BRACE);
//从数组中选择一个随机图片 
$img=array_rand($img_array);
$imgurl=$img_array[$img];
$https=isset($_GET["https"])?$_GET["https"]:1;
if($https == "true"){
    $imgurl='https://'.$_SERVER['SERVER_NAME'].'/api/'.$imgurl;
}else{
    $imgurl='http://'.$_SERVER['SERVER_NAME'].'/api/'.$imgurl;
}
if(isset($_GET["type"])?$_GET["type"]:1=="json"){
    $rTotal='0';
    $gTotal='0';
    $bTotal='0';
    $total='0';
    $imageInfo = getimagesize($img_array[$img]);
    //图片类型
    $imgType = strtolower(substr(image_type_to_extension($imageInfo[2]), 1));
    //对应函数
    $imageFun = 'imagecreatefrom' . ($imgType == 'jpg' ? 'jpeg' : $imgType);
    $i = $imageFun($img_array[$img]);
    //测试图片,自己定义一个,注意路径
    for($x=0;
    $x<imagesx($i);
    $x++){
        for($y=0;
        $y<imagesy($i);
        $y++){
            $rgb=imagecolorat($i,$x,$y);
            $r=($rgb>>16)&0xFF;
            $g=($rgb>>8)&0xFF;
            $b=$rgb&0xFF;
            $rTotal+=$r;
            $gTotal+=$g;
            $bTotal+=$b;
            $total++;
        }
    }
    $rAverage=round($rTotal/$total);
    $gAverage=round($gTotal/$total);
    $bAverage=round($bTotal/$total);
    $arr=array('ImgUrl'=>$imgurl,'Color'=>"$rAverage,$gAverage,$bAverage");
    echo json_encode($arr);
    exit();
}
//在页面显示图片地址
//echo $imgurl;
header("location:$imgurl");
?>

随机图片

<!-- html -->
<img src="https://api.minterjia.com/api/" alt="">

<!-- markdown -->
![随机图片](https://api.minterjia.com/api/)

宝塔面板登录界面背景图

进入文件

找到/www/server/panel/BTPanel/templates/default/login.html

将下面代码贴到如下图的位置

<style>
body{
    background-image: url(https://cdn.jsdelivr.net/gh/chenqicong528/img/3.jpg)!important;
}
.main .login{
    background-color: rgba(255, 255, 255, 0.8)!important;
}
</style>

参考文章

0

评论区