访问附加到codeigniter中控制器方法的php文件中的变量
谢谢大家。 我正在使用一个支付api,我提供了一个回调URL,以便我收到数据通知我的系统,并将支付更新为“已支付”。成功后,api将发布原始json数据,并将事务的详细信息保存在realfile.php中 realfile.php如下所示:访问附加到codeigniter中控制器方法的php文件中的变量,php,json,codeigniter,Php,Json,Codeigniter,谢谢大家。 我正在使用一个支付api,我提供了一个回调URL,以便我收到数据通知我的系统,并将支付更新为“已支付”。成功后,api将发布原始json数据,并将事务的详细信息保存在realfile.php中 realfile.php如下所示: <?php $post = file_get_contents('php://input'); $data = json_decode($post); $reference=$data->reference; $reason=$data
<?php
$post = file_get_contents('php://input');
$data = json_decode($post);
$reference=$data->reference;
$reason=$data->reason;
?>
我的问题:
如何从URL访问变量$txid、$reason、$reference
,以在我的控制器方法中将我的付款标记为完成
非常感谢。因此,如果您提供支付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>';
}
}
实际上,我并没有从文件获取内容('php://input)
。。。因此,我阅读了这些文档,发现:
`$this->load->helper(“安全”)
我现在可以作为关联数组访问$data
。
这真的很有效。。。
感谢控制器的想法您已经有了$reference=$data->reference$原因=$data->原因;这段代码不起作用了吗?你好,Max Phoenix Newbie,你的api响应是什么?它是原始json对象。{“键”:“值”…}非常感谢。。。我会试试这个。。。由于我的声誉仍然低于11,我的支持票不会公开出现,但我已经支持了你。。。谢谢
<?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>';
}
}
$stream = $this->security->xss_clean( $this->input->raw_input_stream );
$data = json_decode(trim($stream), true);`