java soap 集合数组_如何将数组传递给PHP SoapClient调用 (How to pass an array into a PHP SoapClient call)...

2010-09-23 16:33:36

2

Using PHP and SoapClient.

I need to pass the following XML into a soap request - i.e. multiple 's within .

2011-01-01

2011-01-15

2011-01-16

2011-01-30

The problem is that I'm passing the data in as an array:

$xml = array('reservation' => array(

'stays' => array(

array(

'start_date' => '2011-01-01',

'end_date' => 2011-01-15

),

array(

'start_date' => '2011-01-16',

'end_date' => 2011-01-30

)

)

);

The above doesn't work, as is not defined. So the alternative is:

$xml = array('reservation' => array(

'stays' => array(

'stay' => array(

'start_date' => '2011-01-01',

'end_date' => 2011-01-15

),

'stay' => array(

'start_date' => '2011-01-01',

'end_date' => 2011-01-15

)

)

);

But that results in duplicate keys, so only one of the 's is sent.

I'm running this as:

$soapClient->saveReservation($xml);

Any ideas on how I can structure the array so that the above XML is generated?

Some further information. The above examples were super-simplified, so here's a real use example of what I'm doing, with benjy's suggestion implemented.

$options = $this->api->getDefaultOptions();

$options['baseProductCode'] = '123'.$basket->accommodation['feed_primary_identifier'];

# ^^^^^ just to ensure it fails and doesn't process

$reservation = new stdClass();

$reservation->external_id = $order->pb_ref;

$reservation->etab_id = $basket->accommodation['feed_primary_identifier'];

$reservation->reservation_type = 'gin';

$reservation->firstname = $order->forename;

$reservation->lastname = $order->surname;

$reservation->birthdate = date('Y-m-d', strtotime('- 21 YEAR'));

$reservation->stays = array();

$details = $basket->getDetailedBasketContents();

foreach ($details['room_types'] as $roomTypeId => $roomType) {

foreach($roomType['instances'] as $instance) {

$stay = new stdClass();

$stay->nb_rooms = 1;

$stay->room_type_code = $roomTypeId;

$stay->start_date = date('Y-m-d', strtotime($order['checkin']));

$stay->end_date = date('Y-m-d', strtotime($order['checkout']));

$stay->occupants = array();

foreach($instance['occupancy']['occupants'] as $key => $occupantData) {

if ($occupantData['forename'] and $occupantData['surname']) {

$occupant = new stdClass();

$occupant->firstname = $occupantData['forename'];

$occupant->lastname = $occupantData['surname'];

$occupant->pos = 100;

$occupant->birthdate = date('Y-m-d', strtotime('- 21 YEAR'));

$stay->occupants[] = $occupant;

}

}

$reservation->stays[] = $stay;

}

}

$options['reservation'] = new stdClass();

$options['reservation']->reservation = $reservation;

//echo XmlUtil::formatXmlString($this->api->);

try {

$this->parsePlaceOrderResponse($this->api->__soapCall('saveDistribReservation2', $options));

} catch (Exception $e) {

echo $e->getMessage();

echo XmlUtil::formatXmlString($this->api->__getLastRequest());

echo XmlUtil::formatXmlString($this->api->__getLastResponse());

}

exit;

This fails, with the message object hasn't 'stay' property which is due to the same issue, that the tag should contain 1 or more tags. If I set $reservation->stays['stay'] = $stay; then it is accepted, but that again only allows me to have a single within

Additionally, the SOAP request looks like this:

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值