You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PHP调用DHL SOAP接口获取Base64运单标签遇UNKNOWN_ERROR求助

Troubleshooting Your DHL SOAP API Call (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 CreateShipmentOrderRequest key is set to "1" instead of containing the full request payload
  • Critical fields like Version and accountNumber need the cis namespace 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 06:46:03