<?php
header("Content-type: text/html; charset=utf-8");
$webservice_url = "http://test.com/test.svc?wsdl";//webservice地址
$client = new SoapClient($webservice_url);
// echo '<pre/>';
// echo '<xmp>';
// print_r( $client->__getFunctions ());
// echo "相关的数据结构\n";
// print_r($client->__getTypes () );
// echo '</xmp>';
// exit;
//该传参已做优化,参数都为必需值,且与服务端保持一致
$param = array(
'name'=>'test',
'cart'=>array(
'PaymentInfo'=>array(
'CardId'=>'AAABBBCCC'
'CardPassword'=>'123456'
),
'SplitItems'=>array(
'0'=>array(
'Items'=>array(
'0'=>array(
'Product'=>array(
'Amount'=>1,
'SKU'=>'11111'
)
),
'1'=>array(
'Product'=>array(
'Amount'=>1,
'SKU'=>'111111'
)
)
)
)
),
)
);
//microtime() 函数返回当前 Unix 时间戳的微秒数
$time_ago = microtime(true);
try{
//parameters 此参数为必填项,格式固定,否则报错
$arr = $client->__soapCall('index',array('parameters' => $param));//调用其中index方法
}catch(Exception $e){
//打印异常
$arr = $e->getMessage();
}
$time_end = microtime(true);
echo 'webservice执行时间差为:'.($time_end-$time_ago).'s';
print_r($arr);
exit;
php调用soap协议webservice接口方法
最新推荐文章于 2021-03-19 02:38:09 发布