繁体   English   中英

通过PHP cUrl创建DHL船标签不起作用

[英]DHL ship label creation through PHP cUrl is not working

我想通过DHL创建货运标签(以pdf格式)。 因此,我创建了所需的xml格式,并通过PHP cUrl发布了相同的格式。

$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;    

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM