我正在尝试使用 osticket api_create_ticket.php 创建票证,但我收到响应代码 200。一切都与许多文档和示例中的描述相同。我已将服务器 ip 用于 api 密钥也尝试了我的系统 ip。授予文件夹写入权限。但它仍然无法正常工作。
#!/usr/bin/php -q
<?php
$config = array(
'url'=>'http://myweb.in/project1/support/api/tickets.json',
'key'=>'3B2BADDBF72D30DBEBD6378A1DF2E6FB'
);
$data = array(
'name' => 'John Doe',
'email' => 'mailbox@host.com',
'subject' => 'Test API message',
'message' => 'This is a test of the osTicket API',
'ip' => $_SERVER['REMOTE_ADDR'],
);
function_exists('curl_version') or die('CURL support required');
function_exists('json_encode') or die('JSON support required');
set_time_limit(30);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $config['url']);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_USERAGENT, 'osTicket API Client v1.7');
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Expect:', 'X-API-Key: '.$config['key']));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$result=curl_exec($ch);
$code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
print_r($code);
if ($code != 201)
die('Unable to create ticket: '.$result);
$ticket_id = (int) $result;
?>