邮政编码查询
目录
接口使用
我要查询
提示:支持两种查询方式——「省/市/区/地址 查询邮编」与「邮编 查询地区」。请在下面 Demo 中填写后点击查询。
方式一:省/市/区/地址 查询邮编
方式二:邮编 查询地区
查询说明
方式一(getZipcodeInfo):输入省/市/区/地址(至少一项),返回对应邮政编码;
方式二(getZipcodeAreaInfo):输入邮政编码,返回对应省/市/区/地址信息。
接口描述
功能描述
接口一:省(市/自治区)市(区/自治州)区(县/市/区)三级地区+地址 查询邮编
根据输入的省、市、区、地址查询对应的邮政编码,数据模块为 getZipcodeInfo。
接口二:邮政编码+地址 查询地区
根据输入的邮政编码(及可选地址)查询对应的省/市/区/地址,数据模块为 getZipcodeAreaInfo。
URL 示例
1)http 协议,POST 方式:
http://cha.ebaitian.cn/api/json?appid=xxx&module=getZipcodeInfo&province=xxx&city=xxx&dis=xxx&address=xxx&sign=xxx
2)https 协议,POST 方式:
https://cha.ebaitian.cn/api/json?appid=xxx&module=getZipcodeInfo&province=xxx&city=xxx&dis=xxx&address=xxx&sign=xxx
请求参数
数据包体
接口一:getZipcodeInfo(地区→邮编)
{
"type": "get",
"appid": "1000xxxx",
"module": "getZipcodeInfo",
"province": "山西省",
"city": "太原市",
"dis": "小店区",
"address": "坞城西街",
"sign": "ecab4881ee80ad3d76bb1da68387428ca752eb885e52621a3129dcf4d9bc4fd4"
}
接口二:getZipcodeAreaInfo(邮编→地区)
{
"type": "get",
"appid": "1000xxxx",
"module": "getZipcodeAreaInfo",
"zipcode": "030006",
"address": "坞城西街",
"sign": "ecab4881ee80ad3d76bb1da68387428ca752eb885e52621a3129dcf4d9bc4fd4"
}
参数说明
| 接口 | 参数 | 必选 | 类型 | 描述 |
|---|---|---|---|---|
| getZipcodeInfo | module | 是 | string | 数据模块,固定为 getZipcodeInfo |
| getZipcodeInfo | province | 否* | string | 省(市/自治区),如:山西省 |
| getZipcodeInfo | city | 否* | string | 市(区/自治州),如:太原市 |
| getZipcodeInfo | dis | 否* | string | 区(县/市/区),如:小店区 |
| getZipcodeInfo | address | 否* | string | 详细地址,支持模糊匹配,如:坞城西街 |
| getZipcodeAreaInfo | module | 是 | string | 数据模块,固定为 getZipcodeAreaInfo |
| getZipcodeAreaInfo | zipcode | 是 | string | 邮政编码,如:030006 |
| getZipcodeAreaInfo | address | 否 | string | 详细地址,用于精确定位,可空 |
注:* 表示 interface 一(getZipcodeInfo)中 province/city/dis/address 至少需填写一项。
其他说明
1)type:可选值 get,如果赋值 get,则以 get 方式提交数据;默认以 post 方式提交数据;
2)sign:签名校验,根据公式 $sign=sha256(appid=$appid&module=getZipcodeInfo&province=$province&city=$city&dis=$dis&address=$address&appkey=$appkey) 生成;
接口二根据公式 $sign=sha256(appid=$appid&module=getZipcodeAreaInfo&zipcode=$zipcode&address=$address&appkey=$appkey) 生成。
响应参数
数据包体
{
"result":1,
"description":"TRUE",
"flag":"",
"zipcodeInfo":{
"zipcode":"030006",
"province":"山西省",
"city":"太原市",
"dis":"小店区",
"address":"坞城西街",
"area":"山西省太原市小店区"
}
}
参数说明
| 参数 | 必选 | 类型 | 描述 |
|---|---|---|---|
| result | 是 | string | 接口响应结果:0-失败;1-成功 |
| description | 是 | string | 接口响应描述:一般为 TURE(result=1) 与 FALSE(result=0) |
| flag | 否 | string | 错误说明,没有错误则返回空 |
| zipcodeInfo | 是 | object | 查询结果,包含 zipcode(邮编)、province(省)、city(市)、dis(区/县)、address(地址)、area(行政地区) |
SDK 及代码示例
PHP SDK
以 POST 方式请求数据:
//接口参数
$api_url='http://cha.ebaitian.cn/api/json';
$api_appid='1000xxxx';
$api_appkey='56cf61af4b7897e704f67deb88ae8f24';
//函数:省市区+地址 查询邮编
function getZipcodeInfo($province,$city,$dis,$address){
global $api_url,$api_appid,$api_appkey;
$data='appid='.$api_appid.'&module=getZipcodeInfo&province='.$province.'&city='.$city.'&dis='.$dis.'&address='.$address;
$sign=hash("sha256",$data.'&appkey='.$api_appkey);
$postdata=array("appid"=>$api_appid,"appkey"=>$api_appkey,"module"=>"getZipcodeInfo","province"=>$province,"city"=>$city,"dis"=>$dis,"address"=>$address,'sign'=>$sign);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $api_url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
$output = curl_exec($curl);
curl_close($curl);
$obj=json_decode($output);
if($obj->result==1){
return $obj->zipcodeInfo->zipcode;
}else{
return $obj->flag;
}
}
//函数:邮编 查询地区
function getZipcodeAreaInfo($zipcode,$address){
global $api_url,$api_appid,$api_appkey;
$data='appid='.$api_appid.'&module=getZipcodeAreaInfo&zipcode='.$zipcode.'&address='.$address;
$sign=hash("sha256",$data.'&appkey='.$api_appkey);
$postdata=array("appid"=>$api_appid,"appkey"=>$api_appkey,"module"=>"getZipcodeAreaInfo","zipcode"=>$zipcode,"address"=>$address,'sign'=>$sign);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $api_url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
$output = curl_exec($curl);
curl_close($curl);
$obj=json_decode($output);
if($obj->result==1){
return $obj->zipcodeInfo->area;
}else{
return $obj->flag;
}
}
//调用函数
echo getZipcodeInfo('山西省','太原市','小店区','坞城西街');
echo getZipcodeAreaInfo('030006','');
exit;
其他语言 SDK
Java / Python / Node.js / C# / JavaScript / ASP 等语言的调用方式与「手机号码查询」一致,仅需将参数 module 替换为 getZipcodeInfo(或 getZipcodeAreaInfo)并传入对应字段即可,返回结构为 zipcodeInfo。
常见问题
API 接口参数为空
此错误返回 JSON 数据如下:
{
"result":0,
"description":"API接口参数为空",
"flag":"appid:sign"
}
解决方法:
1)请检查 appid 及 sign 是否为空;
2)确保 appid 是从官网获取到正确的接口授权;
3)确保 sign 计算生成是正确的。
API 接口参数无效
此错误返回 JSON 数据如下:
{
"result":0,
"description":"API接口参数无效",
"flag":"appid"
}
解决方法:
1)请检查 appid 是否正确;
2)确保 appid 是从官网获取到正确的接口授权。
API 接口授权已到期
此错误返回 JSON 数据如下:
{
"result":0,
"description":"API接口授权已到期",
"flag":"end:2018-12-31 23:59:59"
}
解决方法:
1)请检查 appid 对应接口授权的期限是否过期;
2)如果接口授权过期,请到官网更新(免费用户直接更新,无需续费)或续费(针对商业付费用户)。
签名错误
接口一:省(市/自治区)市(区/自治州)区(县/市/区)三级地区+地址
此错误返回 JSON 数据如下:
{
"result":0,
"description":"签名错误",
"flag":"getZipcodeInfo->sign"
}
解决方法:
1)请检查 sign 签名计算是否正确;
2)签名 sign 根据公式 $sign=sha256(appid=$appid&module=getZipcodeInfo&province=$province&city=$city&dis=$dis&address=$address&appkey=$appkey) 生成;其中:appkey 为授权接口的 AppKey,请填写您在我要查官网上申请到的 AppKey 。
接口二:邮政编码+地址
此错误返回 JSON 数据如下:
{
"result":0,
"description":"签名错误",
"flag":"getZipcodeAreaInfo->sign"
}
解决方法:
1)请检查 sign 签名计算是否正确;
2)签名 sign 根据公式 $sign=sha256(appid=$appid&module=getZipcodeAreaInfo&zipcode=$zipcode&address=$address&appkey=$appkey) 生成。
请求受限
接口一:省(市/自治区)市(区/自治州)区(县/市/区)三级地区+地址
此错误返回 JSON 数据如下:
{
"result":0,
"description":"请求受限",
"flag":"getZipcodeInfo->daylimit"
}
解决方法:
1)授权接口已超出当前接口产品请求的最大限制;
2)请根据实际使用需求升级您的接口产品。
接口二:邮政编码+地址
此错误返回 JSON 数据如下:
{
"result":0,
"description":"请求受限",
"flag":"getZipcodeAreaInfo->daylimit"
}
解决方法:
1)授权接口已超出当前接口产品请求的最大限制;
2)请根据实际使用需求升级您的接口产品。
其他问题
如果您遇到其他的问题,请用以下方式联系我们,我们将为您提供 API 技术对接帮助。
请直接添加 QQ 技术交流群寻求我们帮助。
我要查API技术对接群①:
群号:821884327
扫码加入我要查API技术对接群①: