Tôi đang cố gắng xử lý các phản hồi SWA từ một dịch vụ SOAP Java. Trong phản hồi SWA đó là một tệp đính kèm nhị phân được thêm vào cuối XML cùng với một số tiêu đề MIME. Tôi không thể sử dụng WSO2 cho các giới hạn yêu cầu phụ thuộc.PHP - mở rộng SoapClient để xử lý SWA (SOAP với phần đính kèm)
Mọi trợ giúp sẽ được đánh giá cao!
// Input
------=_Part_42_539586119.1332526191981
Content-Type: text/xml; charset=UTF-8
Content-Transfer-Encoding: binary
Content-Id: <03B4708A9544C182C43E51D9ADA1E456>
<?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body> ... TRUNCATED XML SOAP RESPONSE ... </soapenv:Body></soapenv:Envelope>
------=_Part_42_539586119.1332526191981
Content-Type: image/png
Content-Transfer-Encoding: binary
Content-Id: <D637B1257E3E5EEA06AF0E45494F8448>
BINARY DATA GOES HERE
// End of input
// Script để phân chia các phản ứng + trở StdObj giống như lớp cha mẹ SoapClient + làm điều gì đó với các tập tin
namespace Project;
class SoapClient extends \SoapClient
{
public function __call ($function_name, $arguments)
{
// have the parent do a soap call, catch the lastResponse() if an error
// occurred (eg has an attachment) and parse it out.
try {
$r = parent::__call($function_name, $arguments);
return $r;
} catch (\Exception $e) {
// Assumption: When this is sent, it means that a file is being sent
// because SimpleXML can't process it.
if ($e->getMessage() == "looks like we got no XML document") {
$response = parent::__getLastResponse();
$partString = "/(------=_[a-zA-Z0-9_\\.]+)/";
$outputArr = preg_split($partString, $response);
// $outputAtt[0] -- empty and is the first MIME Part Header
// $outputArr[1] -- Mime Header + XML (The SOAP Response)
// $outputArr[n+1] -- additional files w/ MIME headers
if (array_key_exists(1, $outputArr)) {
// remove the first 5 lines (4 MIME Header lines) + 1 Blank
// line
$data = implode("\n",
array_slice(explode("\n", $outputArr[1]), 5));
/// Simple XML Object ... appears to be an empty SimpleXMLElement though ... >:-(
$xml = simplexml_load_string($data, null, null, "http://schemas.xmlsoap.org/soap/envelope/");
} else {
// OK Maybe this doesn't actually contain the XML... throw
// the original exception.
throw new \SoapFault($e->getMessage(), $e->getCode(),
$e->getPrevious());
}
} else {
throw new \SoapFault($e->getMessage(), $e->getCode(),
$e->getPrevious());
}
}
}
}
Bạn nên cung cấp thêm thông tin, tôi không thể hiểu được vấn đề ở đâu. Các bộ phận này có được mã hóa không? XML hợp lệ phải không? Bạn đã phân tích nó chưa? Bạn đã thử một số lỗi đăng nhập với [libxml_get_errors()] (http://php.net/manual/function.libxml-get-errors.php)? –
đó là một nỗ lực kiểu hack thú vị để lấy tệp đính kèm nhị phân từ tiêu đề. Tôi đã đi vào hướng này một lúc. –
Bạn nên thử sử dụng [mở rộng trình phân tích cú pháp MIME] (https://code.google.com/p/php-mime-mail-parser/) để phân tích cú pháp tải trọng, thay vì tự động chỉnh sửa. – quickshiftin