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

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


付款成功后,会出现一个重定向表单https://api.razorpay.com,$_POST重定向 URL 为http://safebrowser.tk/payment/verify.php


验证.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);

?>

但是在网络服务器中我没有得到转储值


Your payment was successful


Payment ID:


array(0) { }

但是当我在本地主机上尝试时,我得到了转储值


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从其他领域获得价值?


侃侃无极
浏览 134回答 2
2回答

慕码人2483693

检查 Razorpay 的设置,可能有一个设置需要允许您的 safebrowser.tk 域。您也可能处于“沙盒”模式,这种模式通常只允许某些开发域,例如本地主机。

人到中年有点甜

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){&nbsp; &nbsp; $api = new Api($keyId, $keySecret);&nbsp; &nbsp; try&nbsp; &nbsp; {&nbsp; &nbsp; // Please note that the razorpay order ID must&nbsp; &nbsp; &nbsp; &nbsp; // come from a trusted source (session here, but&nbsp; &nbsp; &nbsp; &nbsp; // could be database or something else)&nbsp; &nbsp; &nbsp; &nbsp; $attributes = array(&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'razorpay_order_id' => $_POST['razorpay_order_id'],&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'razorpay_payment_id' => $_POST['razorpay_payment_id'],&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'razorpay_signature' => $_POST['razorpay_signature']&nbsp; &nbsp; &nbsp; &nbsp; );&nbsp; &nbsp; &nbsp; &nbsp; $api->utility->verifyPaymentSignature($attributes);&nbsp; &nbsp; }&nbsp; &nbsp; catch(SignatureVerificationError $e)&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; $success = false;&nbsp; &nbsp; &nbsp; &nbsp; $error = 'Razorpay Error : ' . $e->getMessage();&nbsp; &nbsp; }}if ($success === true){&nbsp; &nbsp; $payment = $api->payment->fetch($_POST['razorpay_payment_id']);&nbsp; &nbsp; print_r($payment);&nbsp; &nbsp; echo "<br><br><br>";&nbsp; &nbsp; $html = "<p>Your payment was successful</p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<p>Payment ID: {$_POST['razorpay_payment_id']}</p>";}else{&nbsp; &nbsp; $html = "<p>Your payment failed</p>&nbsp; &nbsp; &nbsp;<p>{$error}</p>";}echo $html;
打开App,查看更多内容
随时随地看视频慕课网APP