feat(新增): 🚀 IP地址查询

This commit is contained in:
bunny 2024-07-18 16:53:04 +08:00
parent 166b519cea
commit bbd3bd7dcd
5 changed files with 67 additions and 51 deletions

View File

@ -59,5 +59,11 @@
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
</dependency>
<!-- 查询ip地址 -->
<dependency>
<groupId>org.lionsoul</groupId>
<artifactId>ip2region</artifactId>
<version>2.6.5</version>
</dependency>
</dependencies>
</project>

View File

@ -1,51 +0,0 @@
package cn.bunny.common.service.utils;
import cn.bunny.vo.user.comment.CommentVo;
import java.util.ArrayList;
import java.util.List;
public class CommentUtil {
/**
* 构建树型结构
*
* @param commentList 评论列表
* @return 结构列表
*/
public static List<CommentVo> buildTree(List<CommentVo> commentList) {
// 构建树形结构
List<CommentVo> tree = new ArrayList<>();
// 遍历评论列表
for (CommentVo comment : commentList) {
// 找到顶级评论没有父评论
if (comment.getPCommentId() == 0) {
// 递归构建子评论
comment.setChildren(getChildren(comment.getId(), commentList));
tree.add(comment);
}
}
return tree;
}
/**
* 递归获取子评论
*
* @param commentId 当前评论ID
* @param commentList 评论列表
* @return 子评论列表
*/
private static List<CommentVo> getChildren(Long commentId, List<CommentVo> commentList) {
List<CommentVo> children = new ArrayList<>();
// 遍历评论列表
for (CommentVo comment : commentList) {
// 找到当前评论的子评论
if (Long.valueOf(comment.getPCommentId()).equals(commentId)) {
// 递归构建子评论的子评论
comment.setChildren(getChildren(comment.getId(), commentList));
children.add(comment);
}
}
return children;
}
}

Binary file not shown.

View File

@ -0,0 +1,45 @@
<body style="margin: 0; padding: 0; background-color: #f5f5f5;">
<div style="max-width: 600px; margin: 0 auto;">
<table style="width: 100%; border-collapse: collapse; background-color: #ffffff; font-family: Arial, sans-serif;">
<tr>
<th style="height: 60px; padding: 20px; background-color: #0074d3; border-radius: 5px 5px 0 0;"
valign="middle">
<h1 style="margin: 0; color: #ffffff; font-size: 24px;">BunnyBBS邮箱验证码</h1>
</th>
</tr>
<tr>
<td style="padding: 20px;">
<div style="background-color: #ffffff; padding: 25px;">
<h2 style="margin: 10px 0; font-size: 18px; color: #333333;">
尊敬的用户,
</h2>
<p style="margin: 10px 0; font-size: 16px; color: #333333;">
感谢您注册我们的产品. 您的账号正在进行电子邮件验证.
</p>
<p style="margin: 10px 0; font-size: 16px; color: #333333;">
验证码为: <span class="button" style="color: #1100ff;">${verifyCode}</span>
</p>
<p style="margin: 10px 0; font-size: 16px; color: #333333;">
验证码的有效期只有一分钟,请抓紧时间进行验证吧!
</p>
<p style="margin: 10px 0; font-size: 16px; color: #dc1818;">
如果非本人操作,请忽略此邮件
</p>
</div>
</td>
</tr>
<tr>
<td style="text-align: center; padding: 20px; background-color: #f5f5f5;">
<p style="margin: 0; font-size: 12px; color: #747474;">
XXXXX<br>
Contact us: XXXXXXX@qq.com
</p>
<p style="margin: 10px 0; font-size: 12px; color: #747474;">
This is an automated email, please do not reply.<br>
© Company Name
</p>
</td>
</tr>
</table>
</div>
</body>

View File

@ -0,0 +1,16 @@
package cn.bunny.ipdb;
import cn.bunny.common.service.utils.IpUtil;
import org.junit.jupiter.api.Test;
public class IpDbTest {
@Test
public void test() {
String ip = "220.248.12.158"; // IpRegion:上海
// String ip = "47.52.236.180"; // IpRegion:香港
// String ip = "172.22.12.123"; // IpRegion:内网IP
// String ip = "164.114.53.60"; // IpRegion:美国
String ipRegion = IpUtil.getIpRegion(ip);
System.out.println(ipRegion);
}
}