| 接口地址:https://restapi.amap.com/v3/weather/weatherInfo |
|---|
| 返回格式:json |
| 请求方式:get |
| 请求示例:https://restapi.amap.com/v3/weather/weatherInfo?city=110101&key=<用户key> |
| 名称 | 类型 | 必填 | 说明 |
|---|---|---|---|
| key | string | 必填 | 高德Key 扫码关注公众号 |
| city | string | 必填 | 城市编码下载地址 |
| extensions | string | 选填 | 气象类型 |
| output | string | 选填 | 返回数据格式类型,默认json |
| 名称 | 类型 | 说明 |
|---|---|---|
| 见json返回实例 | - | - |
{
"status": "1",
"count": "1",
"info": "OK",
"infocode": "10000",
"lives": [
"0": {
"province": "北京",
"city": "东城区",
"adcode": "110101",
"weather": "阴",
"temperature": "27",
"winddirection": "西北",
"windpower": "≤3",
"humidity": "81",
"reporttime": "2001-07-20 16:23:16"
}
]
}| 错误码 | 说明 |
|---|---|
| 10001 | key不正确或过期 |
| 10002 | 没有权限使用相应的服务或者请求接口的路径拼写错误 |
| 10003 | 访问已超出日访问量 |
| 10004 | 单位时间内访问过于频繁 |
| 10005 | IP白名单出错,发送请求的服务器IP不在IP白名单内 |
| 10006 | 绑定域名无效 |
| 10007 | 数字签名未通过验证 |
| 10008 | MD5安全码未通过验证 |
| 10009 | 请求key与绑定平台不符 |
| 10010 | IP访问超限 |
| 10011 | 服务不支持https请求 |
| 10012 | 权限不足,服务请求被拒绝 |
| 10013 | Key被删除 |
| 10014 | 云图服务QPS超限 |
| 10015 | 受单机QPS限流限制 |
| 10016 | 服务器负载过高 |
| 10017 | 所请求的资源不可用 |
| 10019 | 使用的某个服务总QPS超限 |
| 10020 | 某个Key使用某个服务接口QPS超出限制 |
| 10021 | 来自于同一IP的访问,使用某个服务QPS超出限制 |
| 10022 | 某个Key,来自于同一IP的访问,使用某个服务QPS超出限制 |
| 10023 | 某个KeyQPS超出限制 |
| 20000 | 请求参数非法 |
| 20001 | 缺少必填参数 |
| 20002 | 请求协议非法 |
| 20003 | 其他未知错误 |
| 20011 | 询坐标或规划点(包括起点、终点、途经点)在海外,但没有海外地图权限 |
| 20012 | 查询信息存在非法内容 |
| 20800 | 规划点(包括起点、终点、途经点)不在我们陆地范围内 |
| 20801 | 划点(起点、终点、途经点)附近搜不到路 |
| 20802 | 路线计算失败,通常是由于道路连通关系导致 |
| 20803 | 起点终点距离过长 |
| 300** | 服务响应失败 |
<?php
/**
* Created by PhpStorm.
* User: FZS
* Time: 2019/7/20 17:50
*/
//----------------------------------
// 天气查询 调用类
//----------------------------------
class freeApi{
private $apiUrl = 'https://restapi.amap.com/v3/weather/weatherInfo?city=110101&key=<用户key>';
/**
* 获取 天气查询 结果
* @return array
*/
public function getResult(){
return $this->freeApiCurl($this->apiUrl);
}
/**
* 请求接口返回内容
* @param string $url [请求的URL地址]
* @param string $params [请求的参数]
* @param int $ipost [是否采用POST形式]
* @return string
*/
public function freeApiCurl($url,$params=false,$ispost=0){
$ch = curl_init();
curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );
curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );
curl_setopt( $ch, CURLOPT_USERAGENT , 'chuanshuoapi' );
curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 60 );
curl_setopt( $ch, CURLOPT_TIMEOUT , 60);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true );
if( $ispost )
{
curl_setopt( $ch , CURLOPT_POST , true );
curl_setopt( $ch , CURLOPT_POSTFIELDS , $params );
curl_setopt( $ch , CURLOPT_URL , $url );
}
else
{
if($params){
curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params );
}else{
curl_setopt( $ch , CURLOPT_URL , $url);
}
}
$response = curl_exec( $ch );
if ($response === FALSE) {
return false;
}
curl_close( $ch );
return $response;
}
}