dougu5847 2019-04-11 12:24
浏览 253

UPS装运API。 无法进行多件装运

I downloaded UPS Shipping API for PHP from DEV center. Everything woks, except I can make only 1 package shipment. But i need to make multipackage shipments. There has to be few tags with all Child info for each box in shipment. But due to tags name are array keys, i can't make duplicate tags. Can anyone help me to solve this?

<?php

  //Configuration
  $access = "xxx";
  $userid = "xxx";
  $passwd = "A123xxx
  $wsdl = "WSDLs_Shipping/Ship.wsdl";
  $operation = "ProcessShipment";
  $endpointurl = 'https://wwwcie.ups.com/webservices/Ship';
  //$endpointurl = 'https://onlinetools.ups.com/webservices/Ship';
  $outputFileName = "XOLTResult.xml";

  function processShipment()
  {

      //create soap request
    $requestoption['RequestOption'] = 'nonvalidate'; //Valid values: nonvalidate = No street level address validation would be performed, but Postal Code/State combination validation would still be performed. validate = No street level address validation would be performed, but City/State/Postal Code/ combination validation would still be performed.
    $request['Request'] = $requestoption;

    $shipment['Description'] = 'Spare parts'; //The Description of Goods for the shipment. Applies to international and domestic shipments. Provide a detailed description of items being shipped for documents and non-documents. Examples: "annual reports" and "9 mm steel screws".

    $shipper['Name'] = 'FD'; //Shippers company name. For forward Shipment 35 characters are accepted, but only 30 characters will be printed on the label.
    $shipper['AttentionName'] = 'Andriy'; //попробую убрать Shippers Attention Name. For forward Shipment 35 characters are accepted, but only 30 characters will be printed on the label.
    //$shipper['TaxIdentificationNumber'] = '123456'; //Shipper’s Tax Identification Number. Conditionally required if EEI form (International forms) is requested and ship From is not mentioned.
    $shipper['ShipperNumber'] = 'xxxxxx'; //Account number
    $address['AddressLine'] = 'Polevaya 61a'; //The Shipper street address including name and number (when applicable). Up to three occurrences are allowed; only the first is printed on the label. 35 characters are accepted, but for the first occurrence, only 30 characters will be printed on the label for return shipments.
    $address['City'] = 'Kiev';
    //$address['StateProvinceCode'] = 'MD'; //Shipper's state or province code. For forward Shipment 5 characters are accepted, but only 2 characters will be printed on the label.For US, PR and CA accounts, the account must be either a daily pickup account, an occasional account, or a customer B.I.N account.
    $address['PostalCode'] = '03067';
    $address['CountryCode'] = 'UA';
    $shipper['Address'] = $address;
    $phone['Number'] = '+38067611212';
    $phone['Extension'] = '';
    $shipper['Phone'] = $phone;
    $shipment['Shipper'] = $shipper;

$shipment['ReturnService'] = '1';
    $ReturnService['Code'] = '8'; //Return Service types: 2 = UPS Print and Mail (PNM) 3 = UPS Return Service 1-Attempt (RS1) 5 = UPS Return Service 3-Attempt (RS3) 8 = UPS Electronic Return Label (ERL)
    $shipment['ReturnService'] = $ReturnService;
    //$package['Description'] = 'descr';






    $shipto['Name'] = 'Vitaliy '; //Consignee’s company name.
    $shipto['AttentionName'] = 'Vitaliy '; //Contact name at the consignee’s location.
    $addressTo['AddressLine'] = 'Polevaya 61A'; //Address Line of the consignee. Required: Yes Type: String Max Allowed: 3 Length: 1…35.Max occurrence: 3 Only first two Address Lines will be printed on the label.
    $addressTo['City'] = 'Kiev';
    $addressTo['PostalCode'] = '03058';
    $addressTo['CountryCode'] = 'UA';
    $phone2['Number'] = '064655544';
    $shipto['Address'] = $addressTo;
    $shipto['Phone'] = $phone2;
    $shipment['ShipTo'] = $shipto;


    $shipfrom['Name'] = ' Sender 1'; //The ship from location’s name or company name. 35 characters are accepted, but for return Shipment only 30 characters will be printed on the label.
    $shipfrom['AttentionName'] = 'Sender 1'; //The ship from Attention name. 35 characters are accepted, but for return Shipment only 30 characters will be printed on the label.
    $addressFrom['AddressLine'] = '2311 York Rd'; //The Ship from street address including name and number (when applicable). 35 characters are accepted, but for return Shipment only 30 characters will be printed on the label. Required: Yes* Type: String Max Allowed: 3 Length: 1…35. Max occurrence: 3
    $addressFrom['City'] = 'Timonium';
    //$addressFrom['StateProvinceCode'] = 'MD'; //Origin locations state or province code. Required if ShipFrom tag is in the XML, and ShipFrom Country or territory is US. If ShipFrom country or territory is US or CA, then the value must be a valid US State/ Canadian Province code. If the country or territory is Ireland, the StateProvinceCode will contain the county.
    $addressFrom['PostalCode'] = '21093';
    $addressFrom['CountryCode'] = 'CN';
    $phone3['Number'] = '1234567890';
    $phone3['Extension'] = '';
    $shipfrom['Address'] = $addressFrom;
    $shipfrom['Phone'] = $phone3;
    $shipment['ShipFrom'] = $shipfrom;

    $shipmentcharge['Type'] = '01';

    //$billshipper['CreditCard'] = $creditcard;
    $billshipper['AccountNumber'] = 'xxxxxx';
    $shipmentcharge['BillShiper'] = 'xxxxxx';
    $shipmentcharge['BillShipper'] = $billshipper;
    $paymentinformation['ShipmentCharge'] = $shipmentcharge;
    $shipment['PaymentInformation'] = $paymentinformation;

    $service['Code'] = '65';
    $service['Description'] = 'Express Saver';
    $shipment['Service'] = $service;



    $product['NumberOfPackagesPerCommodity'] = '2';
    $internationalForm['Product'] = $product;
    $shpServiceOptions['InternationalForms'] = $internationalForm;
    $shipment['ShipmentServiceOptions'] = $shpServiceOptions;

    $shpLabelDeliveryEmail[LabelLinksIndicator] = ''; //Попробуем, чтобы прислало ссылку на ярлык
    $EmailLabelDelivery[EMailAddress] = 'admin@test.ua';
    $EmailLabelDelivery[UndeliverableEMailAddress] = 'admin@test.ua';
    $EmailLabelDelivery[FromEMailAddress] = 'admin@test.ua';
    $shpLabelDeliveryEmail[EMail] = $EmailLabelDelivery;
    $shpLabelDelivery[LabelDelivery] = $shpLabelDeliveryEmail;

    $shipment['ShipmentServiceOptions'] = $shpLabelDelivery;


    $package['Description'] = 'desc'; //Merchandise description of package.Required for shipment with return service.
    $packaging['Code'] = '02'; //02 = Customer Supplied package
    $packaging['Description'] = 'Nails'; //Description of packaging type. Examples are letter, customer supplied, express box.
    $package['Packaging'] = $packaging;
    $unit['Code'] = 'CM';
    $unit['Description'] = 'CM';
    $dimensions['UnitOfMeasurement'] = $unit;
    $dimensions['Length'] = '50';
    $dimensions['Width'] = '50';
    $dimensions['Height'] = '20';
    $package['Dimensions'] = $dimensions;
    $unit2['Code'] = 'KGS';
    $unit2['Description'] = 'KGS';
    $packageweight['UnitOfMeasurement'] = $unit2;
    $packageweight['Weight'] = '10';
    $package['PackageWeight'] = $packageweight;
    $shipment['Package'] = $package;



    //$shipment['NumOfPiecesInShipment'] = '3';

    $labelimageformat['Code'] = 'GIF';
    $labelimageformat['Description'] = 'GIF';
    $labelspecification['LabelImageFormat'] = $labelimageformat;
    $labelspecification['HTTPUserAgent'] = 'Mozilla/4.5';
    $shipment['LabelSpecification'] = $labelspecification;




//print_r($shipment1);

//    $shipment['DocumentsOnlyIndicator'] = '1'; // IF ONLY documents

    $request['Shipment'] = $shipment;


    echo "Request.......
";
    print_r($request);
    echo "

";
    return $request;

  }

  function processShipConfirm()
  {

    //create soap request

  }

  function processShipAccept()
  {
    //create soap request
  }

  try
  {

    $mode = array
    (
         'soap_version' => 'SOAP_1_1',  // use soap 1.1 client
         'trace' => 1
    );

    // initialize soap client
    $client = new SoapClient($wsdl , $mode);

    //set endpoint url
    $client->__setLocation($endpointurl);


    //create soap header
    $usernameToken['Username'] = $userid;
    $usernameToken['Password'] = $passwd;
    $serviceAccessLicense['AccessLicenseNumber'] = $access;
    $upss['UsernameToken'] = $usernameToken;
    $upss['ServiceAccessToken'] = $serviceAccessLicense;

    $header = new SoapHeader('http://www.ups.com/XMLSchema/XOLTWS/UPSS/v1.0','UPSSecurity',$upss);
    $client->__setSoapHeaders($header);

    if(strcmp($operation,"ProcessShipment") == 0 )
    {
        //get response
    $resp = $client->__soapCall('ProcessShipment',array(processShipment()));

         //get status
        echo "Response Status: " . $resp->Response->ResponseStatus->Description ."
";

        //save soap request and response to file
        $fw = fopen($outputFileName , 'w');
        fwrite($fw , "Request: 
" . $client->__getLastRequest() . "
");
        fwrite($fw , "Response: 
" . $client->__getLastResponse() . "
");
        fclose($fw);

    }
    else if (strcmp($operation , "ProcessShipConfirm") == 0)
    {
            //get response
    $resp = $client->__soapCall('ProcessShipConfirm',array(processShipConfirm()));

         //get status
        echo "Response Status: " . $resp->Response->ResponseStatus->Description ."
";

        //save soap request and response to file
        $fw = fopen($outputFileName , 'w');
        fwrite($fw , "Request: 
" . $client->__getLastRequest() . "
");
        fwrite($fw , "Response: 
" . $client->__getLastResponse() . "
");
        fclose($fw);

    }
    else
    {
        $resp = $client->__soapCall('ProcessShipeAccept',array(processShipAccept()));

        //get status
        echo "Response Status: " . $resp->Response->ResponseStatus->Description ."
";

    //save soap request and response to file
    $fw = fopen($outputFileName ,'w');
    fwrite($fw , "Request: 
" . $client->__getLastRequest() . "
");
        fwrite($fw , "Response: 
" . $client->__getLastResponse() . "
");
        fclose($fw);
    }

  }
  catch(Exception $ex)
  {
    print_r ($ex);
  }

?>
  • 写回答

1条回答 默认 最新

  • douyou9923 2019-04-29 00:42
    关注

    Check this one UPS API wsdl soap call - cannot set multiple packages

    Your problematic code:

        $package['Description'] = 'desc'; //Merchandise description of package.Required for shipment with return service.
        $packaging['Code'] = '02'; //02 = Customer Supplied package
        $packaging['Description'] = 'Nails'; //Description of packaging type. Examples are letter, customer supplied, express box.
        $package['Packaging'] = $packaging;
        $unit['Code'] = 'CM';
        $unit['Description'] = 'CM';
        $dimensions['UnitOfMeasurement'] = $unit;
        $dimensions['Length'] = '50';
        $dimensions['Width'] = '50';
        $dimensions['Height'] = '20';
        $package['Dimensions'] = $dimensions;
        $unit2['Code'] = 'KGS';
        $unit2['Description'] = 'KGS';
        $packageweight['UnitOfMeasurement'] = $unit2;
        $packageweight['Weight'] = '10';
        $package['PackageWeight'] = $packageweight;
        $shipment['Package'] = $package; //Where is the second package?
    

    Something like this should work:

        $package['Shipment']['Package'] = array();
        foreach ($packaging as $p) {
            $pkg = array();
            $pkg['PackagingType'] = array(
                'Code' => '02',
                'Description' => 'Nails'
            );
            $pkg['PackageWeight'] = array(
                'Weight' => (int)$p["weight"],
                'UnitOfMeasurement' => array('Code' => 'KGS', 'Description' => 'KGS')
            );
            $pkg['Dimensions'] = array(
                'Length' => (int)$p["length"],
                'Width' => (int)$p["width"],
                'Height' => (int)$p["height"],
                'UnitOfMeasurement' => array('Code' => 'CM', 'Description' => 'CM')
            );
    
            array_push($package['Shipment']['Package'], $pkg);
        }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败