php调用soap协议webservice接口方法

<?php
    header("Content-type: text/html; charset=utf-8");  
    $webservice_url = "http://test.com/test.svc?wsdl";//webservice地址
    $client = new SoapClient($webservice_url);
    
    // echo '
';
    // echo '';</span>
    <span class="token comment">// print_r( $client->__getFunctions ()); </span>
    <span class="token comment">// echo "相关的数据结构\n";</span>
    <span class="token comment">// print_r($client->__getTypes () ); </span>
    <span class="token comment">// echo '';
    // 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)