基于TP5的简单的WebService 例子

function minus_func($i,$j){
    $res = $i - $j;
    return $res;
}
function greet($param) {
    if(!$param || !is_array ($param)){
        return 'parameat error';
    }
    $value  = 'Hello word ' . $param;
    return $value;
}
class Test
{
    public function soapservice (  )
    {
        $soap  = new \SoapServer(null,['uri'=>'http://local.adver2.com/customer/test/soapservice']);
        $soap->addFunction ('minus_func');
        $soap->addFunction ('greet');
        $soap->handle ();
    }

    public function soapclient (  )
    {
        try {
            $client = new \SoapClient(null, [
                'location' => 'http://local.adver2.com/customer/test/soapservice',
//                'location' => 'http://local.adver2.com/Service.php',
                'uri' => 'http://local.adver2.com/customer/test/soapservice'
            ]);

//    $result =  $client->__soapCall('greet', [
//        new SoapParam('world', 'name'),
//        new SoapParam('java', 'name2'),
//    ]);
            $result = $client->greet('廖工');
//            $result = $client->minus_func(100,50);
            echo $result;
        } catch (\Exception $e) {
            print_r ($e->getMessage ());
        }
    }
}

 

posted @ 2022-08-12 14:29  廖亚平  阅读(114)  评论(0)    收藏  举报