gpt4 book ai didi

php - 来自 Paypal 的 Laravel 5.1 csrftoken curl

转载 作者:太空宇宙 更新时间:2023-11-03 15:45:24 25 4
gpt4 key购买 nike

当 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 文档:http://laravel.com/docs/5.1/routing#csrf-protection .

Excluding URIs From CSRF Protection

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 webhook handler route from Laravel's CSRF protection.

You may exclude URIs by adding them to the $except property of the VerifyCsrfToken middleware:

<?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/*',
];
}

如果还是不清楚,请告诉我。

关于php - 来自 Paypal 的 Laravel 5.1 csrftoken curl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32762630/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com