无法连接到ws安全性启用的Web服务的主机PHP SOAP错误

时间:2016-02-09 11:36:13

标签: php web-services soap wsse

我正在尝试从SOAP webservice获取数据但是它让我无法连接到主机我在我的代码中尝试了许多解决方案如下:

require 'soap-wsse.php';

define('PRIVATE_KEY', 'technologyally.me.key.pem');
define('CERT_FILE', 'technologyally.me.crt');

class MySoap extends SoapClient
{

    private $_username;
    private $_password;
    private $_digest;

    public function addUserToken($username, $password, $digest = false)
    {
        $this->_username = $username;
        $this->_password = $password;
        $this->_digest = $digest;
    }

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

        $objWSSE = new WSSESoap($doc);

        /* Sign all headers to include signing the WS-Addressing headers */
        $objWSSE->signAllHeaders = true;

        $objWSSE->addTimestamp();
        $objWSSE->addUserToken($this->_username, $this->_password, $this->_digest);

        /* create new XMLSec Key using RSA SHA-1 and type is private key */
        $objKey = new XMLSecurityKey(XMLSecurityKey::RSA_SHA1, array('type' => 'private'));

        /* load the private key from file - last arg is bool if key in file (true) or is string (FALSE) */
        $objKey->loadKey(PRIVATE_KEY, true);

        /* Sign the message - also signs appropraite WS-Security items */
        $objWSSE->signSoapDoc($objKey);

        /* Add certificate (BinarySecurityToken) to the message and attach pointer to Signature */
        $token = $objWSSE->addBinaryToken(file_get_contents(CERT_FILE));
        $objWSSE->attachTokentoSig($token);

        $request = $objWSSE->saveXML();
        //print_r($request);
        //echo $location;
        //  $location='https://impl.hub.cms.gov/Imp1/ApplicantEligibilityService';
        return parent::__doRequest($request, $location, $saction, $version);
    }
}
ini_set('soap.wsdl_cache_enabled',0);
ini_set('soap.wsdl_cache_ttl',0);
$wsdl = 'WSDL/ApplicantEligibility.wsdl';
$context = stream_context_create(array('ssl' => array(
           "verify_peer"=>false,
                 //               ,"allow_self_signed"=>false,
        //'cafile'        => 'cacert.pem',
      //  'verify_depth'  => 5,
      //  'local_pk'=>PRIVATE_KEY,

     //   'allow_self_signed' => false,
        'ciphers' => 'DHE-RSA-AES256-SHA:DHE-DSS-AES256-SHA:AES256-SHA:KRB5-DES-CBC3-MD5:KRB5-DES-CBC3-SHA:EDH-RSA-DES-CBC3-SHA:EDH-DSS-DES-CBC3-SHA:DES-CBC3-SHA:DES-CBC3-MD5:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA:AES128-SHA:RC2-CBC-MD5:KRB5-RC4-MD5:KRB5-RC4-SHA:RC4-SHA:RC4-MD5:RC4-MD5:KRB5-DES-CBC-MD5:KRB5-DES-CBC-SHA:EDH-RSA-DES-CBC-SHA:EDH-DSS-DES-CBC-SHA:DES-CBC-SHA:DES-CBC-MD5:EXP-KRB5-RC2-CBC-MD5:EXP-KRB5-DES-CBC-MD5:EXP-KRB5-RC2-CBC-SHA:EXP-KRB5-DES-CBC-SHA:EXP-EDH-RSA-DES-CBC-SHA:EXP-EDH-DSS-DES-CBC-SHA:EXP-DES-CBC-SHA:EXP-RC2-CBC-MD5:EXP-RC2-CBC-MD5:EXP-KRB5-RC4-MD5:EXP-KRB5-RC4-SHA:EXP-RC4-MD5:EXP-RC4-MD5',
        )));
$sClient = new MySoap($wsdl, array(
   // 'location' => 'https://impl.hub.cms.gov/Imp1/ApplicantEligibilityService',
   // 'style' => SOAP_DOCUMENT,
    'trace' => 1,
    'soap_version' => SOAP_1_2,
    'exceptions' => true,
    'compression' => SOAP_COMPRESSION_ACCEPT | SOAP_COMPRESSION_GZIP,
    'cache_wsdl' => WSDL_CACHE_NONE,
  //  'ssl_method' => SOAP_SSL_METHOD_TLS,
    'stream_context' => $context,
    "style" => SOAP_DOCUMENT,
            "use" => SOAP_LITERAL,

   'connection_timeout'=>60
    ));
//$sClient = new MySoap($wsdl, array('stream_context' => $context));
//echo file_get_contents('https://impl.hub.cms.gov/Imp1/HubConnectivityService');exit();
$sClient->__setLocation('https://impl.hub.cms.gov/Imp1/ApplicantEligibilityService');
$sClient->addUserToken('04.BKS.KS*.913.430', 'Qzk@4iTjUodAn2R', true);
//print_R($sClient->__getFunctions());
$parameter['PartnerWebSiteInformationExchangeSystem']['InformationExchangeSystemIdentification']['IdentificationID'] =
    '04.DSH.TS*.001.001';
$parameter['ExchangeInformationExchangeSystem']['InformationExchangeSystemStateCode'] =
    'GA';
$parameter['ExchangeInformationExchangeSystem']['InformationExchangeSystemIdentification']['IdentificationID'] =
    '04.DSH.TS*.001.001';

$parameter['PartnerAssignedConsumerIdentification']['IdentificationID'] =
    'ConsumerScenario';

$parameter['PartnerWebSiteUserCode'] = 'Consumer';
$parameter['ExchangeAssignedConsumerIdentification']['IdentificationID'] =
    '124838339';
$parameter['ExchangeUser']['ExchangeUserIdentification']['IdentificationID'] =
    'geoge.washington@yopmail.com';
$parameter['ExchangeUser']['RoleOfPersonReference'] = '';
//print_R($parameter);
try
{
    $out = $sClient->FetchApplicantEligibility($parameter);

    var_dump($out);
}
catch (SoapFault $fault)
{
    //echo $sClient->__getLastRequest();
    print_R($fault);
}

我在SOAPUI上成功得到了响应,这是使用密钥库和ws-security标头,我做错了什么我能指出正确的方向,提前谢谢,我永远陷入困境:(

0 个答案:

没有答案