我的一位客户在SOAP上创建了一个Web服务:
POST /TiendaOnLine.asmx HTTP/1.1
Host: tiendawow.webvillanet.com
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tiendawow.webvillanet.com/ObtenerExistencia"
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<ObtenerExistencia xmlns="http://tiendawow.webvillanet.com/">
<articulo>string</articulo>
<usuario>string</usuario>
<password>string</password>
</ObtenerExistencia>
</soap:Body>
</soap:Envelope>
然后,我创建了一个php文件来使用Web服务:
<?php
$url="http://tiendawow.webvillanet.com/TiendaOnLine.asmx?WSDL";
$parameters=array();
$parameters['articulo']="code";
$parameters['usuario']="user";
$parameters['password']="pass";
$client = new SoapClient($url,$parameters);
$result = $client->ObtenerExistencia($parameters);
var_dump($result);
?>
我得到这样的输出:
object(stdClass)#2 (1) { ["ObtenerExistenciaResult"]=> string(5) "11.00" }
我需要的是只能将11.00(或任何值取决于关节)保存到变量中以供以后使用,例如将其保存在数据库中。我该怎么做?
您需要访问对象ObtenerExistenciaResult
中的$result
属性。
if(property_exists($result, 'ObtenerExistenciaResult')) {
$value = $result->ObtenerExistenciaResult;
}
$value
现在将包含字符串(11.00
如果属性存在)。
您应该在那里有一些逻辑可以处理错误,并确保返回的数据符合您的期望。但这会在假定属性存在的情况下为您提供该属性的值。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句