Ver código fonte

Merge branch 'master' of http://svn.ouj.com:3000/eos_sicbo/chat

eosgetdice12 5 anos atrás
pai
commit
8c69ff289d

+ 6 - 4
protected/controllers/TgController.php

@@ -20,7 +20,7 @@ class TgController extends BaseController {
     public function actionWebhook($args) {
         $content = file_get_contents("php://input");
         $update = json_decode($content, true);
-        file_put_contents('/tmp/telegram_message.log', var_export($update, true), FILE_APPEND);
+//        file_put_contents('/tmp/telegram_message.log', var_export($update, true), FILE_APPEND);
         if (isset($update["message"])) {
             try {
                 Telegram::processMessage($update["message"]);
@@ -69,7 +69,8 @@ class TgController extends BaseController {
         $alreadySync = $objGroup->objTable->getCount(['tg_group_id' => $tgGroupId]);
 
         // 未绑定的群
-        $groups = $objGroup->objTable->getAll(['creator' => $userId, 'tg_group_id' => 0], [
+        $groupIds = (new UserGroup())->objTable->getCol(['user_id' => $meeChatId, 'is_admin' => 1, 'state' => UserGroup::STATE_IN_GROUP], ['_field' => 'group_id']);
+        $groups = $objGroup->objTable->getAll(['group_id' => $groupIds, 'tg_group_id' => 0], [
             '_field' => 'group_id, group_title, group_name',
             '_sortKey' => 'group_id DESC',
         ]);
@@ -94,8 +95,8 @@ class TgController extends BaseController {
         $tgGroupId = intval($args['tg_group_id']);
         $objGroup = new GroupInfo();
 
-        $group = $objGroup->objTable->getRow(['creator' => $userId, 'group_id' => $args['group_id']]);
-        if (!$group) {
+
+        if (!(new UserGroup())->isAdmin($args['group_id'], $userId)) {
             Response::error(CODE_NO_PERMITION, 'no permission');
         }
 
@@ -103,6 +104,7 @@ class TgController extends BaseController {
             Response::error(CODE_NORMAL_ERROR, 'already sync other group');
         }
 
+        $group = $objGroup->objTable->getRow(['group_id' => $args['group_id']]);
         try {
             $objGroup->joinGroup(TG_BOT_ID, $args['group_id'], $group);
         } catch (Exception $e) {

+ 3 - 3
protected/models/Telegram.php

@@ -66,11 +66,11 @@ class Telegram {
                 if (!$groupId) {
                     $text = "Wrong operation!!";
                 } else {
-                    $creatorId = ThirdApi::getTelegramGroupCreator($groupId);
-                    if ($creatorId == $from) {
+                    $administrators = ThirdApi::getTelegramGroupAdministrators($groupId);
+                    if (in_array($from, $administrators)) {
                         $text = self::buildSyncText($from, $groupId);
                     } else {
-                        $text = "you are not creator";
+                        $text = "you are not administrator";
                     }
                 }
 

+ 8 - 9
protected/models/ThirdApi.php

@@ -104,14 +104,15 @@ class ThirdApi {
     }
 
     /**
-     * 获取群创建者id
+     * 获取群管理id
      * @author solu
      * @param $groupId
-     * @return int
+     * @return array
      */
-    public static function getTelegramGroupCreator($groupId) {
+    public static function getTelegramGroupAdministrators($groupId) {
+        $admins = [];
         if (!$groupId) {
-            return 0;
+            return $admins;
         }
 
         $url = TELEGRAM_API_URL . 'getChatAdministrators?chat_id=' . $groupId;
@@ -119,15 +120,13 @@ class ThirdApi {
         $resp = json_decode($resp, true);
         $data = $resp['result'];
 
-        $creatorId = 0;
         foreach ($data as $u) {
-            if ($u['status'] == 'creator') {
-                $creatorId = intval($u['user']['id']);
-                break;
+            if (in_array($u['status'],['creator', 'administrator'])) {
+                $admins[] = intval($u['user']['id']);
             }
         }
 
-        return $creatorId;
+        return $admins;
     }
 
     /**

+ 1 - 0
protected/models/User.php

@@ -123,6 +123,7 @@ class User extends Singleton {
             } else {
                 // 添加用户信息
                 $data['first_type'] = $type;
+                $data['first_account'] = $account;
                 $data['nick_name'] = $name ?: self::getNewName($account);
                 $data['user_name'] = $data['nick_name'] . '-' . strtoupper($type);
                 $objUserInfo->addObject($data);