Skip to content
This repository was archived by the owner on Jun 5, 2018. It is now read-only.

Commit 03a404b

Browse files
committed
Merge pull request #1 from odirus/master
解决 webpush 域名变化的问题
2 parents 73f8766 + c709e14 commit 03a404b

File tree

2 files changed

+61
-7
lines changed

2 files changed

+61
-7
lines changed

src/main/java/me/biezhi/weixin/App.java

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import java.awt.EventQueue;
44
import java.io.File;
5+
import java.net.MalformedURLException;
6+
import java.net.URL;
57
import java.util.Arrays;
68
import java.util.List;
79

@@ -16,6 +18,7 @@
1618
import blade.kit.logging.Logger;
1719
import blade.kit.logging.LoggerFactory;
1820
import me.biezhi.weixin.util.CookieUtil;
21+
import me.biezhi.weixin.util.JSUtil;
1922
import 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){
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package me.biezhi.weixin.util;
2+
3+
import blade.kit.logging.Logger;
4+
import blade.kit.logging.LoggerFactory;
5+
6+
import javax.script.ScriptEngine;
7+
import javax.script.ScriptEngineManager;
8+
import javax.script.ScriptException;
9+
10+
public class JSUtil {
11+
private static final Logger LOGGER = LoggerFactory.getLogger(JSUtil.class);
12+
13+
private static String eval(String script) {
14+
ScriptEngineManager sem = new ScriptEngineManager();
15+
ScriptEngine se = sem.getEngineByName("javascript");
16+
String res = "";
17+
18+
try {
19+
res = String.valueOf(se.eval(script));
20+
} catch (ScriptException e) {
21+
e.printStackTrace();
22+
}
23+
24+
return res;
25+
}
26+
27+
public static String getPushServer(String host) {
28+
String pushServer = JSUtil.eval(" var e = '" + host + "',\n" +
29+
" t = 'weixin.qq.com',\n" +
30+
" o = 'file.wx.qq.com',\n" +
31+
" n = 'webpush.weixin.qq.com';\n" +
32+
" e.indexOf('wx2.qq.com') > -1 ? (t = 'weixin.qq.com', o = 'file2.wx.qq.com', n = 'webpush2.weixin.qq.com') : e.indexOf('qq.com') > -1 ? (t = 'weixin.qq.com', o = 'file.wx.qq.com', n = 'webpush.weixin.qq.com') : e.indexOf('web1.wechat.com') > -1 ? (t = 'wechat.com', o = 'file1.wechat.com', n = 'webpush1.wechat.com') : e.indexOf('web2.wechat.com') > -1 ? (t = 'wechat.com', o = 'file2.wechat.com', n = 'webpush2.wechat.com') : e.indexOf('wechat.com') > -1 ? (t = 'wechat.com', o = 'file.wechat.com', n = 'webpush.wechat.com') : e.indexOf('web1.wechatapp.com') > -1 ? (t = 'wechatapp.com', o = 'file1.wechatapp.com', n = 'webpush1.wechatapp.com') : (t = 'wechatapp.com', o = 'file.wechatapp.com', n = 'webpush.wechatapp.com');");
33+
34+
35+
return pushServer;
36+
}
37+
}

0 commit comments

Comments
 (0)