All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.mg.common.user.service.SmsCodeServiceImpl Maven / Gradle / Ivy

There is a newer version: 1.0.5
Show newest version
package com.mg.common.user.service;

import com.mg.common.entity.SmsCodeEntity;
import com.mg.common.user.dao.SmsCodeDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * Created by liukefu on 2017/6/24.
 */
@Service
public class SmsCodeServiceImpl  implements SmsCodeService {
    @Autowired
    private SmsCodeDao smsCodeDao;
    @Override
    public SmsCodeEntity findByMobileAndSmsCode(String mobile, String smsCode) {
        List list = smsCodeDao.findByMobileAndSmsCodeOrderBySendTimeDesc(mobile,smsCode);
        if(list!=null){
            //验证码不能超过10分钟
            SmsCodeEntity smsCodeEntity = list.get(0);
            long distance = (new Date().getTime() - smsCodeEntity.getSendTime().getTime()) / 1000 /60;
            if(distance > 10){
                return null;
            }
            return list.get(0);
        }
        return null;
    }

    @Override
    public SmsCodeEntity save(SmsCodeEntity smsCodeEntity) {
       return smsCodeDao.save(smsCodeEntity);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy