Skip to content

Commit

Permalink
更新依赖版本
Browse files Browse the repository at this point in the history
  • Loading branch information
Godfunc committed Jul 29, 2021
1 parent acb0002 commit c2c6c5c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

import com.godfunc.modules.security.service.CaptchaService;
import com.google.code.kaptcha.Producer;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import org.apache.commons.lang3.StringUtils;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.awt.image.BufferedImage;
Expand All @@ -18,27 +17,29 @@
public class CaptchaServiceImpl implements CaptchaService {

private final Producer producer;
private final StringRedisTemplate redisTemplate;

public CaptchaServiceImpl(Producer producer) {
public CaptchaServiceImpl(Producer producer, StringRedisTemplate redisTemplate) {
this.producer = producer;
this.redisTemplate = redisTemplate;
}

/**
* 有需要可以替换成redis
*/
Cache<String, String> captchaCache = CacheBuilder.newBuilder().maximumSize(1000).expireAfterAccess(5, TimeUnit.MINUTES).build();

@Override
public BufferedImage create(String uuid) {
String code = producer.createText();
captchaCache.put(uuid, code);
redisTemplate.opsForValue().set(uuid, code, 5, TimeUnit.MINUTES);
return producer.createImage(code);
}

@Override
public boolean validate(String uuid, String code) {
String text = captchaCache.getIfPresent(uuid);
if(StringUtils.isNotBlank(text)) {
String text = redisTemplate.opsForValue().get(uuid);
if (StringUtils.isNotBlank(text)) {
redisTemplate.delete(uuid);
return code.equalsIgnoreCase(text);
}
return false;
Expand Down
8 changes: 4 additions & 4 deletions manage/src/main/resources/bootstrap-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ spring:
cloud:
nacos:
config:
server-addr: 192.168.31.62:8848
namespace: 97a12ee4-81a2-420f-ba7b-564b47b3279b
discovery:
server-addr: 192.168.31.61:8848
namespace: 97a12ee4-81a2-420f-ba7b-564b47b3279b
namespace: fd744ed2-0b38-4fe3-9414-662bf018e1df
discovery:
server-addr: 192.168.31.62:8848
namespace: fd744ed2-0b38-4fe3-9414-662bf018e1df
log:
path: /usr/local/log/prod/gpay/gpay-manage
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<jsoup.version>1.13.1</jsoup.version>
<jBCrypt.version>0.4.3</jBCrypt.version>
<rocketmq.version>2.2.0</rocketmq.version>
<spring-cloud-alibaba.version>2.2.1.RELEASE</spring-cloud-alibaba.version>
<spring-cloud-alibaba.version>2.2.6.RELEASE</spring-cloud-alibaba.version>
</properties>

<modules>
Expand Down

0 comments on commit c2c6c5c

Please sign in to comment.