|
@@ -7,9 +7,12 @@ import com.example.mos.weChatLogin.awt.MyImageShowFrame;
|
|
import com.example.mos.weChatLogin.model.WxResultBody;
|
|
import com.example.mos.weChatLogin.model.WxResultBody;
|
|
import com.example.mos.weChatLogin.okhttp.MyCookieStore;
|
|
import com.example.mos.weChatLogin.okhttp.MyCookieStore;
|
|
import com.example.mos.weChatLogin.utils.HttpUtils;
|
|
import com.example.mos.weChatLogin.utils.HttpUtils;
|
|
|
|
+import jakarta.annotation.PostConstruct;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.boot.SpringApplication;
|
|
import org.springframework.boot.SpringApplication;
|
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
|
|
+import org.springframework.boot.builder.SpringApplicationBuilder;
|
|
|
|
+import org.springframework.context.ApplicationContext;
|
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
|
|
|
|
|
import javax.swing.*;
|
|
import javax.swing.*;
|
|
@@ -26,93 +29,12 @@ import java.util.concurrent.FutureTask;
|
|
@SpringBootApplication
|
|
@SpringBootApplication
|
|
@EnableScheduling
|
|
@EnableScheduling
|
|
public class MosApplication {
|
|
public class MosApplication {
|
|
|
|
+ @Autowired
|
|
|
|
+ private MainView mainView;
|
|
|
|
+
|
|
// private static MyImageShowFrame myImageShowFrame;
|
|
// private static MyImageShowFrame myImageShowFrame;
|
|
public static void main(String[] args) throws IOException {
|
|
public static void main(String[] args) throws IOException {
|
|
-
|
|
|
|
-// //图片显示控件
|
|
|
|
-// myImageShowFrame = new MyImageShowFrame();
|
|
|
|
-//
|
|
|
|
-// // 1. POST请求开始登录接口,初始化cookie
|
|
|
|
-// String sessionid = "" + System.currentTimeMillis() + (int)(Math.random()*100);//生成一个包含当前时间戳以及随机数的字符串
|
|
|
|
-// WxResultBody wxResultBody = WeiXinApi.startLogin(sessionid);
|
|
|
|
-// System.out.println("---请求开始登录接口 返回结果:" + wxResultBody.toString());
|
|
|
|
-// // 2. 请求获取二维码图片接口,得到流
|
|
|
|
-// InputStream qrCodeIs = WeiXinApi.getQRCode();
|
|
|
|
-// //转成图片显示
|
|
|
|
-// myImageShowFrame.setTitle("请使用微信扫码登录");
|
|
|
|
-// myImageShowFrame.showImage(qrCodeIs);
|
|
|
|
-// myImageShowFrame.setLocation(500,100);
|
|
|
|
-// // 3.轮询二维码状态接口
|
|
|
|
-// FutureTask<Integer> futureTask = new FutureTask<>(new Callable<Integer>() {
|
|
|
|
-// @Override
|
|
|
|
-// public Integer call() throws Exception {
|
|
|
|
-// while (true) {
|
|
|
|
-// WxResultBody askQRCode = WeiXinApi.askQRCode();
|
|
|
|
-// Integer status = askQRCode.getStatus();
|
|
|
|
-// if (status == 3) {
|
|
|
|
-// System.out.println("二维码已过期");
|
|
|
|
-// return 3;
|
|
|
|
-// } else if (status == 4) {
|
|
|
|
-// System.out.println("已扫码,等待确认");
|
|
|
|
-// } else if (status == 1) {
|
|
|
|
-// System.out.println("已确认登录,请稍后...");
|
|
|
|
-// return 1;
|
|
|
|
-// }
|
|
|
|
-// try {
|
|
|
|
-// Thread.sleep(1000);
|
|
|
|
-// } catch (InterruptedException e) {
|
|
|
|
-// e.printStackTrace();
|
|
|
|
-// }
|
|
|
|
-// }
|
|
|
|
-// }
|
|
|
|
-// });
|
|
|
|
-//
|
|
|
|
-// while (true) {
|
|
|
|
-// Thread queryThread = new Thread(futureTask);
|
|
|
|
-// queryThread.start();
|
|
|
|
-// if (!futureTask.isDone()) {
|
|
|
|
-// System.out.println("--正在查询扫码状态,请尽快扫码!");
|
|
|
|
-// }
|
|
|
|
-//
|
|
|
|
-// try {
|
|
|
|
-// Integer integer = futureTask.get();
|
|
|
|
-// if (integer == 1) {
|
|
|
|
-// //说明扫码确认成功,否则重新获取图片
|
|
|
|
-// //关闭图片显示
|
|
|
|
-// myImageShowFrame.close();
|
|
|
|
-// break;
|
|
|
|
-// } else {
|
|
|
|
-// //重新获取二维码图片显示
|
|
|
|
-// myImageShowFrame.showImage(WeiXinApi.getQRCode());
|
|
|
|
-// }
|
|
|
|
-// } catch (Exception e) {
|
|
|
|
-// System.out.println("查询接口出错了");
|
|
|
|
-// break;
|
|
|
|
-// }
|
|
|
|
-// }
|
|
|
|
-//
|
|
|
|
-// // 4.确认登录后,请求登录接口,拿到登录状态的cookie
|
|
|
|
-// WxResultBody bizlogin = WeiXinApi.bizlogin();
|
|
|
|
-// //重定向地址
|
|
|
|
-// String redirect_url = bizlogin.getRedirect_url();
|
|
|
|
-// //解析成键值对
|
|
|
|
-// Map<String, String> loginRes = HttpUtils.parseQueryParams(redirect_url);
|
|
|
|
-// //得到token
|
|
|
|
-// String token = loginRes.get("token");
|
|
|
|
-// //设置全局token值
|
|
|
|
-// MyCookieStore.setToken(token);
|
|
|
|
-//
|
|
|
|
-// System.out.println("---恭喜你,登录成功!");
|
|
|
|
-
|
|
|
|
-// SpringApplication.run(MosApplication.class, args);
|
|
|
|
-// System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()) + "后台程序已启动,请运行前台");
|
|
|
|
-// GraphicsEnvironment.isHeadless();
|
|
|
|
-// System.out.println(GraphicsEnvironment.isHeadless());
|
|
|
|
-// SwingUtilities.invokeLater(() -> {
|
|
|
|
-// new MainView();
|
|
|
|
-// });
|
|
|
|
-
|
|
|
|
-
|
|
|
|
|
|
+// ApplicationContext ctx = new SpringApplicationBuilder(MosApplication.class).headless(false).run(args);
|
|
// 设置虚拟机参数允许图形界面操作
|
|
// 设置虚拟机参数允许图形界面操作
|
|
System.setProperty("java.awt.headless", "false");
|
|
System.setProperty("java.awt.headless", "false");
|
|
// 检查系统是否支持 Headless 模式
|
|
// 检查系统是否支持 Headless 模式
|
|
@@ -121,11 +43,18 @@ public class MosApplication {
|
|
} else {
|
|
} else {
|
|
SpringApplication.run(MosApplication.class, args);
|
|
SpringApplication.run(MosApplication.class, args);
|
|
System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()) + "后台程序已启动,请运行前台");
|
|
System.out.println(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()) + "后台程序已启动,请运行前台");
|
|
- // 在非 Headless 模式下运行 Swing GUI
|
|
|
|
- SwingUtilities.invokeLater(() -> {
|
|
|
|
- new MainView();
|
|
|
|
- });
|
|
|
|
|
|
+// // 在非 Headless 模式下运行 Swing GUI
|
|
|
|
+// SwingUtilities.invokeLater(() -> {
|
|
|
|
+// new MainView();
|
|
|
|
+// });
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ @PostConstruct
|
|
|
|
+ public void init() {
|
|
|
|
+ SwingUtilities.invokeLater(() -> {
|
|
|
|
+ mainView.setVisible(true);
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|