使用运输验证时收到肥皂错误

时间:2014-06-04 10:19:24

标签: php soap

我正在使用purolator.com的ValidateShipment.php。我包含了所有wsdl文件,包括产品密钥和密码。但仍然得到错误。 肥皂已经启用。

你可以在这里看到错误

Warning: Creating default object from empty value in /home/bandito/public_html/ValidateShipment.php on line 64

Warning: Creating default object from empty value in /home/bandito/public_html/ValidateShipment.php on line 71

Warning: Creating default object from empty value in /home/bandito/public_html/ValidateShipment.php on line 75

Warning: Creating default object from empty value in /home/bandito/public_html/ValidateShipment.php on line 82

Warning: Creating default object from empty value in /home/bandito/public_html/ValidateShipment.php on line 90

 Warning: Creating default object from empty value in /home/bandito/public_html/ValidateShipment.php on line 95

Warning: Creating default object from empty value in /home/bandito/public_html/ValidateShipment.php on line 99

Warning: Creating default object from empty value in /home/bandito/public_html/ValidateShipment.php on line 101

Warning: Creating default object from empty value in /home/bandito/public_html/ValidateShipment.php on line 106

 Fatal error: Uncaught SoapFault exception: [HTTP] Unauthorized in /home/bandito/public_html/ValidateShipment.php:110 Stack trace: #0 [internal function]: SoapClient->__doRequest('<?xml version="...', 'https://webserv...', 'http://purolato...', 1, 0) #1 /home/bandito/public_html/ValidateShipment.php(110): SoapClient->__call('ValidateShipmen...', Array) #2 /home/bandito/public_html/ValidateShipment.php(110): SoapClient->ValidateShipment(Object(stdClass)) #3 {main} thrown in /home/bandito/public_html/ValidateShipment.php on line 110

这是我的PHP代码 - :

define("PRODUCTION_KEY", "**********************");
define("PRODUCTION_PASS", "***********");
define("BILLING_ACCOUNT", "**********");
define("REGISTERED_ACCOUNT", "**********");

function createPWSSOAPClient()
{
  $client = new SoapClient( "wsdl/ShippingService.wsdl", 
                        array   (
                                'trace'         =>  true,
                                'location'  =>  "https://webservices.purolator.com/PWS/V1/Shipping/ShippingService.asmx",
                                'uri'               =>  "http://purolator.com/pws/datatypes/v1",
                                'login'         =>  PRODUCTION_KEY,
                                'password'  =>  PRODUCTION_PASS
                              )
                      );
   //Define the SOAP Envelope Headers
     $headers[] = new SoapHeader ( 'http://purolator.com/pws/datatypes/v1', 
                            'RequestContext', 
                            array (
                                    'Version'           =>  '1.4',
                                    'Language'          =>  'en',
                                    'GroupID'           =>  'xxx',
                                    'RequestReference'  =>  'Rating Example'
                                  )
                          ); 
      //Apply the SOAP Header to your client                            
      $client->__setSoapHeaders($headers);

  return $client;
   }

 /********************************************************************************* 
  Validate Shipment Example(s)
  EXAMPLE 01:
  1 piece shipment, 10lbs, Purolator Express Service on a Thermal 4x6 Label
 *********************************************************************************/ 
  //Create a SOAP Client for Example 01
  $client = createPWSSOAPClient();

  //Populate the Origin Information
    $request->Shipment->SenderInformation->Address->Name = "Aaron Summer";
     $request->Shipment->SenderInformation->Address->StreetNumber = "1234";
    $request->Shipment->SenderInformation->Address->StreetName = "Main Street";
   $request->Shipment->SenderInformation->Address->City = "Mississauga";
   $request->Shipment->SenderInformation->Address->Province = "ON";
   $request->Shipment->SenderInformation->Address->Country = "CA";
   $request->Shipment->SenderInformation->Address->PostalCode = "L4W5M8";    
   $request->Shipment->SenderInformation->Address->PhoneNumber->CountryCode = "1";
   $request->Shipment->SenderInformation->Address->PhoneNumber->AreaCode = "905";
   $request->Shipment->SenderInformation->Address->PhoneNumber->Phone = "5555555";
   //Populate the Desination Information
   $request->Shipment->ReceiverInformation->Address->Name = "Aaron Summer";
   $request->Shipment->ReceiverInformation->Address->StreetNumber = "2245";
   $request->Shipment->ReceiverInformation->Address->StreetName = "Douglas Road";
   $request->Shipment->ReceiverInformation->Address->City = "Burnaby";
   $request->Shipment->ReceiverInformation->Address->Province = "BC";
   request->Shipment->ReceiverInformation->Address->Country = "CA";
   $request->Shipment->ReceiverInformation->Address->PostalCode = "V5C5A9";    
   $request->Shipment->ReceiverInformation->Address->PhoneNumber->CountryCode = "1";
   $request->Shipment->ReceiverInformation->Address->PhoneNumber->AreaCode = "604";
   $request->Shipment->ReceiverInformation->Address->PhoneNumber->Phone = "2982181";

   //Future Dated Shipments - YYYY-MM-DD format
   $request->Shipment->ShipmentDate = "YOUR_SHIPMENT_DATE_HERE";

   //Populate the Package Information
   $request->Shipment->PackageInformation->TotalWeight->Value = "10";
   $request->Shipment->PackageInformation->TotalWeight->WeightUnit = "lb";
   $request->Shipment->PackageInformation->TotalPieces = "1";
   $request->Shipment->PackageInformation->ServiceID = "PurolatorExpress";
   //Populate the Payment Information
   $request->Shipment->PaymentInformation->PaymentType = "Sender";
   $request->Shipment->PaymentInformation->BillingAccountNumber = BILLING_ACCOUNT;
   $request->Shipment->PaymentInformation->RegisteredAccountNumber = REGISTERED_ACCOUNT;
   //Populate the Pickup Information
   $request->Shipment->PickupInformation->PickupType = "DropOff";
   //Shipment Reference
   $request->Shipment->TrackingReferenceInformation->Reference1 = "Reference For Shipment";
   //Define the Shipment Document Type
   $request->PrinterType = "Thermal";

   //Define OptionsInformation
   $request->OptionsInformation->Options->OptionIDValuePair->ID = "residentialsignaturedomestic";
   $request->OptionsInformation->Options->OptionIDValuePair->Value = "true";

   //Execute the request and capture the response
   $response = $client->ValidateShipment($request);

   print_r($response);

2 个答案:

答案 0 :(得分:0)

未声明$request类。 PHP猜测它是一个对象并声明它。

尝试:

$request = new stdClass;
$request->Shipment = new stdClass;
$request->Shipment->ReceiverInformatio = new stdClass;

$request列表开始之前放置。

//Populate the Origin Information
$request->Shipment->SenderInformation->Address->Name = "Aaron Summer";

答案 1 :(得分:0)

替换此行

$request->Shipment->SenderInformation->Address->Name = "Aaron Summer";

使用

@$request->Shipment->SenderInformation->Address->Name = "Aaron Summer";
相关问题