Php 来自paypal的Laravel 5.1 csrftoken curl

Php 来自paypal的Laravel 5.1 csrftoken curl,php,laravel,curl,paypal,Php,Laravel,Curl,Paypal,当paypal在我的网站上发送帖子时,我如何添加或使用csrftoken。 我的错误代码: VerifyCsrfToken.php第53行中的TokenMismatchException 此处代码: public function getPaypal(Request $request) { $uri = $request->all(); if(isset($uri['tx'])) { $pp_hostname = "www.sandb

当paypal在我的网站上发送帖子时,我如何添加或使用csrftoken。 我的错误代码: VerifyCsrfToken.php第53行中的TokenMismatchException

此处代码:

    public function getPaypal(Request $request)
   {

    $uri = $request->all();

    if(isset($uri['tx']))
    {

      $pp_hostname = "www.sandbox.paypal.com"; // Change to www.sandbox.paypal.com to test against sandbox
      // read the post from PayPal system and add 'cmd'
      $req = 'cmd=_notify-synch';

      $tx_token = $uri['tx'];
      $auth_token = "EHNebv....e";
      $req .= "&tx=$tx_token&at=$auth_token";

      $ch = curl_init();
      curl_setopt($ch, CURLOPT_URL, "https://$pp_hostname/cgi-bin/webscr");
      curl_setopt($ch, CURLOPT_POST, 1);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
      curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
      //set cacert.pem verisign certificate path in curl using 'CURLOPT_CAINFO' field here,
      //if your server does not bundled with default verisign certificates.
      curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
      curl_setopt($ch, CURLOPT_HTTPHEADER, array("Host: $pp_hostname"));
      $res = curl_exec($ch);
      curl_close($ch);

   }

令牌失配异常
是一个Laravel错误,而不是PayPal。对于每个
POST
请求,您需要通过它发送一个
\u令牌

如果通过表单发送,只需将
csrf\u field()
回显到表单模板中即可

如果您不是从Laravel发送请求,您可以禁用该路由上的CSRF保护。请在此处阅读有关中间件的更多信息:


请在此处阅读更多信息:

您不需要完全禁用中间件,只需转到app\Http\Middle中的VerifyCrsfToken文件,然后编辑受保护的数组$except和include,并输入paypal发布到的路由

protected $except = [
    /paypal/data,


];

根据Laravel文件:

从CSRF保护中排除URI

有时,您可能希望从CSRF保护中排除一组URI。 例如,如果您正在使用条带处理付款,并且 利用他们的webhook系统,您需要排除您的webhook 处理程序从Laravel的CSRF保护路径

您可以通过将URI添加到 VerifyCsrfToken中间件:

<?php

namespace App\Http\Middleware;

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

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