php调用webservice接口
1 <?php 2 header("Content-type: text/html; charset=utf-8"); 3 $webservice_url = "http://test.com/test.svc?wsdl";//webservice地址 4 $client = new SoapClient($webservice_url); 5 6 // echo '<pre/>'; 7 // echo '<xmp>'; 8 // print_r( $client->__getFunctions ()); 9 // echo "相关的数据结构\n"; 10 // print_r($client->__getTypes () ); 11 // echo '</xmp>'; 12 // exit; 13 14 15 //该传参已做优化,参数都为必需值 16 $param = array( 17 'name'=>'test', 18 'cart'=>array( 19 'PaymentInfo'=>array( 20 'CardId'=>'AAABBBCCC' 21 'CardPassword'=>'123456' 22 ), 23 'SplitItems'=>array( 24 '0'=>array( 25 'Items'=>array( 26 '0'=>array( 27 'Product'=>array( 28 'Amount'=>1, 29 'SKU'=>'11111' 30 ) 31 ), 32 '1'=>array( 33 'Product'=>array( 34 'Amount'=>1, 35 'SKU'=>'111111' 36 ) 37 ) 38 ) 39 ) 40 ), 41 ) 42 ); 43 $time_ago = microtime(true); 44 try{ 45 $arr = $client->__soapCall('index',array('parameters' => $param));//调用其中index方法 46 }catch(Exception $e){ 47 $arr = $e->getMessage(); 48 } 49 $time_end = microtime(true); 50 echo 'webservice执行时间差为:'.($time_end-$time_ago).'s'; 51 print_r($arr); 52 exit;