public static function identifyCode($phone, $code, $type = 0) { $memCode = MyRedis::get("identifyCode.pub:{$type}:{$phone}"); if ($memCode != 0 && $memCode == $code) { return true; } return false; }
public static function get($key_footer = null) { if (self::$_redis) { //开启了redis缓存 return MyRedis::get($key_footer); } elseif (self::$_memcache) { //开启了memcache缓存 return MyMemcache::get($key_footer); } else { return false; } }
/** * 获取某个手机号某种业务类型在一定时间内发送的次数,并加一 * @param $phone 手机号码 * @param $codetype 业务类型:0-注册帐号 1-发送验证码到旧绑定手机 2-更换绑定手机 3-提现 4-重置密码 * @return int */ private static function updateSendNums($phone, $codetype) { $num = 0; if (MyRedis::exists("identifyCode:num:{$codetype}:{$phone}")) { $num = intval(MyRedis::get("identifyCode:num:{$codetype}:{$phone}")); } $expire = 3 * 60; // 统计3分钟内的点击次数 MyRedis::set("identifyCode:num:{$codetype}:{$phone}", $num + 1, $expire); // 次数加1 return $num; }