在UPS运输标签上添加公司徽标

时间:2014-10-09 06:04:33

标签: php api shipping ups

我已在我的网站中集成了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] . '"/>';
    

    }

1 个答案:

答案 0 :(得分:0)

由于您使用的是激光标签,因此只需在运输标签图像上方或下方返回公司图片的其他HTML。