我试图使用osticket api_create_ticket.php创建ticket,但得到的响应代码为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;
?>
试试我从这里得到的代码https://github.com/osTicket/osTicket-1.7/blob/develop/setup/scripts/rcron.php
<?php
$config = array(
'url'=>'http://myweb.in/project1/support/api/tickets.json',
'key'=>'3B2BADDBF72D30DBEBD6378A1DF2E6FB'
);
#check if curl is enabled
function_exists('curl_version') or die('CURL support required');
#set execution time. Make it 0 if there is no time limit
set_time_limit(60);
$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 NOT SUPORTED');
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, TRUE);
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);
if(preg_match('/HTTP/.* ([0-9]+) .*/', $result, $status) && $status[1] == 200)
exit(0);
$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;
?>