当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);
}
答案 0 :(得分:4)
根据Laravel文件:http://laravel.com/docs/5.1/routing#csrf-protection。
从CSRF保护中排除URI
有时您可能希望从CSRF保护中排除一组URI。 例如,如果您使用条带来处理付款,那么 利用他们的webhook系统,您需要排除您的webhook 来自Laravel的CSRF保护的处理程序路线。
您可以通过将URI添加到$的except属性来排除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/*',
];
}
如果还不清楚,请告诉我。
答案 1 :(得分:3)
您不需要完全禁用中间件,只需转到app \ Http \ Middle中的VerifyCrsfToken文件,然后编辑受保护的数组$,并将paypal的路由包含并输入到。
protected $except = [
/paypal/data,
];
答案 2 :(得分:1)
var RE_BLOCKS = new RegExp([
/\/(\*)[^*]*\*+(?:[^*\/][^*]*\*+)*\//.source, // $1: multi-line comment
/\/(\/)[^\n]*$/.source, // $2 single-line comment
/"(?:[^"\\]*|\\[\S\s])*"|'(?:[^'\\]*|\\[\S\s])*'/.source, // - string, don't care about embedded eols
/(?:[$\w\)\]]|\+\+|--)\s*\/(?![*\/])/.source, // - division operator
/\/(?=[^*\/])[^[/\\]*(?:(?:\[(?:\\.|[^\]\\]*)*\]|\\.)[^[/\\]*)*?\/[gim]*/.source
].join('|'), // - regex
'gm' // note: global+multiline with replace() need test
);
// remove comments, keep other blocks
function stripComments(str) {
return str.replace(RE_BLOCKS, function (match, mlc, slc) {
return mlc ? ' ' : // multiline comment (replace with space)
slc ? '' : // single/multiline comment
match; // divisor, regex, or string, return as-is
});
}
是Laravel错误,而不是PayPal。对于每个TokenMismatchException
请求,您需要通过它发送POST
值。
如果您通过表单发送此内容,只需将_token
回显到表单模板中即可。
如果您从Laravel以外的其他地方发送请求,则可以在该路由上禁用CSRF保护。在此处阅读有关中间件的更多信息:http://laravel.com/docs/5.1/middleware