非程序员,医学生,我是这么写的代码,你可以参考,可扫码,可短信验证登陆,基于目前的2.15.0-M1: public static void login(Long botAccount, String botPassword) {
Configuration config = ConfigManager.getConfig();
ClassLoader loader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(GlobalEventChannel.class.getClassLoader());
boolean loginByQR = config.getBoolean("loginByQR");
File workingDir = new File(ConfigManager.pluginDirectory, "bot");
if(!workingDir.exists()) workingDir.mkdirs();
BotFactory.BotConfigurationLambda botConfigurationLambda = botConfiguration -> {
botConfiguration.setWorkingDir(workingDir);
if (config.getBoolean("redirectBotLogToDirectory")) {
botConfiguration.redirectBotLogToDirectory();
}
if (config.getBoolean("noNetworkLog")) {
botConfiguration.noNetworkLog();
}
if (config.getBoolean("noBotLog")) {
botConfiguration.noBotLog();
}
botConfiguration.setProtocol(BotConfiguration.MiraiProtocol.valueOf(config.getString("bot-login-device")));
botConfiguration.setCacheDir(new File("cache"));
botConfiguration.fileBasedDeviceInfo();
File deviceFile = new File(botConfiguration.getWorkingDir(), "device.json");
if (deviceFile.exists()) {
botConfiguration.setDeviceInfo(bot1 -> DeviceInfo.from(deviceFile));
}
};
bot = loginByQR ? BotFactory.INSTANCE.newBot(botAccount, BotAuthorization.byQRCode(), botConfigurationLambda) :
BotFactory.INSTANCE.newBot(botAccount, botPassword, new BotConfiguration() {{
setWorkingDir(workingDir);
if (config.getBoolean("redirectBotLogToDirectory")) {
redirectBotLogToDirectory();
}
if (config.getBoolean("noNetworkLog")) {
noNetworkLog();
}
if (config.getBoolean("noBotLog")) {
noBotLog();
}
//FixProtocolVersion.update();
setProtocol(MiraiProtocol.valueOf(config.getString("bot-login-device")));
setCacheDir(new File("cache"));
fileBasedDeviceInfo();
File deviceFile = new File(getWorkingDir(), "device.json");
if (deviceFile.exists()) {
setDeviceInfo(bot1 -> DeviceInfo.from(deviceFile));
}
}});
bot.login();
Thread.currentThread().setContextClassLoader(loader);
}