gpt4 book ai didi

php - HotelBeds Php API 提供空结果

转载 作者:可可西里 更新时间:2023-11-01 12:17:12 25 4
gpt4 key购买 nike

我试过这段代码来访问数据但无法获取。任何人都知道我该如何添加到这个文件 (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 => 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());

}
?>

谁能指导我如何调用 hotel Beds API?我哪里出错了

谢谢

最佳答案

我想您需要针对 API 发布 xml。

我不知道 API,但如果端点正确,您可以尝试使用 POST 请求:

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

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

关于php - HotelBeds Php API 提供空结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34435343/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com