【发布时间】:2018-06-20 12:30:06
【问题描述】:
我正在尝试将数据发布到支付网关 API。它需要 xml 格式的发布数据。我有以下代码:
<?php
$requestUrl = 'https://api.given.bypg'; //$block->getPaymentUrl();
$amount = 100; // $block->totalOrderAmount()*100;
$approveUrl = $block->approveUrl();
$cancelUrl = $block->cancelUrl();
$declineUrl = $block->declineUrl();
$merchant = 'mydomain.com';
//$amount = '100'; // in cents. 1$ = 100cents.
$currency = '840'; // for dollar
$description = 'Happy customers is what we make.';
$merchantId = 'Nobel106513';
?>
<?php
echo $requestUrl;
$xml_data = '<TKKPG>
<Request>
<Operation>CreateOrder</Operation>
<Language>EN</Language>
<Order>
<OrderType>Purchase</OrderType>
<Merchant>'.$merchantId.'</Merchant>
<Amount>'.$amount.'</Amount>
<Currency>'.$currency.'</Currency>
<Description>'.$description.'</Description>
<ApproveURL>'.$approveUrl.'</ApproveURL>
<CancelURL>'.$cancelUrl.'</CancelURL>
<DeclineURL>'.$declineUrl.'</DeclineURL>
</Order>
</Request>
</TKKPG>';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $requestUrl);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 60000);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_data);//My post data
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_CAPATH, "/etc/apache2/ssl/m4/mydomain.com.crt");
curl_setopt($ch, CURLOPT_CAINFO, "/etc/apache2/ssl/m4/mydomain.com.crt");
curl_setopt($ch, CURLOPT_CERTINFO, 1);
$headers = [];
array_push($headers, 'Content-Type: text/xml;charset=UTF-8');
//array_push($headers, 'SoapAction: *');
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$content = trim(curl_exec($ch));
var_dump($content);
var_dump(curl_getinfo($ch));
var_dump(curl_errno($ch));
var_dump(curl_error($ch));
curl_close($ch);
-
var_dump($content);的输出为空''。 -
var_dump(curl_getinfo($ch));的输出。数组(大小=26)
'url' => 字符串'https://api.given.bypg'
'content_type' => 空
'http_code' => int 0
'header_size' => int 0
'request_size' => int 0
'文件时间' => int -1
'ssl_verify_result' => int 1
'redirect_count' => int 0
'total_time' => 浮动 0.488533
'namelookup_time' => 浮动 0.028558
'connect_time' => 浮动 0.256858
'pretransfer_time' => 浮动 0
'size_upload' => 浮动 0
'size_download' => 浮动 0
'speed_download' => 浮动 0
'speed_upload' => 浮动 0
'download_content_length' => 浮动 -1
'upload_content_length' => 浮动 -1
'starttransfer_time' => 浮动 0
'redirect_time' => 浮动 0
'redirect_url' => 字符串'' (长度=0)
'primary_ip' => 字符串'91.227.244.57'(长度=13)
'certinfo' =>
数组(大小=0)
空
'primary_port' => int 8444
'local_ip' => 字符串'192.168.100.64'(长度=14)
'local_port' => int 53456 var_dump(curl_errno($ch));的输出:int 60-
var_dump(curl_error($ch));的输出:string 'SSL 证书问题:无法获取本地颁发者证书'(长度=63) 正如 curl_getinfo() 所见,API 似乎没有返回任何数据。请帮助我,我已经看到了社区中建议的几乎所有解决方案。
我已经编辑了我的php.ini 文件以提供从 curl 网站下载的证书的路径。但这也不起作用。
【问题讨论】:
-
该错误表示 /etc/apache2/ssl/m4/mydomain.com.crt 不包含签署 HTTPS 服务器证书的 CA 证书。您需要添加它们。
-
@Oleg 对不起,我没明白。我从我的支付网关获得了这个证书。你能不能再详细点。感谢您的回复。
标签: ssl curl ssl-certificate php-curl