我也在尋找追蹤號碼。我成功創建了PDF,並且有一個條形碼號碼,但沒有跟蹤號碼。
下面是我的代碼,它工作正常。
$devurl = "https://secure.shippingapis.com/ShippingAPI.dll";
$xml = rawurlencode('<DelivConfirmCertifyV4.0Request USERID="your User id">
<Option>1</Option>
<ImageParameters>
<LabelSequence>
<PackageNumber>1</PackageNumber>
<TotalPackages>99</TotalPackages>
</LabelSequence>
</ImageParameters>
<FromName>Joe Smith</FromName>
<FromFirm>ABC Corp.</FromFirm>
<FromAddress1>Apt. 3C</FromAddress1>
<FromAddress2>6406 Ivy Lane</FromAddress2>
<FromCity>Greenbelt</FromCity>
<FromState>MD</FromState>
<FromZip5>20770</FromZip5>
<FromZip4>1234</FromZip4>
<ToName>Tom XofY</ToName>
<ToFirm>XYZ Corp.</ToFirm>
<ToAddress1>Suite 4D</ToAddress1>
<ToAddress2>8 Wildwood Drive</ToAddress2>
<ToCity>Old Lyme</ToCity>
<ToState>CT</ToState>
<ToZip5>06371</ToZip5>
<ToZip4></ToZip4>
<WeightInOunces>2</WeightInOunces>
<ServiceType>Priority</ServiceType>
<InsuredAmount></InsuredAmount>
<SeparateReceiptPage></SeparateReceiptPage>
<POZipCode></POZipCode>
<ImageType>PDF</ImageType>
<LabelDate></LabelDate>
<CustomerRefNo></CustomerRefNo>
<AddressServiceRequested></AddressServiceRequested>
<SenderName> Imtiyaz</SenderName>
<SenderEMail>[email protected]</SenderEMail>
<RecipientName></RecipientName>
<RecipientEMail></RecipientEMail>
<Container>Variable</Container>
<Size>Regular</Size>
<CommercialPrice>True</CommercialPrice>
<Content>
<ContentType>LIVES</ContentType>
<ContentDescription>Bees</ContentDescription>
</Content>
</DelivConfirmCertifyV4.0Request>');
$service = 'DelivConfirmCertifyV4';
$request = $devurl . "?API=" . $service . "&xml=" . $xml;
$response = SendRequest($request);
//print_r($response);
$xml = new SimpleXMLElement($response);
$myfile = fopen("trackingcreate.pdf", "w") or die("Unable to open file!");
fwrite($myfile, base64_decode($xml->DeliveryConfirmationLabel));
$json =json_encode($xml);
$resarray = json_decode($json);
echo "<br><b>DeliveryConfirmationNumber :</b> ".$resarray->DeliveryConfirmationNumber;
echo "<br><br><b>ToName : </b> ".$resarray->ToName;
echo " <br><br><b>ToFirm : </b> ".$resarray->ToFirm;
echo "<br><br><b>ToAddress1 : </b> ".$resarray->ToAddress1;
echo "<br><br><b>ToCity : </b> ".$resarray->ToCity;
echo "<br><br><b>Postnet : </b> ".$resarray->Postnet;
echo "<br><br><b>RDC : </b> ".$resarray->RDC;
echo "<br><br><b>InsuranceFee : </b> ".$resarray->InsuranceFee;
echo "<br><br><b>Postage : </b> ".$resarray->Postage;
echo "<br><br><b>CarrierRoute : </b> ". $resarray->CarrierRoute;
function SendRequest($request){
$session = curl_init();
curl_setopt($session, CURLOPT_URL, $request);
curl_setopt($session, CURLOPT_HTTPGET, 1);
curl_setopt($session, CURLOPT_HEADER, false);
curl_setopt($session, CURLOPT_SSL_VERIFYPEER , false);
curl_setopt($session, CURLOPT_SSL_VERIFYHOST , false);
curl_setopt($session, CURLOPT_HTTPHEADER, array('Accept: application/xml', 'Content-Type: application/xml'));
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($session);
curl_close($session);
return $response;
}
注意顯示的API(DelivConfirmCertifyV4.0Request)僅用於測試。爲了使這種生產代碼,使這兩個變化:
只需複製並粘貼到任何文件示例我的文件夾/ filename.php 運行代碼,您將在我的文件夾中獲得pdf文件(trackingcreate.pdf) –