php webservice 数组,php调用webservice接口程序,返回xml格式,php解析xml形成数组

set_time_limit(0);

ini_set('soap.wsdl_cache_enabled','0');//关闭缓存

header('Content-Type: text/html; charset=UTF-8');

$soap=new SoapClient('http://192.168.1.33:6321/services/OAInterface?wsdl',array('encoding'=>'utf-8','cache_wsdl' => 0,'compression'=>true));

$soap->soap_defencoding = 'utf-8';

$soap->xml_encoding = 'utf-8';

echo "

";

print_r($soap->__getFunctions());

echo "

";

echo "

";

print_r($soap->__getTypes () );

echo "

";

/*

echo '__getFunctions = ';

var_dump($soap->__getFunctions());

echo '
-----------------------
';

echo '__getLastRequest = '.$soap->__getLastRequest();

echo '
-----------------------
';

echo '__getLastResponse = '.$soap->__getLastResponse();

echo '
-----------------------
';

*/

//echo "123123";

//exit;

/*

$result=$soap->__call('IP_DEPT_CHARGE',array("2019-02-19"));

print_r($result);

$arr=array('2019-02-19');

$result=$soap->__Call('IP_DEPT_CHARGE',$arr);

print_r($result);

$a="2019-02-19";

//$aa=(string)$a;

$result=$soap->IP_DEPT_CHARGE("2019-02-19");

print_r($result);

*/

$param = array('input'=>"2019-02-19");//参数拼接xml字符串

$result = $soap->IP_DEPT_CHARGE($param);//返回值

//print_r($result);

$arr1=object_array($result);

//print_r($arr1);

$re=$arr1["payload"];

//echo $re;

$simple1=str_replace("

$simple2=str_replace("]]>","",$simple1); //< ? xml version='1.0' encoding='utf-8' ? >

$simple3=str_replace("<?xml version='1.0' encoding='utf-8'?>","",$simple2);

$simple4=str_replace(">","",$simple3);

$simple=str_replace(">","",$simple4);

$simple=$re;

$postObj = simplexml_load_string($re, 'SimpleXMLElement', LIBXML_NOCDATA);

$jsonStr = json_encode($postObj);

$jsonArray = json_decode($jsonStr,true);

//echo "

";

//print_r($jsonArray);

//echo "

";

//echo "


";

$string = <<

$simple

XML;

echo $string."
";

$xml = simplexml_load_string($string);

$xml = simplexml_load_string($re, 'SimpleXMLElement', LIBXML_NOCDATA);//使用此方法

print_r($xml);

$arr=object_array($xml);

echo "

";

print_r($arr);

echo "";

/*

$result=$soap->__soapCall('IP_DEPT_CHARGE',array($arr));

print_r($result);

*/

/*

echo $soap->Add(1,2);

echo "
";

//echo $soap->_soapCall('Add',array(1,2));//或者这样调用也可以

//echo $soap->_soapCall('Add',array(1,2));//或者这样调用也可以

echo "
";

echo iconv('UTF-8', 'GB2312',$soap->Hello());//解决中文乱码的问题 从utf8转换成gb2312

echo "
";

echo $soap->abc('asd');

*/

/*

* 对象转换成数组

*/

function object2Array($objParam) {

$obj_param = ( array )$objParam;

foreach ($obj_param as $key => $value) {

if (is_object($value)) {

object2Array($value);

$obj_param [$key] = ( array )$value;

}

}

}

function object_array($array){

if(is_object($array)){

$array = (array)$array;

}

if(is_array($array)){

foreach($array as $key=>$value){

$array[$key] = object_array($value);

}

}

return $array;

}

?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值