php - PayPal 自动返回脚本总是被调用两次
问题描述
我目前正在使用 PayPal 进行付款。直到最近,一切都很顺利。我有一个订阅按钮。我已经设置了返回 URL 来处理从交易中获取数据然后将其邮寄给用户。我需要的所有数据都已成功检索,但是,问题是我的函数在返回时运行了两次。我收到了我应该收到两次的电子邮件。几周前这工作正常,所以现在我想知道发生了什么,为什么它突然出现了这个错误。
我在这里读过:Paypal 自适应支付返回 url 调用了两次,这可能是因为我点击了“单击此处”按钮,即使它还没有 10 秒。我已经尝试单击而不是单击它,但我仍然得到相同的结果。
我还读到这可能是因为它在付款时被调用,然后在订阅开始时被调用。知道我该如何处理吗?
$pp_hostname = "www.sandbox.paypal.com"; // Change to www.sandbox.paypal.com to test against sandbox
$req = 'cmd=_notify-synch';
$tx_token = $_GET['tx'];
$auth_token = "my_token_from_paypal";
$req .= "&tx=$tx_token&at=$auth_token";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://$pp_hostname/cgi-bin/webscr");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
//set cacert.pem verisign certificate path in curl using 'CURLOPT_CAINFO' field here,
//if your server does not bundled with default verisign certificates.
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Host: $pp_hostname"));
$res = curl_exec($ch);
curl_close($ch);
if(!$res){
//HTTP ERROR
}else{
// parse the data
$lines = explode("\n", trim($res));
$keyarray = array();
if (strcmp ($lines[0], "SUCCESS") == 0)
{
for ($i = 1; $i < count($lines); $i++) {
$temp = explode("=", $lines[$i],2);
$keyarray[urldecode($temp[0])] = urldecode($temp[1]);
}
// code for mail handling
}
else if (strcmp ($lines[0], "FAIL") == 0) {
echo 'there has been an error';
}
}
解决方案
推荐阅读
- swift - 当列表中的最后一项是 HStack 时,应用程序崩溃
- rest - 当我使用spring boot和restful在application.properties文件中有属性时如何获取Json格式输出
- xml - 使用 Groovy 在 SOAP 响应中替换为“”
- php - 对 Google 的 DCM/DFA API 的未经授权的 HTTP 请求
- javascript - 悬停在 ul li 上时更改 body bgcolor。CSS
- javascript - 无法解决错误:`RangeError: Invalid time zone specified: undefined at new DateTimeFormat (native) at Date.toLocaleString (native)`
- go - 如何使用 *time.Time 在协议缓冲区的结构中声明
- c# - StackExchange.Redis - 如何获取密钥的类型?
- javascript - className 如何将错误的东西返回给我?
- python - 如何使用 python 查找图像文件并以不同的文件格式保存它们?