How to make a PHP SOAP call using the SoapClient class

后端 未结 12 719
星月不相逢
星月不相逢 2020-11-22 17:28

I\'m used to writing PHP code, but do not often use Object-Oriented coding. I now need to interact with SOAP (as a client) and am not able to get the syntax right. I\'ve got

12条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-22 17:41

    I don't know why my web service has the same structure with you but it doesn't need Class for parameter, just is array.

    For example: - My WSDL:

    
        
        
            
                
                    5390a7006cee11e0ae3e0800200c9a66
                    831f8c1ad25e1dc89cf2d8f23d2af...fa85155f5c67627
                    VITS-STAELENS
                
                
                    
                    
                
                
                    Zoethout thee
                    0.100
                    10K24
                    2012-12-31
                
                
                    Gladys
                    Roldan de Moras
                    
    Calle General Oraá 26 (4º izda) 28006 Madrid ES
    gverbruggen@kiala.com es

    I var_dump:

    var_dump($client->getFunctions());
    var_dump($client->getTypes());
    

    Here is result:

    array
      0 => string 'OrderConfirmation createOrder(OrderRequest $createOrder)' (length=56)
    
    array
      0 => string 'struct OrderRequest {
     Identification identification;
     Delivery delivery;
     Parcel parcel;
     Receiver receiver;
     string reference;
    }' (length=130)
      1 => string 'struct Identification {
     string sender;
     string hash;
     string originator;
    }' (length=75)
      2 => string 'struct Delivery {
     Node from;
     Node to;
    }' (length=41)
      3 => string 'struct Node {
     string country;
     string node;
    }' (length=46)
      4 => string 'struct Parcel {
     string description;
     decimal weight;
     string orderNumber;
     date orderDate;
    }' (length=93)
      5 => string 'struct Receiver {
     string firstName;
     string surname;
     Address address;
     string email;
     string language;
    }' (length=106)
      6 => string 'struct Address {
     string line1;
     string line2;
     string postalCode;
     string city;
     string country;
    }' (length=99)
      7 => string 'struct OrderConfirmation {
     string trackingNumber;
     string reference;
    }' (length=71)
      8 => string 'struct OrderServiceException {
     string code;
     OrderServiceException faultInfo;
     string message;
    }' (length=97)
    

    So in my code:

        $client  = new SoapClient('http://packandship-ws.kiala.com/psws/order?wsdl');
    
        $params = array(
            'reference' => $orderId,
            'identification' => array(
                'sender' => param('kiala', 'sender_id'),
                'hash' => hash('sha512', $orderId . param('kiala', 'sender_id') . param('kiala', 'password')),
                'originator' => null,
            ),
            'delivery' => array(
                'from' => array(
                    'country' => 'es',
                    'node' => '',
                ),
                'to' => array(
                    'country' => 'es',
                    'node' => '0299'
                ),
            ),
            'parcel' => array(
                'description' => 'Description',
                'weight' => 0.200,
                'orderNumber' => $orderId,
                'orderDate' => date('Y-m-d')
            ),
            'receiver' => array(
                'firstName' => 'Customer First Name',
                'surname' => 'Customer Sur Name',
                'address' => array(
                    'line1' => 'Line 1 Adress',
                    'line2' => 'Line 2 Adress',
                    'postalCode' => 28006,
                    'city' => 'Madrid',
                    'country' => 'es',
                    ),
                'email' => 'test.ceres@yahoo.com',
                'language' => 'es'
            )
        );
        $result = $client->createOrder($params);
        var_dump($result);
    

    but it successfully!

提交回复
热议问题