0
我試圖使用PHP SoapClient使用soap feed並將其轉換爲數組。它運行良好,直到遇到一個complexType類型的對象。通過PHP消耗ComplexType對象SoapClient
然後,它返回...
[0] => stdClass的對象
...而不是示出當我否則訪問SOAP進料時所顯示的多個元素。
我對SOAP很陌生,所以任何幫助表示讚賞。
的WSDL的相關部分看起來像這樣...
<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>
我爲我的PHP代碼看起來像這樣...
$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;
輸出結果是這樣的.. 。
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
(
)
)
)
下面是原始的XML輸出是什麼樣子......
<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>[email protected]</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>
嗨!歡迎來到StackOverflow。請務必閱讀[關於](http://stackoverflow.com/about)並獲得您的第一張徽章。你可能想編輯你的答案,並在其中解釋你寫的代碼。 – RyPeck 2013-09-24 14:25:17