PHP SoapClient 警告:SoapClient::SoapClient():无法设置私钥文件

发布于 2024-08-19 02:25:41 字数 1143 浏览 3 评论 0原文

我正在尝试使用肥皂来调用网络服务,但我不断收到以下错误“警告:SoapClient::SoapClient():无法设置私钥文件”。

我假设错误是由于我使用的 .cer 文件仅包含公钥而没有私钥这一事实引起的。但我不确定使用 .cer 文件的另一种方法。如果我不使用 .cer 文件,我可以很好地连接,并且当我使用 __getFunctions() 方法时,我可以调用并接收结果。但是,当我尝试使用其他方法时,我需要获得授权,这会导致问题。下面是我尝试使用的简单代码。如果需要更多信息,请告诉我。

ini_set('display_errors',1);
error_reporting(E_ALL);

ini_set('soap.wsdl_cache_enabled', 0);
$username = 'user';
$password = 'pass';

$ns = 'GatewayEDI.WebServices';
$auth = array();
$auth['User'] = new SOAPVar($username, XSD_STRING, null, null, null, $ns);
$auth['Password'] = new SOAPVar($password, XSD_STRING, null, null, null, $ns);
$headerBody = new SOAPVar($auth, SOAP_ENC_OBJECT);
$header = new SOAPHeader($ns, 'AuthSOAPHeader', $headerBody);

$client=new SoapClient('https://url/Service.asmx?WSDL',
                   array(
                  'local_cert' => 'file.cer'
                   ));

$client->__setSOAPHeaders(array($header));

$param = array(
  'X12Input'=>"testing",
  "GediPayerID"=>"52",
  "ResponseDataType"=>"Xml"
);

//this leads to private key error
echo $result = $client->DoInquiryByX12Data($param,$header);

I'm trying to use soap to call a webservice but I keep getting the following error "Warning: SoapClient::SoapClient(): Unable to set private key file".

I'm assuming that the error comes due to the fact the the .cer file I am using only includes public key and no private key. But i'm not sure of another way to use the .cer file. If i don't use the .cer file i can connect just fine and I am able to call and receive results when i use the __getFunctions() method. However, when i try to use other methods i need to be authorized and that leads to the problem. Below is the simple code i am trying to use. Please let me know if more information is required.

ini_set('display_errors',1);
error_reporting(E_ALL);

ini_set('soap.wsdl_cache_enabled', 0);
$username = 'user';
$password = 'pass';

$ns = 'GatewayEDI.WebServices';
$auth = array();
$auth['User'] = new SOAPVar($username, XSD_STRING, null, null, null, $ns);
$auth['Password'] = new SOAPVar($password, XSD_STRING, null, null, null, $ns);
$headerBody = new SOAPVar($auth, SOAP_ENC_OBJECT);
$header = new SOAPHeader($ns, 'AuthSOAPHeader', $headerBody);

$client=new SoapClient('https://url/Service.asmx?WSDL',
                   array(
                  'local_cert' => 'file.cer'
                   ));

$client->__setSOAPHeaders(array($header));

$param = array(
  'X12Input'=>"testing",
  "GediPayerID"=>"52",
  "ResponseDataType"=>"Xml"
);

//this leads to private key error
echo $result = $client->DoInquiryByX12Data($param,$header);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

束缚m 2024-08-26 02:25:41

我相信您的 .pem/.cer 文件中应该包含您的私钥:

-----BEGIN RSA PRIVATE KEY----- 
# base64 encoded key 
-----END RSA PRIVATE KEY----- 
-----BEGIN CERTIFICATE----- 
# base64 encoded cert
-----END CERTIFICATE-----

如果您的私钥的第一行有类似于“Proc-Type: 4,ENCRYPTED”的指令,则在构建时需要包含“passphrase”选项您的 SoapClient()。您还可以使用 OpenSSL 删除密码短语要求,我的语法有点生疏,因此您可能需要仔细检查是否尝试:

openssl rsa -in /path/to/private.key -out /path/to/private.key

“private.key”应该只是此上下文中的私钥(您可以将其添加到 .删除密码后的 cer/.pem 文件。

I believe your .pem/.cer file should have your private key in it:

-----BEGIN RSA PRIVATE KEY----- 
# base64 encoded key 
-----END RSA PRIVATE KEY----- 
-----BEGIN CERTIFICATE----- 
# base64 encoded cert
-----END CERTIFICATE-----

If your private key's first line has a directive similar to "Proc-Type: 4,ENCRYPTED" you'll need to include the "passphrase" option when constructing your SoapClient(). You can also strip the passphrase requirement with OpenSSL, my syntax is a bit rusty so you may want to double check if you try it:

openssl rsa -in /path/to/private.key -out /path/to/private.key

"private.key" should be just the private key in this context (you can add it into the .cer/.pem file after the passphrase has been removed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文