php UPS配送API:在SoapFault对象中未找到错误

ct3nt3jp  于 2023-01-16  发布在  PHP
关注(0)|答案(1)|浏览(77)

我从ups.com下载的航运PHP的例子。我试图将此集成在Opencart CMS。我希望当管理员输入订单ID,然后与API的帮助下,我想生成跟踪代码。
现在,我正在使用的测试航运值的参数参数。一旦代码工作正常,我会使他们根据订单ID的动态。
但是当我运行代码时,我得到了一个未找到的异常。我看了UPS的文档,但文档写得不好,我没有找到错误的原因。下面是异常输出:

SoapFault Object
    (
        [message:protected] => Not Found
        [string:Exception:private] => 
        [code:protected] => 0
        [file:protected] => my_opencart_root_path/admin/controller/sale/ups_shipping.php
        [line:protected] => 50
        [trace:Exception:private] => Array
            (
                [0] => Array
                    (
                        [function] => __doRequest
                        [class] => SoapClient
                        [type] => ->
                        [args] => Array
                            (
                                [0] => 
    nonvalidateTest Product for shipping APIMy StoreShipperZs Attn Name12345611155547581Your Shipper Number2311 York RdTimoniumMD21093USHappy Dog Pet SupplyShip To Attention Name9225377171GOERLITZER STR.1Neuss41456DET and T Designs1160b_7412345678902311 York RdTimoniumMD21093US0106471699528764062512/20138642010 warsaw roadRoswellGA30076US08Expedited01Sold To NameSold To Attn Name123456789012340134 Queen StFrankfurt60547DEProduct 1147BOXBOX478111222AAUSLBSLBS10asdf12320151225999jjj777CFRSaleYour CommentsYour Declaration Statement1005020050MiscUSD02NailsINInches752LBSPounds10

                                [1] => http://www.ups.com/XMLSchema/XOLTWS/UPSS/v1.0
                                [2] => http://onlinetools.ups.com/webservices/ShipBinding/v1.0
                                [3] => 1
                                [4] => 0
                            )

                    )

                [1] => Array
                    (
                        [file] => my_opencart_root_path/admin/controller/sale/ups_shipping.php
                        [line] => 50
                        [function] => __soapCall
                        [class] => SoapClient
                        [type] => ->
                        [args] => Array
                            (
                                [0] => ProcessShipment
                                [1] => Array
                                    (
                                        [0] => Array
                                            (
                                                [Request] => Array
                                                    (
                                                        [RequestOption] => nonvalidate
                                                    )

                                                [Shipment] => Array
                                                    (
                                                        [Description] => Test Product for shipping API
                                                        [Shipper] => Array
                                                            (
                                                                [Name] => My Store
                                                                [AttentionName] => ShipperZs Attn Name
                                                                [TaxIdentificationNumber] => 123456
                                                                [ShipperNumber] => Your Shipper Number
                                                                [Address] => Array
                                                                    (
                                                                        [AddressLine] => 2311 York Rd
                                                                        [City] => Timonium
                                                                        [StateProvinceCode] => MD
                                                                        [PostalCode] => 21093
                                                                        [CountryCode] => US
                                                                    )

                                                                [Phone] => Array
                                                                    (
                                                                        [Number] => 1115554758
                                                                        [Extension] => 1
                                                                    )

                                                            )

                                                        [ShipTo] => Array
                                                            (
                                                                [Name] => Happy Dog Pet Supply
                                                                [AttentionName] => Ship To Attention Name
                                                                [Address] => Array
                                                                    (
                                                                        [AddressLine] => GOERLITZER STR.1
                                                                        [City] => Neuss
                                                                        [PostalCode] => 41456
                                                                        [CountryCode] => DE
                                                                    )

                                                                [Phone] => Array
                                                                    (
                                                                        [Number] => 9225377171
                                                                    )

                                                            )

                                                        [ShipFrom] => Array
                                                            (
                                                                [Name] => T and T Designs
                                                                [AttentionName] => 1160b_74
                                                                [Address] => Array
                                                                    (
                                                                        [AddressLine] => 2311 York Rd
                                                                        [City] => Timonium
                                                                        [StateProvinceCode] => MD
                                                                        [PostalCode] => 21093
                                                                        [CountryCode] => US
                                                                    )

                                                                [Phone] => Array
                                                                    (
                                                                        [Number] => 1234567890
                                                                    )

                                                            )

                                                        [PaymentInformation] => Array
                                                            (
                                                                [ShipmentCharge] => Array
                                                                    (
                                                                        [Type] => 01
                                                                        [BillShipper] => Array
                                                                            (
                                                                                [CreditCard] => Array
                                                                                    (
                                                                                        [Type] => 06
                                                                                        [Number] => 4716995287640625
                                                                                        [SecurityCode] => 864
                                                                                        [ExpirationDate] => 12/2013
                                                                                        [Address] => Array
                                                                                            (
                                                                                                [AddressLine] => 2010 warsaw road
                                                                                                [City] => Roswell
                                                                                                [StateProvinceCode] => GA
                                                                                                [PostalCode] => 30076
                                                                                                [CountryCode] => US
                                                                                            )

                                                                                    )

                                                                            )

                                                                    )

                                                            )

                                                        [Service] => Array
                                                            (
                                                                [Code] => 08
                                                                [Description] => Expedited
                                                            )

                                                        [ShipmentServiceOptions] => Array
                                                            (
                                                                [InternationalForms] => Array
                                                                    (
                                                                        [FormType] => 01
                                                                        [InvoiceNumber] => asdf123
                                                                        [InvoiceDate] => 20151225
                                                                        [PurchaseOrderNumber] => 999jjj777
                                                                        [TermsOfShipment] => CFR
                                                                        [ReasonForExport] => Sale
                                                                        [Comments] => Your Comments
                                                                        [DeclarationStatement] => Your Declaration Statement
                                                                        [Contacts] => Array
                                                                            (
                                                                                [SoldTo] => Array
                                                                                    (
                                                                                        [Option] => 01
                                                                                        [AttentionName] => Sold To Attn Name
                                                                                        [Name] => Sold To Name
                                                                                        [Phone] => Array
                                                                                            (
                                                                                                [Number] => 1234567890
                                                                                                [Extension] => 1234
                                                                                            )

                                                                                        [Address] => Array
                                                                                            (
                                                                                                [AddressLine] => 34 Queen St
                                                                                                [City] => Frankfurt
                                                                                                [PostalCode] => 60547
                                                                                                [CountryCode] => DE
                                                                                            )

                                                                                    )

                                                                            )

                                                                        [Product] => Array
                                                                            (
                                                                                [Description] => Product 1
                                                                                [CommodityCode] => 111222AA
                                                                                [OriginCountryCode] => US
                                                                                [Unit] => Array
                                                                                    (
                                                                                        [Number] => 147
                                                                                        [Value] => 478
                                                                                        [UnitOfMeasurement] => Array
                                                                                            (
                                                                                                [Code] => BOX
                                                                                                [Description] => BOX
                                                                                            )

                                                                                    )

                                                                                [ProductWeight] => Array
                                                                                    (
                                                                                        [Weight] => 10
                                                                                        [UnitOfMeasurement] => Array
                                                                                            (
                                                                                                [Code] => LBS
                                                                                                [Description] => LBS
                                                                                            )

                                                                                    )

                                                                            )

                                                                        [Discount] => Array
                                                                            (
                                                                                [MonetaryValue] => 100
                                                                            )

                                                                        [FreightCharges] => Array
                                                                            (
                                                                                [MonetaryValue] => 50
                                                                            )

                                                                        [InsuranceCharges] => Array
                                                                            (
                                                                                [MonetaryValue] => 200
                                                                            )

                                                                        [OtherCharges] => Array
                                                                            (
                                                                                [MonetaryValue] => 50
                                                                                [Description] => Misc
                                                                            )

                                                                        [CurrencyCode] => USD
                                                                    )

                                                            )

                                                        [Package] => Array
                                                            (
                                                                [Description] => 
                                                                [Packaging] => Array
                                                                    (
                                                                        [Code] => 02
                                                                        [Description] => Nails
                                                                    )

                                                                [Dimensions] => Array
                                                                    (
                                                                        [UnitOfMeasurement] => Array
                                                                            (
                                                                                [Code] => IN
                                                                                [Description] => Inches
                                                                            )

                                                                        [Length] => 7
                                                                        [Width] => 5
                                                                        [Height] => 2
                                                                    )

                                                                [PackageWeight] => Array
                                                                    (
                                                                        [UnitOfMeasurement] => Array
                                                                            (
                                                                                [Code] => LBS
                                                                                [Description] => Pounds
                                                                            )

                                                                        [Weight] => 10
                                                                    )

                                                            )

                                                        [LabelSpecification] => Array
                                                            (
                                                                [LabelImageFormat] => Array
                                                                    (
                                                                        [Code] => GIF
                                                                        [Description] => GIF
                                                                    )

                                                                [HTTPUserAgent] => Mozilla/4.5
                                                            )

                                                    )

                                            )

                                    )

                            )

                    )

                [2] => Array
                    (
                        [file] => my_opencart_root_path/system/storage/modification/system/engine/action.php
                        [line] => 51
                        [function] => index
                        [class] => ControllerSaleUpsShipping
                        [type] => ->
                        [args] => Array
                            (
                            )

                    )
                )

        [previous:Exception:private] => 
        [faultstring] => Not Found
        [faultcode] => HTTP
    )

下面是我创建的控制器代码:

<?php
class ControllerSaleUpsShipping extends Controller {
    //Configuration
    private $access = "my_access_key";
    private $userid = "my_ups_userid";
    private $passwd = "my_ups_password";
    private $wsdl = HTTPS_UPS."Ship.wsdl";
    private $operation = "ProcessShipment";
    private $endpointurl = 'http://www.ups.com/XMLSchema/XOLTWS/UPSS/v1.0';
    private $outputFileName = HTTPS_UPS."XOLTResult.txt";

    public function index()
    {
        try
        {
            $opts = array(
                'http' => array(
                    'user_agent' => 'PHPSoapClient'
                )
            );
            $context = stream_context_create($opts);
            $mode = array
            (
                'soap_version' => 'SOAP_1_1',  // use soap 1.1 client
                'trace' => 1,
                'stream_context' => $context
            );

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

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

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

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

            if(strcmp($this->operation,"ProcessShipment") == 0 )
            {
                //get response
            $resp = $client->__soapCall('ProcessShipment',array($this->processShipment()));
                 //get status
                echo "Response Status: " . $resp->Response->ResponseStatus->Description ."\n";

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

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

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

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

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

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

            //save soap request and response to file
            $fw = fopen($this->outputFileName ,'w');
            fwrite($fw , "Request: \n" . $client->__getLastRequest() . "\n");
                fwrite($fw , "Response: \n" . $client->__getLastResponse() . "\n");
                fclose($fw);
            }
        }
        catch(Exception $ex)
        {
            echo "<pre>";print_r ($ex);echo "</pre>";
        }
    }

    public function processShipment()
    {
        //create soap request
        $requestoption['RequestOption'] = 'nonvalidate';
        $request['Request'] = $requestoption;

        $shipment['Description'] = 'Test Product for shipping API';
        $shipper['Name'] = 'Furniture Store';
        $shipper['AttentionName'] = 'ShipperZs Attn Name';
        $shipper['TaxIdentificationNumber'] = '123456';
        $shipper['ShipperNumber'] = 'Your Shipper Number';
        $address['AddressLine'] = '2311 York Rd';
        $address['City'] = 'Timonium';
        $address['StateProvinceCode'] = 'MD';
        $address['PostalCode'] = '21093';
        $address['CountryCode'] = 'US';
        $shipper['Address'] = $address;
        $phone['Number'] = '1115554758';
        $phone['Extension'] = '1';
        $shipper['Phone'] = $phone;
        $shipment['Shipper'] = $shipper;

        $shipto['Name'] = 'Happy Dog Pet Supply';
        $shipto['AttentionName'] = 'Ship To Attention Name';
        $addressTo['AddressLine'] = 'GOERLITZER STR.1';
        $addressTo['City'] = 'Neuss';
        $addressTo['PostalCode'] = '41456';
        $addressTo['CountryCode'] = 'DE';
        $phone2['Number'] = '9225377171';
        $shipto['Address'] = $addressTo;
        $shipto['Phone'] = $phone2;
        $shipment['ShipTo'] = $shipto;

        $shipfrom['Name'] = 'T and T Designs';
        $shipfrom['AttentionName'] = '1160b_74';
        $addressFrom['AddressLine'] = '2311 York Rd';
        $addressFrom['City'] = 'Timonium';
        $addressFrom['StateProvinceCode'] = 'MD';
        $addressFrom['PostalCode'] = '21093';
        $addressFrom['CountryCode'] = 'US';
        $phone3['Number'] = '1234567890';
        $shipfrom['Address'] = $addressFrom;
        $shipfrom['Phone'] = $phone3;
        $shipment['ShipFrom'] = $shipfrom;

        $shipmentcharge['Type'] = '01';
        $creditcard['Type'] = '06';
        $creditcard['Number'] = '4716995287640625';
        $creditcard['SecurityCode'] = '864';
        $creditcard['ExpirationDate'] = '12/2013';
        $creditCardAddress['AddressLine'] = '2010 warsaw road';
        $creditCardAddress['City'] = 'Roswell';
        $creditCardAddress['StateProvinceCode'] = 'GA';
        $creditCardAddress['PostalCode'] = '30076';
        $creditCardAddress['CountryCode'] = 'US';
        $creditcard['Address'] = $creditCardAddress;
        $billshipper['CreditCard'] = $creditcard;
        $shipmentcharge['BillShipper'] = $billshipper;
        $paymentinformation['ShipmentCharge'] = $shipmentcharge;
        $shipment['PaymentInformation'] = $paymentinformation;

        $service['Code'] = '08';
        $service['Description'] = 'Expedited';
        $shipment['Service'] = $service;

        $internationalForm['FormType'] = '01';
        $internationalForm['InvoiceNumber'] = 'asdf123';
        $internationalForm['InvoiceDate'] = '20151225';
        $internationalForm['PurchaseOrderNumber'] = '999jjj777';
        $internationalForm['TermsOfShipment'] = 'CFR';
        $internationalForm['ReasonForExport'] = 'Sale';
        $internationalForm['Comments'] = 'Your Comments';
        $internationalForm['DeclarationStatement'] = 'Your Declaration Statement';
        $soldTo['Option'] = '01';
        $soldTo['AttentionName'] = 'Sold To Attn Name';
        $soldTo['Name'] = 'Sold To Name';
        $soldToPhone['Number'] = '1234567890';
        $soldToPhone['Extension'] = '1234';
        $soldTo['Phone'] = $soldToPhone;
        $soldToAddress['AddressLine'] = '34 Queen St';
        $soldToAddress['City'] = 'Frankfurt';
        $soldToAddress['PostalCode'] = '60547';
        $soldToAddress['CountryCode'] = 'DE';
        $soldTo['Address'] = $soldToAddress;
        $contact['SoldTo'] = $soldTo;
        $internationalForm['Contacts'] = $contact;
        $product['Description'] = 'Product 1';
        $product['CommodityCode'] = '111222AA';
        $product['OriginCountryCode'] = 'US';
        $unitProduct['Number'] = '147';
        $unitProduct['Value'] = '478';
        $uom['Code'] = 'BOX';
        $uom['Description'] = 'BOX';
        $unitProduct['UnitOfMeasurement'] = $uom;
        $product['Unit'] = $unitProduct;
        $productWeight['Weight'] = '10';
        $uomForWeight['Code'] = 'LBS';
        $uomForWeight['Description'] = 'LBS';
        $productWeight['UnitOfMeasurement'] = $uomForWeight;
        $product['ProductWeight'] = $productWeight;
        $internationalForm['Product'] = $product;
        $discount['MonetaryValue'] = '100';
        $internationalForm['Discount'] = $discount;
        $freight['MonetaryValue'] = '50';
        $internationalForm['FreightCharges'] = $freight;
        $insurance['MonetaryValue'] = '200';
        $internationalForm['InsuranceCharges'] = $insurance;
        $otherCharges['MonetaryValue'] = '50';
        $otherCharges['Description'] = 'Misc';
        $internationalForm['OtherCharges'] = $otherCharges;
        $internationalForm['CurrencyCode'] = 'USD';
        $shpServiceOptions['InternationalForms'] = $internationalForm;
        $shipment['ShipmentServiceOptions'] = $shpServiceOptions;

        $package['Description'] = '';
        $packaging['Code'] = '02';
        $packaging['Description'] = 'Nails';
        $package['Packaging'] = $packaging;
        $unit['Code'] = 'IN';
        $unit['Description'] = 'Inches';
        $dimensions['UnitOfMeasurement'] = $unit;
        $dimensions['Length'] = '7';
        $dimensions['Width'] = '5';
        $dimensions['Height'] = '2';
        $package['Dimensions'] = $dimensions;
        $unit2['Code'] = 'LBS';
        $unit2['Description'] = 'Pounds';
        $packageweight['UnitOfMeasurement'] = $unit2;
        $packageweight['Weight'] = '10';
        $package['PackageWeight'] = $packageweight;
        $shipment['Package'] = $package;

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

        echo "Request.......\n";
        print_r($request);
        echo "\n\n";
        return $request;

    }

    function processShipConfirm()
    {

    //create soap request

    }

    function processShipAccept()
    {
    //create soap request
    }
}
?>

有谁能帮我纠正我的错误吗?

58wvjzkj

58wvjzkj1#

终点错误。

在您的代码中,您可以:

private $endpointurl = 'http://www.ups.com/XMLSchema/XOLTWS/UPSS/v1.0';
...

$client->__setLocation($this->endpointurl);

将你的$endpointurl属性更改为上述之一。你可能还需要确保你的wsdl包含正确的端点。这些端点是开箱即用的,测试端点在末尾的一个块中,看起来像这样:

<!-- Ship Web Service-->
<wsdl:service name="ShipService">
    <wsdl:port name="ShipPort" binding="tns:ShipBinding">
        <!-- Production URL -->
        <!-- <soap:address location="https://onlinetools.ups.com/webservices/Ship"/> -->
        <!-- CIE (Customer Integration Environment) URL -->
        <soap:address location="https://wwwcie.ups.com/webservices/Ship"/>
    </wsdl:port>
</wsdl:service>

因此,一旦你的应用程序准备好生产,你就可以取消注解第一个地址,并注解掉第二个地址。

相关问题