问题
I am using wsdl SOAP call in PHP for UPS API. The request object have package information, from/to zipcodes, and other information. I want to set multiple packages but it shows error when more than one package is added in the request object.
I am trying to assign multiple packages by pushing package array in the $request['Shipment']['Package'] array. Something is wrong in this part.
Here is my code:
$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.
}
来源:https://stackoverflow.com/questions/47240148/ups-api-wsdl-soap-call-cannot-set-multiple-packages