带有私钥和wsdl的SOAP请求

时间:2018-11-06 13:36:31

标签: php soap client-certificates wsse

我需要一些帮助。我一直在绕着这个头。

我有:

  • 私人密钥库文件(crt)
  • 本地WSDL文件

我需要发出一个SOAP请求,我假设WSDL代表函数接受。.

我的代码如下:

    $opts = array(
        'ssl' => array(
            'ciphers'=>'RC4-SHA', 
            'verify_peer'=>false, 
            'verify_peer_name'=>false,
            'allow_self_signed' => true
        )
    );
    // SOAP 1.2 client
    $params = array (
        'encoding' => 'UTF-8', 
        'verifypeer' => false, 
        'verifyhost' => false, 
        'soap_version' => SOAP_1_2, 
        'trace' => true, 
        'exceptions' => true, 
        'connection_timeout' => 1,
        "local_cert" => "localpem.pem",
        "passphrase" => "somepassword123",
        'stream_context' => stream_context_create($opts) 
    );

    $ns_wsse = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd';
    $password_type = 'http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText';
    $soap_env = 'http://schemas.xmlsoap.org/soap/envelope/';
    $header = new SimpleXMLElement('<Header/>');
    $header->registerXPathNamespace('wsse', $ns_wsse);
    $soap_root = $header->addChild('header');
    $security = $soap_root->addChild('wsse:Security', null, $ns_wsse);
    $usernameToken = $security->addChild('wsse:UsernameToken', null, $ns_wsse);
    $usernameToken->addChild('wsse:Username', "someUsername", $ns_wsse);
    $usernameToken->addChild('wsse:Password', "somepassword123", $ns_wsse)->addAttribute('Type', $password_type);
    $auth = $header->xpath('/Header/header')[0]->asXML();

    $soap_client = new SoapClient('localwsdlfile.wsdl', $params);
    $soap_client->__setSoapHeaders(new SoapHeader($ns_wsse, 'Security', new SoapVar($auth, XSD_ANYXML), true));
    $soap_client->__setLocation('https://service-site/services/someservice');

我用它来称呼它。

$tst = $soap_client->getSomeValuesFunc(array('date' => '2000-02-02 2 02:02:02'));

 } catch(SoapFault $exception)
 {
    echo $exception->getMessage(), '<br />', $exception->getTraceAsString();
 }

它掉落了我

Could not connect to host
#0 [internal function]: SoapClient->__doRequest('__call('...

这种“无法连接到主机”是一种广泛的说法,现在我想知道什么可以解决这个问题。

我认为我的证书生成不正确?由于我需要将密码存储到它。所以我做了什么,我将证书格式存入crt-> jks,然后将jks保存到pem文件中,以便将其附加。

还有什么可以鼓励我的代码出现连接错误?

0 个答案:

没有答案