<?php

/* PHP SDK
 * @version 2.0.0
 * @author magicsky0@163.com
 * @copyright © 2014, Ctrip Corporation. All rights reserved.
 */

class OTA_FltGetCityInfos {

    public $open_api = '/Flight/FlightProduct/OTA_FltGetCityInfos.asmx';


    public function __construct($open_api, $args) {
        $this->open_api = $open_api . $this->open_api; // TODO:检测open api，如果不合法则覆盖重写
    }
    
    /**
     * 构造请求xml字符串
     * @param int $uid
     * @param int $sid
     * @param string $stmp
     * @param string $sign
     * @param stirng $type
     */
    public function request_xml($uid, $sid, $stmp, $sign, $type) {
        $request_xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>
<!--接口提供方：携程；调用方：合作方-->
<Request>
<!--AllianceID:分销商ID;SID:站点ID;TimeStamp:响应时间戳（从1970年到现在的秒数）;RequestType:请求接口的类型;Signature:MD5加密串-->
<Header  AllianceID=\"$uid\" SID=\"$sid\" TimeStamp=\"$stmp\"  RequestType=\"OTA_FltGetCityInfos\" Signature=\"$sign\" />
   <GetCityInfosRequest>
<!--城市Code：string类型；可空 -->
		<CityCode>SHA</CityCode>
<!--城市ID：string类型；可空-->
		<CityId></CityId>  
   <!--城市中文名称：string类型；可空-->
		<CityName></CityName>
	</GetCityInfosRequest>
</Request>
                ";
        
//echo $request_xml;
        // 需要将此处的xml嵌入到外层xml中，故需要将其转义
        $request_xml = str_replace("<", @"&lt;", $request_xml);
        $request_xml = str_replace(">", @"&gt;", $request_xml);

        return $request_xml;
    }

    public function respond_xml($string) {
        // 将内层xmll中转义的符号恢复
        $string = str_replace("&lt;", "<", $string);
        $string = str_replace("&gt;", ">", $string);

        return simplexml_load_string($string);
    }

}
