上传备份

master
王兵 4 weeks ago
parent 415d8f738d
commit acf81b10aa

@ -41,6 +41,7 @@ import cn.zhouyafeng.itchat4j.utils.enums.parameters.LoginParaEnum;
import cn.zhouyafeng.itchat4j.utils.enums.parameters.StatusNotifyParaEnum; import cn.zhouyafeng.itchat4j.utils.enums.parameters.StatusNotifyParaEnum;
import cn.zhouyafeng.itchat4j.utils.enums.parameters.UUIDParaEnum; import cn.zhouyafeng.itchat4j.utils.enums.parameters.UUIDParaEnum;
import cn.zhouyafeng.itchat4j.utils.tools.CommonTools; import cn.zhouyafeng.itchat4j.utils.tools.CommonTools;
import xyz.wbsite.itchat4j.util.ImageUtil;
/** /**
* *
@ -140,7 +141,8 @@ public class LoginServiceImpl implements ILoginService {
out.flush(); out.flush();
out.close(); out.close();
try { try {
CommonTools.printQr(qrPath); // 打开登陆二维码图片 // CommonTools.printQr(qrPath); // 打开登陆二维码图片
ImageUtil.show(ImageUtil.load(new File(qrPath)));
} catch (Exception e) { } catch (Exception e) {
LOG.info(e.getMessage()); LOG.info(e.getMessage());
} }

@ -64,13 +64,8 @@ public class JMainApplication extends Application {
} }
}); });
// FileUtil.file(FileUtil.getTmpDir(), "itchat4j."); // 服务初始化
String qrPath = "C:\\Users\\Administrator\\Desktop\\111"; // 保存登陆二维码图片的路径,这里需要在本地新建目录 JMainService.init();
IMsgHandlerFace msgHandler = new JMsgHandler(); // 实现IMsgHandlerFace接口的类
Wechat wechat = new Wechat(msgHandler, qrPath); // 【注入】
// 启动服务会在qrPath下生成一张二维码图片扫描即可登陆注意二维码图片如果超过一定时间未扫描会过期过期时会自动更新所以你可能需要重新打开图片
wechat.start();
} }
public static void main(String[] args) { public static void main(String[] args) {

@ -96,6 +96,14 @@ public class JMainController implements Initializable {
this.start.setDisable(true); this.start.setDisable(true);
this.stop.setDisable(false); this.stop.setDisable(false);
Logger.info("启动服务"); Logger.info("启动服务");
if (!JMainService.getInstance().run) {
boolean start = JMainService.start();
if (!start) {
Logger.error("服务启动失败");
return;
}
Logger.info("服务启动成功");
}
} }
} }
@ -108,6 +116,15 @@ public class JMainController implements Initializable {
this.start.setDisable(false); this.start.setDisable(false);
this.stop.setDisable(true); this.stop.setDisable(true);
Logger.info("停止服务"); Logger.info("停止服务");
if (JMainService.getInstance().run) {
boolean stop = JMainService.stop();
if (!stop) {
Logger.error("服务停止失败");
return;
}
Logger.info("服务停止成功");
this.preview.setImage(null);
}
} }
} }

@ -0,0 +1,100 @@
package xyz.wbsite.itchat4j;
import cn.hutool.core.io.FileUtil;
import cn.zhouyafeng.itchat4j.Wechat;
import xyz.wbsite.itchat4j.util.Logger;
import java.io.File;
/**
* 线
*
* @author wangbing
* @version 0.0.1
* @since 1.8
*/
public class JMainService {
/**
*
*/
private static JMainService instance;
private static Wechat wechat;
public static synchronized JMainService getInstance() {
if (instance == null) {
JMainService.instance = new JMainService();
}
return instance;
}
/**
*
*/
public boolean run;
/**
* 线
*/
public LoginThread loginThread;
/**
*
*/
private JMainService() {
Logger.info("初始化服务");
}
public static void init() {
}
public void createDaemon() {
Logger.info("初始化线程");
this.loginThread = new LoginThread();
this.loginThread.setDaemon(true);
Logger.info("启动线程");
this.run = true;
this.loginThread.start();
}
public static boolean start() {
if (JMainService.getInstance().run) {
Logger.info("服务已启动");
return false;
}
// 创建线程
JMainService.getInstance().createDaemon();
return true;
}
public static boolean stop() {
if (!JMainService.getInstance().run) {
Logger.info("服务未启动");
return false;
}
// 停止服务
JMainService.getInstance().run = false;
// 关闭守护线程
JMainService.getInstance().loginThread.interrupt();
Logger.info("正在停止脚本");
return true;
}
/**
* 线
*/
public class LoginThread extends Thread {
@Override
public void run() {
// 保存登陆二维码图片的路径,这里需要在本地新建目录
File qrPath = FileUtil.mkdir(new File(FileUtil.getTmpDir(), "itchat4j"));
wechat = new Wechat(new JMsgHandler(), qrPath.getAbsolutePath());
// 启动服务会在qrPath下生成一张二维码图片扫描即可登陆注意二维码图片如果超过一定时间未扫描会过期过期时会自动更新所以你可能需要重新打开图片
wechat.start();
}
}
}

@ -90,16 +90,7 @@ public class ImageUtil {
* @param image * @param image
*/ */
public static void show(BufferedImage image) { public static void show(BufferedImage image) {
Image showImage = image; Image showImage = ImgUtil.scale(image, 192, 192);
// 图片宽高都大于预览窗口时进行缩放显示
if (image.getWidth() > 192 || image.getHeight() > 108) {
// 宽高比大于预览窗口,适配宽, 否则适配高
if (1D * image.getWidth() / image.getHeight() > 192D / 108D) {
showImage = ImgUtil.scale(showImage, 1.0f * 192 / image.getWidth());
} else {
showImage = ImgUtil.scale(showImage, 1.0f * 108 / image.getHeight());
}
}
byte[] bytes = ImgUtil.toBytes(showImage, "PNG"); byte[] bytes = ImgUtil.toBytes(showImage, "PNG");
javafx.scene.image.Image image1 = new javafx.scene.image.Image(IoUtil.toStream(bytes)); javafx.scene.image.Image image1 = new javafx.scene.image.Image(IoUtil.toStream(bytes));
JMainApplication.mainController.preview(image1); JMainApplication.mainController.preview(image1);

Loading…
Cancel
Save

Powered by TurnKey Linux.