PHP : 如何为 SOAP https 请求添加密钥库

PHP : How to add keystore for SOAP https request

我是 PHP 的新手。我的一个 PHP 项目需要进行 SOAP 调用以通过 HTTPS 访问 Web 服务。

服务商只给了我们三个文件.jks,.p12。和 .wsdl file.I 在 SOAPUI 工具中测试了 .wsdl 文件 working.I 在 SOAPUI preference >ssl settings

中上传了我的 .jks 文件

然后我写了我的 PHP 代码

<?php



$wsdl = 'http://localhost/RbphpGateway/librb/RB_OLP_INITIATE_PAYMENT.wsdl';


try{
    $clinet=new SoapClient($wsdl);

    $ver =array("olpIdAlias"=>"****","merchantId"=>"***","merchantRefNum"=>"418934223","paymentAmount"=>"100","paymentCurrency"=>"USD","dynamicMerchantLandingURL"=>"","dynamicMerchantFailureURL"=>"");
    $quates=$clinet->executeRB_OLP_INITIATE_PAYMENT($ver);

    echo  $quates->initiatePaymentDetailsRes->ibURL;


}catch(SoapFault $e){
    echo $e->getMessage();
}

我的输出是

Could not connect to host

根据我对安全 https 连接的了解,我们需要使用代码添加一个密钥库。
谁能给我提示如何在 PHP 中添加证书?我可以用 php 添加我的 .jks 文件吗?

我怀疑这个问题与 https 有关,尤其是当你描述它在 SoupUI 中工作时。

您无法连接到哪个主机?
您引用本地主机上的 wsdl 文件,我怀疑 Web 服务位于不同的主机上?
那么问题是链接到 localhost 还是 ws-host?

开始确保您有权访问 wsdl 文件,并在创建 $clinet 时添加选项 trace = 1 和 exception = 0 :

$clinet=new SoapClient($wsdl,array('trace' => 1, 'exception' => 0));

它允许您使用 $client->__getLastRequest()

进一步检查 soap 结果

我找到了解决方案。首先,我使用 .p12

中的 openssl 生成了 .pem 文件
$wsdl = dirname(__FILE__).'/librb/xxxxxx.wsdl';

$endpoint       = 'https://pay.bnk.com/soap?service=payment';
$local_cert = dirname(__FILE__)."/key1.pem";
$passphrase = "*****";
$options = array(

    'location'      => $endpoint,
    'keep_alive'    => true,
    'trace'         => true,
    'local_cert'    => $local_cert,
    'passphrase'    => $passphrase,
    'cache_wsdl'    => WSDL_CACHE_NONE,
'trace'       => 1,     // traces let us look at the actual SOAP messages later
        'exceptions'  => 1 ,

);

try{
   $client = new SoapClient($wsdl,$options)
    } catch (SoapFault $E) { 
        echo $E->getMessage();
    }