【问题标题】:Call SOAP method via CURL in PHP,call require client authenticationPHP中通过CURL调用SOAP方法,调用需要客户端认证
【发布时间】:2011-04-07 09:33:19
【问题描述】:

概述:

代码是关于使用需要客户端身份验证的 SOAP 和 Curl 调用 escreen Web 服务。目前我没有得到任何结果,只有 HTTP 403 和 500 错误。 该调用要求客户端身份验证证书位于调用站点上。

代码:

$content = "<TicketRequest>
  <Version>1.0</Version>
  <Mode>Test</Mode>
  <CommitAction></CommitAction>
  <PartnerInfo>
  <UserName>xxxxxxxxxx</UserName>
  <Password>xxxxxxxxxxx</Password>
  </ PartnerInfo>
  <RequestorOrderID></RequestorOrderID>
  <CustomerIdentification>
    <IPAddress></IPAddress>
    <ClientAccount>xxxxxxxxxx</ClientAccount>
    <ClientSubAccount>xxxxxxxxxx</ClientSubAccount>
    <InternalAccount></InternalAccount>
    <ElectronicClientID></ElectronicClientID>
  </CustomerIdentification>
  <TicketAction>
    <Type></Type>
    <Params>
      <Param>
      <ID>4646</ID>
      <Value></Value>
      </Param>
    </Params>
  </TicketAction>
</TicketRequest>";

$wsdl  = "https://services.escreen.com/SingleSignOnStage/SingleSignOn.asmx";

$headers = array(  "Content-type: text/xml;charset=\"utf-8\"", 
     "Accept: text/xml", 
     "Cache-Control: no-cache", 
     "Pragma: no-cache", 
  //   "SOAPAction: \"\"", 
     "Content-length: ".strlen($content),
    ); 


$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $wsdl); 
curl_setopt($ch, CURLOPT_HEADER, 1); 
curl_setopt($ch, CURLOPT_VERBOSE, '1');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $content); 

curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, '1');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, '1');
//curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: text/xml"));
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
//curl_setopt($ch, CURLOPT_HTTPHEADER, array('SOAPAction: ""')); 
curl_setopt($ch, CURLOPT_CAPATH, '/home/pps/');
curl_setopt($ch, CURLOPT_CAINFO,  '/home/pps/authority.pem');
curl_setopt($ch, CURLOPT_SSLCERT, 'PROTPLUSSOL_SSO.pem');
curl_setopt($ch, CURLOPT_SSLCERTPASSWD, 'xxxxxxxxxxxx');

$output = curl_exec($ch);

// Check if any error occured
if(curl_errno($ch))
{
    echo 'Error no : '.curl_errno($ch).' Curl error: ' . curl_error($ch);
}

print_r($output);

问题:

  1. 我需要调用 RequestTicket 方法并将 XML 字符串传递给它。 这里不知道怎么弄(传方法名调用)。

  2. 对于客户端身份验证,他们给了我们三个证书,一个根证书,一个中间证书 证书和客户端身份验证证书 PROTPLUSSOL_SSOpem(它是一个 .pfx 文件)。由于我们在 linux 上,我们将它们转换为 pem 。在 curl 调用中,我找不到如何同时包含根证书和中间证书的方法,所以我通过创建一个新的 pem 文件并复制中间证书和根证书并将其命名为 authority.pem 来组合它们。 我不确定它是否有效,并希望得到您的意见。

  3. 对于当前代码,我得到了错误 错误编号:77 卷曲错误:错误设置证书验证位置:CAfile:/home/pps/authority.pem CApath:/home/pps/

    如果我禁用 curl 错误消息,我会得到带有页面标题 403 - 禁止的空白页面。访问被拒绝。

    如果我注释掉 CURLOPT_CAPATH 和 CURLOPT_CAINFO 行,它会给出 http 500 错误页面,其中消息作为内容,并且在顶部显示以下内容。

    HTTP/1.1 500 内部服务器错误。缓存控制:私有 内容类型:文本/html 服务器:Microsoft-IIS/7.5 X-AspNet-Version:1.1.4322 X-Powered-By:ASP.NET 日期:2010 年 9 月 2 日星期四 14:46:38 GMT内容长度:1208

如果我如上所述注释掉 CURLOPT_SSLCERT 和 CURLOPT_SSLCERTPASSWD ,则会将消息作为内容给出 403 错误。

所以我会请求你帮助我,指出当前代码有什么问题。

谢谢。

【问题讨论】:

  • 您的PROTPLUSSOL_SSO.pem 是否包含私钥(使用文本编辑器打开并检查是否有---BEGIN ... PRIVATE KEY--- 部分或是否只是---BEGIN CERT...---?您是如何从.pfx 转换为@ 987654326@?

标签: php soap ssl curl


【解决方案1】:

PHP 自带一个soap客户端:

http://php.net/manual/en/book.soap.php

您可以通过将选项local_cert 传递给构造函数来告诉它使用证书。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-03-02
  • 1970-01-01
  • 2016-06-03
  • 1970-01-01
  • 2015-05-03
  • 2016-06-20
相关资源
最近更新 更多