Sending data arrays in nusoap and PHP

一个人想着一个人 提交于 2019-12-10 10:14:23

问题


Hope someone can help me with this. I am building nusoap client using the following partial WSDL:

      <s:element name="SavePrestaPicklist">
        <s:complexType>
          <s:sequence>
            <s:element minOccurs="0" maxOccurs="1" name="USERNAME" type="s:string" />
            <s:element minOccurs="0" maxOccurs="1" name="PASSWORD" type="s:string" />
            <s:element minOccurs="0" maxOccurs="1" name="BRANCH" type="s:string" />
            <s:element minOccurs="0" maxOccurs="1" name="CUSTOMERNUMBER" type="s:string" />
            <s:element minOccurs="0" maxOccurs="1" name="CUSTOMERPO" type="s:string" />
            <s:element minOccurs="0" maxOccurs="1" name="SHIPMETHOD" type="s:string" />
            <s:element minOccurs="0" maxOccurs="1" name="PRESTAPO" type="s:string" />
            <s:element minOccurs="0" maxOccurs="1" name="PICKITEMS" type="tns:ArrayOfPICKITEM" />
          </s:sequence>
        </s:complexType>
      </s:element>
      <s:complexType name="ArrayOfPICKITEM">
        <s:sequence>
          <s:element minOccurs="0" maxOccurs="unbounded" name="PICKITEM" nillable="true" type="tns:PICKITEM" />
        </s:sequence>
      </s:complexType>
      <s:complexType name="PICKITEM">
        <s:sequence>
          <s:element minOccurs="0" maxOccurs="1" name="PARTNUMBER" type="s:string" />
          <s:element minOccurs="0" maxOccurs="1" name="BRANCH" type="s:string" />
          <s:element minOccurs="0" maxOccurs="1" name="MFRCODE" type="s:string" />
          <s:element minOccurs="0" maxOccurs="1" name="QUANTITY" type="s:string" />
        </s:sequence>
      </s:complexType>

My client looks like this:

   $orderdata = getorder('123');
   $orderdata = array(
        'USERNAME' => $config['export_username'],
        'PASSWORD' => $config['export_password'],
        'BRANCH' => '01',
        'CUSTOMERNUMBER' => $data['order']['address1'],
        'CUSTOMERPO' => $data['order']['gift_message'],
        'SHIPMETHOD' => $shipMethod,
        'PRESTAPO' => $data['order']['id_order']);

        // Build the pickitems array of pickitem.

        $pickitems = array();
        foreach($data['products'] as $item) {

            $pickitem = array(
                'PARTNUMBER' => $item['name'],
                'BRANCH' => '01',
                'MFRCODE' => '642',
                'QUANTITY' => $item['product_quantity']);

            $pickitems[] = $pickitem;
        }
        $data['PICKITEMS'] = $pickitems;

    $usingWsdl = true;
    $client = new nusoap_client($config['export_wsdl'], $usingWsdl);

    $response = $client->call('SavePrestaPicklist', $orderdata);

This isn't working and sends a PICKITEMS like this:

<PICKITEMS>
    <0>
       <PARTNUMBER>BLAH</PARTNUMBER>
       <BRANCH>BLAH</BRANCH>
         ETC.
    </0>
    <1>
        ANOTHER ITEM SET
    </1>
 </PICKITEMS>  

What I want is this:

<PICKITEMS>
    <PICKITEM>
       <PARTNUMBER>BLAH</PARTNUMBER>
       <BRANCH>BLAH</BRANCH>
         ETC.
    </PICKITEM>
    <PICKITEM>
        ANOTHER ITEM SET
    </PICKITEM>
 </PICKITEMS>

Since you can't have duplicate 'PICKITEM' keys in PHP I can't figure out how to do this. Any help would be appreciated.


回答1:


'PICKITEMS' => 
    array (
        'PICKITEM' => 
            array(
                0 => array('PARTNUMBER' => 'param1', 'BRANCH' => 'value1'),
                1 => array('PARTNUMBER' => 'param2', 'BRANCH' => 'value2')
        )
    )



回答2:


You can send raw XML with the $client->send() method.

$raw_xml = "<Your_XML>...</Your_XML>";
$msg = $client->serializeEnvelope("$raw_xml");
$result=$client->send($msg, $endpoint);

You can see the example here:

http://itworkarounds.blogspot.com/2011/07/send-raw-xml-with-php-nusoap.html

If that does't work you can try posting the XML with CURL.



来源:https://stackoverflow.com/questions/6286081/sending-data-arrays-in-nusoap-and-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!