index.php 574 B

123456789101112131415161718192021222324
  1. <?php
  2. require __DIR__ .'/vendor/autoload.php';
  3. use Chuckpac\Weather\Weather;
  4. // 高德开放平台应用 API Key
  5. $key = 'bb5e3bd493d1f29f52f9d8ee4bf47049';
  6. $w = new Weather($key);
  7. echo "获取实时天气:\n";
  8. $response = $w->getWeather('深圳');
  9. echo json_encode($response, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  10. echo "\n\n获取天气预报:\n";
  11. $response = $w->getWeather('深圳', 'all');
  12. echo json_encode($response, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);
  13. echo "\n\n获取实时天气(XML):\n";
  14. echo $w->getWeather('深圳', 'base', 'xml');