使用API集成时,命令行curl运行都正常,但是在PHP里执行出错。返回
{"result":"failed","message":"无法解析的事件","data":null,"totalCount":0,"code":"3"}
看起来是发送的请求格式还是有问题,求解
代码如下:
`
$url = “http://api.110monitor.com/alert/api/event”;
$data = array();
$data[‘app’] = ‘3b59c3fd…’; // 申请的key
$data[‘eventId’] = strval(time());
$data[‘eventType’] = ‘trigger’;
$data[‘alarmName’] = $title;
$data[‘entityName’] = $entityName;
$data[‘entityId’] = $entityId;
$data[‘priority’] = $priority;
$data[‘alarmContent’] = $content;
$data = json_encode($data);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_HEADER, array(
‘Content-type: application/json’
));
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$ret = curl_exec($ch);
`