php的soapclient,如何使用SoapClient类进行PHP SOAP调用

这篇博客展示了如何使用PHP的SoapClient类来调用一个需要复杂参数的Web服务,特别是涉及订单创建的过程。作者提供了WSDL的结构,并详细解释了参数的构造方式,包括sender、hash、originator等字段的设置。最后,代码成功执行并返回了结果。
摘要由CSDN通过智能技术生成

我不知道为什么我的Web服务与你的结构相同,但它不需要Class for parameter,只是数组。

例如:  - 我的WSDL:

xmlns:ns="http://www.kiala.com/schemas/psws/1.0">

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

我var_dump:

var_dump($client->getFunctions());

var_dump($client->getTypes());

结果如下:

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)

所以在我的代码中:

$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);

但它成功了!

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值