如何调用获取区域地名列表信息接口
说明:
本文档将介绍说明有赞云开放接口 - 物流 API- 获取区域地名列表信息接口如何调用,如何通过该接口获取到所有区域对应的 id,并存储到本地映射。
接口信息:
接口名称:获取区域地名列表信息
接口 API:youzan.regions.get.3.0.0
接口文档链接:https://doc.youzanyun.com/doc#/content/API/1-316/detail/api/0/187
调用场景:
1. 如何获取所有省的 id;
2. 如何获取浙江省下的市级 id;
3. 如何获取浙江省杭州市下的区域 id;
1. 代码请求示例:
Token token = new Token("21ceba9f18821c3319d2eb779cd3xxx");
DefaultYZClient yzClient = new DefaultYZClient();
YouzanRegionsGet youzanRegionsGet = new YouzanRegionsGet();
//创建参数对象,并设置参数
YouzanRegionsGetParams youzanRegionsGetParams = new YouzanRegionsGetParams();
youzanRegionsGetParams.setLevel(1);
youzanRegionsGet.setAPIParams(youzanRegionsGetParams);
try {
YouzanRegionsGetResult result = yzClient.invoke(youzanRegionsGet, token, YouzanRegionsGetResult.class);
System.out.println(JSON.toJSON(result));
} catch (SDKException n) {
n.printStackTrace();
}
}
}
响应参数:
{"code":200,"data":{"regions":[{"parent_id":0,"name":"天津市","id":120000},{"parent_id":0,"name":"江苏省","id":320000},{"parent_id":0,"name":"江西省","id":360000},{"parent_id":0,"name":"广东省","id":440000},{"parent_id":0,"name":"贵州省","id":520000},{"parent_id":0,"name":"宁夏回族自治区","id":640000},{"parent_id":0,"name":"河北省","id":130000},{"parent_id":0,"name":"辽宁省","id":210000},{"parent_id":0,"name":"浙江省","id":330000},{"parent_id":0,"name":"山东省","id":370000},{"parent_id":0,"name":"河南省","id":410000},{"parent_id":0,"name":"广西壮族自治区","id":450000},{"parent_id":0,"name":"云南省","id":530000},{"parent_id":0,"name":"陕西省","id":610000},{"parent_id":0,"name":"新疆维吾尔自治区","id":650000},{"parent_id":0,"name":"香港特别行政区","id":810000},{"parent_id":0,"name":"山西省","id":140000},{"parent_id":0,"name":"吉林省","id":220000},{"parent_id":0,"name":"安徽省","id":340000},{"parent_id":0,"name":"湖北省","id":420000},{"parent_id":0,"name":"海南省","id":460000},{"parent_id":0,"name":"重庆市","id":500000},{"parent_id":0,"name":"西藏自治区","id":540000},{"parent_id":0,"name":"甘肃省","id":620000},{"parent_id":0,"name":"澳门特别行政区","id":820000},{"parent_id":0,"name":"北京市","id":110000},{"parent_id":0,"name":"内蒙古自治区","id":150000},{"parent_id":0,"name":"黑龙江省","id":230000},{"parent_id":0,"name":"上海市","id":310000},{"parent_id":0,"name":"福建省","id":350000},{"parent_id":0,"name":"湖南省","id":430000},{"parent_id":0,"name":"四川省","id":510000},{"parent_id":0,"name":"青海省","id":630000},{"parent_id":0,"name":"台湾省","id":710000}]},"success":true,"message":"successful"}
注意:
该接口的入参:fields( 这个字段不再维护,已废弃,不论何种情况都无需传入);
当获取所有省的 id 的情况下,只需入参传入 level 即可;
2. 代码请求示例
通过(1)可获取到浙江省的 id 为 33000
Token token = new Token("21ceba9f18821c3319d2eb779cd31xxx");
DefaultYZClient yzClient = new DefaultYZClient();
YouzanRegionsGet youzanRegionsGet = new YouzanRegionsGet();
//创建参数对象,并设置参数
YouzanRegionsGetParams youzanRegionsGetParams = new YouzanRegionsGetParams();
youzanRegionsGetParams.setLevel(2);
youzanRegionsGetParams.setId(330000);
youzanRegionsGetParams.setParentId(330000);
youzanRegionsGet.setAPIParams(youzanRegionsGetParams);
try {
YouzanRegionsGetResult result = yzClient.invoke(youzanRegionsGet, token, YouzanRegionsGetResult.class);
System.out.println(JSON.toJSON(result));
} catch (SDKException n) {
n.printStackTrace();
}
}
}
响应参数:
{"code":200,"data":{"regions":[{"parent_id":330000,"name":"杭州市","id":330100},{"parent_id":330000,"name":"湖州市","id":330500},{"parent_id":330000,"name":"舟山市","id":330900},{"parent_id":330000,"name":"嘉兴市","id":330400},{"parent_id":330000,"name":"衢州市","id":330800},{"parent_id":330000,"name":"温州市","id":330300},{"parent_id":330000,"name":"金华市","id":330700},{"parent_id":330000,"name":"丽水市","id":331100},{"parent_id":330000,"name":"宁波市","id":330200},{"parent_id":330000,"name":"绍兴市","id":330600},{"parent_id":330000,"name":"台州市","id":331000}]},"success":true,"message":"successful"}
3. 代码请求示例:
通过(2)可获取到浙江省杭州市的 id 为 330100
Token token = new Token("21ceba9f18821c3319d2eb779cd31xxx");
DefaultYZClient yzClient = new DefaultYZClient();
YouzanRegionsGet youzanRegionsGet = new YouzanRegionsGet();
//创建参数对象,并设置参数
YouzanRegionsGetParams youzanRegionsGetParams = new YouzanRegionsGetParams();
youzanRegionsGetParams.setLevel(3);
youzanRegionsGetParams.setId(330100);
youzanRegionsGetParams.setParentId(330100);
youzanRegionsGet.setAPIParams(youzanRegionsGetParams);
try {
YouzanRegionsGetResult result = yzClient.invoke(youzanRegionsGet, token, YouzanRegionsGetResult.class);
System.out.println(JSON.toJSON(result));
} catch (SDKException n) {
n.printStackTrace();
}
}
}
响应参数:
{"code":200,"data":{"regions":[{"parent_id":330100,"name":"建德市","id":330182},{"parent_id":330100,"name":"临安区","id":330112},{"parent_id":330100,"name":"淳安县","id":330127},{"parent_id":330100,"name":"桐庐县","id":330122},{"parent_id":330100,"name":"下城区","id":330103},{"parent_id":330100,"name":"上城区","id":330102},{"parent_id":330100,"name":"萧山区","id":330109},{"parent_id":330100,"name":"滨江区","id":330108},{"parent_id":330100,"name":"富阳区","id":330111},{"parent_id":330100,"name":"余杭区","id":330110},{"parent_id":330100,"name":"拱墅区","id":330105},{"parent_id":330100,"name":"江干区","id":330104},{"parent_id":330100,"name":"西湖区","id":330106}]},"success":true,"message":"successful"}