commit | author | age
|
3e083b
|
1 |
<?php |
B |
2 |
|
|
3 |
define('IN_ECS', true); |
|
4 |
|
|
5 |
require(dirname(__FILE__) . '/includes/init.php'); |
|
6 |
include_once('includes/cls_json.php'); |
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
if (!isset($_REQUEST['step'])) |
|
11 |
{ |
|
12 |
$_REQUEST['step'] = ""; |
|
13 |
} |
|
14 |
|
|
15 |
$result = array('error' => 0, 'message' => ''); |
|
16 |
$json = new JSON; |
|
17 |
|
|
18 |
$mobile = trim($_POST['mobile']); |
|
19 |
|
|
20 |
$count = $db->getOne("SELECT COUNT(id) FROM " . $ecs->table('verifycode') ." WHERE getip='" . real_ip() . "' AND dateline>'" . gmtime() ."'-120"); |
|
21 |
|
|
22 |
if ($_REQUEST['step'] == 'getverifycode') |
|
23 |
{ |
|
24 |
require(dirname(__FILE__) . '/send.php'); |
|
25 |
|
|
26 |
/* 是否开启手机短信验证 */ |
|
27 |
if($_CFG['sms_register'] == '0') { |
|
28 |
$result['error'] = 1; |
|
29 |
$result['message'] = '客户注册发送手机验证码未开启'; |
|
30 |
die($json->encode($result)); |
|
31 |
} |
|
32 |
|
|
33 |
/* 提交的手机号是否已经注册帐号 */ |
|
34 |
$sql = "SELECT COUNT(user_id) FROM " . $ecs->table('users') ." WHERE mobile_phone = '$mobile'"; |
|
35 |
|
|
36 |
if ($db->getOne($sql) > 0) |
|
37 |
{ |
|
38 |
$result['error'] = 3; |
|
39 |
$result['message'] = '手机号已经被注册,请重新输入!'; |
|
40 |
die($json->encode($result)); |
|
41 |
} |
|
42 |
|
|
43 |
|
|
44 |
/* 获取验证码请求是否获取过 */ |
|
45 |
$sql = "SELECT COUNT(id) FROM " . $ecs->table('verifycode') ." WHERE status=1 AND getip='" . real_ip() . "' AND dateline>'" . gmtime() ."'-"."60"; |
|
46 |
|
|
47 |
if ($db->getOne($sql) > 0) |
|
48 |
{ |
|
49 |
$result['error'] = 4; |
|
50 |
$result['message'] = '每个ip每120秒只能获取一次验证码'; |
|
51 |
die($json->encode($result)); |
|
52 |
} |
|
53 |
$shuzi = "0123456789"; |
|
54 |
$verifycode = mc_random(6,$shuzi); |
|
55 |
|
|
56 |
$smarty->assign('user_mobile', $mobile); |
|
57 |
$smarty->assign('verify_code', $verifycode); |
|
58 |
|
|
59 |
$content = '您的验证码为'.$verifycode.''; |
|
60 |
/* 发送注册手机短信验证 */ |
|
61 |
$ret = sendSMS($mobile, $content); |
|
62 |
|
|
63 |
$db->query("delete from ".$ecs->table('verifycode')." where mobile='$mobile'"); |
|
64 |
|
|
65 |
//插入获取验证码数据记录 |
|
66 |
$sql = "INSERT INTO " . $ecs->table('verifycode') . "(mobile, getip, verifycode, dateline) VALUES ('" . $mobile . "', '" . real_ip() . "', '$verifycode', '" . gmtime() ."')"; |
|
67 |
$db->query($sql); |
|
68 |
|
|
69 |
$result['error'] = 0; |
|
70 |
$result['message'] = '发送手机验证码成功'; |
|
71 |
die($json->encode($result)); |
|
72 |
} |
|
73 |
|
|
74 |
if ($_REQUEST['step'] == 'getverifycode2') |
|
75 |
{ |
|
76 |
require(dirname(__FILE__) . '/send.php'); |
|
77 |
|
|
78 |
/* 是否开启手机短信验证 */ |
|
79 |
if($_CFG['sms_register'] == '0') { |
|
80 |
$result['error'] = 1; |
|
81 |
$result['message'] = '客户注册发送手机验证码未开启'; |
|
82 |
die($json->encode($result)); |
|
83 |
} |
|
84 |
|
|
85 |
/* 获取验证码请求是否获取过 */ |
|
86 |
$sql = "SELECT COUNT(id) FROM " . $ecs->table('verifycode') ." WHERE status=1 AND getip='" . real_ip() . "' AND dateline>'" . gmtime() ."'-"."60"; |
|
87 |
|
|
88 |
if ($db->getOne($sql) > 0) |
|
89 |
{ |
|
90 |
$result['error'] = 4; |
|
91 |
$result['message'] = '每个ip每120秒只能获取一次验证码'; |
|
92 |
die($json->encode($result)); |
|
93 |
} |
|
94 |
$shuzi = "0123456789"; |
|
95 |
$verifycode = mc_random(6,$shuzi); |
|
96 |
|
|
97 |
$smarty->assign('user_mobile', $mobile); |
|
98 |
$smarty->assign('verify_code', $verifycode); |
|
99 |
|
|
100 |
$content = '您的验证码为'.$verifycode.''; |
|
101 |
/* 发送注册手机短信验证 */ |
|
102 |
$ret = sendSMS($mobile, $content); |
|
103 |
|
|
104 |
$db->query("delete from ".$ecs->table('verifycode')." where mobile='$mobile'"); |
|
105 |
|
|
106 |
//插入获取验证码数据记录 |
|
107 |
$sql = "INSERT INTO " . $ecs->table('verifycode') . "(mobile, getip, verifycode, dateline) VALUES ('" . $mobile . "', '" . real_ip() . "', '$verifycode', '" . gmtime() ."')"; |
|
108 |
$db->query($sql); |
|
109 |
|
|
110 |
$result['error'] = 0; |
|
111 |
$result['message'] = '发送手机验证码成功'; |
|
112 |
die($json->encode($result)); |
|
113 |
} |
|
114 |
|
|
115 |
|
|
116 |
function mc_random($length,$char_str = 'abcdefghijklmnopqrstuvwxyz0123456789'){ |
|
117 |
$hash=''; |
|
118 |
$chars = $char_str; |
|
119 |
$max=strlen($chars); |
|
120 |
for($i=0;$i<$length;$i++){ |
|
121 |
$hash .=substr($chars,(rand(0,1000)%$max),1); |
|
122 |
} |
|
123 |
return $hash; |
|
124 |
} |
|
125 |
|
|
126 |
?> |