La consommation objet de ComplexType par PHP SoapClient

voix
0

Je suis en train de consommer un aliment de savon en utilisant la SoapClient PHP et le convertir en un tableau. Il fonctionne très bien jusqu'à ce que je tombe sur un objet qui est un complexType.

Ensuite, il retourne ...

[0] => stdClass Object

... au lieu de montrer les multiples éléments qui sont affichés lorsque j'accéder à l'alimentation SOAP autrement.

Je suis très nouveau pour SOAP, de sorte que toute aide est appréciée.

La partie pertinente du WSDL ressemble à ceci ...

<xs:complexType name=UserInfo> 
            <xs:complexContent> 
                <xs:extension base=tns:UserBaseInfo> 
                    <xs:sequence> 
                        <xs:element minOccurs=0 name=contact_name type=xs:string/> 
                        <xs:element minOccurs=0 name=group_name type=xs:string/> 
                        <xs:element name=active type=xs:boolean/> 
                        <xs:element name=validated type=xs:boolean/> 
                        <xs:element name=deleted type=xs:boolean/> 
                        <xs:element name=hidden type=xs:boolean/> 
                        <xs:element minOccurs=0 name=deleted_date type=xs:dateTime/> 
                        <xs:element minOccurs=0 name=pref_contact type=xs:string/> 
                        <xs:element minOccurs=0 name=last_login_date type=xs:dateTime/> 
                        <xs:element minOccurs=0 name=last_modify type=xs:dateTime/> 
                        <xs:element minOccurs=0 name=updated_by type=xs:string/> 
                        <xs:element name=no_mass_email type=xs:boolean/> 
                        <xs:element minOccurs=0 name=pref_bb_contact type=xs:string/> 
                        <xs:element minOccurs=0 name=pref_bb_image type=xs:string/> 
                        <xs:element maxOccurs=unbounded minOccurs=0 name=attribute_list type=tns:UserAttInfo/> 
                    </xs:sequence> 
                </xs:extension> 
            </xs:complexContent> 
        </xs:complexType> 

        <xs:complexType name=UserAttInfo> 
            <xs:sequence> 
                <xs:element name=user_id type=xs:string/> 
                <xs:element name=att_id type=xs:string/> 
                <xs:element minOccurs=0 name=att_name type=xs:string/> 
                <xs:element minOccurs=0 name=att_type_id type=xs:string/> 
                <xs:element minOccurs=0 name=att_type_name type=xs:string/> 
                <xs:element minOccurs=0 name=att_data type=xs:string/> 
                <xs:element name=hidden type=xs:boolean/> 
                <xs:element minOccurs=0 name=last_modify type=xs:dateTime/> 
                <xs:element name=view_only type=xs:boolean/> 
                <xs:element name=editable type=xs:boolean/> 
            </xs:sequence> 
        </xs:complexType> 

Je suis mon code PHP ressemble à ceci ...

$wsdl = new SoapClient('https://location.com/UserService?wsdl', array('features' => SOAP_SINGLE_ELEMENT_ARRAYS));


    $data = $wsdl->$method($params);

    $result['gusername']            = $username;
    $result['password']             = $password;

    $result['user_id']              = $data->return->user_id;           // 8 digits integer <user_id>16977408</user_id>
    $result['group_id']             = $data->return->group_id;          // 6 digits integer
    $result['org_id']               = $data->return->org_id;            // 3 letter string
    $result['contact_name']         = $data->return->contact_name;      // string
    $result['active']               = $data->return->active;            // boolean
    $result['validated']            = $data->return->validated;         // boolean
    $result['deleted']              = $data->return->deleted;           // boolean
    $result['hidden']               = $data->return->hidden;            // boolean
    $result['last_login_date']      = $data->return->last_login_date;   // date string
    $result['last_modify']          = $data->return->last_modify;       // date string
    $result['updated_by']           = $data->return->updated_by;        // string
    $result['no_mass_email']        = $data->return->no_mass_email;     // boolean
    $result['pref_bb_contact']      = $data->return->pref_bb_contact;   // string
    $result['pref_bb_image']        = $data->return->pref_bb_image;     // string
    $result['attribute_list']       = $data->return->attribute_list; 

La sortie résultante ressemble à ceci ...

    Array
(
    [gusername] => jsmith
    [password] => password
    [user_id] => 123456789
    [group_id] => 123456
    [org_id] => obs
    [contact_name] => John Smith
    [active] => 1
    [validated] => 1
    [deleted] => 
    [hidden] => 
    [last_login_date] => 2010-08-17T14:39:41Z
    [last_modify] => 2010-03-29T22:43:42Z
    [updated_by] => John Smith
    [no_mass_email] => 
    [pref_bb_contact] => 
    [pref_bb_image] => 
    [attribute_list] => Array
        (
            [0] => stdClass Object
                (
                )

        )

)

Voici ce que la sortie xml brute ressemble ...

<soapenv:Envelope xmlns:soapenv=http://schemas.xmlsoap.org/soap/envelope/ >
    -<soapenv:Body>
        -<authenticateUserResponse xmlns=http://ws.domain.com/xsd>
        -<return>
            -<user_id>12345679</user_id>
            -<group_id>100400</group_id>
            -<org_id>obs</org_id>
            -<contact_name>John Smith</contact_name>
            -<active>true</active>
            -<validated>true</validated>
            -<deleted>false</deleted>
            -<hidden>false</hidden>
            -<last_login_date>2010-08-17T14:39:41Z</last_login_date>
            -<last_modify>2010-03-29T22:43:42Z</last_modify>
            -<updated_by>John Smith</updated_by>
            -<no_mass_email>false</no_mass_email>
            -<pref_bb_contact></pref_bb_contact>
            -<pref_bb_image></pref_bb_image>
            -<attribute_list>
                -<UserAttInfo>
                    -<user_id>123456798</user_id>
                    -<att_id>406833</att_id>
                    -<att_name>Contact Name</att_name>
                    -<att_type_id>16</att_type_id>
                    -<att_type_name>Contact Center Greeting</att_type_name>
                    -<att_data>John Smith</att_data>
                    -<hidden>false</hidden>
                    -<last_modify>2009-11-11T22:13:13Z</last_modify>
                    -<view_only>false</view_only>
                    -<editable>true</editable>
                </UserAttInfo>
                -<UserAttInfo>
                    -<user_id>16977408</user_id>
                    -<att_id>406824</att_id>
                    -<att_name>Email</att_name>
                    -<att_type_id>1</att_type_id>
                    -<att_type_name>E-mail Address (Contact Center)</att_type_name>
                    -<att_data>jsmith@domain.com</att_data>
                    -<hidden>false</hidden>
                    -<last_modify>2009-11-11T22:13:13Z</last_modify>
                    -<view_only>false</view_only>
                    -<editable>true</editable>
                </UserAttInfo>
            </attribute_list>
        </return>
        </authenticateUserResponse>
    </soapenv:Body>
</soapenv:Envelope>
Créé 17/08/2010 à 17:08
source utilisateur
Dans d'autres langues...                            


1 réponses

voix
0

XML:

<ns1:Products>
    <ns1:WebProductInPurchaseInfo>
        <ns1:Amount>65</ns1:Amount>
        <ns1:Price>65</ns1:Price>
        <ns1:DiscountAmount>0</ns1:DiscountAmount>
        <ns1:Position>1</ns1:Position>
        <ns1:Present>0</ns1:Present>
        <ns1:ProductCode>1182</ns1:ProductCode>
        <ns1:Quantity>5</ns1:Quantity>
    </ns1:WebProductInPurchaseInfo>
    <ns1:WebProductInPurchaseInfo>
        <ns1:Amount>65</ns1:Amount>
        <ns1:Price>65</ns1:Price>
        <ns1:DiscountAmount>0</ns1:DiscountAmount>
        <ns1:Position>2</ns1:Position>
        <ns1:Present>0</ns1:Present>
        <ns1:ProductCode>1174</ns1:ProductCode>
        <ns1:Quantity>3</ns1:Quantity>
    </ns1:WebProductInPurchaseInfo>
</ns1:Products>

PHP:

$stdData->Products = new ArrayObject();
foreach($basket->product_list as $i => $obj) {

        $product = new stdClass();

        $product->Amount         = $obj->price;
        $product->Price          = $obj->discount_price;
        $product->DiscountAmount = $basket->discount;
        $product->Position       = $k;
        $product->Present        = 0;
        $product->ProductCode    = $obj->code;
        $product->Quantity       = $obj->count;

        foreach($product as $k => $v) {
            $product->$k = new SoapVar($v, XSD_ANYTYPE, null, null, $k, 'namespaces');
        }

        $product = new SoapVar($product, SOAP_ENC_OBJECT, null, null, 'WebProductInPurchaseInfo', 'namespaces');

        $stdData->Products->append($product);
    }

$stdData->Products = new SoapVar($stdData->Products, SOAP_ENC_OBJECT, null, null);
Créé 24/09/2013 à 14:58
source utilisateur

Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more