Paypal IPN 持续 returns 来自 Sandbox 的无效

Paypal IPN continually returns invalid from Sandbox

我知道这个问题已经被问了很多,但我已经完成了我能找到的所有答案并且 none 对我有所帮助;很多都是岁,所以我不确定这是否是问题的一部分。

我一直在通过沙盒发送 IPN 来测试贝宝 IPN 侦听器。它声明 IPN 已发送并且握手已验证,但返回给侦听器的状态始终无效。我尝试了几个不同的示例,但 none 有效。我已经剥离了我的代码,只记录输入文本、输出文本、来自 paypal 的验证状态和 http 状态代码:

<?php

define("LOG_FILE", "./ipn.log");
define("DEBUG", 0);
define("USE_SANDBOX", 1); //for testing

//get raw input
$stream_input = file_get_contents('php://input');
error_log(date('[Y-m-d H:i e] '). $stream_input. PHP_EOL, 3, LOG_FILE); //log result for comparison to return string

//choose correct URL
if(USE_SANDBOX == 1) {
    $paypal_url = "https://www.sandbox.paypal.com/cgi-bin/webscr";
} else {
    $paypal_url = "https://www.paypal.com/cgi-bin/webscr";
}

// add cmd for return request
$return_string = 'cmd=_notify-validate&' . $stream_input;
error_log(date('[Y-m-d H:i e] '). $return_string. PHP_EOL, 3, LOG_FILE); //log result for comparison

//cURL setup
$ch = curl_init($paypal_url);
if ($ch == FALSE) {
    return FALSE;
}
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $return_string);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close'));
$verification_status = curl_exec($ch);
$http_status   = curl_getinfo($ch, CURLINFO_HTTP_CODE);

//log result
error_log(date('[Y-m-d H:i e] '). $verification_status . PHP_EOL, 3, LOG_FILE);
error_log(date('[Y-m-d H:i e] '). $http_status . PHP_EOL, 3, LOG_FILE);

//log cURL errors
if (curl_errno($ch) != 0) // cURL error
    {
    if(DEBUG == true) { 
        error_log(date('[Y-m-d H:i e] '). "Can't connect to PayPal to validate IPN message: " . curl_error($ch) . PHP_EOL, 3, LOG_FILE);
    }
    curl_close($ch);
    exit;
} else {
        // Log the entire HTTP response if debug is switched on.
        if(DEBUG == true) {
            error_log(date('[Y-m-d H:i e] '). "HTTP request of validation request:". curl_getinfo($ch, CURLINFO_HEADER_OUT) ." for IPN payload: $return_array" . PHP_EOL, 3, LOG_FILE);
            error_log(date('[Y-m-d H:i e] '). "HTTP response of validation request: $verification_status" . PHP_EOL, 3, LOG_FILE);
        }
        curl_close($ch);
}
?>

这是我在日志中得到的输出:

[2016-06-20 03:52 America/New_York] payment_type=instant&payment_date=Mon%20Jun%2020%202016%2017%3A50%3A12%20GMT+1000%20%28AUS%20Eastern%20Standard%20Time%29&payment_status=Canceled_Reversal&address_status=confirmed&payer_status=verified&first_name=John&last_name=Smith&payer_email=buyer@paypalsandbox.com&payer_id=TESTBUYERID01&address_name=John%20Smith&address_country=United%20States&address_country_code=US&address_zip=95131&address_state=CA&address_city=San%20Jose&address_street=123%20any%20street&business=seller@paypalsandbox.com&receiver_email=seller@paypalsandbox.com&receiver_id=seller@paypalsandbox.com&residence_country=US&item_name=something&item_number=AK-1234&quantity=1&shipping=3.04&tax=2.02&mc_currency=USD&mc_fee=0.44&mc_gross=12.34&mc_gross_1=12.34&txn_type=web_accept&txn_id=146655022&notify_version=2.1&parent_txn_id=SOMEPRIORTXNID003&reason_code=other&custom=xyz123&invoice=abc1234&test_ipn=1&verify_sign=AFcWxV21C7fd0v3bYYYRCpSSRl31AXwY9QNq9ZSeZMzEi6Nyk68hdvbc
[2016-06-20 03:52 America/New_York] cmd=_notify-validate&payment_type=instant&payment_date=Mon%20Jun%2020%202016%2017%3A50%3A12%20GMT+1000%20%28AUS%20Eastern%20Standard%20Time%29&payment_status=Canceled_Reversal&address_status=confirmed&payer_status=verified&first_name=John&last_name=Smith&payer_email=buyer@paypalsandbox.com&payer_id=TESTBUYERID01&address_name=John%20Smith&address_country=United%20States&address_country_code=US&address_zip=95131&address_state=CA&address_city=San%20Jose&address_street=123%20any%20street&business=seller@paypalsandbox.com&receiver_email=seller@paypalsandbox.com&receiver_id=seller@paypalsandbox.com&residence_country=US&item_name=something&item_number=AK-1234&quantity=1&shipping=3.04&tax=2.02&mc_currency=USD&mc_fee=0.44&mc_gross=12.34&mc_gross_1=12.34&txn_type=web_accept&txn_id=146655022&notify_version=2.1&parent_txn_id=SOMEPRIORTXNID003&reason_code=other&custom=xyz123&invoice=abc1234&test_ipn=1&verify_sign=AFcWxV21C7fd0v3bYYYRCpSSRl31AXwY9QNq9ZSeZMzEi6Nyk68hdvbc
[2016-06-20 03:52 America/New_York] INVALID
[2016-06-20 03:52 America/New_York] 200

我已经对输入和输出字符串进行了对比测试,除了输出字符串开头的 'cmd=_notify-validate&' 之外,它们完全相同。我尝试像大多数示例一样使用 urlencode 将输出作为数组发回,但也没有成功。

拜托,我错过了什么?

我遇到了完全相同的问题。这似乎是 IPN 模拟器和任何日期字段中的错误。编码似乎全乱了,这意味着当您尝试 post 返回数据以验证它时,PayPal 认为消息不一样。

清除所有日期字段,然后它应该可以工作了。