1.你要注册一个高德开放平台的账号,创建一个项目,然后获取app_key.
2.下面是将调用的数据封装在了服务层,使用的时候只需要调用这个Services就可以了。
namespace App\Services;
use GuzzleHttp\Client;
class WeatherService
{
/**
* @var string
*/
protected $key;
/**
* @var array
*/
protected $guzzleOptions = [];
/**
* Weather constructor.
*
*/
public function __construct()
{
$this->key = config('app.api_key', 'xxxxxxxxxxxxxx');
}
/**
* @return \GuzzleHttp\Client
*/
public function getHttpClient()
{
return new Client($this->guzzleOptions);
}
/**
* @param array $options
*/
public function setGuzzleOptions(array $options)
{
$this->guzzleOptions = $options;
}
/**
* @param string $city
* @param string $format
*
* @return \Psr\Http\Message\ResponseI