Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
heavyrain2012 committed Jul 15, 2020
1 parent c7b492b commit 4167a9c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ java -jar app-XXXXX.jar
+ 0.43版本把Web和PC登录的短轮询改为长轮询,如果应用服务升级需要对Web和PC进行对应修改。

#### 注意事项
服务中对同一个IP的请求会有限频,默认是一个ip一小时可以请求200次,可以根据您的实际情况调整(搜索rateLimiter字符串就能找到)。如果使用了nginx做反向代理需要注意把用户真实ip带过去,避免获取不到真实ip从而影响正常使用。
服务中对同一个IP的请求会有限频,默认是一个ip一小时可以请求200次,可以根据您的实际情况调整(搜索rateLimiter字符串就能找到)。如果使用了nginx做反向代理需要注意把用户真实ip传递过去(使用X-Real-IP或X-Forwarded-For),避免获取不到真实ip从而影响正常使用。

#### 使用到的开源代码
1. [TypeBuilder](https://github.com/ikidou/TypeBuilder) 一个用于生成泛型的简易Builder
Expand Down
25 changes: 22 additions & 3 deletions src/main/java/cn/wildfirechat/app/ServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,30 @@ private void init() {
rateLimiter = new RateLimiter(60, 200);
}

@Override
public RestResult sendCode(String mobile) {
private String getIp() {
ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
HttpServletRequest request = requestAttributes.getRequest();
String remoteIp = request.getRemoteAddr();
String ip = request.getHeader("X-Real-IP");
if (!StringUtils.isEmpty(ip) && !"unknown".equalsIgnoreCase(ip)) {
return ip;
}
ip = request.getHeader("X-Forwarded-For");
if (!StringUtils.isEmpty(ip) && !"unknown".equalsIgnoreCase(ip)) {
// 多次反向代理后会有多个IP值,第一个为真实IP。
int index = ip.indexOf(',');
if (index != -1) {
return ip.substring(0, index);
} else {
return ip;
}
} else {
return request.getRemoteAddr();
}
}

@Override
public RestResult sendCode(String mobile) {
String remoteIp = getIp();
LOG.info("request send sms from {}", remoteIp);

//判断当前IP发送是否超频。
Expand Down

0 comments on commit 4167a9c

Please sign in to comment.