腾讯回调用户在线状态
This commit is contained in:
@@ -7,7 +7,6 @@ use fast\Http;
|
||||
use think\Db;
|
||||
use think\Log;
|
||||
use think\Model;
|
||||
use think\facade\Env;
|
||||
use fast\Tencentst;
|
||||
|
||||
class Tencent extends Model
|
||||
@@ -887,5 +886,49 @@ class Tencent extends Model
|
||||
}
|
||||
}
|
||||
|
||||
//腾讯IM回调
|
||||
public function tencent_call_back($data,$sign_data){
|
||||
//回调鉴权
|
||||
// $token = '2k1j90av9rtl2ozbnbqxzyrtuj4a4oy5';
|
||||
// $sign = sha256($token.$sign_data['RequestTime']);
|
||||
// // $datas = json_encode($data);
|
||||
// // error_log($datas, 3, '1.txt');
|
||||
// // $sign_datas = json_encode($sign_data);
|
||||
// if($sign != $sign_data['Sign']){
|
||||
// return ['ActionStatus' => 'FAIL', 'ErrorInfo' => '', 'ErrorCode' => 1];
|
||||
// }
|
||||
// dump($data);exit;
|
||||
|
||||
|
||||
//在线状态更新
|
||||
if($data['CallbackCommand'] == 'State.StateChange'){
|
||||
$info = $data['Info'];
|
||||
$reslut = $this->tencent_member_status_change($info);
|
||||
}
|
||||
return ['ActionStatus' => 'OK', 'ErrorInfo' => '', 'ErrorCode' => 0];
|
||||
}
|
||||
|
||||
//腾讯IM监控在线状态更新
|
||||
public function tencent_member_status_change($info){
|
||||
$uid = substr($info['To_Account'],1);
|
||||
$action = $info['Action'];
|
||||
|
||||
if($action == 'Disconnect') {
|
||||
Db::name('user')->where('id', $uid)->update(['is_online' => 0, 'updatetime' => time()]);
|
||||
$quit_room = Db::name('vs_room_visitor')->where('user_id', $uid)->select();
|
||||
|
||||
if($quit_room) {
|
||||
foreach ($quit_room as &$v){
|
||||
model('Room')->quit_room($v['user_id'], $v['room_id'],$v['user_id']);
|
||||
}
|
||||
}
|
||||
|
||||
} elseif ($action == 'Login') {
|
||||
Db::name('user')->where('id', $uid)->update(['is_online' => 1, 'updatetime' => time()]);
|
||||
}elseif ($action == 'Logout'){
|
||||
Db::name('user')->where('id', $uid)->update(['is_online' => 0, 'updatetime' => time()]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user