【问题标题】:Livechat API - Queue timeLivechat API - 排队时间
【发布时间】: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 月提出。

标签: php date time livechat


【解决方案1】:

试试这个代码,让我知道它是如何工作的:

<?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_USERPWD, LOGIN . ":" . API_KEY);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-API-Version:2'));
$result = curl_exec($ch);
curl_close($ch);
$visitors = json_decode($result); // decoding the result

$queueTime = array();
foreach ($visitors as $key => $value)
{
// getting the queue start time for all queued visitors
$queueTime[] = $value->queue_start_time;
}
$longest = min($queueTime); // 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.
$queuetimeMinutes = floor($queuetime / 60);
$queuetimeSeconds = $queuetime % 60;
echo "$queuetimeMinutes min and $queuetimeSeconds seconds";  //displaying the visitor queue time in minutes

?>

干杯亚当

【讨论】:

  • 请突出显示您所做的更改以及您认为问题所在。
  • @iblamefish 如您所见,代码发生了很大变化。我们尽最大努力提供可行的解决方案,但我认为一开始就有问题,这是问题的主要原因。
  • 感谢您的回复。不幸的是,项目被放弃了,问题于 2015 年 8 月提出。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-10-28
  • 2020-09-27
  • 1970-01-01
  • 2011-01-26
  • 2020-03-30
  • 2022-11-17
  • 2017-11-20
相关资源
最近更新 更多