谢谢大家。我正在使用一个支付api,我提供了一个回调URL,这样我就可以接收数据来通知我的系统,并将支付更新为“已支付”。应用编程接口在成功时发布原始json数据,并将事务的详细信息保存在realfile.php中。
realfile.php如下:
<?php
$post = file_get_contents('php://input');
$data = json_decode($post);
$reference=$data->reference;
$reason=$data->reason;
?>我的回调URL是这样的:
http://localhost/index.php/controller/method/realfile.php我的问题是:
我如何从网址访问变量$txid, $reason, $reference,以便在我的控制器方法中将我的付款标记为完成?
非常感谢。
发布于 2018-03-11 16:51:34
因此,如果您提供支付api的URL,那么我认为这是您做出第一个重要决定的地方。您说您的回调URL是:
/index.php/controller/method/realfile.php但是使用CodeIgniter,根据您的配置,您可以简单地将URL设置为:
/index.php/realfile这将允许您创建具有以下内容的Realfile.php控制器:
<?php
defined('BASEPATH') or exit('No direct script access allowed');
class Realfile extends CI_Controller
{
public function index()
{
$post = file_get_contents('php://input');
$data = json_decode($post);
$reference = $data->reference;
$reason = $data->reason;
// Actually, you have access to anything that is inside data:
echo '<pre>';
var_dump( $data );
echo '</pre>';
}
}这样,您就可以完全访问CodeIgniter的所有核心类、库、帮助器、数据库等。
发布于 2018-03-12 13:28:48
实际上我在file_get_contents('php://input')上并没有得到结果...因此,我阅读了文档,并发现了以下内容:
`$this->load->helper("security");
$stream = $this->security->xss_clean( $this->input->raw_input_stream );
$data = json_decode(trim($stream), true);`我现在可以将$data作为关联数组进行访问。这真的很有效。感谢你的控制器点子
https://stackoverflow.com/questions/49214871
复制相似问题