首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用SoapClient在PHP中为WebServices API创建WSSE Auth SOAP调用

使用SoapClient在PHP中为WebServices API创建WSSE Auth SOAP调用
EN

Stack Overflow用户
提问于 2014-03-13 02:53:38
回答 3查看 12.6K关注 0票数 2

我从一家供应商的API获得了以下内容:

我需要使用php创建一个Soap调用。我该怎么做呢?到目前为止,我有这个:但它不起作用:

代码语言:javascript
复制
private function booking_soap_connect() {
        // the wsdl URL of your service to test 
        $serviceWsdl = 'https://apitest.com/bookingapi.asmx?WSDL';

        // the parmeters to initialize the client with 
        $serviceParams = array(
            'login' => 'un',
            'password' => 'pw'
        );

        // create the SOAP client 
        $client = new SoapClient($serviceWsdl, $serviceParams);

        $data['Brand'] = "All";
        $data['TourCode'] = "QBE";
        $data['DepartureCode'] = "8000321";
        $data['VendorId'] = "test";
        $data['VendorPassword'] = "test";

        $results = $client->GVI_DepartureInfo($data)
        echo $results;
    }

请帮帮忙

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2014-03-14 04:40:06

解决方案:我终于用下面的代码解决了这个问题:

代码语言:javascript
复制
class WsseAuthHeader extends SoapHeader {

    private $wss_ns = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd';

    function __construct($user, $pass, $ns = null) {
        if ($ns) {
            $this->wss_ns = $ns;
        }

        $auth = new stdClass();
        $auth->Username = new SoapVar($user, XSD_STRING, NULL, $this->wss_ns, NULL, $this->wss_ns);
        $auth->Password = new SoapVar($pass, XSD_STRING, NULL, $this->wss_ns, NULL, $this->wss_ns);

        $username_token = new stdClass();
        $username_token->UsernameToken = new SoapVar($auth, SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'UsernameToken', $this->wss_ns);

        $security_sv = new SoapVar(
                new SoapVar($username_token, SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'UsernameToken', $this->wss_ns), SOAP_ENC_OBJECT, NULL, $this->wss_ns, 'Security', $this->wss_ns);
        parent::__construct($this->wss_ns, 'Security', $security_sv, true);
    }

}

$username = 'test';
$password = 'test123';
$wsdl = 'https://yoururl.com/api.asmx?WSDL';

$wsse_header = new WsseAuthHeader($username, $password);

$client = new SoapClient($wsdl, array(
    //"trace" => 1,
    //"exceptions" => 0
        )
);

$client->__setSoapHeaders(array($wsse_header));


$request = array(
    "functionResponseName" => array(
        'param1' => "string",
        "param2" => "string"
    )
);

$results = $client->FunctionName($request);

var_dump($results);
票数 11
EN

Stack Overflow用户

发布于 2014-03-13 02:58:08

改用Nusoap,你的Soap客户端可能不能与php版本一起工作。

票数 -1
EN

Stack Overflow用户

发布于 2014-03-13 03:01:44

看看我之前在Send XML with php via post给出的答案。在php中,你需要的一切都可以很好地处理SOAP了。

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22361180

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档