PHP将数据发布到API页面

PHP将数据发布到API页面,php,Php,我有一个用于API的PHP类: class Integra { public function __construct() { $this->api_key = 'API-XXXXXXX'; $this->api_salt = ''; } public function build_query($type, $data = array()) { //$salted = hash_hmac('md

我有一个用于API的PHP类:

class Integra {
    public function __construct()
    {
        $this->api_key = 'API-XXXXXXX';
        $this->api_salt = '';
    }

    public function build_query($type, $data = array())
    {
        //$salted = hash_hmac('md5', $this->api_key, $this->api_salt);

        //$data['api_key'] = $salted;
        //$data['key'] = $this->api_key;
        $params = $data;

        $data_string = json_encode($params);  

        $ch = curl_init('http://domain.com/api.php');                                                               
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");                                                                     
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);                                                                  
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
        curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          
        'Content-Type: application/json')
        );

        $response = curl_exec($ch);
        curl_close($ch);

        $response = json_decode($response);

        return $response;
    }
}
因此,这是将数据发布到相关页面/函数

我希望能够以对象的形式返回数据,我在发布数据的页面上尝试了以下操作,但没有返回任何内容

我做错了什么

<?php
return array('status' => 'test', 'reason' => 'test2');
?>

初始化数组后,可以键入cast将其转换为
object

return (object) array('status' => 'test', 'reason' => 'test2');

我收到了这个错误:注意:在第46行的/home/sites/pjford.co.uk/public_html/test.php中尝试获取非对象的属性注意:在第47行的/home/sites/pjford.co.uk/public_html/test.php中尝试获取非对象的属性转储变量
$response
(新解码的json)看看你从API中真正得到了什么。把
curl\u exec()
的返回值转储掉,你可能知道哪里不对了。我刚刚注意到你在
$this->domain
domain.com/API
中有一个域,当你初始化curl时,你用
$this->domain./API/”填充它$键入
,使其成为
domain.com/api/api/$type
,我认为它应该是
$this->domain.'/'$键入
。检查我的更新,我刚刚做了一个更改,使其直接发布到一个页面,但仍然返回相同的错误
return (object) array('status' => 'test', 'reason' => 'test2');