浏览代码

判断患者用户im是否在线

lizhen_gitee 10 月之前
父节点
当前提交
14ed9ffc3a
共有 2 个文件被更改,包括 38 次插入0 次删除
  1. 5 0
      application/api/controller/doctor/Wenzhen.php
  2. 33 0
      application/common/library/Tenim.php

+ 5 - 0
application/api/controller/doctor/Wenzhen.php

@@ -337,6 +337,11 @@ class Wenzhen extends Apic
         }
 
         //判断患者在线状态
+        $tenim = new Tenim();
+        $rs_online = $tenim->is_online('user'.$wenzhen_order['user_id']);
+        if($rs_online != true){
+            $this->error('患者现在不在线,请稍后拨打');
+        }
 
         $this->success('操作成功');
     }

+ 33 - 0
application/common/library/Tenim.php

@@ -139,6 +139,39 @@ class Tenim
         return true;
     }
 
+    //某个用户是否im在线
+    public function is_online($userid){
+        $random = rand(10000000,99999999);
+        $usersig = $this->usersig("administrator");
+        //dump($usersig);
+        // 获取配置信息
+        $config = config("tencent_im");
+        $url = "https://console.tim.qq.com/v4/openim/query_online_status";
+        $url .= "?sdkappid=".$config["sdkappid"];
+        $url .= "&identifier=administrator";
+        $url .= "&usersig=".$usersig;
+        $url .= "&random=".$random;
+        $url .= "&contenttype=json";
+        $tencentObj = new tencentim($url);
+
+        $data = [
+            'To_Account' => [$userid],
+        ];
+
+        $res = $tencentObj->toSend($data);
+
+        if (!empty($res['ActionStatus']) && $res['ActionStatus'] == 'OK') {
+            if(    isset($res['QueryResult'][0]['To_Account'])
+                && isset($res['QueryResult'][0]['Status'])
+                && $res['QueryResult'][0]['To_Account'] == $userid
+                && $res['QueryResult'][0]['Status'] == 'Online'){
+                return true;
+            }
+        }
+
+        return false;
+    }
+
 
 
     /**