【发布时间】:2015-08-30 12:57:17
【问题描述】:
我正在尝试使用 livechat API 获取最长的访问者排队的时间。
下面是我的代码:
<?php
date_default_timezone_set('Europe/Stockholm');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.livechatinc.com/visitors?state=queued");
curl_setopt($ch,CURLOPT_USERNAME, "XXXXXX");
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_HTTPHEADER, array('X-API-Version:2'));
$result = curl_exec($ch);
curl_close($ch);
$string = json_decode($result); // decoding the result
$queued = $string->queue_start_time; // getting the queue start time
$longest = min(array($queued)); // getting the smallest unix time of all visitors
$date = date('U', time()); //getting current time
$queuetime = abs($date-$longest); //calculating the difference between current time and the visitors queue time.
echo intval(date('i',$acttime))." min"; //displaying the visitor queue time in minutes
?>
为什么我不能让它工作?它一直返回“0分钟”。
【问题讨论】:
-
有人有线索吗?
-
你试过
var_dump(json_decode($result))吗?根据 php 文档和 LiveChat API 文档,它将返回访问者数组(将是 stdClasses)。然后我会遍历所有这些并尝试寻找最小值。 -
可能是 ssl 问题
-
感谢您的回复。不幸的是,项目被放弃了,问题于 2015 年 8 月提出。