预订宝/getRegions
来自站长百科
getRegions概述[ ]
- 接口地址:http://api.yudingbao.net/v1.0/hotel/geospatials.ashx?act=getRegions
- 动作标识:getRegions
- 参数:见参数说明
- 请求方式:GET
- 响应模式:JSON、JSONP、Xml
注意:动作标识是大小写敏感的,请养成良好的编码习惯!
参数说明[ ]
参数名称 | 参数类型 | 说明 |
---|---|---|
includeDistricts | bool | 指示响应结果应当包含城市内的行政区或县。默认值为true。 |
includeCommercials | bool | 指示响应结果应当包含城市内的热门商业区的集合。默认值为true。 |
includeLandmarks | bool | 指示响应结果应当包含成好似内的著名地标的集合。默认值为true。 |
数据格式[ ]
- 响应头:
- Status:0为正常,非0表示处理请求时发生异常,通常是参数校验错误;
- Messages:当Status为非0时该字段肯定包含一条或多条消息文本;
- 响应体:
- 地理位置信息包含编号、名称和拼音三个基本属性;
- 该接口返回的最大地理位置信息的级别是区域,在返回的响应体中对应:HttpResponse.ResponseBody.item节点;
- 区域下可能包含多个省份(Provinces);
- 省份下可能包含多个城市(Cities);
- 城市下可能包含多个行政区(DistrictLocations)、商业区(CommercialLocations)和著名地标(LandmarkLocations);
- 另外城市下还包含一个TotalHotels属性,该属性表示该城市内的签约酒店总数;
对于数据格式的理解,请参考下列示例代码中的XML响应演示,其中每个字段都标注了数据类型(日期类型在XML响应中统一使用GMT格式,但被标注为string,请开发者注意)。
示例代码[ ]
以下示例代码是通过HTML表单实现了该接口的部分操作,您在开发过程中应当使用自己的平台语言来模拟这些操作以捕获响应体,然后对响应体做出相应的操作。
请求示例:
<!-- 这是该接口的请求示例,该接口的访问类同于如下表单的提交, 请注意:该表单使用控件的方法模拟了GET请求 --> <form id="myForm" method="get" action="http://api.yudingbao.net/v1.0/hotel/geospatials.ashx"> <p> <!--动作标识,注意动作标识是大小写敏感的--> <input id="act" name="act" value="getRegions" type="text" /> </p> <p> <!--指定响应结果应包含行政区数据--> <input id="includeDistricts" name="withDistricts" value="true" type="text" /> <!--指定响应结果应包含商业区数据--> <input id="includeCommercials" name="withCommercials" value="true" type="text" /> <!--指定响应结果应包含著名地标数据--> <input id="includeLandmarks" name="withLandmarks" value="true" type="text" /> </p> <p> <!--指定响应格式为XML,这里以XML为例--> <input id="format" name="format" value="xml" type="text" /> <!--指定响应体应当是已格式化的,便于阅读代码,在生产环境中应当将该值设置为false--> <input id="indent" name="indent" value="true" type="text" /> <!--产品编号。在我的账户-分销产品的应用列表中可以找到该参数的值。--> <input id="aid" name="aid" value="78663" type="text" /> <!--接口密钥。在我的账户-分销产品的应用列表中可以找到该参数的值。--> <input id="key" name="key" value="0925ed633d24577eb3ffe13f00c55a4f9739f51a77eefb1dba29bb9568acddfd" type="text" /> <!--应用程序授权编号及公钥,这是可选的--> <input id="sid" name="sid" value="" type="text"> <input id="sKey" name="sKey" value="" type="text"> </p> <p> <input id="submit" name="submit" value="提交" type="submit"> </p> </form>
JsonP响应:
// JsonP响应,响应体过大,已删节 jsoncallback({ "Status" : 0, "Messages" : [], "ResponseBody" : [{ "Code" : "1", "Name" : "华北", "Pinyin" : "Hua Bei", "Provinces" : [{ "Code" : "0100", "Name" : "北京", "Pinyin" : "Bei Jing", "Cities" : [{ "Code" : "0101", "Name" : "北京", "Pinyin" : "", "TotalHotels" : 1388, "DistrictLocations" : [{ "Code" : "0001", "Name" : "西城区", "Pinyin" : "" }, { "Code" : "0033", "Name" : "大兴区", "Pinyin" : "" }], "CommercialLocations" : [{ "Code" : "010101", "Name" : "国贸CBD", "Pinyin" : "" }, { "Code" : "010102", "Name" : "燕莎/农展馆", "Pinyin" : "" }], "LandmarkLocations" : [{ "Code" : "0005", "Name" : "东方广场", "Pinyin" : "" }, { "Code" : "0006", "Name" : "中国国际展览中心", "Pinyin" : "" }] }] }, { "Code" : "8", "Name" : "港澳台", "Pinyin" : "Gang Ao Tai", "Provinces" : [{ "Code" : "3201", "Name" : "香港", "Pinyin" : "Xiang Gang", "Cities" : [] }, { "Code" : "3301", "Name" : "澳门", "Pinyin" : "Ao Men", "Cities" : [] }, { "Code" : "9001", "Name" : "台湾", "Pinyin" : "TaiWan", "Cities" : [] }] }] });
Json响应:
// Json响应,响应体过大,已删节 { "Status" : 0, "Messages" : [], "ResponseBody" : [{ "Code" : "1", "Name" : "华北", "Pinyin" : "Hua Bei", "Provinces" : [{ "Code" : "0100", "Name" : "北京", "Pinyin" : "Bei Jing", "Cities" : [{ "Code" : "0101", "Name" : "北京", "Pinyin" : "", "TotalHotels" : 1388, "DistrictLocations" : [{ "Code" : "0001", "Name" : "西城区", "Pinyin" : "" }, { "Code" : "0033", "Name" : "大兴区", "Pinyin" : "" }], "CommercialLocations" : [{ "Code" : "010101", "Name" : "国贸CBD", "Pinyin" : "" }, { "Code" : "010102", "Name" : "燕莎/农展馆", "Pinyin" : "" }], "LandmarkLocations" : [{ "Code" : "0005", "Name" : "东方广场", "Pinyin" : "" }, { "Code" : "0006", "Name" : "中国国际展览中心", "Pinyin" : "" }] }] }, { "Code" : "8", "Name" : "港澳台", "Pinyin" : "Gang Ao Tai", "Provinces" : [{ "Code" : "3201", "Name" : "香港", "Pinyin" : "Xiang Gang", "Cities" : [] }, { "Code" : "3301", "Name" : "澳门", "Pinyin" : "Ao Men", "Cities" : [] }, { "Code" : "9001", "Name" : "台湾", "Pinyin" : "TaiWan", "Cities" : [] }] }] }
XML响应:
<!--XML响应,响应体过大,已删节--> <?xml version="1.0" encoding="utf-8"?> <HttpResponse> <Status type="number">0</Status> <Messages type="array"> </Messages> <ResponseBody type="array"> <item type="object"> <Code type="string">1</Code> <Name type="string">华北</Name> <Pinyin type="string">Hua Bei</Pinyin> <Provinces type="array"> <item type="object"> <Code type="string">0100</Code> <Name type="string">北京</Name> <Pinyin type="string">Bei Jing</Pinyin> <Cities type="array"> <item type="object"> <Code type="string">0101</Code> <Name type="string">北京</Name> <Pinyin type="string"> </Pinyin> <TotalHotels type="number">1388</TotalHotels> <DistrictLocations type="array"> <item type="object"> <Code type="string">0001</Code> <Name type="string">西城区</Name> <Pinyin type="string"> </Pinyin> </item> <item type="object"> <Code type="string">0002</Code> <Name type="string">东城区</Name> <Pinyin type="string"> </Pinyin> </item> </DistrictLocations> <CommercialLocations type="array"> <item type="object"> <Code type="string">010101</Code> <Name type="string">国贸CBD</Name> <Pinyin type="string"> </Pinyin> </item> <item type="object"> <Code type="string">010102</Code> <Name type="string">燕莎/农展馆</Name> <Pinyin type="string"> </Pinyin> </item> </CommercialLocations> <LandmarkLocations type="array"> <item type="object"> <Code type="string">0005</Code> <Name type="string">东方广场</Name> <Pinyin type="string"> </Pinyin> </item> <item type="object"> <Code type="string">0006</Code> <Name type="string">中国国际展览中心</Name> <Pinyin type="string"> </Pinyin> </item> </LandmarkLocations> </item> </Cities> </item> <item type="object"> <Code type="string">0700</Code> <Name type="string">内蒙古</Name> <Pinyin type="string">Nei Meng Gu</Pinyin> <Cities type="array"> <item type="object"> <Code type="string">0701</Code> <Name type="string">呼和浩特</Name> <Pinyin type="string"> </Pinyin> <TotalHotels type="number">91</TotalHotels> <DistrictLocations type="array"> <item type="object"> <Code type="string">0000</Code> <Name type="string">不详</Name> <Pinyin type="string"> </Pinyin> </item> <item type="object"> <Code type="string">0010</Code> <Name type="string">土默特左旗</Name> <Pinyin type="string"> </Pinyin> </item> </DistrictLocations> <CommercialLocations type="array"> <item type="object"> <Code type="string">070101</Code> <Name type="string">满都海公园</Name> <Pinyin type="string"> </Pinyin> </item> <item type="object"> <Code type="string">070110</Code> <Name type="string">青山公园</Name> <Pinyin type="string"> </Pinyin> </item> </CommercialLocations> <LandmarkLocations type="array"> <item type="object"> <Code type="string">0001</Code> <Name type="string">王府井百货(回民区)</Name> <Pinyin type="string"> </Pinyin> </item> <item type="object"> </LandmarkLocations> </item> <item type="object"> <Code type="string">0722</Code> <Name type="string">乌拉特中旗</Name> <Pinyin type="string"> </Pinyin> <TotalHotels type="number">0</TotalHotels> <DistrictLocations type="array"> <item type="object"> <Code type="string">0001</Code> <Name type="string">县中心</Name> <Pinyin type="string"> </Pinyin> </item> </DistrictLocations> <CommercialLocations type="array"> </CommercialLocations> <LandmarkLocations type="array"> </LandmarkLocations> </item> </Cities> </item> </Provinces> </item> <item type="object"> <Code type="string">8</Code> <Name type="string">港澳台</Name> <Pinyin type="string">Gang Ao Tai</Pinyin> <Provinces type="array"> <item type="object"> <Code type="string">3201</Code> <Name type="string">香港</Name> <Pinyin type="string">Xiang Gang</Pinyin> <Cities type="array"> </Cities> </item> <item type="object"> <Code type="string">3301</Code> <Name type="string">澳门</Name> <Pinyin type="string">Ao Men</Pinyin> <Cities type="array"> </Cities> </item> <item type="object"> <Code type="string">9001</Code> <Name type="string">台湾</Name> <Pinyin type="string">TaiWan</Pinyin> <Cities type="array"> </Cities> </item> </Provinces> </item> </ResponseBody> </HttpResponse>