Mirai qq robot ubuntu configuration stepping record
Mirai GitHub链接mirai-github
intellij configuration
Mine is Ultimate 2020.1 version
I created a maven project
Some possible errors:
Intellij idea reported an error: Error: java does not support release version 5
It takes too long to create maven. Modify the maven mirror source in IDEA to add dependencies to the Ali source method
<repositories>
<repository>
<id>jcenter</id>
<url>https://jcenter.bintray.com/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>net.mamoe</groupId>
<artifactId>mirai-core-qqandroid</artifactId>
<version>1.3.0</version> <!-- 替换版本为最新版本 -->
</dependency>
</dependencies>
The 1.3.0 version is currently available, the official website default code 0.23.0 will fail to download, remember to update to the latest version
Write test code
public class Test {
public static void main(String[] args) {
long qq=你的qq号;
String password="密码";
final Bot bot = BotFactoryJvm.newBot(qq,password, new BotConfiguration() {
{
fileBasedDeviceInfo("deviceInfo.json");
}
});
bot.login();
}
}
After that, QQ will prompt to scan the code to verify and click on the link to scan the code to verify the device. After verification, there is no need to verify again.
For more functions, please see the official github document mirai-github
After running, an error "Java does not support release version 5" may appear. Refer to the above link for the solution
Successful login! The message received afterwards will be printed out on the command line.
Package jar
In order to make the program run independently on ubuntu, you need to package the jar package
File->project structure
Click build artifacts
It will generate'Project' \out\artifacts\MiraiMaven3_jar\MiraiMaven3.jar
try
java -jar 你的jar包
If the jar at this time cannot be run directly, provide some possible error solutions
- "Java.lang.SecurityException: Invalid signature file digest for Manifest main attribute
delete the *.SF, *.DSA, *.RSA files in the META-INF directory
Modify the MANIFEST.MF file under META-INF in the jar package without the main manifest attribute . If it is a java file created directly under src, in this code example it is
Main-Class: Test
Test again
java -jar x.jar
, theoretically it can run normally
ubuntu runs without interface
On windows, the verification code is popped up using the java graphical interface. On ubuntu, mirai will store the verification code image on the machine. Find the file according to the path it prompts. It is recommended to use ftp software such as filezilla to view. The usage of filezilla and ftp is no longer in this article. Introduction. If there is another way to see the picture, it is fine.
Successful screenshot