Exemplo n.º 1
0
  /**
   *  注册短信
   */
  public function reg_sms(){
	$tel = $_POST['mobile'];
	$type = $_POST['type'] ? $_POST['type'] : 'reg';
	if(!validateMobile($tel)){
		$msg['notice'] = '手机号码不对!';
		ajaxErrReturn($msg);	  
	}
	$code = str_pad(rand(0,9999),4,0,STR_PAD_LEFT);
	$content = '验证码:'.$code.',请勿将验证码泄漏给其他人';
	$model = M('Member_verify');
	$data['mobile'] = $tel;
	$data['type'] = $type;
	$v_vo = $model->where($data)->find();
	if($v_vo['status']==1){
		$msg['notice'] = '短信已验证';
		ajaxErrReturn($msg);	  
	}
	if($v_vo){
		if(time()-$v_vo['update']<60){
			$msg['notice'] = '请稍后再发';
			ajaxSucReturn($msg);  
		}else{
		  if($v_vo['m']==date('m') && $v_vo['d']==date('d')){
		    if($v_vo['sent_num']>4){
			  $msg['notice'] = '每天最多发送5次,请明天再来';
			  ajaxErrReturn($msg);			  
			}
			$sdata['sent_num'] = $v_vo['sent_num']+1; //今天+1
		  }else{
		    $sdata['sent_num'] = 1; //其他重新统计
		  }
		  $sdata['y'] = date('Y');
		  $sdata['m'] = date('m');
		  $sdata['d'] = date('d');
		  $sdata['code'] = $code;
		  $sdata['tel'] = $tel;
		  $sdata['msg'] = $content;
		  $sdata['status'] = 0;
		  $sdata['update_time'] = time();
		  $model->where($data)->save($sdata);
		  //echo $model->getlastsql();exit;
		}	
	}else{
	  $sdata['member_id'] = $this->user['id'] ? $this->user['id'] : 0;
	  $sdata['code'] = $code;
	  $sdata['type'] = $type;
	  $sdata['mobile'] = $tel;
	  $sdata['y'] = date('Y');
	  $sdata['m'] = date('m');
	  $sdata['d'] = date('d');
	  $sdata['sent_num'] = 1;
	  $sdata['msg'] = $content;
	  $sdata['status'] = 0;
	  $sdata['ip'] = _get_ip();
	  $sdata['update_time'] = time();
	  $v_vo['id'] = $model->add($sdata);
	}
	$result = sent_msm($tel,$content);
	$result = true;
	if($result){
	  $msg['notice'] = '发送成功';
	  ajaxSucReturn($msg);
	}else{
	  $msg['notice'] = '发送失败';
	  ajaxErrReturn($msg);
	}
  }
Exemplo n.º 2
0
 public function reg_sms()
 {
     $tel = $_POST['tel'];
     if (!validateMobile($tel)) {
         $msg['error_code'] = 8002;
         $msg['notice'] = '手机号码不对!';
         echo json_encode($msg);
         exit;
     }
     $code = str_pad(rand(0, 9999), 4, 0, STR_PAD_LEFT);
     $content = '验证码:' . $code . ',请勿将验证码泄漏给其他人【夜猫圈】';
     $model = M('member_verify');
     $data['tel'] = $tel;
     $v_vo = $model->where($data)->find();
     if ($v_vo['status'] == 1) {
         $msg['error_code'] = 8002;
         $msg['notice'] = '用户已验证';
         echo json_encode($msg);
         exit;
     }
     if ($v_vo) {
         if (time() - $v_vo['update'] < 60) {
             $msg['error_code'] = 8002;
             $msg['notice'] = '请稍后再发';
             echo json_encode($msg);
             exit;
         } else {
             if ($v_vo['m'] == date('m') && $v_vo['d'] == date('d')) {
                 if ($v_vo['sent_num'] > 4) {
                     $msg['error_code'] = 80002;
                     $msg['notice'] = '每天最多发送5次,请明天再来';
                     echo json_encode($msg);
                     exit;
                 }
                 $sdata['sent_num'] = $v_vo['sent_num'] + 1;
                 //今天+1
             } else {
                 $sdata['sent_num'] = 1;
                 //其他重新统计
             }
             $sdata['y'] = date('Y');
             $sdata['m'] = date('m');
             $sdata['d'] = date('d');
             $sdata['code'] = $code;
             $sdata['tel'] = $tel;
             $sdata['msg'] = $content;
             $sdata['status'] = 0;
             $sdata['update_time'] = time();
             $model->where($data)->save($sdata);
             //echo $model->getlastsql();exit;
         }
     } else {
         $sdata['member_id'] = 0;
         $sdata['code'] = $code;
         $sdata['tel'] = $tel;
         $sdata['y'] = date('Y');
         $sdata['m'] = date('m');
         $sdata['d'] = date('d');
         $sdata['sent_num'] = 1;
         $sdata['msg'] = $content;
         $sdata['ip'] = _get_ip();
         $sdata['status'] = 0;
         $sdata['update_time'] = time();
         $v_vo['id'] = $model->add($sdata);
     }
     $result = sent_msm($tel, $content);
     if ($result) {
         $msg['error_code'] = 0;
         $msg['notice'] = '发送成功';
         $msg['id'] = $code;
         echo json_encode($msg);
         exit;
     } else {
         $msg['error_code'] = 2001;
         $msg['notice'] = '发送失败';
         echo json_encode($msg);
         exit;
     }
 }