在发现 PHP soap 不处理具有复杂类型的数组后,我现在使用 stdClass() 我编写了一些代码,但它以错误的顺序创建了 soap 请求。我希望 idtag 和 idtaginfo 成对出现,如下所示。
<soap:Body>
<ns:sendLocalListRequest>
<ns:updateType>full</ns:updateType>
<ns:listVersion>1</ns:listVersion>
<ns:localAuthorisationList>
<ns:idTag>1</ns:idTag>
<ns:idTagInfo>
<ns:status>good</ns:status>
</ns:idTagInfo>
<ns:idTag>2</ns:idTag>
<ns:idTagInfo>
<ns:status>bad</ns:status>
</ns:idTagInfo>
</ns:localAuthorisationList>
</ns:sendLocalListRequest>
</soap:Body>
我的肥皂请求是错误的,如下所示
<env:Body><ns1:sendLocalListRequest><ns1:updateType>FULL</ns1:updateType>
<ns1:listVersion>1</ns1:listVersion>
<ns1:localAuthorisationList>
<ns1:idTag>1</ns1:idTag><ns1:idTag>2</ns1:idTag>
<ns1:idTagInfo><ns1:status>good</ns1:status><ns1:status>bad</ns1:status>
</ns1:idTagInfo>
</ns1:localAuthorisationList></ns1:sendLocalListRequest></env:Body>
这是 wsdl 的相关部分
<s:complexType name="SendLocalListRequest">
<s:annotation>
<s:documentation>Defines the SendLocalList.req PDU</s:documentation>
</s:annotation>
<s:sequence>
<s:element name="updateType" type="tns:UpdateType" minOccurs="1" maxOccurs="1" />
<s:element name="listVersion" type="s:int" minOccurs="1" maxOccurs="1" />
<s:element name="localAuthorisationList" type="tns:AuthorisationData"
minOccurs="1" maxOccurs="unbounded" />
<s:element name="hash" type="s:string" minOccurs="0" maxOccurs="1" />
</s:sequence>
</s:complexType>
<s:complexType name="AuthorisationData">
<s:sequence>
<s:element name="idTag" type="tns:string" minOccurs="1" maxOccurs="unbounded"/>
<s:element name="idTagInfo" type="tns:IdTagInfo" minOccurs="1"
maxOccurs="unbounded"/>
</s:sequence>
</s:complexType>
<s:simpleType name="UpdateType">
<s:restriction base="s:string">
<s:enumeration value="Differential"/>
<s:enumeration value="Full"/>
</s:restriction>
</s:simpleType>
<s:complexType name="SendLocalListResponse">
<s:annotation>
<s:documentation>Defines the SendLocalList.conf PDU</s:documentation>
</s:annotation>
<s:sequence>
<s:element name="status" type="tns:UpdateStatus" minOccurs="1" maxOccurs="1" />
<s:element name="hash" type="s:string" minOccurs="0" maxOccurs="1" />
</s:sequence>
</s:complexType>
<s:complexType name="IdTagInfo">
<s:sequence>
<s:element name="status" type="s:string" minOccurs="1" maxOccurs="unbounded" />
<s:element name="expiryDate" type="s:dateTime" minOccurs="0" maxOccurs="1"/>
<s:element name="parentIdTag" type="tns:IdToken" minOccurs="0" maxOccurs="1"/>
</s:sequence>
</s:complexType>
这是我的代码
$search_query = new StdClass();
$search_query->updateType = $updatetype;
$search_query->listVersion = $listversion;
$search_query->localAuthorisationList = new StdClass();
while ($row = $db->getResult()) {
$search_query->localAuthorisationList->idTag[] = $row['rfid'];
$search_query->localAuthorisationList->idTagInfo->status[] = $row['status'];
}
ini_set("soap.wsdl_cache_enabled", "0");
$path = realpath($_SERVER["DOCUMENT_ROOT"]);
$endpoint = $wsdl;
$soapOptions = array( 'exceptions' => 0
,'soap_version' => SOAP_1_2
,'trace' => true
,'uri' => $theversion
,'location' => $url
);
$header = new SoapHeader($theversion,'', $ppid);
$client->__setSoapHeaders($header);
$response = $client->SendLocalList($search_query);
更新
我已经接近但仍然落在最后一个障碍以下将产生列表
while ($row2 = $db->getResult()) {
$search_query[] = new SoapStructAuthorisationData($row2['rfid'],array(new
SoapStructIdTagInfo('ConcurrentTx')));
}
// implode with commas and remove last comma
$search_list=implode(', ', $search_query);
$search_list_nocommaend = rtrim($search_list, ', ');
var_dump 生成 SoapStructAuthorisationData、SoapStructAuthorisationData、SoapStructAuthorisationData、SoapStructAuthorisationData、SoapStructAuthorisationData
如果我将上面的代码包含在语音标记中,例如“new SoapStructAuthorisationData($row2['rfid'],array(new SoapStructIdTagInfo('ConcurrentTx')))”; is 会产生整个事情,但是当我执行以下操作时这不会显示
if($soapServiceSend->SendLocalList(new SoapStructSendLocalListRequest($updateType,
$listversion,
array( $search_list_nocommaend ))))
如果我对测试件做这样的事情,它会起作用
$search=new SoapStructAuthorisationData('BUKIEE',array(new
SoapStructIdTagInfo('ConcurrentTx')));
有什么想法吗?