我正致力于REST服务,以实现在线酒店预订。根据REST服务提供者,我们需要使用JSON格式的输入发送REST请求。根据服务提供商文档的JSON格式是:
{
"ResultIndex": "1",
"HotelCode": "128407",
"HotelName": "Nieuw Slotania Hotel",
"GuestNationality": "IN",
"NoOfRooms": 4,
"ClientReferenceNo": 0,
"HotelRoomsDetails": [
{
"RoomIndex": "1",
"RoomTypeCode": "Xv+rPD4t1XERkUWumdalig==|ST|CG-FIT|221###",
"RoomTypeName": "DOUBLE STANDARD",
"RatePlanCode": "BB-E10",
"BedTypeCode": null,
"SmokingPreference": 0,
"Supplements": null,
"Price": {
"CurrencyCode": "INR",
"RoomPrice": "9518.05",
"Tax": "0.0",
"ExtraGuestCharge": "0.0",
"ChildCharge": "0.0",
"OtherCharges": "0.0",
"Discount": "0.0",
"PublishedPrice": "9518.05",
"PublishedPriceRoundedOff": "9518",
"OfferedPrice": "9518.05",
"OfferedPriceRoundedOff": "9518",
"AgentCommission": "0.0",
"AgentMarkUp": "1241.48",
"ServiceTax": "99.32",
"TDS": "0.0"
},
],
"EndUserIp": "123.1.1.1",
"TokenId": "df141129-c8f1-4a56-84ca-14483e148e75",
"TraceId": "625e8d04-afdc-496c-bb43-39ba59554f89"
}
在我们这边,我们使用“curl”来执行以下JSON输入的Web服务: 使用PHP的JSON输入:
$temp='{
"ResultIndex": "1",
"HotelCode": "'.$_HotelCode.'",
"HotelName": "'.$_HotelName.'",
"GuestNationality": "IN",
"NoOfRooms": 4,
"ClientReferenceNo": 0,
"HotelRoomsDetails": [
{
"RoomIndex": "1",
"RoomTypeCode": "'.$_RoomTypeCode.'",
"RoomTypeName": "'.$_RoomTypeName.'",
"RatePlanCode": "'.$_RatePlanCode.'",
"BedTypeCode": null,
"SmokingPreference": 0,
"Supplements": null,
"Price": {
"CurrencyCode": "INR",
"RoomPrice": "'.$_RoomPrice.'",
"Tax": "'.$_Tax.'",
"ExtraGuestCharge": "0.0",
"ChildCharge": "0.0",
"OtherCharges": "0.0",
"Discount": "0.0",
"PublishedPrice": "'.$_PublishedPrice.'",
"PublishedPriceRoundedOff": "'.$_PublishedPriceRoundedOff.'",
"OfferedPrice": "'.$_OfferedPrice.'",
"OfferedPriceRoundedOff": "'.$_OfferedPriceRoundedOff.'",
"AgentCommission": "'.$_AgentCommission.'",
"AgentMarkUp": "'.$_AgentMarkUp.'",
"ServiceTax": "'.$_ServiceTax.'",
"TDS": "'.$_TDS.'"
}
}
],
"EndUserIp": "192.168.0.1",
"TokenId": "'.$token_id.'",
"TraceId": "'.$_TraceId.'"
}';
WE EXECUTE IT AS FOLLOWS:
$resp_hotel_room= (array) ExecuteURL($url,$temp);
ExecuteURL 是我们的自定义CURL执行功能。输出“$ resp_hotel_room”未来,卷曲状态显示为400 。