0

有人可以为我提供一个 PHP 示例,说明如何在https://gateway2.pagosonline.net/ws/WebServicesClientesUT?wsdl对 wsdl 网络服务进行 WSSoapClient 调用。

我到处寻找代码示例,但找不到如何调用它。我看到您可以扩展 SoapClient 类,但我不知道如何构建调用本身。太感谢了。

例子”

<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:ser="http://server.webservices.web.v2.pagosonline.net"> 
<soapenv:Header>
<wsse:Security soapenv:mustUnderstand="1" 
 xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-    secext1.0.xsd">
<wsse:UsernameToken>
<wsse:Username>1</wsse:Username>
<wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-    token-profile-1.0#PasswordText">
123456</wsse:Password>
</wsse:UsernameToken>
</wsse:Security> 
</soapenv:Header>
<soapenv:Body>
<ser:getVersion soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"/>
</soapenv:Body></soapenv:Envelope>
4

1 回答 1

2

首先,您需要初始化一个新SoapClient对象,将 URL 传递给您的 WSDL 文件,如下所示:

$client = new SoapClient("https://gateway2.pagosonline.net/ws/WebServicesClientesUT?wsdl");

然后,您可以像调用任何其他对象方法一样调用服务方法,如下所示:

$verificaCuenta = true;
$result = $client->setVerificaCuenta($verificaCuenta);

要获取所有可用方法的列表,一旦你创建了你的$client对象,你可以__getFunctions()这样调用:

$client = new SoapClient("https://gateway2.pagosonline.net/ws/WebServicesClientesUT?wsdl");
$functions = $client->__getFunctions();
var_dump($functions);

注意:您必须在文件中启用php_soapphp_openssl启用此功能。php.ini

编辑:似乎您正在调用的服务需要 wsse 标头。我不是专家,但看起来 PHP 对这种事情没有很好的支持。

在 Google Code 上找到了一个项目,该项目似乎可以使用 PHP 简化 wsse。链接在这里:https ://code.google.com/p/wse-php/source/browse/

你可以抓住soap-wsse.phpxmlseclibs.php文件。

然后将soap-wsse.php文件包含到您的代码中并像这样扩展soap客户端:

require "soap-wsse.php";
class mySoap extends SoapClient {

    function __doRequest($request, $location, $saction, $version) {
        $doc = new DOMDocument('1.0');
        $doc->loadXML($request);

        $objWSSE = new WSSESoap($doc);

        $objWSSE->addUserToken("YOUR_USERNAME_HERE", "YOUR_PASSWORD_HERE", TRUE);

        return parent::__doRequest($objWSSE->saveXML(), $location, $saction, $version);
    }
}

然后你应该能够像这样与网络服务交谈:

$wsdl = 'https://gateway2.pagosonline.net/ws/WebServicesClientesUT?wsdl';    
$sClient = new mySoap($wsdl, array('trace'=>1));

try {
    $verificaCuenta = true;
    $result = $sClient->setVerificaCuenta($verificaCuenta);
    print_r($result->return);
} catch (SoapFault $fault) {
    print("Fault string: " . $fault->faultstring . "\n");
    print("Fault code: " . $fault->detail->WebServiceException->code . "\n");
}

echo $sClient->__getLastRequest() . "\n" . $sClient->__getLastResponse();

免责声明

我没有测试过上述任何代码,希望它能让你走上正确的道路。

祝你好运

于 2013-03-02T02:12:31.650 回答