Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 
 
 

91 righe
2.6 KiB

  1. <?php
  2. /**
  3. * @author 0x584A
  4. * 获取WSDL接口数据
  5. */
  6. class getwsdlTest extends PHPUnit_Framework_TestCase
  7. {
  8. public $apiurl = 'http://api.test.cn/xwebservices/testServer?wsdl';
  9. private static $soapClientHandler;
  10. private $infoArr = [
  11. 'err_msg' => 'false',
  12. 'err_code' => '0',
  13. 'date' => '此处是要传输的数据'
  14. ];
  15. public function setUp()
  16. {
  17. $client = new SoapClient('http://api.test.cn/xwebservices/testServer?wsdl');
  18. print "提供的方法\n";
  19. print_r($client->__getFunctions());
  20. print "相关的数据结构\n";
  21. print_r($client->__getTypes());
  22. print "\n\n";
  23. }
  24. /**
  25. * xxxxUserInfo方法
  26. */
  27. public function testxxxxUserInfoData()
  28. {
  29. try {
  30. $ApiInfo = $this->infoArr;
  31. //set request param
  32. $parameter = array(
  33. 'in0' => $ApiInfo['err_msg'],
  34. 'in1' => $ApiInfo['err_code'],
  35. 'in2' => $ApiInfo['date']
  36. );
  37. $result = $this->getSoapClientHandler()->synchUserInfo($parameter);
  38. //调用结果返回异常
  39. if (!$result instanceof stdClass) {
  40. throw new Exception("调用synchUserInfo结果出现异常:" . json_encode($result));
  41. }
  42. //调用接口状态码,输出对应错误详情
  43. if ($result->out == '01') {
  44. throw new Exception("调用synchUserInfo=>error:" . $result->out . ",msg:接口数据异常");
  45. }
  46. $xml_parser = xml_parser_create();
  47. if (!xml_parse($xml_parser, $result->out, true)) {
  48. xml_parser_free($xml_parser);
  49. throw new Exception("调用synchUserInfo返回的不是一个xml结构体");
  50. }
  51. xml_parser_free($xml_parser);
  52. //XXE
  53. libxml_disable_entity_loader(true);
  54. $xml = simplexml_load_string($result->out, 'SimpleXMLElement', LIBXML_NOCDATA);
  55. // 输出参数
  56. var_dump($xml->data);
  57. echo " 成功".PHP_EOL;
  58. } catch (SoapFault $soapFault) {
  59. throw new Exception($soapFault->getMessage() . $this->getSoapClientHandler()->__getLastResponse());
  60. }
  61. }
  62. /**
  63. * @description getSoapClientHandler
  64. */
  65. public function getSoapClientHandler()
  66. {
  67. if (!self::$soapClientHandler) {
  68. self::$soapClientHandler = new SoapClient($this->getSynchApi());
  69. }
  70. return self::$soapClientHandler;
  71. }
  72. /**
  73. * @description getSynchApi
  74. */
  75. public function getSynchApi()
  76. {
  77. return $this->apiurl;
  78. }
  79. }
  80. ?>