PayPal 与 OpenShift Online 集成——SSL IPN 问题

PayPal integration with OpenShift Online -- SSL IPN Issue

我在 OpenShift Online 上构建了一个应用程序,现在我正在尝试与 PayPal 集成。我 运行 陷入 SSL cURL 错误,我不知道如何解决。我查看了 SO、OpenShift Online、PayPal 和其他地方,但无法解决这个问题。

背景:

这部分代码似乎是我的问题的根源:

// CONFIG: Please download 'cacert.pem' from "http://curl.haxx.se/docs/caextract.html" and set the directory path
// of the certificate as shown below. Ensure the file is readable by the webserver.
// This is mandatory for some environments.

//$cert = __DIR__ . "./cacert.pem";
//curl_setopt($ch, CURLOPT_CAINFO, $cert);

问题:

[1] 使用代码 "as is"(第 79-80 行已注释掉)抛出 curl 错误:"SSL connect error"

[2] 使用第 79-80 行未注释掉(并且 cacert.pem 与 php 脚本放在同一目录中)抛出 curl 错误:"Problem with the SSL CA cert (path? access rights?)"

我可能在这里遗漏了一些简单的东西。非常感谢任何帮助让它在 OpenShift Online 上正常工作的帮助。谢谢!

这一行很可疑:

$cert = __DIR__ . "./cacert.pem";

基本上你最终会得到类似 $cert 等于 /home/path./cacert.pem 的东西,我很确定这不是你想要的,为什么你会收到 ssl 错误,它找不到证书。 可以更正为:

$cert = __DIR__ . "/cacert.pem";

最好将 cacert.pem 存储在您的 $OPENSHIFT_DATA_DIR 中并这样引用它:

$cert = getenv("OPENSHIFT_DATA_DIR")."cacert.pem";

并确保 cacert.pem 的权限至少为 0644

chmod 0644 $OPENSHIFT_DATA_DIR/cacert.pem

解决方案:

强制使用 TLS 1.2

注释掉第 79-80 行并添加

curl_setopt($ch, CURLOPT_SSLVERSION, 6); // Force TLS 1.2

帮了我大忙。希望这对其他人有帮助。

P.S。对 TLS 1.2 的需求来自这篇 PayPal 文章 https://www.paypal-knowledge.com/infocenter/index?page=content&widgetview=true&id=FAQ1914&viewlocale=en_US