package com.bonus.auth.api;

import cn.hutool.core.util.ObjectUtil;
import com.bonus.common.redis.service.RedisService;
import com.bonus.domain.SmsCodeVerifyDTO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SmsCodeApi {
   private static final Logger log = LoggerFactory.getLogger(SmsCodeApi.class);

   @Autowired
   private RedisService redisService;

   public boolean verifySmsCode(SmsCodeVerifyDTO smsCodeVerifyDTO, String cacheKey) {
      String key = cacheKey + smsCodeVerifyDTO.getTelephoneNumber();
      String code = redisService.getCacheObject(key); //RedisUtil.getString(key);
      log.info("redis缓存验证码code : {}", code);
      return ObjectUtil.isNotEmpty(code) && ObjectUtil.equal(code, smsCodeVerifyDTO.getCode());
   }
}
