project-mirai / mirai-api-http

Mirai HTTP API (console) plugin
GNU Affero General Public License v3.0
1.66k stars 343 forks source link

访问auth和verify接口出现404 #616

Closed confidire-official closed 1 year ago

confidire-official commented 2 years ago

在centos上部署的mirai-api-http没法访问auth和verify等验证接口,也访问不了事件接口,查了很多相关资料好像都没有人碰到过这种问题,我是外网测试的,请问是怎么回事呢,和版本无关,我换了两三个版本都差不多,现在用的是2.5.2,之前用过2.6以上的,都是一样的问题 这是我的http-api配置文件:

## 配置文件中的值,全为默认值

## 启用的 adapter, 内置有 http, ws, reverse-ws, webhook
adapters:
  - http
  - ws

## 是否开启认证流程, 若为 true 则建立连接时需要验证 verifyKey
## 建议公网连接时开启
enableVerify: true
verifyKey: XXXXX
enableWebsocket: true

## 开启一些调式信息
debug: false

## 是否开启单 session 模式, 若为 true,则自动创建 session 绑定 console 中登录的 bot
## 开启后,接口中任何 sessionKey 不需要传递参数
## 若 console 中有多个 bot 登录,则行为未定义
## 确保 console 中只有一个 bot 登陆时启用
singleMode: false

## 历史消息的缓存大小
## 同时,也是 http adapter 的消息队列容量
cacheSize: 4096

## adapter 的单独配置,键名与 adapters 项配置相同
adapterSettings:
  ## 详情看 http adapter 使用说明 配置
  http:
    host: 0.0.0.0
    port: 9999
    cors: ["*"]
    unreadQueueMaxSize: 100

  ## 详情看 websocket adapter 使用说明 配置
  ws:
    host: 0.0.0.0
    port: 9999
    reservedSyncId: -1

然后这是控制台输出的日志:

[[[root@VM-16-7-centos mirai]# ./java/bin/java -jar ./mcl.jar
  09:46:52 [INFO] iTXTech Mirai Console Loader version 2.1.0-71ec418
  09:46:52 [INFO] https://github.com/iTXTech/mirai-console-loader
  09:46:52 [INFO] This program is licensed under GNU AGPL v3
  09:46:54 [INFO] Mirai Console Loader Announcement:
Mirai Console Loader 公告栏

如果在图片上传的时候遇到问题请与我们联系 (需要提供图片文件源本)
`- 如 Unsupported image type for ExternalResource *
`  considering use gif/png/bmp/jpg format.
`- Tracker: https://github.com/mamoe/mirai/issues/new/choose

常用资源整合
`- https://mirai.mamoe.net/topic/653

MCL 已推出 2.1.0,更好的支持 Mirai 2.11 的插件系统,建议更新。

  09:46:54 [INFO] Verifying "net.mamoe:mirai-console" v2.12.1
  09:46:54 [INFO] Verifying "net.mamoe:mirai-console-terminal" v2.12.1
  09:46:54 [INFO] Verifying "net.mamoe:mirai-core-all" v2.12.1
  09:46:55 [INFO] Verifying "org.itxtech:mcl-addon" v2.0.2
  09:46:55 [INFO] Verifying "net.mamoe:chat-command" v0.5.1
  09:46:55 [WARN] Package "net.mamoe:chat-command" requires "net.mamoe:mirai-console" version 2.0-RC. Current version is 2.12.1
2022-08-19 09:46:55 I/main: Starting mirai-console...
2022-08-19 09:46:55 I/main: Backend: version 2.12.1, built on 2022-07-31 17:49:27.
2022-08-19 09:46:55 I/main: Frontend Terminal: version 2.12.1, provided by Mamoe Technologies
2022-08-19 09:46:55 I/main: Welcome to visit https://mirai.mamoe.net/
2022-08-19 09:46:56 W/stderr: SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
2022-08-19 09:46:56 W/stderr: SLF4J: Defaulting to no-operation (NOP) logger implementation
2022-08-19 09:46:56 W/stderr: SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
2022-08-19 09:46:56 I/plugin: Successfully loaded plugin net.mamoe.mirai-api-http v2.5.2
2022-08-19 09:46:56 I/plugin: Successfully loaded plugin Chat Command v0.5.0
2022-08-19 09:46:56 I/plugin: Successfully loaded plugin MCL Addon v2.0.2
2022-08-19 09:46:56 I/main: Prepared built-in commands: autoLogin, help, login, logout, permission, status, stop
2022-08-19 09:46:56 I/Mirai HTTP API: ********************************************************
2022-08-19 09:46:56 W/stderr: SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
2022-08-19 09:46:56 W/stderr: SLF4J: Defaulting to no-operation (NOP) logger implementation
2022-08-19 09:46:56 W/stderr: SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
2022-08-19 09:46:57 I/http adapter: >>> [http adapter] is listening at http://0.0.0.0:9999
2022-08-19 09:46:57 I/ws adapter: >>> [ws adapter] is listening at ws://0.0.0.0:9999
2022-08-19 09:46:57 I/Mirai HTTP API: Http api server is running with verifyKey: XXXXX
2022-08-19 09:46:57 I/Mirai HTTP API: adaptors: [http,ws]
2022-08-19 09:46:57 I/Mirai HTTP API: ********************************************************
2022-08-19 09:46:57 I/MCL Addon: iTXTech MCL Version: 2.1.0-71ec418
2022-08-19 09:46:57 W/MCL Addon: iTXTech Soyuz 未安装,Soyuz MCL Handler 特性已禁用
2022-08-19 09:46:57 I/main: 3 plugin(s) enabled.
2022-08-19 09:46:57 I/main: Auto-login (QQ号就不放出来了)
2022-08-19 09:46:57 W/stderr: ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath. Using SimpleLogger to log to the console...
2022-08-19 09:46:57 I/Bot.qq: Loaded account secrets from local cache.
2022-08-19 09:46:58 I/Bot.qq: Saved account secrets to local cache for fast login.
2022-08-19 09:46:58 I/Bot.qq: Login successful.
2022-08-19 09:46:58 V/Bot.qq: Event: BotOnlineEvent(bot=Bot(qq))
2022-08-19 09:46:58 I/Bot.qq: Bot login successful.
2022-08-19 09:46:58 I/main: mirai-console started successfully.

请问要怎么解决呢?

ryoii commented 2 years ago

尝试服务器上使用 curl 访问接口能不能正常访问。打开 mah 的 debug 模式可以在成功访问的时候输出访问日志

我猜测是服务器的安全机制把端口禁用的,检查服务器防火墙,检查服务器供应商的安全组配置

confidire-official commented 2 years ago

不好意思刚发现是请求类型的原因,verify接口要求POST格式,浏览器公网访问默认用的是GET格式请求,但是文档里关于这一块的提醒不是很明显,所以被忽视了,刚刚用postman跑通了,感谢感谢

confidire-official commented 2 years ago

使用了POST格式发送请求后返回{"code":400,"msg":"无效参数"}是什么原因呢,我看好像有很多类似的issues,但是没有什么好的解决办法,请问这种问题该怎么解决呢

Numendacil commented 2 years ago

使用了POST格式发送请求后返回{"code":400,"msg":"无效参数"}是什么原因呢,我看好像有很多类似的issues,但是没有什么好的解决办法,请问这种问题该怎么解决呢

这不是说明POST的内容格式不对么。你要不放一下POST的具体内容