【发布时间】:2014-10-09 06:04:33
【问题描述】:
我在我的网站中集成了 UPS 运输 API,它允许用户创建运输标签并从中打印出来,
标签已创建,用户也可以打印标签,但是标签正在生成,这基本上是从我正在使用的代码返回的图像文件,但我还想在其上添加公司徽标,请告诉我该怎么做。
-
以下是我用来创建标签的代码
function create_shipping_label($shipping_digest) { // SHIP ACCEPT REQUEST $xmlRequest1 = '<?xml version = "1.0″ encoding = "ISO-8859-1″?> <AccessRequest> <AccessLicenseNumber>' . UPS_ACCESS_LICENCE_NUMBER . '</AccessLicenseNumber> <UserId>' . UPS_USERNAME . '</UserId> <Password>' . UPS_PASSWORD . '</Password> </AccessRequest> <?xml version = "1.0″ encoding = "ISO-8859-1″?> <ShipmentAcceptRequest> <Request> <TransactionReference> <CustomerContext>Customer Comment</CustomerContext> </TransactionReference> <RequestAction>ShipAccept</RequestAction> <RequestOption>1</RequestOption> </Request> <ShipmentDigest>' . $shipping_digest . '</ShipmentDigest> </ShipmentAcceptRequest> '; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, PREFIX."ups.com/ups.app/xml/ShipAccept"); // uncomment the next line if you get curl error 60: error setting certificate verify locations curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // uncommenting the next line is most likely not necessary in case of error 60 // curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $xmlRequest1); curl_setopt($ch, CURLOPT_TIMEOUT, 3600); $xmlResponse = curl_exec($ch); // SHIP ACCEPT RESPONSE $xml = $xmlResponse; preg_match_all("/\<ShipmentAcceptResponse\>(.*?)\<\/ShipmentAcceptResponse\>/s", $xml, $bookblocks); foreach ($bookblocks[1] as $block) { preg_match_all("/\<GraphicImage\>(.*?)\<\/GraphicImage\>/", $block, $author); // GET LABEL preg_match_all("/\<TrackingNumber\>(.*?)\<\/TrackingNumber\>/", $block, $tracking); // GET TRACKING NUMBER // ( $author[1][0] . "\n" );}
return '<img id="shipping_label_image" src="data:image/gif;base64,' . $author[1][0] . '"/>';}
【问题讨论】: