public function index() { /* //创建验证码表 ,如果表存在则不创建 $table=$GLOBALS['db_config']['DB_PREFIX']."sms_mobile_verify"; $create_table="CREATE TABLE IF NOT EXISTS `".$table."` ( `id` int(11) NOT NULL auto_increment, `mobile_phone` varchar(50) NOT NULL default '', `code` varchar(20) NOT NULL default '', `status` tinyint(1) NOT NULL default '0', `add_time` int(10) default NULL, `send_count` int(11) NOT NULL default '0', `type` tinyint(1) NOT NULL default '0', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8"; $GLOBALS['db']->query($create_table,'SILENT'); //end */ $mobile_phone = trim($GLOBALS['request']['mobile']); $is_login = intval($GLOBALS['request']['is_login']); //is_login 0:仅注册,会判断手机号码,是否存在; 1:可登陆,可注册 不判断手机号码是否存在; $root = array(); //$root['return'] = 1; /* $isMobile = preg_match("/^(13\d{9}|14\d{9}|18\d{9}|15\d{9})|(0\d{9}|9\d{8})$/",$mobile_phone); if(!$isMobile) { $root['info']="请输入正确的手机号码"; $root['status']=0; output($root); } */ if (app_conf("SMS_ON") == 0) { $root['status'] = 0; $root['info'] = '短信功能关闭'; //$GLOBALS['lang']['SMS_OFF']; output($root); } if ($mobile_phone == '') { $root['status'] = 0; $root['info'] = '手机号码不能为空'; output($root); } if (!check_mobile($mobile_phone)) { $root['status'] = 0; $root['info'] = "请输入正确的手机号码"; output($root); } if (!check_ipop_limit(CLIENT_IP, "register_verify_phone", 60, 0)) { $root['status'] = 0; $root['info'] = '发送太快了'; output($root); } $have_user_id = $GLOBALS['db']->getOne("select id from " . DB_PREFIX . "user where mobile = '{$mobile_phone}'"); //is_login 0:仅注册,会判断手机号码,是否存在; 1:可登陆,可注册 不判断手机号码是否存在; if ($is_login == 0 && $have_user_id) { //已经验证的 $root['info'] = '该手机号码已经注册过!'; $root['status'] = 0; output($root); } //删除超过5分钟的验证码 $sql = "DELETE FROM " . DB_PREFIX . "sms_mobile_verify WHERE mobile_phone = '{$mobile_phone}' and add_time <=" . (get_gmtime() - 300); //$root['sql']=$sql; $GLOBALS['db']->query($sql); $smsSubscribe = $GLOBALS['db']->getRow("select `id`,`mobile_phone`,`code`,`send_count`,`add_time` from " . DB_PREFIX . "sms_mobile_verify where mobile_phone = '{$mobile_phone}' and type=0 order by id desc"); $new_time = get_gmtime(); $difftime = $new_time - $smsSubscribe['add_time']; if ($smsSubscribe && intval($smsSubscribe['send_count']) <= 1 && $difftime < 61) { $root['info'] = "验证码已发出,请注意查收"; $root['status'] = 1; output($root); } else { if (empty($smsSubscribe) || empty($smsSubscribe['code'])) { //$tempcode = unpack('H4',str_shuffle(md5(uniqid()))); $code = rand(1111, 9999); //$tempcode[1]; } else { //发送一样的,验证码; $code = $smsSubscribe['code']; } require_once APP_ROOT_PATH . "system/ali_sms/sms.php"; $result = sendSMSAli($mobile_phone, $code); if (!empty($result)) { $add_time = get_gmtime(); $re = $GLOBALS['db']->query("insert into " . DB_PREFIX . "sms_mobile_verify(mobile_phone,code,add_time,send_count,ip) values('{$mobile_phone}','{$code}','{$add_time}',1," . "'" . CLIENT_IP . "')"); /*插入一条发送成功记录到队列表中*/ $msg_data['dest'] = $mobile_phone; $msg_data['send_type'] = 0; $msg_data['content'] = addslashes($message); $msg_data['send_time'] = $add_time; $msg_data['is_send'] = 1; $msg_data['is_success'] = 1; $msg_data['create_time'] = $add_time; $msg_data['user_id'] = intval($have_user_id); $msg_data['title'] = "手机号绑定验证"; $GLOBALS['db']->autoExecute(DB_PREFIX . "deal_msg_list", $msg_data); $root['info'] = "验证码发出,请注意查收"; $root['status'] = 1; } else { $root['info'] = "发送失败" . $send['msg']; $root['status'] = 0; } // $message=$code."(".app_conf("SHOP_TITLE")."手机绑定验证码,请完成验证),如非本人操作,请勿略本短信"; // require_once APP_ROOT_PATH."system/utils/es_sms.php"; // $sms = new sms_sender(); // $send=$sms->sendSms($mobile_phone,$message); // //$send['status']=1; // if($send['status']) // { // $add_time = get_gmtime(); // $re=$GLOBALS['db']->query("insert into ".DB_PREFIX."sms_mobile_verify(mobile_phone,code,add_time,send_count,ip) values('$mobile_phone','$code','$add_time',1,"."'".CLIENT_IP."')"); // /*插入一条发送成功记录到队列表中*/ // $msg_data['dest'] = $mobile_phone; // $msg_data['send_type'] = 0; // $msg_data['content'] = addslashes($message);; // $msg_data['send_time'] = $add_time; // $msg_data['is_send'] = 1; // $msg_data['is_success'] = 1; // $msg_data['create_time'] = $add_time; // $msg_data['user_id'] = intval($have_user_id); // $msg_data['title'] = "手机号绑定验证"; // $GLOBALS['db']->autoExecute(DB_PREFIX."deal_msg_list",$msg_data); // $root['info']="验证码发出,请注意查收"; // $root['status']=1; // } // else // { // $root['info']="发送失败".$send['msg']; // $root['status']=0; // } } output($root); }
public function ajax_send_sms_code() { //已经登录则跳转到mypage if (!empty($this->user)) { app_redirect(url("index", "jsd_user#my_page")); } //检查发送类型 if (empty($_POST)) { $data['status'] = FALSE; $data['info'] = "请求失败"; ajax_return($data); } //验证手机号码格式 $mobile = isset($_POST['mobile']) ? $_POST['mobile'] : NULL; $is_mobile = preg_match('/1[34578]{1}\\d{9}$/', $mobile); if (empty($is_mobile)) { $data['status'] = FALSE; $data['info'] = "手机号不正确"; ajax_return($data); } //查询手机是否被注册 $user = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "user where mobile = '" . $mobile . "' and is_delete = 0"); if (!empty($user)) { $data['status'] = FALSE; $data['info'] = "手机号已经被注册"; ajax_return($data); } // 生成6位短信验证码并发送到手机 $sms_code = rand(100000, 999999); vendor('AliSms.sms'); $resp = sendSMSAli($mobile, $sms_code); if (!empty($resp)) { es_session::set('sms_code', $sms_code); $data['status'] = TRUE; $data['info'] = "发送成功"; ajax_return($data); } $data['status'] = FALSE; $data['info'] = "发送短信失败,稍后请重试"; ajax_return($data); }
public function register_tel() { $user = $this->is_authed(); if (!empty($user)) { redirect('/panchun'); } $user = M('User'); if (I('post.')) { $inputed_code = I('post.verify_code'); $insert_id = 0; if (session('verify_code') == $inputed_code) { $insert_data['tel'] = I('post.tel'); $insert_data['created_at'] = date('Y-m-d H:i:s'); $insert_data['updated_at'] = date('Y-m-d H:i:s'); if ($invite_code = I('post.invite_code')) { $user->startTrans(); $insert_id = $user->add($insert_data); //将share表的count+1 $share_model = M('Share'); $share_condition['invite_code'] = $invite_code; $res = $share_model->where($share_condition)->setInc('count', 1); //获取user_id $share_data = $share_model->where($share_condition)->select(); $count = intval($share_data[0]['count']); $extra_status = TRUE; //此处便于发放奖励失败进行回滚 //如果达到发放奖励的条件 if ($count != 0 && $count % 20 == 0) { //获取price_id $price_model = M('price'); $price = $price_model->where(array('status' => 1))->limit(1)->select(); if (!empty($price)) { //发放奖励 $price_user_data = array('price_id' => $price[0]['price_id'], 'user_id' => $share_data[0]['user_id'], 'created_at' => date('Y-m-d H:i:s'), 'updated_at' => date('Y-m-d H:i:s')); $price_user = M('Price_user'); $price_user_id = $price_user->add($price_user_data); //更新奖品状态,将其标记为已使用 $price_update_res = $price_model->data(array('status' => 1))->where($price[0]['price_id'])->save(); if (empty($price_user_id) || empty($price_update_res)) { $extra_status = FALSE; } } } if (!empty($insert_id) && !empty($res) && !empty($extra_status)) { $user->commit(); //提交事务 } else { $user->rollback(); } } else { $insert_id = $user->add($insert_data); } $this->redirect('register_info', array('user_id' => $insert_id)); } } elseif ($tel = I('get.tel')) { //检查手机号是否注册 $condition['tel'] = $tel; $count = $user->where($condition)->count('user_id'); if (!empty($count)) { $errors['error_mess'] = '手机号已注册,请勿重复注册'; $this->json_error_response($errors); exit; } // 生成6位短信验证码并发送到手机 $verify_code = rand(100000, 999999); vendor('AliSms.sms'); $result = sendSMSAli($tel, $verify_code); $data['res'] = 0; if (!empty($result)) { $data['res'] = 1; session('verify_code', $verify_code); } $this->json_success_response($data); exit; } $invite_code = I('get.in_code') ? I('get.in_code') : NULL; $this->assign('invite_code', $invite_code); $this->display('register_tel'); }
<meta charset="utf-8"> <form action="" method="post"> <input type="text" id="phone" style="padding:5px;font-size:16px" value="13131931531" name='phone'><br> <input type="submit" value="立即发送" id="submit" name='submit'> </form> <?php if (isset($_POST['submit'])) { $mobile = $_POST['phone']; // 生成6位短信验证码 $mobile_code = rand(100000, 999999); include "sms.php"; /* 发送激活验证邮件 */ echo "手机号:" . $mobile . '<br>'; echo "验证码:" . $mobile_code . '<br>'; $result = sendSMSAli($mobile, $mobile_code); //接收返回结果并提示 if ($result) { echo '恭喜!短信发送成功'; } else { echo '对不起,短信验证码发送失败'; } }