THINKPHP3.2 solution to using soap to connect to webservice_php example

韦小宝
Release: 2023-03-17 22:20:02
Original
1580 people have browsed it

THINKPHP3.2 can be used as an introductory framework, which is relatively simple to use, easy to understand and easy to learn. This article mainly introduces in detail the solution of THINKPHP3.2 using soap to connect to webservice. Today I use THINKPHP3.2 to use soap to connect to webservice when developing in the framework. Let me share some insights.

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);
Copy after login


3. Then call the webservice interface method


//获取webservice 接口方法

$client->__getFunctions (); 

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

//执行调用方法

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


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;
 }
}
Copy after login


above That’s all the content of this article. I hope it can be helpful to the students.

Related recommendations:

TP3.2 realizes switching between the previous and next chapters

Solution to the problem of conflicts with the same name when batch uploading in TP3.2

An example analysis of how to implement the online message submission verification code function in TP3.2

The above is the detailed content of THINKPHP3.2 solution to using soap to connect to webservice_php example. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template