auth->id; $this->success('获取成功!',$this->usersig($user_id)); } /** * 获取usersig签名-具体操作 */ private function usersig($user_id) { // 获取配置信息 $config = config('tencent_im'); $usersigObj = new getusersig($config['sdkappid'],$config['key']); $usersig = $usersigObj->genUserSig($user_id); return $usersig; } /** * 回调 */ public function callback() { // 主题信息 $input = input(); //配置 $config = config('tencent_im'); //App 后台在收到回调请求之后,务必校验请求 URL 中的参数 SDKAppID 是否是自己的 SDKAppID。 $SdkAppid = $input['SdkAppid']; if($SdkAppid != $config['sdkappid']){ //应答包示例 $res = ['ActionStatus'=>'OK','ErrorCode'=>0,'ErrorInfo'=>''];echo json_encode($res);exit; } //回掉正文 $CallbackCommand = $input['CallbackCommand']; switch ($CallbackCommand) { case 'State.StateChange': // 用户在线状态变更 $info = $input['Info']; if(strpos($info['To_Account'],'doctor') === false){ //应答包示例 $res = ['ActionStatus'=>'OK','ErrorCode'=>0,'ErrorInfo'=>''];echo json_encode($res);exit; } $role = 'doctor'; $doctor_id = substr($info['To_Account'],6); if($info['Action'] == 'Login') { //登录 Db::name('doctor')->where('id',$doctor_id)->update(['is_online'=>1,'onlinetime'=>time()]); //应答包示例 $res = ['ActionStatus'=>'OK','ErrorCode'=>0,'ErrorInfo'=>''];echo json_encode($res);exit; } elseif($info['Action'] == 'Logout' || $info['Action'] == 'Disconnect') { // 用户退出 不需要管什么原因 // 更新用户在线状态为离线 Db::name('doctor')->where('id',$doctor_id)->update(['is_online'=>0]); //应答包示例 $res = ['ActionStatus'=>'OK','ErrorCode'=>0,'ErrorInfo'=>''];echo json_encode($res);exit; } break; default: break; } //应答包示例 $res = ['ActionStatus'=>'OK','ErrorCode'=>0,'ErrorInfo'=>''];echo json_encode($res);exit; } public function aaa(){ $a = '{"CallbackCommand":"State.StateChange","ClientIP":"182.37.138.94","OptPlatform":"Android","RequestId":"crp5hq2r8lc58sqn92jg-144115245635848666-Disconnect-LinkClose","SdkAppid":"1600053964","contenttype":"json","Info":{"To_Account":"doctor24","Action":"Disconnect","Reason":"LinkClose"},"EventTime":"1727158505072"}'; dump(json_decode($a,true)); } }