gpt4 book ai didi

python - Sandbox Paypal IPN 不发送响应,适用于实时网站 Paypal

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

这个问题是最近才出现的:我无法从paypal沙盒(IPN)中得到响应。

我使用以下代码:

import requests
params = {} #all params paypal sent via IPN, empty here for sake of brevity
params['cmd'] = "_notify-validate"
r = requests.post("https://www.sandbox.paypal.com/cgi-bin/webscr", params = params)

这将返回一条错误消息,指出“连接由对等方重置”

请注意,此代码之前运行良好,如果我使用实时站点 Paypal URL 而不是沙箱,那么我仍然会收到响应而不是连接错误。

任何人都可以验证这是否是 Paypal 端的问题?我的代码都没有改变,但从昨天开始,我使用沙箱进行的所有测试都不再有效。

最佳答案

PayPal 目前在沙盒环境中未遇到 IPN 问题。我已经过测试,但无法重现所描述的问题。请您尝试测试下面的代码,看看是否有相同的结果?

<?php

// change email from xxx@xxxx.com to a valid one.

// read the post from PayPal system and add 'cmd'
if($_SERVER['REQUEST_METHOD']!="POST") die("No data");
$req = 'cmd=_notify-validate';
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}

// post back to PayPal system to validate
$url=(!isset($_POST['test_ipn'])) ? 'https://www.paypal.com/cgi-bin/webscr' : 'https://www.sandbox.paypal.com/cgi-bin/webscr';

$curl_result=$curl_err='';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/x-www-form-urlencoded", "Content-Length: " . strlen($req)));
curl_setopt($ch, CURLOPT_HEADER , 0);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
$curl_result = @curl_exec($ch);
$curl_err = curl_error($ch);
curl_close($ch);

//are we verified? If so, let's process the IPN
if (strpos($curl_result, "VERIFIED")!==false)
{
//do your IPN stuff here
$mail_From = "From: IPN@domain.com"; // enter an email address alias here example ipn@fiercepc.co.uk please note this does not need to be a real email address
$mail_To = "email@domain.com"; //enter the email address you want to receive the email at
$mail_Subject = "VERIFIED IPN";
$mail_Body = $req;

foreach ($_POST as $key => $value){
$emailtext .= $key . " = " .$value ."\r\n\r\n";
}

mail($mail_To, $mail_Subject, $emailtext . "\r\n\r\n" . $mail_Body, $mail_From);
}
else{
$mail_From = "From: IPN@domain.com";
$mail_To = "email@domain.com";
$mail_Subject = "INVALID IPN";
$mail_Body = $req;

$emailtext = "you didn't get anything";
mail($mail_To, $mail_Subject, $emailtext . "\r\n\r\n" . $mail_Body, $mail_From);
}

?>

或转到 GitHub 存储库以查找更多 IPN 示例。

https://github.com/paypal/ipn-code-samples

关于python - Sandbox Paypal IPN 不发送响应,适用于实时网站 Paypal,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26305235/

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