get('SdkAppid'); if(!$this->CheckSdkAppid($SdkAppid)){ // ding()->text('IM回调SdkAppid检查不通过'); return json_encode(['ActionStatus'=>'FAIL','ErrorCode'=>1,'ErrorInfo'=>'SdkAppid验证不通过过']); } $CallbackCommand=$request->get('CallbackCommand'); if($CallbackCommand=='State.StateChange'){ $info= $request->getContent(); return $this->StateChange($info); } } private function StateChange($content){ // info($content); $info=json_decode($content,true); if($info['CallbackCommand']=='State.StateChange'){ $Action= $info['Info']['Action']; $To_Account= $info['Info']['To_Account']; $uid=substr($To_Account,strripos($To_Account,"_")+1); // info('uid='.$uid); $Reason= $info['Info']['Reason']; if($Action=='Login'){//上线 $info=Users::where('id',$uid)->first(); $info->status=1; $info->save(); }else{ if($Reason=='Unregister'){//注销 Users::where('id',$uid)->update(['status'=>3]); }else{ Users::where('id',$uid)->update(['status'=>2]); } } Cache::forget('My'.$uid); Cache::forget('user'.$uid); return json_encode(['ActionStatus'=>'ok','ErrorCode'=>0,'ErrorInfo'=>'成功53']); } return json_encode(['ActionStatus'=>'FAIL','ErrorCode'=>1,'ErrorInfo'=>'回调命令验证不通过过']); } private function CheckSdkAppid($key){ $seting=$this->getIM(); if($key==$seting['SecretId']) return true; return false; } }