# 网易随机美图API请求方式 #
- Method: GET/POST
# 请求地址 #
- https://api.ooopn.com/image/lofter/api.php
# 请求参数 #
- type
- 默认 – API链接不变,显示图片
- json – 输出图片的链接地址,不显示图片
- jump – API链接跳转到图片地址,显示图片(速度最快)
# 调用示例 #
- https://api.ooopn.com/image/lofter/api.php
- https://api.ooopn.com/image/lofter/api.php?type=json
- https://api.ooopn.com/image/lofter/api.php?type=jump
# HTML示例 #
- <img src=”https://api.ooopn.com/image/lofter/api.php”/>
- <img src=”https://api.ooopn.com/image/lofter/api.php?type=jump”/>
# 返回数据 #
- type=json – 返回图片地址
- type=jump – 无返回数据,直接输出图片
# PHP调用 #
1、采用JSON格式输出图片链接方法
<?php
header("Access-Control-Allow-Origin:*");
date_default_timezone_set("PRC");
$result = file_get_contents("https://api.ooopn.com/image/lofter/api.php?type=json");
$arr = json_decode($result,true);
if ($arr['code']==200) {
header('Content-Type:application/json;charset=UTF-8');
//直接输出图片链接时,改成 $arr['imgurl'];
echo json_encode($arr,JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES);
}
?>
2、直接输出图片方法
<?php
header("Access-Control-Allow-Origin:*");
$result = file_get_contents("https://api.ooopn.com/image/lofter/api.php?type=jump");
header("Content-Type: image/JPEG");
echo $result;
?>
注:将以上PHP代码保存成api.php上传至服务器,即可制作自己的API接口
特别说明: 本站资源均来源于网络,仅供学习交流使用,若想体验更多,请支持正版。
转载或复制文章时,请注明本文出处及文章链接: https://www.hezibuluo.com/6385.html