倒计时 心跳检测

 最近在写短信发送验证码,就写了个JS倒计时发送验证码按钮



 PC端支付二维码,通过手机扫码支付成功,PC端跳转到支付成功页面,需要定时心跳检测支付状态

 短信表设计

$content ="您的短信验证码:461930,30分钟有效,请尽快完成验证,请妥善保存,勿泄露!";
CREATE TABLE `sms_verify` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `mobile` varchar(20) NOT NULL COMMENT '手机号',
  `verify_code` varchar(6) NOT NULL COMMENT '验证码数字',
  `user_id` int(11) NOT NULL DEFAULT '0' COMMENT '用户id',
  `type` smallint(2) NOT NULL DEFAULT '0' COMMENT '0注册 1忘记密码 2登录 10修改密码',
  `create_time` int(10) NOT NULL DEFAULT '0' COMMENT '创建时间',
  `update_time` int(10) NOT NULL DEFAULT '0' COMMENT '使用时间',
  `expire_time` int(10) NOT NULL DEFAULT '0' COMMENT '失效时间',
  PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4;

当给注册手机发送一个验证码之后,该手机以前其他的没有过期的注册验证码都设置成过期。

后端60秒内只能发一次的验证(防止恶意消耗短信),过期验证,手机号验证等。

//发送短信验证码
public function addVerifyInfo($mobile, $verify_code, $type, $user_id = 0) {
    //todo 发码把之前的设为过期
    $this->where(['mobile' => $mobile, 'type' => $type, 'user_id' => $user_id, 'expire_time' => 0, 'update_time' => 0])->data(['expire_time' => time()])->save();

    $id = $this->data(['mobile' => $mobile, 'type' => $type, 'verify_code' => $verify_code, 'user_id' => $user_id])->add();
    //todo send sms to mobile
    $id && D("Message", "Logic")->smsVerifyCode($mobile, $verify_code);
}

//短信验证码否过期
public function checkVerifyNotExpired($mobile, $verify_code, $type, $expire_time, $user_id = 0) {
    return $this->where(['mobile' => $mobile, 'type' => $type, 'verify_code' => $verify_code, 'user_id' => $user_id, 'create_time' => ['egt', $expire_time]])->find();
}

//超过60秒能发短信
public function canSendVerifyOverSeconds($mobile, $type, $user_id = 0, $seconds = 60) {
    $createtime_stamp = $this->where(['mobile' => $mobile, 'type' => $type, 'user_id' => $user_id])->order('create_time desc')->getField('create_time');
    return $createtime_stamp < (time() - $seconds);
}

 

 
 
 
 
 
 
 
 
 

你可能感兴趣的:(JS,组件)