Paypal IPN - 无需与 iPN 模拟器握手 - 使用 github 示例代码

2024-01-26

很短,有很多关于此的问题,我已经浏览了很多,但找不到答案。

它应该很简单,我将 github 示例代码复制到我的服务器,将 paypal IPN 模拟器指向它,它应该给我一个握手。事实并非如此。

我启动 IPN 模拟器,收到的错误消息是: “未发送 IPN,且未验证握手。请检查您的信息。”

我已经逐行进行了操作,并且使用了确切的示例代码,我已确保发送到沙箱......

我已经努力了两天才让它发挥作用。任何帮助将不胜感激。

这是课程:

    <?php
    class PaypalIPN
    {
        /**
         * @var bool $use_sandbox     Indicates if the sandbox endpoint is used.
         */
        private $use_sandbox = false;
        /**
         * @var bool $use_local_certs Indicates if the local certificates are used.
         */
        private $use_local_certs = true;
        /** Production Postback URL */
        const VERIFY_URI = 'https://ipnpb.paypal.com/cgi-bin/webscr';
        /** Sandbox Postback URL */
        const SANDBOX_VERIFY_URI = 'ssl:https://ipnpb.sandbox.paypal.com/cgi-bin/webscr';
        /** Response from PayPal indicating validation was successful */
        const VALID = 'VERIFIED';
        /** Response from PayPal indicating validation failed */
        const INVALID = 'INVALID';
        /**
         * Sets the IPN verification to sandbox mode (for use when testing,
         * should not be enabled in production).
         * @return void
         */
        public function useSandbox()
        {
            $this->use_sandbox = true;
        }
        /**
         * Sets curl to use php curl's built in certs (may be required in some
         * environments).
         * @return void
         */
        public function usePHPCerts()
        {
            $this->use_local_certs = false;
        }
        /**
         * Determine endpoint to post the verification data to.
         * @return string
         */
        public function getPaypalUri()
        {
            if ($this->use_sandbox) {
                return self::SANDBOX_VERIFY_URI;
            } else {
                return self::VERIFY_URI;
            }
        }
        /**
         * Verification Function
         * Sends the incoming post data back to PayPal using the cURL library.
         *
         * @return bool
         * @throws Exception
         */
        public function verifyIPN()
        {
            if ( ! count($_POST)) {
                throw new Exception("Missing POST Data");
            }
            $raw_post_data = file_get_contents('php://input');
            $raw_post_array = explode('&', $raw_post_data);
            $myPost = array();
            foreach ($raw_post_array as $keyval) {
                $keyval = explode('=', $keyval);
                if (count($keyval) == 2) {
                    // Since we do not want the plus in the datetime string to be encoded to a space, we manually encode it.
                    if ($keyval[0] === 'payment_date') {
                        if (substr_count($keyval[1], '+') === 1) {
                            $keyval[1] = str_replace('+', '%2B', $keyval[1]);
                        }
                    }
                    $myPost[$keyval[0]] = urldecode($keyval[1]);
                }
            }
            // Build the body of the verification post request, adding the _notify-validate command.
            $req = 'cmd=_notify-validate';
            $get_magic_quotes_exists = false;
            if (function_exists('get_magic_quotes_gpc')) {
                $get_magic_quotes_exists = true;
            }
            foreach ($myPost as $key => $value) {
                if ($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1) {
                    $value = urlencode(stripslashes($value));
                } else {
                    $value = urlencode($value);
                }
                $req .= "&$key=$value";
            }
            // Post the data back to PayPal, using curl. Throw exceptions if errors occur.
            $ch = curl_init($this->getPaypalUri());
            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, $req);
            curl_setopt($ch, CURLOPT_SSLVERSION, 6);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
            // This is often required if the server is missing a global cert bundle, or is using an outdated one.
            if ($this->use_local_certs) {
                curl_setopt($ch, CURLOPT_CAINFO, __DIR__ . "/cert/cacert.pem");
            }
            curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
            curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close'));
            $res = curl_exec($ch);
            if ( ! ($res)) {
                $errno = curl_errno($ch);
                $errstr = curl_error($ch);
                curl_close($ch);
                throw new Exception("cURL error: [$errno] $errstr");
            }
            $info = curl_getinfo($ch);
            $http_code = $info['http_code'];
            if ($http_code != 200) {
                throw new Exception("PayPal responded with http code $http_code");
            }
            curl_close($ch);
            // Check if PayPal verifies the IPN data, and if so, return true.
            if ($res == self::VALID) {
                return true;
            } else {
                return false;
            }
        }
    }

这是listener.php:

    <?php 
    namespace Listener;
    require('PaypalIPN.php');
    use PaypalIPN;
    $ipn = new PaypalIPN();
    // Use the sandbox endpoint during testing.
    $ipn->useSandbox();
    $verified = $ipn->verifyIPN();
    if ($verified) {
        /*
         * Process IPN
         * A list of variables is available here:
         * https://developer.paypal.com/webapps/developer/docs/classic/ipn/integration-guide/IPNandPDTVariables/
         */
    }
    // Reply with an empty 200 response to indicate to paypal the IPN was received correctly.
    header("HTTP/1.1 200 OK");

None

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Paypal IPN - 无需与 iPN 模拟器握手 - 使用 github 示例代码 的相关文章

  • Paypal订阅付款错误消息3005

    我正在尝试贝宝定期付款并使用此表格 表单操作 名称 xclick subscriptions 方法 post gt 登录paypal付款时出现错误消息 抱歉 您的上一个操作无法完成 如果您要进行购买或汇款 我们建议您在 30 分钟后检查您的
  • PayPal API 与 Laravel - 数据更新

    我正在尝试实施API of PayPal payment with Laravel 5 1 但是当我登录到PayPal sandbox 它使用我在帐户中使用的地址 并且还使用 PayPal 帐户中的名称而不是我网站中的数据 这是我的问题 我
  • 为什么我的 build.gradle android studio 中没有 allprojects{}?

    我正在开发一个 Android 应用程序 我需要将 PayPal 付款方式添加到该应用程序 所以我使用这个 https developer paypal com docs business native checkout android h
  • Android应用内购买,如何检查用户是否购买了一件商品

    在 SharedPreference 中设置一个值来标记用户已购买该商品是否可以且安全 如果用户在 SharedPreference 中破解此值会怎样 或者我每次都需要连接IAP服务来检查用户是否可以使用它 1 使用 Google Andr
  • 任意金额、任意时间的定期付款?

    我们希望找到一个支付提供商 可以让我们做类似于 Hailo 的事情 即 用户注册并向我们提供他们的信用卡详细信息 授权我们向他们的帐户收费 他们只需要这样做once 在 Hailo 的例子中 用户可以随时乘坐出租车并收取任意金额的费用 在合
  • Paypal IPN 捐赠

    我有一个 WordPress 1 页网站 可以选择在 Paypal 捐赠后下载音乐曲目 最低金额为 3 99 美元 该按钮工作正常并且贝宝付款通过 但我只是从贝宝返回无效 它似乎没有正确地将内容写回到贝宝 另外 我怎样才能看到贝宝发回给我的
  • PayPal iOS 和 Android SDK 中的 PAYMENT_CREATION_ERROR

    今天 我在 iOS 应用程序中使用 PayPal 结帐时遇到问题 用户登录后 我收到错误 PayPal SDK 请求失败 出现错误 PAYMENT CREATION ERROR 设置此付款时出现问题 请访问 PayPal 网站检查您的帐户
  • Paypal 沙盒显示错误

    单击 继续 按钮登录后 Paypal 沙箱显示错误 Error no template specified at engine x ebay cronus software service nodes ENVaqqittlg2x28 uni
  • 如何防止PayPal重复付款?

    我有一个简单的 立即付款 按钮 通过按钮创建者创建的代码 并添加了一个 自定义 隐藏字段来识别它 我想知道是否可以添加一些额外的隐藏字段来告诉 PayPal 此交易不应进行两次
  • PayPal API:如何获取销售 ID 并通过 PayPal 退款?

    我使用 PHP 中的 PayPal API 来创建交易 既使用信用卡又通过 PayPal 本身 此外 我需要能够退还这些交易 我使用的代码大部分直接来自 PayPal API 示例 对于信用卡交易工作正常 但对于 PayPal 交易则失败
  • 我可以登录 PayPal Sandbox 测试帐户,但无法进入个人资料或设置

    在从 Chrome 中删除 PayPal cookie 之前 我无法登录 PayPal 开发者帐户 这允许我登录 但单击 个人资料 下拉列表中的 个人资料 或 设置 会出现一个错误页面 显示 请登录以使用 PayPal 沙盒功能 再次登录并
  • iPhone 应用程序和 PayPal

    我想将 PayPal 支付功能集成到我的本机 iPhone 应用程序中 而不使用 Web 界面 这样用户就不必离开当前应用程序 怎么可能 我应该使用 SOAP XML 请求 响应机制吗 我通过以下链接来的http www slideshar
  • PayPal API 监听器网站支付标准 URI

    PayPal IPN 指南文档说得很清楚 将请求发布到 www paypal com 或 www sandbox paypal com 具体取决于您是要在沙盒中上线还是测试您的侦听器 等待 PayPal 的响应 该响应要么已验证 要么无效
  • CURL请求问题

    我正在尝试验证 paypal pdt 信息 我生成了模型表单并提交了它 IT 部门也开始工作并返回了信息 我尝试了同样的事情来发出卷曲请求 但我的当前请求对我来说返回空白 我的模型形式
  • PHP - Paypal API 表单和安全性 [关闭]

    Closed 这个问题需要多问focused help closed questions 目前不接受答案 我在我的电子商务应用程序上使用标准 php paypal 表单进行付款 我注意到只有 firebug 的人可以在通过 立即付款 按钮发
  • php paypal 服务器端 REST 集成失败

    我无法发布代码 错误等 因为 你需要至少 10 个声誉才能发布 2 个以上的链接 并且所有内容都包含很多链接 只是花了几个小时写了一篇完整详细的帖子 我在这里 和其他地方 读过类似的帖子 但它们没有帮助 我基本上遵循 https devel
  • 有关 payment_status 的帮助 PayPal 已退款 已撤销 部分退款 ION

    如果会员订阅和 或支付一次付款并且他们请求退款 撤销或部分退款 下面的脚本是否可以与通过 IPN 发送的 IPN 消息一起使用 if payment status Refunded payment status Reversed payme
  • 如何在 ASP.NET 中实现 PayPal Express Checkout? [关闭]

    很难说出这里问的是什么 这个问题是含糊的 模糊的 不完整的 过于宽泛的或修辞性的 无法以目前的形式得到合理的回答 如需帮助澄清此问题以便重新打开 访问帮助中心 help reopen questions 我如何在 ASP NET 中创建快速
  • 我应该使用哪个 PayPal API 向关联公司发送付款

    我在一家网站公司工作 该公司向向我们网站发送流量的合作伙伴支付佣金 目前 我们跟踪从附属机构引向我们网站的流量 然后通过 PayPal 进行繁琐的手动付款过程 这是我们当前流程的要点 1 Review affiliate commissio
  • paymentId 和 TRANSACTIONID 之间的区别

    我正在从 REST 转向经典 API 而且我对两者都是新手 作为一名开发人员 我想记录付款的唯一标识符 以便将网站中的销售与 Paypal 付款 ID 相关联 例如我想要退款时 REST API 曾经给我付款 ID https stacko

随机推荐

  • 绑定和连接之间有什么关系?

    我的印象是 gt gt 由 Haskell 使用 和join 数学家更喜欢 是 相等的 因为一个可以用另一个来写 import Control Monad join join x x gt gt id x gt gt f join fmap
  • 是否值得对数据库中的电子邮件地址进行加密?

    我已经在使用了加盐哈希 http www matasano com log 958 enough with the rainbow tables what you need to know about secure password sch
  • 用vb6实现多线程

    我的任务是通过连接到电脑的多个串行端口实现自动化过程 我如何使用 vb6 实现多线程 以通过附加的串行端口独立执行一些自动化任务 提前致谢 不 vb6 不支持多线程 它通过破解 winapi 在 vb5 中工作 但在 vb6 中完全被破坏
  • JSF不支持跨域验证,有解决方法吗?

    JSF 2 0 只允许您验证一个字段上的输入 例如检查它是否具有特定长度 它不允许您有一个表格 其中显示 输入城市和州 或仅输入邮政编码 你是怎么解决这个问题的 我只对涉及 JSF 验证阶段的答案感兴趣 我对将验证逻辑放入托管 Bean 不
  • 交叉验证 SPARK 期间的自定义评估器

    我的目标是向 CrossValidator 函数 PySpark 添加基于排名的评估器 cvExplicit CrossValidator estimator cvSet numFolds 8 estimatorParamMaps para
  • Angular 2子路由会刷新父路由吗

    我有一个应用程序 在某些情况下 我在父路线的子路线之间进行路线 一个看起来像example com a 1 其他example com a 2 将从切换1 to 2触发页面的重新加载 渲染a 就像播放视频一样a并且有一个与该视频同级的路线出
  • equals 和 hashCode 的通用反射辅助方法

    我正在考虑为 equals 和 hashCode 创建一个反射辅助方法 在 equals 的情况下 辅助方法会通过反射 API 查找 objectA 的字段 并将它们与 objectB 的字段进行比较 对于 hashCode 辅助方法会检查
  • Common Lisp 中的 comma-comma-at

    我对 comma comma at 的作用感到困惑 使用 comma comma at 的示例如下定义 Lisp 宏时是否需要使用双引号 双逗号 https stackoverflow com questions 17938242 is t
  • 注册DLL时出错

    我正在尝试使用命令 regsvr32 dll name dll 注册 DLL 但出现以下错误 模块 Addition dll 已加载 但 找不到入口点 DLLRegisterServer 确保 Addition dll 是有效的 DLL 或
  • AppleScript 和 Mail.app:检查新消息是否包含字符串

    我正在编写一个脚本来检查是否已提交特定的网络表单 到目前为止 脚本内容如下 tell application Mail check for new mail set newmail to get the unread count of in
  • 将 Json String 反序列化为多种 Object 类型

    我有一个从网络服务获得的 Json 字符串 它有一个集合列表 每个集合代表一个对象 例如 Root List First Collection Team Object id 1 team name Equipe Saidi is activ
  • 找不到驱动器 ID。您有权查看此文件吗? Android 谷歌驱动器集成

    我正在使用以下代码github https github com googledrive android demos blob master src com google android gms drive sample demo Edit
  • 基于判别器的 Typescript 窄参数类型

    我有一个旧版 API 如下所示 游乐场链接 https www typescriptlang org play code C4TwDgpgBAwg9gWwQQwHYBMCMUC8UDeAUFCVAMYLoBcUARAiFAGYCWATgM7
  • Django 使用证书身份验证连接到 Postgresql

    在 Django 1 9 中 我必须在 settings py 中进行哪些更改才能使用证书身份验证连接到 postgresql 数据库 将其添加到settings py为我工作 import os DATABASES default ENG
  • 使用 python 删除/替换多行代码部分

    我试图在 python 的帮助下从各种文件中删除包含废弃代码片段的多行 我寻找了一些例子 但无法真正找到我想要的东西 我基本上需要的是原则上执行以下操作 包含非 python 语法 def cleanCode filepath Clean
  • 如何构造一个数组以首先比较然后添加输入

    由于是 React 和 js 的初学者 我很难正确构建数组 我在网上找到一篇文章 说使用concat方法可以构造一个数组 我也遵循同样的技术 但我的问题是它附加数据并比较是否已经存在相同的数据 我想在附加到数组之前比较数据 这样就不会有重复
  • 右值引用和左值引用作为参数之间的区别

    读完帖子后 http www cprogramming com c 11 rvalue references and move semantics in c 11 html http www cprogramming com c 11 rv
  • 通过隐式链接重新链接使用更新的共享库的应用程序?

    假设我更改了共享库并重新编译了它 我是否必须重新链接使用该共享库的所有主要应用程序 如果我使用带有隐式链接的共享库 include myLib h 或重新链接是在这些应用程序加载时自动完成的 仅当满足以下条件时才需要重新编译应用程序二进制接
  • 无法加载插件@typescript-eslint:找不到模块“eslint-plugin-@typescript-eslint”

    我正在将我的项目从 tslint 重新配置为 eslint 我可以手动运行 eslint 但 webpack 无法运行并显示以下错误消息 Module build failed from path node modules eslint l
  • Paypal IPN - 无需与 iPN 模拟器握手 - 使用 github 示例代码

    很短 有很多关于此的问题 我已经浏览了很多 但找不到答案 它应该很简单 我将 github 示例代码复制到我的服务器 将 paypal IPN 模拟器指向它 它应该给我一个握手 事实并非如此 我启动 IPN 模拟器 收到的错误消息是 未发送