code=45, title=禁止登录, message=登录失败,建议升级最新版本后重试,或通过问题反馈与我们联系。

如果你是采用 java 开发的,你可以参考本文章,java 和 kotlin 都是可以相互转换的。 

在解决之前,先说明环境:

  1. JDK版本:java version "17.0.3.1" 【Oracle JDK】
  2. Kotlin版本:1.8.20

  3. 采取simbot核心包开发:simbot-core 3.0.0-RC.3 【最新版本: 3.0.0-RC.3

  4. mirai 组件: 3.0.0.0-RC.2 【最新版本 3.0.0.0-RC.2

 🤩更多信息,我会放在文末【pom.xml文件

讲讲我是怎么解决的?

根据 simpot mirai组件介绍,我们可以添加 mirai 原生配置。

 我们接着在我们的项目中去添加吧!【这里采取协议:MACOS】

添加完了,你现在就可以运行你的代码了 。

💖原理

核心:更改协议

协议?具体有哪些?【更多信息可以查看 github mirai】

在这里我会简单介绍有哪几种,每个协议都去尝试一遍。

  1.  "ANDROID_PHONE"
  2.  "ANDROID_PAD"
  3.  "ANDROID_WATCH"
  4.  "MACOS" 【主要是这个协议,我成功了
  5.  "IPAD" 

 介绍到这里,就差不多了,总结:更换协议,多尝试几遍,你也行

🙌效果展示:

 

机器人登录的账号是 783707308 ,那么用另外一个QQ号(自己的小号或者其他人的,随便你)

向 机器人账号发送消息

根据匹配规则,我可以让机器人发送我自己想要的信息

 


 

😎文末 

😍项目结构:

 

 ❤️pom.xml 文件:【仅供参考】

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.fly.simbot</groupId>
  <artifactId>mirai-demo-1</artifactId>
  <version>1.0-SNAPSHOT</version>

  <properties>
    <kotlin.version>1.8.20</kotlin.version>
  </properties>

  <dependencies>

    <!-- Simple Robot 核心库 -->
    <dependency>
      <groupId>love.forte.simbot</groupId>
      <artifactId>simbot-core</artifactId>
      <version>3.0.0-RC.3</version>
    </dependency>
    <!-- mirai组件-->
    <dependency>
      <groupId>love.forte.simbot.component</groupId>
      <artifactId>simbot-component-mirai-core</artifactId>
      <version>3.0.0.0-RC.2</version>
    </dependency>
    <!-- 日志 -->
    <!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-log4j12 -->
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-log4j12</artifactId>
      <version>1.7.21</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/log4j/log4j-->
    <dependency>
      <groupId>log4j</groupId>
      <artifactId>log4j</artifactId>
      <version>1.2.17</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core -->
    <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-core</artifactId>
      <version>2.9.1</version>
    </dependency>
    <dependency>
      <groupId>org.jetbrains.kotlin</groupId>
      <artifactId>kotlin-stdlib-jdk8</artifactId>
      <version>${kotlin.version}</version>
    </dependency>
    <dependency>
      <groupId>org.jetbrains.kotlin</groupId>
      <artifactId>kotlin-test</artifactId>
      <version>${kotlin.version}</version>
      <scope>test</scope>
    </dependency>
  </dependencies>

  <build>
    <plugins>
      <plugin>
        <groupId>org.jetbrains.kotlin</groupId>
        <artifactId>kotlin-maven-plugin</artifactId>
        <version>${kotlin.version}</version>
        <executions>
          <execution>
            <id>compile</id>
            <phase>compile</phase>
            <goals>
              <goal>compile</goal>
            </goals>
          </execution>
          <execution>
            <id>test-compile</id>
            <phase>test-compile</phase>
            <goals>
              <goal>test-compile</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <jvmTarget>17</jvmTarget>
        </configuration>
      </plugin>
    </plugins>
  </build>

</project>

💕 MainApplication.kt 【main 方法】

package com.fly.simbot

import love.forte.simbot.application.Application
import love.forte.simbot.component.mirai.miraiBots
import love.forte.simbot.component.mirai.useMirai
import love.forte.simbot.core.application.SimpleApplicationBuilder
import love.forte.simbot.core.application.createSimpleApplication
import love.forte.simbot.core.event.listeners
import love.forte.simbot.event.FriendMessageEvent
import net.mamoe.mirai.utils.BotConfiguration

/**
 * @author: fly
 * @Date: 2023-04-15 17:23
 * @Description: 入口类
 */

suspend fun main() {
    val app = createSimpleApplication {
        // 配置 mirai
        configApplication()
    }

    app.apply {
        // 配置事件处理器
        configEventProcessor()
        // 注册 rot
        configBots()
    }

    // 加入线程
    app.join()
}

// 基本配置
private fun SimpleApplicationBuilder.configApplication() {
    useMirai()
}

// 配置事件处理
private fun Application.configEventProcessor() {
    eventListenerManager.listeners {
        // 监听好友消息
        listen(FriendMessageEvent) {
            // 匹配函数
            // 当朋友发送你好时,将会进行触发
            match { event -> "你好" in event.messageContent.plainText.trim() }

            // 处理
            process {
                event -> event.friend().send("我是人工智能——风")
            }
        }
    }
}

private fun BotConfiguration.botConfig() {
    // 指定协议: MACOS
    protocol = BotConfiguration.MiraiProtocol.MACOS
}

// 注册 bot
private suspend fun Application.configBots() {
    miraiBots {
        val bot = register(783707308L,"你的密码") {
            // mirai 原生配置
            botConfiguration {
                botConfig()
            }
        }
        bot.start()
    }
}

💖 log4j.xml 【这个文件在 idea中标红部分不用管

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration PUBLIC "-//log4j/log4j Configuration//EN" "log4j.dtd">

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">

    <appender name="STDOUT" class="org.apache.log4j.ConsoleAppender">
        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d %-5p %c.%M:%L - %m%n"/>
        </layout>
    </appender>

    <!-- specify the logging level for loggers from other libraries -->
    <logger name="com.fly.simbot">
        <level value="ERROR" />
    </logger>

    <!-- for all other loggers log only debug and above log messages -->
    <root>
        <priority value="DEBUG"/>
        <appender-ref ref="STDOUT" />
    </root>

</log4j:configuration>

 

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Fy哥

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值