php curl与证书和密钥文件未与swish付款api连接 [英] php curl with certificate and key file not connecting with swish payment api

查看:115
本文介绍了php curl与证书和密钥文件未与swish付款api连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I need to implement Swish Payment e-commerce API with my website. Testing code given by swish is working fine using Git Bash. Sample is here

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警报握手失败

but when i convert it in php it gives me error cURL Error #:error:14094410:SSL routines:ssl3_read_bytes:sslv3 alert handshake failure

我的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;
}

推荐答案

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

i think the problem here is that your php/libcurl defaulted to SSLv3, and that mss.cpc.getswish.net has turned off support for SSLv3 (most websites don't support it anymore because it's insecure),

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

1: you're running curl_setopt without error checking, fix that

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

2: you forgot to set CURLOPT_SSLVERSION to CURL_SSLVERSION_TLSv1_1 , fix that

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安装.
  • 这篇关于php curl与证书和密钥文件未与swish付款api连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆