简体   繁体   English

paypal ipn没有得到验证

[英]paypal ipn not getting verified

I am using the following code for paypal ipn: 我使用以下代码为paypal ipn:

    <?php

mysql_connect("localhost", "user", "password") or die(mysql_error());
mysql_select_db("PayPal") or die(mysql_error());

// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}
// post back to PayPal system to validate
$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.paypal.com', 443, $errno, $errstr, 30);

if (!$fp) {
// HTTP ERROR
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {

// PAYMENT VALIDATED & VERIFIED!

}

else if (strcmp ($res, "INVALID") == 0) {

// PAYMENT INVALID & INVESTIGATE MANUALY!

}
}
fclose ($fp);
}

    ?>

After testing in every which way, I am getting everything to work except when: 在以各种方式进行测试后,除了以下情况外,我正在努力工作:

if (strcmp ($res, "VERIFIED") == 0)  

does not work 不起作用

if (strcmp ($res, "VERIFIED") == 1)

WORKS 作品

Obviously its not getting verified as I'm sending IPN from sandbox. 显然它没有得到验证,因为我正在从沙箱发送IPN。

What could be missing? 可能会遗漏什么?

Since you both say that strcmp($res, "VERIFIED") == 1 is true, $res is 1 character "bigger" than the string VERIFIED. 由于你们都说strcmp($res, "VERIFIED") == 1为真,所以$ res比字符串VERIFIED“1”字符“更大”。 My guess is that $res has a \\n character at the end or something else that needs to be stripped. 我的猜测是$ res在末尾有一个\\ n字符或者其他需要删除的东西。 Try doing something like str_replace('\\n', '', $res) before calling the lines with strcmp. 在使用strcmp调用行之前str_replace('\\n', '', $res)尝试执行str_replace('\\n', '', $res) Just thinking out loud though. 只是大声思考。 If this is not working, let me know. 如果这不起作用,请告诉我。

Fyi, PayPal has sample code online to verify an IPN in PHP using cURL. Fyi,PayPal在线提供示例代码,使用cURL验证PHP中的IPN。 Link: http://www.x.com/developers/paypal/documentation-tools/paypal-code-samples#instantpaymentnotification 链接: http//www.x.com/developers/paypal/documentation-tools/paypal-code-samples#instantpaymentnotification

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM