php - Laravel Paypal POST 请求被拒绝

标签 php laravel post paypal paypal-ipn

我正在尝试在我的 Laravel 项目中实现 IPN,由于“csrf”,来 self 网站的发布请求正在工作,

我尝试像这里写的那样实现它:

https://developer.paypal.com/docs/api-basics/notifications/ipn/ht-ipn/

在我的routes/web.php中:

Route::post('i', [IController::class, 'y'])->name('i');

在 IController 中,侧面写的是:

public function y()
    {
        error_log('function y called');
        // STEP 1: read POST data

// Reading POSTed data directly from $_POST causes serialization issues with array data in the POST.

// Instead, read raw POST data from the input stream.

        $raw_post_data = file_get_contents('php://input');............

error_log 没有显示,意味着该函数从未进入。

问题:我如何强制 Laravel 排除来自 Paypal 的帖子?

最佳答案

您可以在 Laravel 中从 CSRF 保护中排除 URI。

转到 App\Http\Middleware\VerifyCsrfToken 并添加要排除 csrf token 的 url。

<?php

namespace App\Http\Middleware;

use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;

class VerifyCsrfToken extends Middleware
{
    /**
     * The URIs that should be excluded from CSRF verification.
     *
     * @var array
     */
    protected $except = [
        'i',
       
    ];
}

正如文档所说

Sometimes you may wish to exclude a set of URIs from CSRF protection. For example, if you are using Stripe to process payments and are utilizing their webhook system, you will need to exclude your Stripe webhook handler route from CSRF protection since Stripe will not know what CSRF token to send to your routes.

Typically, you should place these kinds of routes outside of the web middleware group that the App\Providers\RouteServiceProvider applies to all routes in the routes/web.php file. However, you may also exclude the routes by adding their URIs to the $except property of the VerifyCsrfToken middleware:

引用号:https://laravel.com/docs/8.x/csrf#csrf-excluding-uris

关于php - Laravel Paypal POST 请求被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68125778/

相关文章:

javascript - 我想通过使用 php 或其他语言选择多个文本框来进行过滤?

PHP如何确定foreach循环中的第一次和最后一次迭代?

php - 优步吃到与laravel和mysql的集成,如何像mysql表一样保存json post数据?

Laravel Eloquent ->with() 和 ->select() 相互冲突

php - 如何获取/打印对我的 Twig 模板 (Drupal 8) 的实体引用的路径或 url?

php - 为什么在 Laravel 中自定义用户提供程序身份验证后我会收到此 "These credentials do not match our records"消息?

javascript - 无法将 CSRF token 添加到 Django POST 请求的 XMLhttpRequest

php - 自定义 Shopware6 路由给出 "405 Method Not Allowed"

c# - 同时使用 POST 和 GET 的 HttpWebRequest

php - 图书网站条码扫描仪