我遇到加载.pem证书以启动SoapClient PHP的问题。
此问题是SoapClient无法读取CodeIgniter上的.pem证书。
我创建了没有Codeigniter框架的测试PHP文件来测试SOAPClient,并且它与我合作。
PHP代码:
$header = array('local_cert' => "newsfile.pem",
'passphrase' => "Comtrust",
'exceptions' => FALSE,
'trace' => true);
CodeIgniter SOAP客户端类:
路径:controllers /
class EtisalatPaymentGateway {
private $client;
function EtisalatPaymentGateway() {
// setup the transaction array
$header = array('local_cert' => APPPATH."controllers/newsfile.pem",
'passphrase' => "Comtrust",
'exceptions' => FALSE,
'trace' => true);
//var_dump($header);
$this->client = new SoapClient("https://demo-ipg.comtrust.ae:2443/MerchantAPIX.svc?wsdl", $header);
//var_dump($client->__getFunctions());
}
public function getSoapClient(){
return $this->client;
}
}
付款CI_Controller
<?php
require_once(APPPATH.'controllers/EtisalatPaymentGateway.php');
class Payment extends CI_Controller {
private $client;
public function __construct() {
parent::__construct();
//$certificate = $this->load->file(__DIR__."/staging.pem",FALSE);
// setup the transaction array
$this->client = new EtisalatPaymentGateway();
}
function authorize($customer, $AccountNumber, $amount, $OrderID, $OrderInfo, $OrderName) {
$body = new StdClass();
$body->Customer = $customer;
$body->Language = "en";
$body->AccountNumber = $AccountNumber;
$body->Amount = $amount;
$body->Channel = 'Phone';
$body->Currency = 'AED';
$body->ExpiryDate = '2018-04-06T00:00:00';
$body->OrderID = $OrderID;
$body->OrderInfo = $OrderInfo;
$body->OrderName = $OrderName;
$body->TransactionHint = '';
$body->VerifyCode = '123';
$params = array(
"request" => $body
);
$response = $this->client->getSoapClient()->__soapCall("Authorize", array($params));
$this->responseJson($response);
}
private function responseJson($response) {
/* Print webservice response */
//print_r($response);
header('Content-Type: application/json');
echo json_encode($response);
}
}
服务器响应:
既未提供证书也未提供密码。
我知道Codeigniter的问题无法读取证书文件。
.pem证书文件存在于/ controller路径上(在同一目录下)。