网站接入每天60秒读懂世界API接口源码

<?php
/**
* Plugin Name: 60秒读懂世界
* Author: 大米api
* Author URL: https://api.qqsuu.cn/
*/

function callAPI($url, $params) {
$queryString = http_build_query(array_filter($params));
$requestURL = $url . ‘?’ . $queryString;

$options = array(
‘http’ => array(
‘method’ => ‘GET’,
‘header’ => ‘Content-type: application/x-www-form-urlencoded’,
‘ignore_errors’ => true
)
);

$context = stream_context_create($options);
$response = file_get_contents($requestURL, false, $context);

if ($response === false) {
// 请求失败
echo “请求失败”;
} else {
// 请求成功,输出响应内容
if($params[‘type’]==’json’){
echo $response;
}else{
header(“Content-Type:image/png”);
echo $response;
}

}
}

$url = ‘https://api.qqsuu.cn/api/dm-60s’;

$type = isset($_GET[‘type’]) ? $_GET[‘type’] : ”;

$params = array(
‘type’ => $type
);

callAPI($url, $params);

保存为.PHP访问即可使用,输出 ?type=json

版权声明:本站部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如本站内容侵犯了您的权益请联系我们,邮箱:1511977125@qq.com 我们核实后会及时处理,发布内容不代表痴痴资讯网立场,本文标题:网站接入每天60秒读懂世界API接口源码本文链接:https://www.chichizixun.com/5216.html