Skip to content

Commit 3d3e52e

Browse files
committed
支持变更IP
1 parent 4ead731 commit 3d3e52e

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/main/java/com/xlongwei/light4j/handler/service/WeixinHandler.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public void chat(HttpServerExchange exchange) throws Exception {
3030

3131
TextMessage textMsg = new TextMessage();
3232
textMsg.setContent(text);
33+
textMsg.setFromUserName(HandlerUtil.getParam(exchange, "openid"));
3334
AbstractMessage dispatch = WeixinUtil.dispatch(textMsg);
3435
if(dispatch!=null && dispatch instanceof TextMessage) {
3536
text = ((TextMessage)dispatch).getContent();

src/main/java/com/xlongwei/light4j/handler/weixin/KeyHandler.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.util.Collections;
55
import java.util.Map;
66

7+
import com.alibaba.fastjson.JSONObject;
78
import com.xlongwei.light4j.handler.service.IpHandler;
89
import com.xlongwei.light4j.handler.service.MobileHandler;
910
import com.xlongwei.light4j.util.JsonUtil;
@@ -12,6 +13,7 @@
1213
import com.xlongwei.light4j.util.WeixinUtil.AbstractMessageHandler.AbstractTextHandler;
1314

1415
import cn.hutool.core.map.MapUtil;
16+
import cn.hutool.http.HttpRequest;
1517
import cn.hutool.http.HttpUtil;
1618

1719
/**
@@ -40,7 +42,18 @@ public String handle(String content) {
4042
}
4143
return response.toString();
4244
}
43-
}else if(StringUtil.isIp(content)) {
45+
}else if(content.startsWith("ip=")){
46+
content = content.substring("ip=".length());
47+
String openid = message.get().getFromUserName();
48+
if(!StringUtil.isBlank(openid)) {
49+
JSONObject alidnsConfig = JsonUtil.parseNew(RedisConfig.get("alidns.config"));
50+
String token = alidnsConfig.getString("token"), recordId = alidnsConfig.getString(openid);
51+
if(!StringUtil.isBlank(recordId)) {
52+
String ip = StringUtil.isIp(content) ? content : "";
53+
return HttpRequest.get("https://log.xlongwei.com/log?type=alidns&recordId="+recordId+"&ip="+ip).header("X-Request-Token", token).execute().body();
54+
}
55+
}
56+
}else if(StringUtil.isIp(content)) {
4457
Map<String, String> searchToMap = IpHandler.searchToMap(content);
4558
if(searchToMap!=null) {
4659
return searchToMap.get("region");

0 commit comments

Comments
 (0)