2013-03-25 122 views
0

SOAP请求是送往联邦快递送货标签API不发送地址2

<?xml version="1.0" encoding="UTF-8"?> 
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://fedex.com/ws/ship/v12"> 
    <SOAP-ENV:Body> 
    <ns1:ProcessShipmentRequest> 
     <ns1:WebAuthenticationDetail> 
     <ns1:UserCredential> 
      <ns1:Key>kQyj3MtQGLJ3ZYWG</ns1:Key> 
      <ns1:Password>66ywMwyasljK5uRkaNENRZCZW</ns1:Password> 
     </ns1:UserCredential> 
     </ns1:WebAuthenticationDetail> 
     <ns1:ClientDetail> 
     <ns1:AccountNumber>510087682</ns1:AccountNumber> 
     <ns1:MeterNumber>100154483</ns1:MeterNumber> 
     </ns1:ClientDetail> 
     <ns1:TransactionDetail> 
     <ns1:CustomerTransactionId>*** Express Domestic Shipping Request v12 using PHP ***</ns1:CustomerTransactionId> 
     </ns1:TransactionDetail> 
     <ns1:Version> 
     <ns1:ServiceId>ship</ns1:ServiceId> 
     <ns1:Major>12</ns1:Major> 
     <ns1:Intermediate>1</ns1:Intermediate> 
     <ns1:Minor>0</ns1:Minor> 
     </ns1:Version> 
     <ns1:RequestedShipment> 
     <ns1:ShipTimestamp>2013-03-25T14:33:08+00:00</ns1:ShipTimestamp> 
     <ns1:DropoffType>REGULAR_PICKUP</ns1:DropoffType> 
     <ns1:ServiceType>FEDEX_GROUND</ns1:ServiceType> 
     <ns1:PackagingType>YOUR_PACKAGING</ns1:PackagingType> 
     <ns1:TotalWeight> 
      <ns1:Units>LB</ns1:Units> 
      <ns1:Value>17.22</ns1:Value> 
     </ns1:TotalWeight> 
     <ns1:Shipper> 
      <ns1:Contact> 
      <ns1:PersonName>Shipping Department</ns1:PersonName> 
      <ns1:CompanyName>Big Dog Treestands</ns1:CompanyName> 
      <ns1:PhoneNumber>3092636800</ns1:PhoneNumber> 
      </ns1:Contact> 
      <ns1:Address> 
      <ns1:StreetLines>120 E. Detroit Parkway</ns1:StreetLines> 
      <ns1:City>Morton</ns1:City> 
      <ns1:StateOrProvinceCode>IL</ns1:StateOrProvinceCode> 
      <ns1:PostalCode>61550</ns1:PostalCode> 
      <ns1:CountryCode>US</ns1:CountryCode> 
      </ns1:Address> 
     </ns1:Shipper> 
     <ns1:Recipient> 
      <ns1:Contact> 
      <ns1:PersonName>David Sinc</ns1:PersonName> 
      <ns1:CompanyName>TEST COMPANY</ns1:CompanyName> 
      <ns1:PhoneNumber>3093701229</ns1:PhoneNumber> 
      </ns1:Contact> 
      <ns1:Address> 
      <ns1:StreetLines>1202 Chalet Ln</ns1:StreetLines> 
      <ns1:StreetLines>HIDDLY- Test Account</ns1:StreetLines> 
      <ns1:City>PEORIA</ns1:City> 
      <ns1:StateOrProvinceCode>IL</ns1:StateOrProvinceCode> 
      <ns1:PostalCode>61614</ns1:PostalCode> 
      <ns1:CountryCode>US</ns1:CountryCode> 
      <ns1:Residential>false</ns1:Residential> 
      </ns1:Address> 
     </ns1:Recipient> 
     <ns1:ShippingChargesPayment> 
      <ns1:PaymentType>SENDER</ns1:PaymentType> 
      <ns1:Payor> 
      <ns1:ResponsibleParty> 
       <ns1:AccountNumber>510087682</ns1:AccountNumber> 
       <ns1:Contact/> 
       <ns1:Address> 
       <ns1:CountryCode>US</ns1:CountryCode> 
       </ns1:Address> 
      </ns1:ResponsibleParty> 
      </ns1:Payor> 
     </ns1:ShippingChargesPayment> 
     <ns1:LabelSpecification> 
      <ns1:LabelFormatType>COMMON2D</ns1:LabelFormatType> 
      <ns1:ImageType>PDF</ns1:ImageType> 
      <ns1:LabelStockType>PAPER_8.5X11_TOP_HALF_LABEL</ns1:LabelStockType> 
     </ns1:LabelSpecification> 
     <ns1:RateRequestTypes>ACCOUNT</ns1:RateRequestTypes> 
     <ns1:PackageCount>1</ns1:PackageCount> 
     <ns1:RequestedPackageLineItems> 
      <ns1:SequenceNumber>1</ns1:SequenceNumber> 
      <ns1:GroupPackageCount>1</ns1:GroupPackageCount> 
      <ns1:Weight> 
      <ns1:Units>LB</ns1:Units> 
      <ns1:Value>17.22</ns1:Value> 
      </ns1:Weight> 
     </ns1:RequestedPackageLineItems> 
     </ns1:RequestedShipment> 
    </ns1:ProcessShipmentRequest> 
    </SOAP-ENV:Body> 
</SOAP-ENV:Envelope> 

联邦快递应用项目代码

<?php 

// Copyright 2009, FedEx Corporation. All rights reserved. 
// Version 12.0.0 

require_once('library/fedex-common.php5'); 


//The WSDL is not included with the sample code. 
//Please include and reference in $path_to_wsdl variable. 
$path_to_wsdl = "http://bigdog.webdesign309.com/wp-content/themes/bigdogtreestands-new/woocommerce/emails/ShipWebServiceClient/wsdl/ShipService_v12.wsdl"; 
$uploads = wp_upload_dir(); 
define('SHIP_LABEL', $uploads['basedir'].'/shippinglabels/shipexpresslabel'.str_replace('#','',$order->get_order_number()).'.pdf'); // PNG label file. Change to file-extension .pdf for creating a PDF label (e.g. shiplabel.pdf) 

ini_set("soap.wsdl_cache_enabled", "0"); 

$client = new SoapClient($path_to_wsdl, array('trace' => 1)); // Refer to http://us3.php.net/manual/en/ref.soap.php for more information 


$request['WebAuthenticationDetail'] = array(
    'UserCredential' => array(
     'Key' => getProperty('key'), 
     'Password' => getProperty('password') 
    ) 
); 
$request['ClientDetail'] = array(
    'AccountNumber' => getProperty('shipaccount'), 
    'MeterNumber' => getProperty('meter') 
); 
$request['TransactionDetail'] = array('CustomerTransactionId' => '*** Express Domestic Shipping Request v12 using PHP ***'); 
$request['Version'] = array(
    'ServiceId' => 'ship', 
    'Major' => '12', 
    'Intermediate' => '1', 
    'Minor' => '0' 
); 
$ships = $order->get_shipping_method(); 
$shippingType = "FEDEX_GROUND"; 
if($ships == "Fedex Ground"){ 
    $shippingType = "FEDEX_GROUND"; 
} 
else if($ships == "Fedex 2 Day"){ 
    $shippingType = "FEDEX_2_DAY"; 
} 
else if($ships == "Fedex Standard Overnight"){ 
    $shippingType = "STANDARD_OVERNIGHT"; 
} 
else if($ships == "Fedex Home Delivery"){ 
     $shippingType = "GROUND_HOME_DELIVERY"; 
} 
function totalOrderWeight($orders) { 
    $totalWeight = 0; 
    $items = $orders->get_items(); 
    foreach($items as $item) { 
     $product = get_product($item['product_id']); 
     $quantity = intval($item['qty']); 
     $totalWeight += $product->get_weight() * $quantity; 
    } 
    return $totalWeight; 
} 

$request['RequestedShipment'] = array(
    'ShipTimestamp' => date('c'), 
    'DropoffType' => 'REGULAR_PICKUP', // valid values REGULAR_PICKUP, REQUEST_COURIER, DROP_BOX, BUSINESS_SERVICE_CENTER and STATION 
    'ServiceType' => $shippingType, // valid values STANDARD_OVERNIGHT, PRIORITY_OVERNIGHT, FEDEX_GROUND, ... 
    'PackagingType' => 'YOUR_PACKAGING', // valid values FEDEX_BOX, FEDEX_PAK, FEDEX_TUBE, YOUR_PACKAGING, ... 
    'TotalWeight' => array('Value' => totalOrderWeight($order), 'Units' => 'LB'), // valid values LB and KG 
    'Shipper' => addShipper(), 
    'Recipient' => addRecipient($order), 
    'ShippingChargesPayment' => addShippingChargesPayment(), 
    'LabelSpecification' => addLabelSpecification(), 
    'RateRequestTypes' => array('ACCOUNT'), // valid values ACCOUNT and LIST 
    'PackageCount' => 1, 
    'RequestedPackageLineItems' => array(
     '0' => addPackageLineItem1(totalOrderWeight($order)) 
    ) 
); 
try 
{ 
    if(setEndpoint('changeEndpoint')) 
    { 
     $newLocation = $client->__setLocation(setEndpoint('endpoint')); 
    } 

    $response = $client->processShipment($request); // FedEx web service invocation 

    if ($response->HighestSeverity != 'FAILURE' && $response->HighestSeverity != 'ERROR') 
    {  
     printSuccess($client, $response); 


     $label = 
     // Create PNG or PDF label 
     // Set LabelSpecification.ImageType to 'PDF' or 'PNG for generating a PDF or a PNG label  
     $fp = fopen(SHIP_LABEL, 'wb'); 
     fwrite($fp, $response->CompletedShipmentDetail->CompletedPackageDetails->Label->Parts->Image); //Create PNG or PDF file 
     fclose($fp); 
    // echo '<a href="'.$uploads['url'].'/shippinglabels/shipexpresslabel'.str_replace('#','',$order->get_order_number()).'.pdf">Click Here to Download Shipping Label</a> was generated.'; 
    } 
    else 
    { 
     printError($client, $response); 
    } 

    writeToLog($client); // Write to log file 

} catch (SoapFault $exception) { 
    printFault($exception, $client); 
} 
function addShipper(){ 
    $shipper = array(
     'Contact' => array(
      'PersonName' => 'Shipping Department', 
      'CompanyName' => 'Big Dog Treestands', 
      'PhoneNumber' => '3092636800'), 
     'Address' => array(
      'StreetLines' => array('120 E. Detroit Parkway'), 
      'City' => 'Morton', 
      'StateOrProvinceCode' => 'IL', 
      'PostalCode' => '61550', 
      'CountryCode' => 'US') 
    ); 
    return $shipper; 
} 
function addRecipient($orders){ 
    $residential = get_post_meta($orders->get_order_number(), '_residential-indicator'); 
/* echo 'Shipping Address 2:'.$orders->shipping_address_2; 
    echo 'Shipping Address 1:'.$orders->shipping_address_1; */ 
    if($orders->shipping_address_2){ 
     $addressArray = array($orders->shipping_address_1, $orders->shipping_address_2); 
/*  echo 'Shipping Address 2'; */ 
      /* $addressArray =array('StreetLines' => array('Address Line 1' => $orders->shipping_address_1, 'Address Line 2' => $orders->shipping_address_2)); */ 
    } 
    else{ 
     $addressArray = array($orders->shipping_address_1); 
/*  echo 'Shipping Address 1'; */ 
    } 
    $joy = false; 
    if($residential == 1){ 
     $joy = true; 
    } 
    else{ 
     $joy = false; 
    } 
      $recipient = array(
     'Contact' => array(
      'PersonName' => $orders->billing_first_name . ' ' . $orders->billing_last_name, 
      'CompanyName' => $orders->shipping_company, 
      'PhoneNumber' => $orders->billing_phone), 
/*   'Address' => array(
      'StreetLines' => array($orders->shipping_address_1, $orders->shipping_address_2), 
      'City' => $orders->shipping_city, 
      'StateOrProvinceCode' => $orders->shipping_state, 
      'PostalCode' => $orders->shipping_postcode, 
      'CountryCode' => 'US', 
      'Residential' => $joy) */ 
     'Address' => array(
      'StreetLines'=>array($orders->shipping_address_1, $orders->shipping_address_2), 
      //array(utf8_encode($orders->shipping_address_1), utf8_encode($orders->shipping_address_2)), 
      'City' => $orders->shipping_city, 
      'StateOrProvinceCode' => $orders->shipping_state, 
      'PostalCode' => $orders->shipping_postcode, 
      'CountryCode' => 'US', 
      'Residential' => $joy) 
    ); 
    return $recipient;          
} 
function addShippingChargesPayment(){ 
    $shippingChargesPayment = array('PaymentType' => 'SENDER', 
     'Payor' => array(
     'ResponsibleParty' => array(
      'AccountNumber' => getProperty('billaccount'), 
      'Contact' => null, 
      'Address' => array('CountryCode' => 'US')))); 
    return $shippingChargesPayment; 
} 
function addLabelSpecification(){ 
    $labelSpecification = array(
     'LabelFormatType' => 'COMMON2D', // valid values COMMON2D, LABEL_DATA_ONLY 
     'ImageType' => 'PDF', // valid values DPL, EPL2, PDF, ZPLII and PNG 
     'LabelStockType' => 'PAPER_8.5X11_TOP_HALF_LABEL'); 
    return $labelSpecification; 
} 
function addPackageLineItem1($weight){ 
    $packageLineItem = array(
     'SequenceNumber'=>1, 
     'GroupPackageCount'=>1, 
     'Weight' => array(
      'Value' => $weight, 
      'Units' => 'LB') 

    ); 
    return $packageLineItem; 
} 

?> 

它返回http://bigdog.webdesign309.com/assets/shippinglabels/shipexpresslabel1303.pdf

我已经尝试了一切甚至称联邦快递,他们说他们不支持这个问题,因为代码是一种便利而非服务。如果任何人都可以对这个最令人困惑的问题进行阐述,那么为什么第二个地址字段永远不会显示出来会很棒。 对此有任何想法?

+0

如果您对任何问题有任何想法,请发布任何内容。我有任何建议。谢谢! – 2013-03-26 14:08:37

+0

我假设你的意思是你在收件人地址2上遇到问题而没有在标签上显示?您的.PDF文件链接已损坏,因此我看不到它。 – RianBattle 2015-08-18 17:35:18

回答

0

它应该有多个地址行,因为您的XML看起来有效。 FedEx支持应能够基于SOAP请求/响应提供帮助,但不会为您的PHP编码提供帮助。

2

如果有其他人遇到此问题,请注意,FedEx的暂存环境中的测试标签似乎永远不会包含第二条地址线。

我所有的测试标签都没有第二个地址行,但只要切换到生产服务器,标签就有第二行。