HotelBeds Php API为我提供空洞的结果

时间:2015-12-23 12:06:24

标签: php api

我尝试使用此代码访问数据但无法获取。任何人都知道如何添加此文件(Xml)

XML文件

<availabilityRQ xmlns="http://www.hotelbeds.com/schemas/messages" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
<stay checkIn="2015-12-28" checkOut="2015-12-29"/>
 <occupancies>
  <occupancy rooms="1" adults="1" children="1">
   <paxes>
    <pax type="AD" age="31"/>
    <pax type="CH" age="3"/> 
    </paxes>
  </occupancy> 
 </occupancies>
 <hotels>
           <hotel>1067</hotel> 
           <hotel>1070</hotel>
           <hotel>135813</hotel> 
        </hotels> 
</availabilityRQ>

致电代码

以下示例要求PHP版本大于5.5.x且库pecl_http =&gt; 2.5.3您可以通过https://pecl.php.net安装它     

// Your API Key and secret
$apiKey = "6355445214552444";
$sharedSecret = "5456842";

// Signature is generated by SHA256 (Api-Key + Shared Secret + Timestamp (in seconds))
$signature = hash("sha256", $apiKey.$sharedSecret.time());

// Example of call to the API
$endpoint = "https://api.test.hotelbeds.com/hotel-api/1.0/status";

$request = new http\Client\Request("GET",
    $endpoint,
    [ "Api-Key"     => $apiKey,
      "X-Signature" => $signature,
      "Accept"      => "application/xml" ]);
try
{

    $client = new http\Client;

    $client->enqueue($request)->send();



    // pop the last retrieved response

    $response = $client->getResponse();

    if ($response->getResponseCode() != 200) {  

       printf("%s returned '%s' (%d)\n",

           $response->getTransferInfo("effective_url"),

           $response->getInfo(),

           $response->getResponseCode()

       );

    } else {

       printf($response->getBody());

    }

} catch (Exception $ex) {

    printf("Error while sending request, reason: %s\n",$ex->getMessage());

}
?>

任何人都可以指导我如何称酒店床API?在哪里我犯了错误

谢谢

3 个答案:

答案 0 :(得分:4)

我猜你需要针对API发布xml。

我不知道API,但鉴于端点是正确的,您可以尝试使用POST请求:

$request = new http\Client\Request("POST",
    $endpoint,
    [ "Api-Key"     => $apiKey,
      "X-Signature" => $signature,
      "Accept"      => "application/xml" ],
   $xml);

其中 $ xml var包含您发布的xml。

答案 1 :(得分:4)

答案 2 :(得分:0)

您正在使用用于检查api状态的端点。

https://api.test.hotelbeds.com/hotel-api/1.0/status

您需要致电以下端点以获取酒店的实时空房

https://api.test.hotelbeds.com/hotel-api/{version}/{operation}