PHP调用DHL SOAP接口获取Base64运单标签遇UNKNOWN_ERROR求助
Let's work through your DHL SOAP API issue step by step. I spot a few key problems in your code that are likely causing that UNKNOWN_ERROR and preventing a successful request:
1. Incorrect SOAP Authentication Header
You're using a Basic Auth-style header, but the DHL API expects a custom Authentification header with explicit user and signature fields (matching the official example). Your current header isn't sending credentials in the format the API expects.
Fix:
Replace your header creation code with this:
// Use the correct namespace from DHL's official example $authNamespace = 'http://dhl.de/webservice/cisbase'; $authHeader = new SoapHeader( $authNamespace, 'Authentification', [ 'user' => '*userid*', // Your actual DHL user ID (e.g., 2222222222_01) 'signature' => '*secret_password*' // Your actual DHL password ] ); // Attach the header to your SOAP client $client->__setSoapHeaders($authHeader);
2. Malformed Request Structure & Missing Namespaces
Your $request array has several mismatches compared to the official SOAP example:
- The
CreateShipmentOrderRequestkey is set to"1"instead of containing the full request payload - Critical fields like
VersionandaccountNumberneed thecisnamespace prefix required by the API - You're passing the request incorrectly to
__soapCall(it expects an array of parameters, not just the request array directly)
Fix:
Reconstruct your request with proper structure and adjust the __soapCall invocation:
$request = [ 'CreateShipmentOrderRequest' => [ 'Version' => [ 'majorRelease' => 2, 'minorRelease' => 0 ], 'ShipmentOrder' => [ 'SequenceNumber' => '01', 'Shipment' => [ 'ShipmentDetails' => [ 'product' => 'V01PAK', 'accountNumber' => '22222222220101' ] // Important: Add mandatory fields here! // The API requires sender/receiver addresses, shipment item details, etc. ] ] ] ]; // Correct __soapCall usage: wrap the request in an array try { $response = $client->__soapCall("createShipmentOrder", [$request]); var_dump($response); } catch (SoapFault $e) { echo 'SOAP Error: ' . $e->getMessage(); // Debug with raw XML to spot discrepancies echo '<br>Request XML: ' . htmlspecialchars($client->__getLastRequest()); echo '<br>Response XML: ' . htmlspecialchars($client->__getLastResponse()); }
3. Missing Mandatory Shipment Fields
Your current request only includes product and accountNumber, but the DHL API requires additional mandatory data to generate a shipment label, including:
- Full sender address details
- Full receiver address details
- Shipment item information (weight, dimensions, content description, etc.)
Refer to DHL's official documentation to add all required fields to your Shipment object—missing these will almost certainly trigger an error even with a correctly formatted request.
Bonus: Debugging Tips
Enable full request/response logging to see exactly what's being sent to the API:
// After making the call, print raw XML for debugging echo '<h3>Raw Request XML</h3>'; echo htmlspecialchars($client->__getLastRequest()); echo '<h3>Raw Response XML</h3>'; echo htmlspecialchars($client->__getLastResponse());
This will help you compare your request to the official SOAP example and spot any remaining issues.
内容的提问来源于stack exchange,提问作者Samuel Zeh

