使用 Soap 从 PHP 中的 WSDL 获取元素

Get element from WSDL in PHP using Soap

我需要制作肥皂php才能获得优惠券 从 https://planetwin365.com/Controls/CouponWS.asmx?wsdl

有问题的 WSDL 是 Planetwin365 。有问题的片段看起来像这样:

    <wsdl:service name="CouponWS">
<wsdl:port name="CouponWSSoap" binding="tns:CouponWSSoap">
<soap:address location="http://planetwin365.com/Controls/CouponWS.asmx"/>
</wsdl:port>
<wsdl:port name="CouponWSSoap12" binding="tns:CouponWSSoap12">
<soap12:address location="http://planetwin365.com/Controls/CouponWS.asmx"/>
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

我目前正在这样做:

$xml = new DOMDocument();
$xml->load($this->wsdl);
$version = $xml->getElementsByService('CouponWS')->item(0)->nodeValue;

他没有工作

我强烈建议您使用 WSDL 到 php 生成器,以便从 PackageGenerator

获得易于使用的 SDK/soap 客户端

要创建 soap 客户端,您可以这样做:

$client = new SoapClient("https://planetwin365.com/Controls/CouponWS.asmx?wsdl");

您没有明确说明要执行哪个方法。您可以选择多种与优惠券相关的方法。你可以列出他们这样做:

var_dump($client->__getFunctions());

您可以执行哪些returns操作:

GetSaldoResponse GetSaldo(GetSaldo $parameters)
GetDisbilitazioneGirocontiResponse GetDisbilitazioneGiroconti(GetDisbilitazioneGiroconti $parameters)
GetStatoCouponResponse GetStatoCoupon(GetStatoCoupon $parameters)
CouponPromozioneOKResponse CouponPromozioneOK(CouponPromozioneOK $parameters)
GetStatoCouponAsincronoResponse GetStatoCouponAsincrono(GetStatoCouponAsincrono $parameters)
GetSaldoResponse GetSaldo(GetSaldo $parameters)
GetDisbilitazioneGirocontiResponse GetDisbilitazioneGiroconti(GetDisbilitazioneGiroconti $parameters)
GetStatoCouponResponse GetStatoCoupon(GetStatoCoupon $parameters)
CouponPromozioneOKResponse CouponPromozioneOK(CouponPromozioneOK $parameters)
GetStatoCouponAsincronoResponse GetStatoCouponAsincrono(GetStatoCouponAsincrono $parameters)

选择你要呼叫的那个。例如,让我们看一下GetStatoCoupon()。我们可以看到这个方法有一个参数叫做$parameters,它是一个GetStatoCoupon类型的结构体。方法returns一GetStatoCouponResponse.

GetStatoCoupon 类型是什么样的?要找出答案:

var_dump($client->__getTypes());

我们可以看到 GetStatoCoupon 看起来像:

  [4]=>
string(40) "struct GetStatoCoupon {
int IDCoupon;
}"

我们现在有足够的信息来构造一个基本调用:

$client = new SoapClient("https://planetwin365.com/Controls/CouponWS.asmx?wsdl");
$parameters = new StdClass();
$parameters->IDCoupon = 1234;
$response = $client->GetStatoCoupon($parameters);

我的调用出错了,因为我不知道 IDCoupon 中可以输入哪些值,但希望这能回答您有关如何创建 SOAP 客户端以获取优惠券的问题。