php handles wsdl
0x00 Preface
I have been writing interfaces recently. Before this, interface data transmission was transmitted or obtained using json or xml format. But this time when jointly debugging with a third party, they provided the wsdl format. Changed to SB in an instant...
Google the test code, and the test calls the third-party interface to return status 200. I thought it would be over if nothing happened, but when I got closer, I discovered that no matter how I called their interface, the correct data was not returned. Later, after checking the log, they found that they had not received the passed parameters at all. They were confused for an afternoon and into the evening before they solved the problem. I thought it was quite interesting, so I wrote it down first.
0x01 What is wsdl? Based on what someone said, it is an xml format document used to describe the definition of Web Server, that is to say, it is a Web Server method and parameter description.
See: http://baike.baidu.com/link?url=R7x3FdekxbndR4SlzQLZE_2m1ebpt_SWt9IMjoHSErvLlbZ3-hwhR3ERrinXS1xZaDvkYFpxWnUchrk34_WkZq
When we request http://api.test.cn/xwebservice s/testServer?wsdl', what ends like this? When setting the URL of wsdl, a bunch of xml structured data will be given to you.
That's right, it's just a lump...
Next, how to understand it and the method it says is the key, everything else is useless.
0x02 Understanding the description document
When I first looked at this xml document, I was confused, but it became much more obvious after using the PHP extension.
<?php $client = new SoapClient('http://api.test.cn/xwebservices/testServer?wsdl'); print "\n提供的方法\n"; print_r($client->__getFunctions()); print "相关的数据结构\n"; print_r($client->__getTypes()); print "\n\n";
Here we use the SOAP extension. This extension is the operation processing WebServer service extension provided in the official PHP copy. In the end, we also use it to realize parameter transmission.
As can be understood from the above picture, this interface provides three methods, namely:
xxxxUserInfo
xxxxResumeNum
download**
The relevant data structure refers to the parameter name and parameter type in the method . For example, the xxxxUserInfo method requires three string type parameters. Correspond to in0, in1 and in2 respectively.
Note
The parameter key here must be in0, which is an arbitrary parameter name that does not require an array, user-defined or agreed upon by both parties. When I started writing the interface method, I performed the transmission based on the parameter descriptions given in the interface copy, such as: err_msg (indicating error information), err_code (indicating error coding), and date (final data transmitted). Then change it to an ordered array and fill in the corresponding parameters one by one. At this time, the key is 0 to 2. But after trying it, it still didn't work. Finally, with the mentality of giving it a try, I tried using int0 as the key name and the corresponding err_msg content as the value. OK~, perfect solution.
Code:
<?php /** * @author 0x584A * 获取WSDL接口数据 */ class getwsdlTest extends PHPUnit_Framework_TestCase { public $apiurl = 'http://api.test.cn/xwebservices/testServer?wsdl'; private static $soapClientHandler; private $infoArr = [ 'err_msg' => 'false', 'err_code' => '0', 'date' => '此处是要传输的数据' ]; public function setUp() { $client = new SoapClient('http://api.test.cn/xwebservices/testServer?wsdl'); print "提供的方法\n"; print_r($client->__getFunctions()); print "相关的数据结构\n"; print_r($client->__getTypes()); print "\n\n"; } /** * xxxxUserInfo方法 */ public function testxxxxUserInfoData() { try { $ApiInfo = $this->infoArr; //set request param $parameter = array( 'in0' => $ApiInfo['err_msg'], 'in1' => $ApiInfo['err_code'], 'in2' => $ApiInfo['date'] ); $result = $this->getSoapClientHandler()->synchUserInfo($parameter); //调用结果返回异常 if (!$result instanceof stdClass) { throw new Exception("调用synchUserInfo结果出现异常:" . json_encode($result)); } //调用接口状态码,输出对应错误详情 if ($result->out == '01') { throw new Exception("调用synchUserInfo=>error:" . $result->out . ",msg:接口数据异常"); } $xml_parser = xml_parser_create(); if (!xml_parse($xml_parser, $result->out, true)) { xml_parser_free($xml_parser); throw new Exception("调用synchUserInfo返回的不是一个xml结构体"); } xml_parser_free($xml_parser); //XXE libxml_disable_entity_loader(true); $xml = simplexml_load_string($result->out, 'SimpleXMLElement', LIBXML_NOCDATA); // 输出参数 var_dump($xml->data); echo " 成功".PHP_EOL; } catch (SoapFault $soapFault) { throw new Exception($soapFault->getMessage() . $this->getSoapClientHandler()->__getLastResponse()); } } /** * @description getSoapClientHandler */ public function getSoapClientHandler() { if (!self::$soapClientHandler) { self::$soapClientHandler = new SoapClient($this->getSynchApi()); } return self::$soapClientHandler; } /** * @description getSynchApi */ public function getSynchApi() { return $this->apiurl; } } ?>

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Alipay PHP...

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

Session hijacking can be achieved through the following steps: 1. Obtain the session ID, 2. Use the session ID, 3. Keep the session active. The methods to prevent session hijacking in PHP include: 1. Use the session_regenerate_id() function to regenerate the session ID, 2. Store session data through the database, 3. Ensure that all session data is transmitted through HTTPS.

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

How to debug CLI mode in PHPStorm? When developing with PHPStorm, sometimes we need to debug PHP in command line interface (CLI) mode...

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.
