MENU

已内置随机色图(Safe for Work)

• August 4, 2022 • Read: 469 • 二次元傻卵,码农养成中

今天研究了一下神代綺凛大佬的LoliconAPI这个名字没救了,询问群友了解到访问 api 返回的是包含图片信息的 json 文件,于是想创建一个独立的 php 界面来随机生成一张色图。
php 源码如下:(curl 函数部分是抄的,参考自https://www.runoob.com/php/php-ref-curl.html)

<?php
    function geturl($url){
        $headerArray =array("Content-type:application/x-www-form-urlencoded;","Accept:application/json","charset=UTF-8");
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); 
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headerArray);
        $output = curl_exec($ch);
        curl_close($ch);
        $output = json_decode($output,true);
        return $output;
    }
    function loadImg(){
        $r18 = 0;
        if(!empty($_GET)){
            if($_GET['r18'] == 1){
                $r18 = 1; 
            }
        }
        $response = geturl("https://api.lolicon.app/setu/v2?r18=$r18&tag=".urlencode("萝莉"));

        $img[0] = $response["data"][0]["urls"]["original"];
        $img[1] = $response["data"][0]["author"];
        return $img;
    }
    $img = loadImg();?>

<html>

<head>
    <style>
        img {height: 100%;}
        p {text-align:center;}
    </style>
    <meta name='robots' content='noindex,nofollow' />
    <title>随机loli setu</title>
</head>
<body>
    
    <p>画师:<?php echo $img[1]; ?><br></p>
    <p><img src="<?php echo $img[0]; ?>"></p>
    
    <footer>
        <p>使用API:<a href="https://api.lolicon.app/#/">LoliconAPI</a></p>
        <p>返回<a href="https://www.kaze-blog.co">风子的blog</a></p>
    </footer>
</body>

</html>

即刻来点setu(非r18)

Last Modified: August 21, 2023