通过jks证书在PHP上进行Soap身份验证

时间:2016-09-29 22:13:06

标签: php soap jks

我正在尝试传递我的请求,但我遇到了各种错误。好像是我的auth方法不起作用。我使用SoapUI时工作正常。我试图通过PHP实现这一点。

SoapUI将xml添加到标头中。我应该如何用PHP添加它。 它看起来像是信息不是静态的。

<?php

/*
<wsse:Security xmlns:wsse=http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd xmlns:wsu=http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd>
<ds:Signature Id=SIG-DAB3AC9FCFC1D2CFFE147510914159070 xmlns:ds=http://www.w3.org/2000/09/xmldsig#>
    <ds:SignedInfo>
        <ds:CanonicalizationMethod Algorithm=http://www.w3.org/TR/2001/REC-xml-c14n-20010315/>
        <ds:SignatureMethod Algorithm=http://www.w3.org/2000/09/xmldsig#rsa-sha1/>
        <ds:Reference URI=#id-DAB3AC9FCFC1D2CFFE147510914159069>
            <ds:Transforms>
                <ds:Transform Algorithm=http://www.w3.org/2001/10/xml-exc-c14n#>
                <InclusiveNamespaces PrefixList=v2 whol xmlns=http://www.w3.org/2001/10/xml-exc-c14n#/>
                </ds:Transform>
            </ds:Transforms>
            <ds:DigestMethod Algorithm=http://www.w3.org/2000/09/xmldsig#sha1/>
            <ds:DigestValue>Kfw1HATmg4wLayS1zEeSKzLgaLE=</ds:DigestValue>
        </ds:Reference>
    </ds:SignedInfo>
    <ds:SignatureValue>VA6ETCI+RzMGWsITElyP4DuXgl27hxmlp827ShCVz/1CuOA0Es9oDWpXIOB8KMO+cmG4/UMf/wTg
    XMly9QW0U79Czgyue7EtjAPdpfDLMesqY116IUkx4Aq+G8cT8T2/Mxw8e6Up71DtoR6F6oa7uPNP
    mJkTwXRphcZi7AlVS70=</ds:SignatureValue>
    <ds:KeyInfo Id=KI-DAB3AC9FCFC1D2CFFE147510914158967>
        <wsse:SecurityTokenReference wsu:Id=STR-DAB3AC9FCFC1D2CFFE147510914159068>
            <ds:X509Data>
                <ds:X509IssuerSerial>
                    <ds:X509IssuerName>O=Sprint,C=US</ds:X509IssuerName>
                    <ds:X509SerialNumber>1192967129</ds:X509SerialNumber>
                </ds:X509IssuerSerial>
            </ds:X509Data>
        </wsse:SecurityTokenReference>
    </ds:KeyInfo>
</ds:Signature>
</wsse:Security>
*/

$timestamp = date("c");

$local_cert = realpath(dirname(__FILE__))."/ecomobile-01.jks";
$options = array(
    'local_cert' => $local_cert,
    'passphrase' => 'Gogr33n!', 
    'keep_alive' => true,
    "trace" => 1
);

$headerbody = array('trackingMessageHeader' => array('applicationId' => '2014091601', 'applicationUserId' => 'Ecomobile', 'messageId' => rand(100000, 500000), 'timeToLive' => 60, 'messageDateTimeStamp' => $timestamp));       
$ns = 'http://integration.sprint.com/common/header/WSMessageHeader/v2';
$header = new SOAPHeader($ns, 'wsMessageHeader', $headerbody);

$deviceInfo = array('deviceDetailInfo' => array('esnMeidDec' => '09104990674'));

$soapclient = new SoapClient('https://webservicesgatewaytest.sprint.com:444/rtb1/services/mvno/WholesaleQueryDeviceInfoService/v1?wsdl', $options);
$soapclient->__setSoapHeaders($header);

$params = array('deviceInfo' => $deviceInfo, 'resellerPartnerId' => '210246456764464');

try{
    $response = $soapclient->wholesaleValidateDeviceV3($params);
    var_dump($response);
} catch (SoapFault $e) {
    echo "====== REQUEST HEADERS =====<br>";
    var_dump($soapclient->__getLastRequestHeaders());
    echo "<br>========= REQUEST ==========<br>";
    var_dump($soapclient->__getLastRequest());
    echo "<br>========= RESPONSE HEADER =========<br>" ;
    var_dump($soapclient->__getLastResponseHeaders());
    echo "<br>========= RESPONSE =========<br>" ;
    echo $e->getMessage();
}

?>

我得到的错误:

====== REQUEST HEADERS =====
NULL
========= REQUEST ==========
string(984) " xxxxxxxxx "
========= RESPONSE HEADER =========
NULL
========= RESPONSE =========
Could not connect to host

0 个答案:

没有答案