php curl与证书和密钥文件未与swish付款api连接

时间:2019-03-21 13:43:11

标签: php curl certificate pem swish

我需要在我的网站上实施Swish Payment电子商务API。 swish给出的测试代码可以使用Git Bash正常运行。 样品在这里

curl -s -S -i --cert ./Swish_Merchant_TestCertificate_1231181189.pem --key ./Swish_Merchant_TestCertificate_1231181189.key --cacert ./Swish_TLS_RootCA.pem --tlsv1.1 --header "Content-Type: application/json" https://mss.cpc.getswish.net/swish-cpcapi/api/v1/paymentrequests --data '{ "payeePaymentReference" : "0123456789", "callbackUrl" : "https://myfakehost.se/swishcallback.cfm", "payerAlias" : "4671234768", "payeeAlias" : "1231181189", "amount" : "100", "currency" : "SEK", "message" : "Kingston USB Flash Drive 8 GB" }'

但是当我在php中转换它给我错误 cURL错误#:error:14094410:SSL例程:ssl3_read_bytes:sslv3警报握手失败

我的php代码在这里

    $data = array(
    "content-type: application/json",
    "accept: application/json",
    "payeePaymentReference: 0123456789",
    "callbackUrl: https://myfakehost.se/swishcallback.cfm",
    "payerAlias: 4671234768",
    "payeeAlias: 1231181189",
    "amount: 100",
    "currency: SEK",
    "message: Kingston USB Flash Drive 8 GB"
);
$curl = curl_init();
curl_setopt($curl, CURLOPT_SSLCERT, getcwd() . '/Swish_Merchant_TestCertificate_1231181189.pem');
curl_setopt($curl, CURLOPT_SSLKEY, getcwd() .'/Swish_Merchant_TestCertificate_1231181189.key');
curl_setopt($curl, CURLOPT_SSLKEYPASSWD,  'swish');
curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://mss.cpc.getswish.net/swish-cpcapi/v1/paymentrequests/',
  CURLOPT_RETURNTRANSFER => TRUE,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_POSTFIELDS => json_encode($data),
  CURLOPT_HTTPHEADER => array(
    "content-type: application/json"
  )
));

$response = curl_exec($curl);

$err = curl_error($curl);
curl_close($curl);
if ($err) {
   echo "cURL Error #:" . $err;
} else {
   echo "Well:" .$response;
}

1 个答案:

答案 0 :(得分:0)

我认为这里的问题是您的php / libcurl默认为SSLv3,并且mss.cpc.getswish.net已关闭了对SSLv3的支持(大多数网站不再支持它,因为它不安全),

1:您正在运行curl_setopt而不进行错误检查,请解决此问题

2:您忘记将CURLOPT_SSLVERSION设置为CURL_SSLVERSION_TLSv1_1,请解决此问题

if(!curl_setopt($ch,CURLOPT_SSLVERSION,CURL_SSLVERSION_TLSv1_1)){
    throw new \RuntimeException('failed to set CURL_SSLVERSION_TLSv1_1');
}
  • 但是鉴于您的php / libcurl安装默认为SSLv3,因此您的php安装可能太旧而无法使用TLS1.1。.这意味着您可能需要更新php / libcurl安装。