Paypal IPN 无法验证

发布于 2024-11-02 05:35:14 字数 1422 浏览 0 评论 0原文

我正在尝试实施 Paypal IPN,但它从未到达我设置的 url。我编写了一个脚本来记录对此网址的访问,我得到的只是我的访问。

Paypal 需要多长时间发送通知?

编辑

IPN 突然开始出现,但现在我无法验证...以下是代码:

$url = 'https://www.paypal.com/cgi-bin/webscr';
        $postdata = '';
        foreach ($_POST as $i => $v) {
            $postdata .= $i . '=' . urlencode($v) . '&';
        }
        $postdata .= 'cmd=_notify-validate';

        $web = parse_url($url);
        if ($web['scheme'] == 'https') {
            $web['port'] = 443;
            $ssl = 'ssl://';
        } else {
            $web['port'] = 80;
            $ssl = '';
        }
        $fp = @fsockopen($ssl . $web['host'], $web['port'], $errnum, $errstr, 30);

        if (!$fp) {
            echo $errnum . ': ' . $errstr;
        } else {
            fputs($fp, "POST " . $web['path'] . " HTTP/1.1\r\n");
            fputs($fp, "Host: " . $web['host'] . "\r\n");
            fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
            fputs($fp, "Content-length: " . strlen($postdata) . "\r\n");
            fputs($fp, "Connection: close\r\n\r\n");
            fputs($fp, $postdata . "\r\n\r\n");

            while (!feof($fp)) {
                $info[] = @fgets($fp, 1024);
            }
            fclose($fp);
            $info = implode(',', $info);
            if (eregi('VERIFIED', $info)) {

            } else {

}

}

I am trying to implement Paypal IPN but it never reaches the url I've set. I've written a script to log visits to this url and all I get are my visits.

How long does it take for Paypal to sent the notification?

EDIT

IPNs suddenly started to come but now I can't verify...Here is the code:

$url = 'https://www.paypal.com/cgi-bin/webscr';
        $postdata = '';
        foreach ($_POST as $i => $v) {
            $postdata .= $i . '=' . urlencode($v) . '&';
        }
        $postdata .= 'cmd=_notify-validate';

        $web = parse_url($url);
        if ($web['scheme'] == 'https') {
            $web['port'] = 443;
            $ssl = 'ssl://';
        } else {
            $web['port'] = 80;
            $ssl = '';
        }
        $fp = @fsockopen($ssl . $web['host'], $web['port'], $errnum, $errstr, 30);

        if (!$fp) {
            echo $errnum . ': ' . $errstr;
        } else {
            fputs($fp, "POST " . $web['path'] . " HTTP/1.1\r\n");
            fputs($fp, "Host: " . $web['host'] . "\r\n");
            fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
            fputs($fp, "Content-length: " . strlen($postdata) . "\r\n");
            fputs($fp, "Connection: close\r\n\r\n");
            fputs($fp, $postdata . "\r\n\r\n");

            while (!feof($fp)) {
                $info[] = @fgets($fp, 1024);
            }
            fclose($fp);
            $info = implode(',', $info);
            if (eregi('VERIFIED', $info)) {

            } else {

}

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

只想待在家 2024-11-09 05:35:14

我上面已经评论过了。但我很确定 html 编码的 & 会弄乱你的回调。

URL 编码HTML 编码 之间存在很大差异。

将此 '&' 更改为此 '&'& 是一个 url/post 字符,用于分隔不同的键/值对集。通过将其更改为 &,您可以使整个回调成为单个值。

另外,只是一些建议,但我会放弃这个

if (eregi('VERIFIED', $info)) {} else {}

并用这个已贬值的 eregi 替换它

if (preg_match('/VERIFIED/', $info))  {} else {}


http://php.net/manual/en/function.eregi.php

I already commented above. But I'm pretty sure the html encoded & is messing up your callback.

There's big difference between URL encoding and HTML encoding.

Change this '&' to this '&'. & is a url/post character used to separate different sets of key/value pairs. By changing it to &, you made your whole callback a single value.

Also, just some advice, but I would ditch this

if (eregi('VERIFIED', $info)) {} else {}

and replace it with this

if (preg_match('/VERIFIED/', $info))  {} else {}

eregi is depreciated.
http://php.net/manual/en/function.eregi.php

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文