【问题标题】:callback url for APIAPI回调地址
【发布时间】:2017-10-10 10:45:55
【问题描述】:

我需要集成一个 API 来在我的 codeigniter 项目中注册短信模板。这是我的代码:

$postdata = array('userid'          => 'user',
                    'password'          => 'user@321',
                    'template'          => 'Demo template',
                    'callback_url'      => base_url().'API/templateCallback'
                ); 

$postdata = json_encode($postdata);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,"http://example.com/TemplateRegistration2/registerTemplate.jsp");

curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$postdata);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec ($ch);
curl_close ($ch);
$response = json_decode($response); 
print_r($response);

响应将是一个 json 对象,例如,

{"req_id":"809ff62f-74a9-45a5-9cb5-5e60763289af","status":"0" ,"comment":"OK"} 

但是我是如何在我的 templateCallback() 函数中读取这个 json 对象的。有没有内置函数可以做同样的事情

【问题讨论】:

    标签: php json api codeigniter callback


    【解决方案1】:

    模板回调是 PHP 文件。那么你应该解析请求。

    类似这样的:

    $json = file_get_contents('php://input');
    $obj = json_decode($json, TRUE);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-19
      • 2015-09-18
      • 2015-04-25
      • 1970-01-01
      相关资源
      最近更新 更多