gpt4 book ai didi

php - 使用 fsockopen 警告握手失败 paypal IPN 集成

转载 作者:太空宇宙 更新时间:2023-11-03 16:07:36 28 4
gpt4 key购买 nike

我在将 Paypal IPN 集成到我的网站时遇到问题。警告是

"Warning: fsockopen() [function.fsockopen]: SSL operation failed with code 1

OpenSSL 错误信息:

error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure in /home/..." on this line: $fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);

我使用 fsockopen,因为几个月前我只能找到工作样本。但是当我 2 天前尝试时,它显示了错误。这是我的代码:

<?php

$return_url = "http://www.domain.com.au/member/payment.php";
$cancel_url = "http://www.domain.com.au/member/request.php";
$notify_url = "http://www.domain.com.au/member/payment.php";

// Check if paypal request or response
if (!isset($_POST["txn_id"]) && !isset($_POST["txn_type"])){
$querystring = '';
$paypalQueryString = "?business=".urlencode('my-facilitator@yahoo.com')."&";

$paypalQueryString .= "item_name=".urlencode('Item Name')."&";
$paypalQueryString .= "amount=".urlencode($totalPrice)."&";
$paypalQueryString .= "cmd=_xclick&no_note=1&lc=AU&currency_code=AUD&bn=PP-BuyNowBF%3Abtn_buynow_LG.gif%3ANonHostedGuest&";
$paypalQueryString .= "first_name=".urlencode($niceName)."&";
$paypalQueryString .= "last_name=&";
$paypalQueryString .= "payer_email=".urlencode($payerEmail)."&";
$paypalQueryString .= "item_number=".urlencode($accountID)."&";
$paypalQueryString .= "submit=Submit+Payment&";
$paypalQueryString .= "return=".urlencode(stripslashes($return_url))."&";
$paypalQueryString .= "cancel_return=".urlencode(stripslashes($cancel_url))."&";
$paypalQueryString .= "notify_url=".urlencode($notify_url);

// Redirect to paypal IPN
header('location:https://www.sandbox.paypal.com/cgi-bin/webscr'.$paypalQueryString);
//header('location:https://www.paypal.com/cgi-bin/webscr'.$paypalQueryString);
exit();
}
else {
//Response from Paypal
//echo "<pre>".var_dump($_POST)."</pre>";

// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$value = preg_replace('/(.*[^%^0^D])(%0A)(.*)/i','${1}%0D%0A${3}',$value);// IPN fix
$req .= "&$key=$value";
}

// assign posted variables to local variables
$data['item_name'] = $_POST['item_name'];
$data['item_number'] = $_POST['item_number'];
$data['payment_status'] = $_POST['payment_status'];
$data['payment_amount'] = $_POST['mc_gross'];
$data['payment_currency'] = $_POST['mc_currency'];
$data['txn_id'] = $_POST['txn_id'];
$data['receiver_email'] = $_POST['receiver_email'];
$data['payer_email'] = $_POST['payer_email'];
$data['custom'] = $_POST['custom'];

$header = "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";

$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
//$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);

if (!$fp) {
echo "HTTP Error";
}
else {
fputs($fp, $header . $req);
$res = stream_get_contents($fp, 2048);
if (strpos(trim($res), "VERIFIED") !== false) {
// update transaction --> paid status
}
else if (strpos (trim($res), "INVALID") !== false) {
}
else{
}
fclose ($fp);
}
}
?>

希望有人能帮助我。谢谢

最佳答案

我处于类似情况,但我使用的是 cURL 而不是 fsockopen。 PayPal 刚刚开始要求所有与沙箱的连接都通过 TLS 1.2(和 HTTP 1.1)完成。

https://devblog.paypal.com/upcoming-security-changes-notice/

也许尝试改变这条线

$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);

为了这个?

$fp = fsockopen ('tls://www.sandbox.paypal.com', 443, $errno, $errstr, 30);

关于php - 使用 fsockopen 警告握手失败 paypal IPN 集成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34961916/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com