给网站增加“每天60s读懂世界”的方法


你和这个世界,只差60秒!

参考自冷筱宇的小窝

效果展示

点击查看→60秒看世界

纯图片方法

新建文章或独立页面,加入以下代码即可。(位置、样式等自行调整)

<img src="http://api.03c3.cn/zb" />

API方法

header("content-type:image/jpg");
echo file_get_contents(json_decode(file_get_contents("http://api.03c3.cn/zb/api.php"))->imageUrl);

截取头图

如图所示

<img src="https://api.03c3.cn/zb/H.php" />

也可以自己截取调整图片

<?php
$src_path = 'https://api.03c3.cn/zb/';
$src = imagecreatefromstring(file_get_contents($src_path));
$x = 50;
$y = 50;
$width = 520;
$height = 285;
$final_width = 500;
$final_height=188;
$new_image = imagecreatetruecolor($final_width, $final_height);
imagecopyresampled($new_image, $src, 0, 0, $x, $y, $final_width, $final_height, $width, $height);
imagejpeg($new_image, 'map.jpg');

知乎接口

https://www.zhihu.com/api/v4/columns/c_1261258401923026944/items

解析方式

<?php
/*
 * @Descripttion: 
 * @version: 
 * @Author: lengxiaoyu
 * @Date: 2022-05-25 18:07:26
 * @LastEditTime: 2022-06-21 17:47:59
 */
header("Content-Type: text/html;charset=utf-8");
header("Content-Type: text/json; charset=$charset");
header("Access-Control-Allow-Origin:*");
header('Access-Control-Allow-Methods:GET');
header('Access-Control-Allow-Headers:x-requested-with, content-type');
require('phpQuery/phpQuery.php');
$a = file_get_contents("https://www.zhihu.com/api/v4/columns/c_1261258401923026944/items");
$data = json_decode(Unicode($a))->{"data"};
$html = $data[0]->{"url"};
phpQuery::newDocumentFile($html);
$p = pq('p')->text();
echo ($p);

// 编码转换
function Unicode($str)
{
    return preg_replace_callback(
        "#\\\u([0-9a-f]{4})#i",
        function ($r) {
            return iconv('UCS-2BE', 'UTF-8', pack('H4', $r[1]));
        },
        $str
    );
}

声明:目的地-Destination|版权所有,违者必究|如未注明,均为原创|本网站采用BY-NC-SA协议进行授权

转载:转载请注明原文链接 - 给网站增加“每天60s读懂世界”的方法


前程似锦、未来可期、寻得良人、共赴白头,祝你也祝我。