PHP SoapServer instance code
Server code:
The code is as follows: |
Copy code |
<? Php If (! Isset ($ _ SERVER ['php _ AUTH_USER ']) |! Isset ($ _ SERVER ['php _ AUTH_PW ']) | ! ($ _ SERVER ['php _ AUTH_USER '] = 'outsider' & $ _ SERVER ['php _ AUTH_PW'] = '2016 ')){ Header ('www-Authenticate: Basic realm = "WEBSERVICE "'); Header ("HTTP/1.0 401 Unauthorized "); Echo "You must enter a valid login ID and password to access this resource/n "; Die; } Class test { Function show ($ one, $ two ){ Return $ one + $ two; } Function user_info (){ $ User_info = array ( 'Name' => 'outsider ', 'Sex' => 'male ', 'Email '=> 'outsider @ outsiderla. Me ', 'Tel '=> '2017 *******', ); Return json_encode ($ user_info ); } } $ Server = new SoapServer (null, array ('uri '=> 'Server. Php', 'location' => 'http: // demo.test.com/server.php ')); $ Server-> setClass ('test '); // $ Server-> addFunction ('getuserinfo '); $ Server-> handle (); ?> |
Third-party call code:
The code is as follows: |
Copy code |
<? Php $ Soap = new SoapClient (null, array ('location' => 'http: // demo.test.com/server.php', 'uris '=> 'Server. php', "login" => "outsider", "password" => "123456 ")); $ User_info = json_decode ($ soap-> user_info ()); Echo $ user_info-> email; ?> |