|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091 |
- <?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;
- }
-
- }
- ?>
|