22
33import java .awt .EventQueue ;
44import java .io .File ;
5+ import java .net .MalformedURLException ;
6+ import java .net .URL ;
57import java .util .Arrays ;
68import java .util .List ;
79
1618import blade .kit .logging .Logger ;
1719import blade .kit .logging .LoggerFactory ;
1820import me .biezhi .weixin .util .CookieUtil ;
21+ import me .biezhi .weixin .util .JSUtil ;
1922import me .biezhi .weixin .util .Matchers ;
2023
2124/**
@@ -63,7 +66,7 @@ public String getUUID() {
6366
6467 String res = request .body ();
6568 request .disconnect ();
66-
69+
6770 if (StringKit .isNotBlank (res )){
6871 String code = Matchers .match ("window.QRLogin.code = (\\ d+);" , res );
6972 if (null != code ){
@@ -92,7 +95,7 @@ public void showQrCode() {
9295 "t" , "webwx" ,
9396 "_" , DateKit .getCurrentUnixTime ())
9497 .receive (output );
95-
98+
9699 if (null != output && output .exists () && output .isFile ()){
97100 EventQueue .invokeLater (new Runnable () {
98101 public void run () {
@@ -122,7 +125,7 @@ public String waitForLogin(){
122125
123126 String res = request .body ();
124127 request .disconnect ();
125-
128+
126129 if (null == res ){
127130 LOGGER .info ("[*] 扫描二维码验证失败" );
128131 return "" ;
@@ -139,6 +142,17 @@ public String waitForLogin(){
139142 } else if (code .equals ("200" )){
140143 LOGGER .info ("[*] 正在登录..." );
141144 String pm = Matchers .match ("window.redirect_uri=\" (\\ S+?)\" ;" , res );
145+
146+ String redirectHost = "wx.qq.com" ;
147+ try {
148+ URL pmURL = new URL (pm );
149+ redirectHost = pmURL .getHost ();
150+ } catch (MalformedURLException e ) {
151+ e .printStackTrace ();
152+ }
153+ String pushServer = JSUtil .getPushServer (redirectHost );
154+ webpush_url = "https://" + pushServer + "/cgi-bin/mmwebwx-bin" ;
155+
142156 this .redirect_uri = pm + "&fun=new" ;
143157 LOGGER .info ("[*] redirect_uri=%s" , this .redirect_uri );
144158 this .base_uri = this .redirect_uri .substring (0 , this .redirect_uri .lastIndexOf ("/" ));
@@ -167,7 +181,7 @@ public boolean login(){
167181
168182 String res = request .body ();
169183 this .cookie = CookieUtil .getCookie (request );
170-
184+
171185 request .disconnect ();
172186
173187 if (StringKit .isBlank (res )){
@@ -268,7 +282,7 @@ public boolean wxStatusNotify (){
268282 LOGGER .info ("[*] " + request );
269283 String res = request .body ();
270284 request .disconnect ();
271-
285+
272286 if (StringKit .isBlank (res )){
273287 return false ;
274288 }
@@ -303,7 +317,7 @@ public boolean getContact(){
303317 LOGGER .info ("[*] " + request );
304318 String res = request .body ();
305319 request .disconnect ();
306-
320+
307321 if (StringKit .isBlank (res )){
308322 return false ;
309323 }
@@ -371,7 +385,7 @@ public int[] syncCheck(){
371385 LOGGER .info ("[*] " + request );
372386 String res = request .body ();
373387 request .disconnect ();
374-
388+
375389 if (StringKit .isBlank (res )){
376390 return arr ;
377391 }
@@ -580,6 +594,9 @@ public void run() {
580594 }
581595
582596 public static void main (String [] args ) throws InterruptedException {
597+
598+ System .out .println (JSUtil .getPushServer ("wx.qq.com" ));
599+
583600 App app = new App ();
584601 String uuid = app .getUUID ();
585602 if (null == uuid ){
0 commit comments