API 文件聲明不需 id,但 WSDL 定義中 minOccurs 預設為 1,導致 PHP 強制要求該屬性。深入 PHP 原始碼 php_encoding.c 中的 model_to_xml_object 函式,發現當 min_occurs == 0 才會跳過驗證。解決方案:在請求中補入任意 id 值通過驗證(服務端規範不足所致)。
抓包發現回應為 multipart/related 格式(MTOM),非純 XML。CXF 啟用 mtom-enabled="true",但 PHP SOAP 擴展預設不支援 MTOM。
__doRequestclass ZSoapClient extends SoapClient {
public function __doRequest($request, $location, $action, $version, $one_way = 0) {
$response = parent::__doRequest($request, $location, $action, $version, $one_way);
$start = strpos($response, '<soap');
$end = strrpos($response, '>');
return substr($response, $start, $end - $start + 1);
}
}
此法提取純 SOAP 訊息主體,繞過 MTOM 多部件封裝,完美解決解析失敗。