UPS API wsdl soap调用 - 无法设置多个包

时间:2017-11-11 16:26:34

标签: php wsdl shipping fedex ups

我在PHP中使用wsdl SOAP调用UPS API。请求对象具有包信息,从/到邮政编码和其他信息。我想设置多个包但在请求对象中添加多个包时显示错误。

我试图通过在$ request [' Shipment'] [' Package']数组中推送包数组来分配多个包。这部分出了点问题。

这是我的代码:

$request['Request'] = array('RequestOption' => 'Shop');
    $request['PickupType'] = array('Code' => '01', 'Description' => 'Daily Pickup');
    $request['CustomerClassification'] = array('Code' => '01', 'Description' => 'Classfication');
    $request['Shipment']['Shipper'] = array(
          // Shipper information here
        )
    );
    $request['Shipment']['ShipFrom'] = array('Address' => array(
        'PostalCode' => XX,
        'CountryCode' => 'US'
    )
    );
    $request['Shipment']['ShipTo'] = array('Address' => array(
        'PostalCode' => XX,
        'CountryCode' => 'US'
    )
    );
    $request['Shipment']['Service'] = array('Code' => '03', 'Description' => 'Service Code');

   // Multiple packages are added to the request
    $request['Shipment']['Package'] = array();
    foreach ($packages as $package) {
        $pkg = array();
        $pkg['PackagingType'] = array(
            'Code' => '02',
            'Description' => 'Rate'
        );
        $pkg['PackageWeight'] = array(
            'Weight' => (int)$package["weight"],
            'UnitOfMeasurement' => array('Code' => 'LBS', 'Description' => 'Pounds')
        );
        $pkg['Dimensions'] = array(
            'Length' => (int)$package["length"],
            'Width' => (int)$package["width"],
            'Height' => (int)$package["height"],
            'UnitOfMeasurement' => array('Code' => 'IN', 'Description' => 'inches')
        );

        array_push($request['Shipment']['Package'], $pkg);
    }
   // END packages

    $request['Shipment']['ShipmentServiceOptions'] = '';
    $request['Shipment']['LargePackageIndicator'] = '';

    $mode = array(
        'trace' => 1
    );
    $wsdl = PATH_WSDL . DS . 'RateWS.wsdl';
    $ups_client = new SoapClient($wsdl, $mode);
    $usernameToken['Username'] = XX);
    $usernameToken['Password'] = XX;
    $serviceAccessLicense['AccessLicenseNumber'] = XX;
    $upss['UsernameToken'] = $usernameToken;
    $upss['ServiceAccessToken'] = $serviceAccessLicense;

    $header = new SoapHeader('http://www.ups.com/XMLSchema/XOLTWS/UPSS/v1.0', 'UPSSecurity', $upss);
    $ups_client->__setSoapHeaders($header);
    $resp = $ups_client->__soapCall('ProcessRate', array($request));
    if ($resp->Response->ResponseStatus->Description == 'Success') {
        // Dealing with response here.
    }

0 个答案:

没有答案