今天在處理串接 遇到了一個奇怪個串接格式 WSDL
以下是相關的文章
<?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;
}
}
?>