通过 PHP cUrl 创建 DHL 寄件标签无效

DHL ship label creation through PHP cUrl is not working

我想通过 DHL 创建发货标签(pdf 格式)。因此,我通过 PHP cUrl.

创建了所需的 xml 格式和 post 相同的格式
$message_ref = '';
for ($i=0; $i< 30; $i++)
{
    $message_ref .= rand(0, 9);

}   
$message_time = date("Y-m-d") . "T" . date("H:i:sP");

下面是XML的代码

<?xml version="1.0" encoding="ISO-8859-1"?>
<req:ShipmentValidateRequest xmlns:req="http://www.dhl.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.dhl.com ship-val-req.xsd">
<Request>
<ServiceHeader>
<MessageTime>$message_time</MessageTime>
<MessageReference>$message_ref</MessageReference>
<SiteID>XXXXX</SiteID>
<Password>XXXXX</Password>
</ServiceHeader>
</Request>
<RequestedPickupTime>N</RequestedPickupTime>
<NewShipper>N</NewShipper>
<LanguageCode>en</LanguageCode>
<PiecesEnabled>Y</PiecesEnabled>
<Billing>
<ShipperAccountNumber>XXXXX</ShipperAccountNumber>
<ShippingPaymentType>S</ShippingPaymentType>
<BillingAccountNumber>XXXXX</BillingAccountNumber>
<DutyPaymentType>R</DutyPaymentType>
</Billing>
<Consignee>
<CompanyName>-</CompanyName>
<AddressLine>Address 1 </AddressLine>
<City>Enugu</City>
<Division>Enugu</Division>
<DivisionCode>EN</DivisionCode>
<PostalCode></PostalCode>
<CountryCode>NG</CountryCode>
<CountryName>Nigeria</CountryName>
<Contact>
<PersonName>DDDDDD</PersonName>
<PhoneNumber>+23555555555</PhoneNumber>
<PhoneExtension></PhoneExtension>
</Contact>
</Consignee>
<Dutiable>
<DeclaredValue>0.00</DeclaredValue>
<DeclaredCurrency>USD</DeclaredCurrency>
<TermsOfTrade>DAP</TermsOfTrade>
</Dutiable>
<Reference>
<ReferenceID>129624</ReferenceID>
<ReferenceType>St</ReferenceType>
</Reference>
<ShipmentDetails>
<NumberOfPieces>1</NumberOfPieces>
<Pieces><Piece>
<PieceID>1</PieceID>
<PackageType>EE</PackageType>
<Weight>1</Weight>
<DimWeight>1</DimWeight>
<Width>1</Width>
<Height>1</Height>
<Depth>1</Depth>
<PieceContents></PieceContents>
</Piece></Pieces>
<Weight>1</Weight>
<WeightUnit>L</WeightUnit>
<GlobalProductCode>P</GlobalProductCode>
<Date>2018-06-22</Date>
<Contents>SHIPMENT #129624</Contents>
<DoorTo>DD</DoorTo>
<DimensionUnit>I</DimensionUnit>
<PackageType>EE</PackageType>
<IsDutiable>N</IsDutiable>
<CurrencyCode>USD</CurrencyCode>
</ShipmentDetails>
<Shipper>
<ShipperID>XXXXXX</ShipperID>
<CompanyName>CompanyName</CompanyName>
<RegisteredAccount>848XXXX</RegisteredAccount>
<AddressLine>MyAddress </AddressLine>
<City>Houston</City>
<Division>Texas</Division>
<DivisionCode>TX</DivisionCode>
<PostalCode>77031</PostalCode>
<CountryCode>US</CountryCode>
<CountryName>United States</CountryName>
<Contact>
<PersonName>Urama</PersonName>
<PhoneNumber>65656565</PhoneNumber>
<PhoneExtension></PhoneExtension>
</Contact>
</Shipper>
<EProcShip>N</EProcShip>
<LabelImageFormat>PDF</LabelImageFormat>
<RequestArchiveDoc>Y</RequestArchiveDoc>
<Label>
<LabelTemplate>8X4_thermal</LabelTemplate>
<Logo>Y</Logo>
<Resolution>200</Resolution>
</Label>
</req:ShipmentValidateRequest>

下面是 cUrl 代码:

$url = "https://xmlpi-ea.dhl.com/XMLShippingServlet";

已修改 ---

$ch = curl_init($url);
            curl_setopt($ch, CURLOPT_MUTE, 1);
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: text/xml'));
            curl_setopt($ch, CURLOPT_POSTFIELDS, "$query");
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            $output = curl_exec($ch);
            curl_close($ch);
#print_r($output);

preg_match("/<OutputImage>(.*?)<\/OutputImage>/", $output, $matches);
   $image = base64_decode($matches[1]);

<img src="data:image/gif;base64,<?=$image?>">

现在我看到图像在浏览器中显示垃圾字符。我在 $image 之前附加了 "data:image/gif;base64," 但仍然显示垃圾字符。有人可以帮助我如何显示图像吗?

最后我通过添加代码解决了它:

header("Content-type:application/pdf");
header("Content-Disposition:inline;filename=label_123demo.pdf");
echo $image;