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?apiKey=bVd6b080ejhaMEpabG0yMmJCaWNYZz09';

$type = isset($_GET['type']) ? $_GET['type'] : '';

$params = array(
  'type' => $type
);

callAPI($url, $params);

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

THE END