无法从其他域接收$ _POST数据

问题描述 投票:0回答:3

无法接收$_POST数据表https://api.razorpay.com

成功付款后,将带有https://api.razorpay.com的重定向表格$_POST和重定向URL为http://safebrowser.tk/payment/verify.php

verify.php

<?php

include("$_SERVER[DOCUMENT_ROOT]/include/config.php");
require_once("$_SERVER[DOCUMENT_ROOT]/vendor/autoload.php");

use Razorpay\Api\Api;
use Razorpay\Api\Errors\SignatureVerificationError;

$success = true;

$error = "Payment Failed";

if (empty($_POST['razorpay_payment_id']) === false) {
    $api = new Api(RP_KEY, RP_SECRET);

    try {
        // Please note that the razorpay order ID must
        // come from a trusted source (session here, but
        // could be database or something else)
        $attrbutes = array(
            'razorpay_signature' => filter_input(INPUT_POST, 'razorpay_signature'),
            'razorpay_payment_id' => filter_input(INPUT_POST, 'razorpay_payment_id'),
            'razorpay_order_id' => filter_input(INPUT_POST, 'razorpay_order_id')
        );

        $api->utility->verifyPaymentSignature($attrbutes);
    } catch (SignatureVerificationError $e) {
        $success = false;
        $error = 'Razorpay Error : ' . $e->getMessage();
    }
}

if ($success === true) {
    $html = "<p>Your payment was successful</p>
             <p>Payment ID: ".filter_input(INPUT_POST, 'razorpay_payment_id')."</p>";
} else {
    $html = "<p>Your payment failed</p>
             <p>{$error}</p>";
}

echo $html;
var_dump($_POST);
?>

但是在Web服务器中我没有任何转储值

Your payment was successful

Payment ID:

array(0) { }

但是当我尝试使用localhost时,我会得到转储值

Your payment was successful

Payment ID: pay_EeJzbCSZQLPap8

array(3) { ["razorpay_payment_id"]=> string(18) "pay_EeJzbCSZQLPap8" ["razorpay_order_id"]=> string(20) "order_EeJyrQD9A7Iqrx" ["razorpay_signature"]=> string(64) "31d210c64f3834751dec82e5d166e7ca92186c2b37d4175e4083832a49f0a548" }

我尝试将其添加到verify.php

header('Access-Control-Allow-Origin: *');

仍然我没有得到任何$ _POST值。

我如何从其他域获取$_POST值?

php post
3个回答
1
投票

检查Razorpay的设置,可能需要进行允许您的safebrowser.tk域的设置。您也可能处于“沙盒”模式,该模式通常只允许某些开发人员域,例如localhost。


0
投票
require('config.php');
session_start();
require('razorpay-php/Razorpay.php');
use Razorpay\Api\Api;
use Razorpay\Api\Errors\SignatureVerificationError;
$success = true;
$error = "Payment Failed";
if (empty($_POST['razorpay_payment_id']) === false)
{
    $api = new Api($keyId, $keySecret);
    try
    {
    // Please note that the razorpay order ID must
        // come from a trusted source (session here, but
        // could be database or something else)
        $attributes = array(
            'razorpay_order_id' => $_SESSION['razorpay_order_id'],
            'razorpay_payment_id' => $_POST['razorpay_payment_id'],
            'razorpay_signature' => $_POST['razorpay_signature']
        );
        $api->utility->verifyPaymentSignature($attributes);
    }
    catch(SignatureVerificationError $e)
    {
        $success = false;
        $error = 'Razorpay Error : ' . $e->getMessage();
    }
}
if ($success === true)
{
    $payment = $api->payment->fetch($_POST['razorpay_payment_id']);
    print_r($payment);
    echo "<br><br><br>";
    $html = "<p>Your payment was successful</p>
             <p>Payment ID: {$_POST['razorpay_payment_id']}</p>";
}
else
{
    $html = "<p>Your payment failed</p>
     <p>{$error}</p>";
}
echo $html;

输出图像如下:

enter image description here


0
投票
require('config.php');
session_start();
require('razorpay-php/Razorpay.php');
use Razorpay\Api\Api;
use Razorpay\Api\Errors\SignatureVerificationError;
$success = true;
$error = "Payment Failed";
if (empty($_POST['razorpay_payment_id']) === false)
{
    $api = new Api($keyId, $keySecret);
    try
    {
    // Please note that the razorpay order ID must
        // come from a trusted source (session here, but
        // could be database or something else)
        $attributes = array(
            'razorpay_order_id' => $_SESSION['razorpay_order_id'],
            'razorpay_payment_id' => $_POST['razorpay_payment_id'],
            'razorpay_signature' => $_POST['razorpay_signature']
        );
        $api->utility->verifyPaymentSignature($attributes);
    }
    catch(SignatureVerificationError $e)
    {
        $success = false;
        $error = 'Razorpay Error : ' . $e->getMessage();
    }
}
if ($success === true)
{
    $payment = $api->payment->fetch($_POST['razorpay_payment_id']);
    print_r($payment);
    echo "<br><br><br>";
    $html = "<p>Your payment was successful</p>
             <p>Payment ID: {$_POST['razorpay_payment_id']}</p>";
}
else
{
    $html = "<p>Your payment failed</p>
     <p>{$error}</p>";
}
echo $html;
© www.soinside.com 2019 - 2024. All rights reserved.