$msg, "group_id" => Cache::get("admin_group")]); } return false; } public static function __callStatic($name, $arg) { $all = self::getSupportedAPIs(); $find = null; if (in_array($name, $all)) $find = $name; else { foreach ($all as $v) { if (strtolower($name) == strtolower(str_replace("_", "", $v))) { $find = $v; break; } } } if ($find === null) { Console::error("Unknown API " . $name); return false; } $reply = ["action" => $find]; if (!is_array($arg[1])) { Console::error("Error when parsing params. Please make sure your params is an array."); return false; } if ($arg[1] != []) { $reply["params"] = $arg[1]; } return self::processAPI($arg[0], $reply, $arg[2]); } /********************** non-API Part **********************/ private static function getSupportedAPIs() { return [ "send_private_msg", "send_group_msg", "send_discuss_msg", "send_msg", "delete_msg", "send_like", "set_group_kick", "set_group_ban", "set_group_anonymous_ban", "set_group_whole_ban", "set_group_admin", "set_group_anonymous", "set_group_card", "set_group_leave", "set_group_special_title", "set_discuss_leave", "set_friend_add_request", "set_group_add_request", "get_login_info", "get_stranger_info", "get_group_list", "get_group_member_info", "get_group_member_list", "get_cookies", "get_csrf_token", "get_credentials", "get_record", "get_status", "get_version_info", "set_restart", "set_restart_plugin", "clean_data_dir", "clean_plugin_log", "_get_friend_list", "_get_group_info", "_get_vip_info", //异步API "send_private_msg_async", "send_group_msg_async", "send_discuss_msg_async", "send_msg_async", "delete_msg_async", "set_group_kick_async", "set_group_ban_async", "set_group_anonymous_ban_async", "set_group_whole_ban_async", "set_group_admin_async", "set_group_anonymous_async", "set_group_card_async", "set_group_leave_async", "set_group_special_title_async", "set_discuss_leave_async", "set_friend_add_request_async", "set_group_add_request_async" ]; } public static function getLoggedAPIs() { return [ "send_private_msg", "send_group_msg", "send_discuss_msg", "send_msg", "send_private_msg_async", "send_group_msg_async", "send_discuss_msg_async", "send_msg_async" ]; } /** * @param $self_id * @param $reply * @param callable|null $function * @return bool */ private static function processAPI($self_id, $reply, callable $function = null) { $api_id = Cache::$api_id->get(); $reply["echo"] = $api_id; Cache::$api_id->add(1); if ($self_id instanceof RobotWSConnection) { $connection = $self_id; $self_id = $connection->getQQ(); } else $connection = ConnectionManager::getRobotConnection($self_id); if ($connection instanceof NullConnection) { Console::error("未找到qq号:" . $self_id . "的API连接"); return false; } if ($connection->push(json_encode($reply))) { Cache::appendKey("sent_api", $api_id, [ "data" => $reply, "time" => microtime(true), "func" => $function, "self_id" => $self_id ]); if (in_array($reply["action"], self::getLoggedAPIs())) { Console::msg($reply); Cache::$out_count->add(1); } return true; } else return false; } }