提交 97a050c1 作者: han

授权手机号bug修复

上级 8b7af01d
流水线 #8284 已通过 于阶段
in 2 分 7 秒
......@@ -23,6 +23,7 @@ import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletRequest;
......@@ -93,6 +94,7 @@ public class WxServiceImpl implements WxService {
@Override
public String getStableAccessToken() {
//token有效期为7200s,需要保存起来,先从redis中获取accessToken,没有则请求获取
stringRedisTemplate.setValueSerializer(RedisSerializer.json());
String accessToken = stringRedisTemplate.opsForValue().get(WxConstant.IUAV_MINI_PROGRAM_STABLE_ACCESS_TOKEN);
if (StringUtils.isBlank(accessToken)) {
Map<String, String> params = new HashMap<String, String>();
......@@ -113,6 +115,7 @@ public class WxServiceImpl implements WxService {
accessToken = tokenResult.getString("access_token");
long expiresIn = tokenResult.getLong("expires_in");
//保存进redis
stringRedisTemplate.setValueSerializer(RedisSerializer.json());
stringRedisTemplate.opsForValue().set(WxConstant.IUAV_MINI_PROGRAM_STABLE_ACCESS_TOKEN, accessToken, expiresIn, TimeUnit.SECONDS);
return accessToken;
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论