Home  >  Article  >  Backend Development  >  How to use soap to connect webservice method in thinkPHP3.2

How to use soap to connect webservice method in thinkPHP3.2

小云云
小云云Original
2017-12-14 10:24:331758browse

How to use soap to connect to webservice when developing in thinkPHP3.2 framework? This article mainly introduces in detail the solution of using soap to connect to webservice in THINKPHP3.2. It has certain reference value. Interested friends can refer to it. I hope it can help everyone.

1. First we need to open it in php.ini

php_openssl.dll

php_soap.dll

2. Create an instance of the SoapClient class in the method


$url="https://www.test.com/adwebservice.asmx?wsdl";
$client = new \SoapClient($url);

3. Then call the webservice interface method


//获取webservice 接口方法

$client->__getFunctions (); 

//获取webservice接口方法的参数类型
$client->__getTypes ();

//执行调用方法

$aryResult = $client->ChangePassword($methodparam);
 var_dump($aryResult);//打印结果

4. The complete code is as follows


class WebseviceSoap
{
 public function WebService($url,$methodparam=array()){
  try{
    header("content-type:text/html;charset=UTF-8");
   $client = new \SoapClient($url);
   //$client->__getFunctions ();
   //$client->__getTypes ();
   // 参数转为数组形式传
   // 调用远程函数
   $aryResult = $client->ChangePassword($methodparam);
   return (array)$aryResult;
  }catch(Exception $e){
   $aryResult="";
  }
  return $aryResult;
 }
}

Have you learned it? Hurry up and give it a try.

Related recommendations:

Example of Nodejs calling WebService

php Sample code for creating and calling webservice interface

10 recommended courses about webservice

The above is the detailed content of How to use soap to connect webservice method in thinkPHP3.2. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn