我在我的 REST API(使用 SLIM 框架)中创建了一个测试函数,用于测试我对 cloudconvert API的包装类的实现。
$app->get('/test', 'authenticate', function() use ($app) {
$response = array();
$converter = new CloudConverter();
$url = $converter->createProcess("docx","pdf");
$response["url"] = $url;
echoRespnse(201, $response);
});
CloudConverter 类中的 createProcess 函数如下所示:
public function createProcess($input_format,$output_format)
{
$this->log->LogInfo("CreateProcess Called");
$headers = array('Content-type: application/json');
$curl_post_data = array('apikey' => API_KEY,'inputformat' => $input_format,'outputformat' => $output_format);
$curl = curl_init(CLOUD_CONVERT_HTTP);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($curl_post_data));
$curl_response = curl_exec($curl);
if ($curl_response === false)
{
$info = curl_getinfo($curl);
curl_close($curl);
die('error occured during curl exec. Additioanl info: ' . var_export($info));
$this->log->LogInfo('error occured during curl exec. Additioanl info: ' . var_export($info));
}
curl_close($curl);
$decoded = json_decode($curl_response,true);
return $decoded['url'];
}
我已经使用 Chrome Advanced Rest Client 测试了我的 API,我看到调用 cloudconvert API 得到了成功的响应,但这不是我所期望的,如上面的代码所示。我期待提取 url 并在我的回复中返回 THAT。
我的问题是:我 如何从 cloudconvert 的响应中提取 url 并在我自己的响应中返回。