1. 创建站点

在宝塔面板的网站中添加站点作为API地址,将网站开启PHP,并申请一个SSL认证并打开强制https

2. 创建图片链接

打开这个站点的目录,创建一个img.txt和一个index.php

在PicList的管理中中全部选中并复制图片url,将链接粘贴到img.txt中

index.php写入如下内容

<?php
//存有image链接的文件名img.txt
$filename = "img.txt";
if(!file_exists($filename)){
    die('文件不存在');
}
 
//从文本获取链接
$pics = [];
$fs = fopen($filename, "r");
while(!feof($fs)){
    $line=trim(fgets($fs));
    if($line!=''){
        array_push($pics, $line);
    }
}
 
//从数组随机获取链接
$pic = $pics[array_rand($pics)];
 
//返回指定格式
$type=$_GET['type'];
switch($type){
 
//JSON返回
case 'json':
    header('Content-type:text/json');
    die(json_encode(['pic'=>$pic]));
 
default:
    die(header("Location: $pic"));
}
?>

参考文章

创建自己的随机图片api