[英]error in creating ticket by using osticket api_create_ticket.php
我正在尝试使用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;
?>
试试这个代码,我从这里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;
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.