【问题标题】:UPS Shipment API. Can't make multipackage shipmentUPS 运输 API。无法进行多件包裹发货
【发布时间】:2019-04-11 12:24:39
【问题描述】:

我从开发中心下载了适用于 PHP 的 UPS Shipping API。 一切都很好,除了我只能运送 1 件包裹。但我需要进行多包裹运输。 装运中的每个箱子都必须有几个带有所有儿童信息的标签。 但由于标签名称是数组键,我不能制作重复的标签。 谁能帮我解决这个问题?

<?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.......\n";
    print_r($request);
    echo "\n\n";
    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 ."\n";

        //save soap request and response to file
        $fw = fopen($outputFileName , 'w');
        fwrite($fw , "Request: \n" . $client->__getLastRequest() . "\n");
        fwrite($fw , "Response: \n" . $client->__getLastResponse() . "\n");
        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 ."\n";

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

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

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

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

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

?>

【问题讨论】:

    标签: php api ups


    【解决方案1】:

    查看这个UPS API wsdl soap call - cannot set multiple packages

    您有问题的代码:

        $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?
    

    这样的事情应该可以工作:

        $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);
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-07-18
      • 1970-01-01
      • 2020-09-19
      • 1970-01-01
      相关资源
      最近更新 更多