/
client_chat.php
82 lines (68 loc) · 1.99 KB
/
client_chat.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
ini_set('display_errors', 1);
header('Content-Type:text/html;charset=utf-8');
include('includes/welive.Core.php');
header_nocache();
if($_CFG['cActived'])
{
$kickout_time = time() - $_CFG['cAutoOffline'];
//踢掉长时间未请求的客服
$DB->exe("UPDATE ".TABLE_PREFIX."user SET isonline = 0 WHERE last_request < $kickout_time");
//$online_cache_file = BASEPATH.'cache/online_cache.php';
//@include($online_cache_file);
//if(!isset($welive_onlines) OR !is_array($welive_onlines)){
$welive_onlines = storeCache();
//if(!$welive_onlines) die('Save cache failed!');
//}
$from_url = base64_encode($_SERVER['HTTP_REFERER']);
$cm_user_id = isset($_GET['userId']) ? $_GET['userId'] : '';
$online_users = array();
$offline_users = array();
foreach($welive_onlines as $usergroup)
{
foreach($usergroup['user'] as $user_id => $user)
{
//print_r($user);
if( $user['type'] != 1 ) continue;
if( $user['isonline'] == 1 )
{
$online_users[$user_id] = $user;
}
else
{
$offline_users[$user_id] = $user;
}
}
}
$vvckey = PassGen(8);
$code = null;
if( !empty($online_users) )
{
$rand_key = array_rand($online_users);
$selected_user = $online_users[$rand_key];
$code = base64_encode(authcode(COOKIE_KEY.$rand_key, 'ENCODE', $vvckey, 3600));
}
elseif( !empty($offline_users) )
{
$rand_key = array_rand($offline_users);
$selected_user = $online_users[$rand_key];
$code = base64_encode(authcode(COOKIE_KEY.$rand_key, 'ENCODE', $vvckey, 3600));
}
else
{
die('系统没有添加客服');
}
/*if($selected_user['isonline'])
{*/
$location_url = BASEURL.'enter.php?uid='.$rand_key.'&code='.$code.'&vvckey='.$vvckey.'&url='.$from_url.'&cm_user_id='.$cm_user_id;
/*}
else
{
$location_url = BASEURL.'comment.php?uid='.$rand_key.'&code='.$code.'&vvckey='.$vvckey.'&cm_user_id='.$cm_user_id;
}*/
header('Location:'.$location_url);
}
else
{
echo '客服系统已停用';
}