Php 无法为客户端soap请求创建对象xml
我正在尝试为soap web服务发出客户端请求,当我尝试使用simplexml\u load\u字符串创建xml时,它会说:Php 无法为客户端soap请求创建对象xml,php,xml,soap,Php,Xml,Soap,我正在尝试为soap web服务发出客户端请求,当我尝试使用simplexml\u load\u字符串创建xml时,它会说: Error: Cannot create object 没有任何其他错误,所以我无法找出我做错了什么,我的代码如下,我希望你能帮助我解决这个问题 <?php $produccion = false; //Cambiar a verdadero por producction $url = "http://ws.maxirest.co
Error: Cannot create object
没有任何其他错误,所以我无法找出我做错了什么,我的代码如下,我希望你能帮助我解决这个问题
<?php
$produccion = false; //Cambiar a verdadero por producction
$url = "http://ws.maxirest.com/wsclientes/wscli06896.php";
//print_r($_POST);
$posts = $_POST;
if ($produccion == false) {
$posts['nombre'] =
$posts['apellido'] =
$posts['direccion'] =
$posts['pisodto'] =
$posts['localidad'] =
$posts['partido'] =
$posts['provincia'] =
$posts['telefono'] =
$posts['celular'] =
"PRUEBA";
}
$Datos = "<cliente>
<nombre>".$posts['nombre']."</nombre>
<apellido>".$posts['apellido']."</apellido>
<calle>".$posts['direccion']."</calle>
<altura>".$posts['altura']."</altura>
<pisodto>".$posts['pisodto']."</pisodto>
<localidad>".$posts['localidad']."</localidad>
<partido>".$posts['partido']."</partido>
<provincia>".$posts['provincia']."</provincia>
<telefono>".$posts['telefono']."</telefono>
<celular>".$posts['celular']."</celular>
<num_tarjeta>".$posts['num_tarjeta']."</num_tarjeta>
</cliente>";
$myXMLData = '<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.maxisistemas.com.ar">
<soapenv:Header/>
<soapenv:Body>
<ws:AltaSolicitud soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<cXml>'.$Datos.'</cXml>
<Clave>123ClubMilaMREST5</Clave>
</ws:AltaSolicitud>
</soapenv:Body>
</soapenv:Envelope>';
$xml=simplexml_load_string($myXMLData) or die("Error: Cannot create object"); //<-Here is the error
$client = new SoapClient($url);
$result1 = $client->AltaSolicitud($xml);
$result2 = $client->ConsultaPuntos($xml);
?>
ConsultaPuntos($xml);
?>
我找不到答案,但是
=>“错误。帐户没有权限”
但是有了正确的证书和数据,你应该能够在课堂上获得你需要的信息
只需在setData()
函数中设置数据/首先调用它,然后使用Clave
作为参数调用AltoSolicitud()
class Request extends \SoapClient
{
public $Datos;
public function __construct(array $options = [], $wsdl = 'http://ws.maxirest.com/wsclientes/wscli06896.php?wsdl')
{
$options = [
'features' => 1,
];
parent::__construct($wsdl, $options);
}
/**
* @param string $Clave
* @return string
*/
public function AltaSolicitud()
{
$Data = $this->getData();
try {
return $this->__soapCall('AltaSolicitud', [
$Data
]);
} catch (\SoapFault $e) {
return ($e->getMessage());
}
}
public function setData($posts,$produccion = false)
{
if ( ! $produccion) {
$posts['nombre'] =
$posts['apellido'] =
$posts['direccion'] =
$posts['pisodto'] =
$posts['localidad'] =
$posts['partido'] =
$posts['provincia'] =
$posts['telefono'] =
$posts['celular'] =
"PRUEBA";
}
$Datos = "<cliente><nombre>".$posts['nombre']."</nombre>
<apellido>".$posts['apellido']."</apellido>
<calle>".$posts['direccion']."</calle>
<altura>".$posts['altura']."</altura>
<pisodto>".$posts['pisodto']."</pisodto>
<localidad>".$posts['localidad']."</localidad>
<partido>".$posts['partido']."</partido>
<provincia>".$posts['provincia']."</provincia>
<telefono>".$posts['telefono']."</telefono>
<celular>".$posts['celular']."</celular>
<num_tarjeta>".$posts['num_tarjeta']."</num_tarjeta></cliente>";
$Clave = '123ClubMilaMREST5';
$myXMLData = <<<XML
<soapenv:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ws="http://ws.maxisistemas.com.ar">
<soapenv:Header/>
<soapenv:Body>
<ws:AltaSolicitud soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<cXml xsi:type="xsd:string">' . str_replace(PHP_EOL,'',$Datos) . '</cXml>
<Clave xsi:type="xsd:string">' . $Clave . '</Clave>
</ws:AltaSolicitud>
</soapenv:Body>
</soapenv:Envelope>
XML;
$this->Datos = $myXMLData;
return $this;
}
/**
* @param string $Cod_Tarj
* @param string $Clave
* @return string
*/
public function ConsultaPuntos($Cod_Tarj, $Clave)
{
return $this->__soapCall('ConsultaPuntos', [$Cod_Tarj, $Clave]);
}
public function getData(){
return $this->Datos;
}
$request = (new Request)->setData($_POST,false)->AltaSolicitud();
var_dump($request);
类请求扩展\SoapClient
{
公帑$Datos;
公共函数构造(数组$options=[],$wsdl=]http://ws.maxirest.com/wsclientes/wscli06896.php?wsdl')
{
$options=[
“功能”=>1,
];
父项::_构造($wsdl,$options);
}
/**
*@param string$Clave
*@返回字符串
*/
公共职能
{
$Data=$this->getData();
试一试{
返回$this->\uuuuSOAPCALL('AltaRequestUD'[
$Data
]);
}捕获(\SoapFault$e){
返回($e->getMessage());
}
}
公共函数setData($posts,$produccion=false)
{
如果(!$produccion){
$posts['nombre']=
$posts['apellido']=
$posts['direccion']=
$posts['pisodto']=
$posts['localidad']=
$posts['partido']=
$posts['provincia']=
$posts['telefono']=
$posts['celular']=
“普鲁巴”;
}
$Datos=”“.$posts['nombre']
“$posts['apellido']”
“$posts['direccion']”
“$posts['altura']”
“$posts['pisodto']”
“$posts['localidad']”
“$posts['partido']”
“$posts['provincia']”
“$posts['telefono']”
“$posts['celular']”
“$posts['num_tarjeta'”;
$Clave='123clubmilest5';
$myXMLData=Datos;
}
$request=(新请求)->setData($\u POST,false)->AltaRequestUD();
var_dump($请求);
@Ricardo
通过向url添加“wsdl”,我可以使您的代码正常工作。在此更改之后,我没有看到错误“无法创建对象”
我做了一些其他的小改动,但我认为它们并不重要:
$xml = simplexml_load_string( $myXMLData ); //or die("Error: Cannot create object"); //<-Here is the error
$client = new SoapClient( $url , array('trace' => 1 ));
$result1 = $client->AltaSolicitud($xml);
echo "Response:\n" . $client->__getLastResponse() . "\n";
$xml=simplexml_load_string($myXMLData);//或die(“错误:无法创建对象”);//1);
$result1=$client->AltaRequestUD($xml);
echo“Response:\n”。$client->\uu getLastResponse()。“\n”;
结果是相同的“ERROR.ACCESO NO permitito”已经被注意到。对我来说,soap参数123ClubMilaMREST5
似乎不正确或过期。我注意到这一点是因为这个词在意大利语中几乎相同(chiave=clave=key)。我假设这是一个API键,就像许多web服务所要求的那样
SOAP响应
<?xml version="1.0" encoding="ISO-8859-1"?>
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns1:AltaSolicitudResponse xmlns:ns1="http://ws.maxisistemas.com.ar">
<return xsi:type="xsd:string">ERROR. ACCESO NO PERMITIDO</return>
</ns1:AltaSolicitudResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
错误。帐户没有权限
他们不提供wsdl数据吗?@michael看一下code中的$url变量,我想你的意思是这样的?->你必须在$url
的末尾添加?wsdl
。另外,你必须发送字符串,而不是SimpleXML对象作为AltaRequestUD
和ConsultaPantos
的参数。我认为所有带有soapenv>的标记
也将是不必要的。@michael及其评论的更改->致命错误:未捕获的SoapFault异常:[WSDL]SOAP错误:解析WSDL:无法从“”加载:标记html第2行中的数据过早结束,位于G:\wamp\www\bsmart\phptoml2\envirarxml.php:104堆栈跟踪:#0 G:\wamp\www\bsmart\phptoml2\envirarxml.php(104):SoapClient->SoapClient(')#1{main}在第104行的G:\wamp\www\bsmart\phptomml2\enviraXML.php中抛出的是Codeigniter吗?如果是我需要在纯php上做这项工作,但很好的回答只是询问,因为它会给我一些错误,并且Clave参数也在我的代码中是123clubmilamrest5,我将如何使用该类进行调用?不应该给出错误,但它没有身份验证。复制ed我把代码放到一个文件中,然后运行它,如果可以的话是的,我也有这个,看起来你需要经过身份验证
<?xml version="1.0" encoding="ISO-8859-1"?>
<SOAP-ENV:Envelope SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
<ns1:AltaSolicitudResponse xmlns:ns1="http://ws.maxisistemas.com.ar">
<return xsi:type="xsd:string">ERROR. ACCESO NO PERMITIDO</return>
</ns1:AltaSolicitudResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>