Просмотр исходного кода

交友-ip-v0.03

(cherry picked from commit e9dea867b20f9246e3458c0976dd059aa90ced30)
MOKASZ\lw12420 2 лет назад
Родитель
Сommit
351cf01905

+ 18 - 18
launch-admin/src/main/java/com/webflux/launchadmin/mysql/controller/planNew/PlanNewCommonOutController.java

@@ -133,24 +133,24 @@ public class PlanNewCommonOutController {
                 if (!materialList.isEmpty()) {
                     Material material = materialList.get(RandomUtil.randomInt(0, materialList.size()));
                     String content = material.content();
-//                    String clientIP = exchange.getRequest().getHeaders().getFirst("X-Forwarded-For");
-//                    if ((clientIP == null || clientIP.isEmpty()) && Objects.nonNull(exchange.getRequest().getRemoteAddress())) {
-//                        clientIP = exchange.getRequest().getRemoteAddress().getAddress().getHostAddress();
-//                    }
-//                    if (StrUtil.isNotBlank(clientIP)) {
-//                        JSONObject ipInfo = ipAnalyzeServiceInterface.getIpInfo(clientIP);
-//                        if (null != ipInfo) {
-//                            String city = ipInfo.getStr("city");
-//                            if (StrUtil.isNotBlank(city)) {
-//                                content = city + content;
-//                            } else {
-//                                String province = ipInfo.getStr("region");
-//                                if (StrUtil.isNotBlank(province)) {
-//                                    content = province + content;
-//                                }
-//                            }
-//                        }
-//                    }
+                    String clientIP=null ;//exchange.getRequest().getHeaders().getFirst("X-Forwarded-For");
+                    if ( Objects.nonNull(exchange.getRequest().getRemoteAddress())) {
+                        clientIP = exchange.getRequest().getRemoteAddress().getAddress().getHostAddress();
+                    }
+                    if (StrUtil.isNotBlank(clientIP)) {
+                        JSONObject ipInfo = ipAnalyzeServiceInterface.getIpInfo(clientIP);
+                        if (null != ipInfo) {
+                            String city = ipInfo.getStr("city");
+                            if (StrUtil.isNotBlank(city)) {
+                                content = city + content;
+                            } else {
+                                String province = ipInfo.getStr("region");
+                                if (StrUtil.isNotBlank(province)) {
+                                    content = province + content;
+                                }
+                            }
+                        }
+                    }
                     h5ImageAndText.setName(content);
                     h5ImageAndText.setRemark(material.remark());
                 }