ak = $ak; return $this; } /** * 国内天气查询 * http://lbsyun.baidu.com/index.php?title=webapi/weather * @param int $district_id * @param string $coordtype * @param string $location * @return array|bool|mixed|string * @throws DtaException */ public function weather($district_id = 110100, string $coordtype = "bd09ll", string $location = "") { if (empty($this->ak)) { throw new DtaException('请检查ak参数'); } $data = http_build_query([ "district_id" => $district_id, "coordtype" => $coordtype, "ak" => $this->ak, "location" => $location, "data_type" => 'all', "output" => $this->output, ]); return HttpService::instance() ->url("http://api.map.baidu.com/weather/v1/?{$data}") ->toArray(); } /** * 国外天气查询 * http://lbsyun.baidu.com/index.php?title=webapi/weather-abroad * @param int $district_id * @param string $coordtype * @param string $location * @param string $language * @return array|bool|mixed|string * @throws DtaException */ public function weatherAbroad($district_id = 110100, string $coordtype = "bd09ll", string $location = "", string $language = "cn") { if (empty($this->ak)) { throw new DtaException('请检查ak参数'); } $data = http_build_query([ "district_id" => $district_id, "coordtype" => $coordtype, "ak" => $this->ak, "location" => $location, "data_type" => 'all', "language" => $language, "output" => $this->output, ]); return HttpService::instance() ->url("http://api.map.baidu.com/weather_abroad/v1/?{$data}") ->toArray(); } }