-
Notifications
You must be signed in to change notification settings - Fork 5
/
sms.php
179 lines (144 loc) · 5.25 KB
/
sms.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<?php
define('IN_ECS', true);
require(dirname(__FILE__) . '/includes/init.php');
include_once('includes/cls_json.php');
require(ROOT_PATH . 'includes/lib_sms.php');
require_once(ROOT_PATH . 'languages/' .$_CFG['lang']. '/sms.php');
if (!isset($_REQUEST['step']))
{
$_REQUEST['step'] = "";
}
$result = array('error' => 0, 'message' => '');
$json = new JSON;
$mobile = trim($_POST['mobile']);
$count = $db->getOne("SELECT COUNT(id) FROM " . $ecs->table('verify_code') ." WHERE getip='" . real_ip() . "' AND dateline>'" . gmtime() ."'-86400");
if ($count >= $_CFG['ihuyi_sms_ip_num'])
{
$result['error'] = 6;
$result['message'] = sprintf($_LANG['get_ip_excessived'], $_CFG['ihuyi_sms_ip_num']);
die($json->encode($result));
}
if ($_REQUEST['step'] == 'getverifycode1')
{
/* 是否开启手机短信验证注册 */
if($_CFG['ihuyi_sms_mobile_reg'] == '0') {
$result['error'] = 1;
$result['message'] = $_LANG['ihuyi_sms_mobile_reg_closed'];
die($json->encode($result));
}
/* 防止短信轰炸机 */
if ($_SESSION['sms_code']!=trim($_POST['smscode']))
{
$result['error'] = 2;
$result['message'] = $_LANG['invalid_sms_code'];
die($json->encode($result));
}
/* 提交的手机号是否正确 */
if (!ismobile($mobile))
{
$result['error'] = 2;
$result['message'] = $_LANG['invalid_mobile_phone'];
die($json->encode($result));
}
/* 提交的手机号是否已经注册帐号 */
$sql = "SELECT COUNT(user_id) FROM " . $ecs->table('users') ." WHERE mobile_phone = '$mobile'";
if ($db->getOne($sql) > 0)
{
$result['error'] = 3;
$result['message'] = $_LANG['mobile_phone_registered'];
die($json->encode($result));
}
/* 获取验证码请求是否获取过 */
$sql = "SELECT COUNT(id) FROM " . $ecs->table('verify_code') ." WHERE status=1 AND getip='" . real_ip() . "' AND dateline>'" . gmtime() ."'-".$_CFG['ihuyi_sms_smsgap'];
if ($db->getOne($sql) > 0)
{
$result['error'] = 4;
$result['message'] = sprintf($_LANG['get_verifycode_excessived'], $_CFG['ihuyi_sms_smsgap']);
die($json->encode($result));
}
$verifycode = getverifycode();
$smarty->assign('shop_name', $_CFG['shop_name']);
$smarty->assign('user_mobile', $mobile);
$smarty->assign('verify_code', $verifycode);
$content = $smarty->fetch('str:' . $_CFG['ihuyi_sms_mobile_reg_value']);
/* 发送注册手机短信验证 */
$ret = sendsms($mobile, $content);
if($ret === true)
{
//插入获取验证码数据记录
$sql = "INSERT INTO " . $ecs->table('verify_code') . "(mobile, getip, verifycode, dateline) VALUES ('" . $mobile . "', '" . real_ip() . "', '$verifycode', '" . gmtime() ."')";
$db->query($sql);
$result['error'] = 0;
$result['message'] = $_LANG['send_mobile_verifycode_successed'];
die($json->encode($result));
}
else
{
$result['error'] = 5;
$result['message'] = $_LANG['send_mobile_verifycode_failured'] . $ret;
die($json->encode($result));
}
}
elseif ($_REQUEST['step'] == 'getverifycode2')
{
/* 是否开启手机绑定 */
if($_CFG['ihuyi_sms_mobile_bind'] == '0') {
$result['error'] = 1;
$result['message'] = $_LANG['ihuyi_sms_mobile_bind_closed'];
die($json->encode($result));
}
/* 防止短信轰炸机 */
if ($_SESSION['sms_code']!=trim($_POST['smscode']))
{
$result['error'] = 2;
$result['message'] = $_LANG['invalid_sms_code'].$_SESSION['sms_code']."sdafads".trim($_POST['smscode']);
$result['message'] = $_LANG['invalid_sms_code'];
die($json->encode($result));
}
/* 提交的手机号是否正确 */
if (!ismobile($mobile))
{
$result['error'] = 2;
$result['message'] = $_LANG['invalid_mobile_phone'];
die($json->encode($result));
}
/* 提交的手机号是否已经绑定帐号 */
$sql = "SELECT COUNT(user_id) FROM " . $ecs->table('users') ." WHERE mobile_phone = '$mobile'";
if ($db->getOne($sql) > 0)
{
$result['error'] = 3;
$result['message'] = $_LANG['mobile_phone_binded'];
die($json->encode($result));
}
/* 获取验证码请求是否获取过 */
$sql = "SELECT COUNT(id) FROM " . $ecs->table('verify_code') ." WHERE (status=4 or status=5) AND getip='" . real_ip() . "' AND dateline>'" . gmtime() ."'-".$_CFG['ihuyi_sms_smsgap'];
if ($db->getOne($sql) > 0)
{
$result['error'] = 4;
$result['message'] = sprintf($_LANG['get_verifycode_excessived'], $_CFG['ihuyi_sms_smsgap']);
die($json->encode($result));
}
$verifycode = getverifycode();
$smarty->assign('shop_name', $_CFG['shop_name']);
$smarty->assign('user_mobile', $mobile);
$smarty->assign('verify_code', $verifycode);
$content = $smarty->fetch('str:' . $_CFG['ihuyi_sms_mobile_bind_value']);
/* 发送注册手机短信验证 */
$ret = sendsms($mobile, $content);
if($ret === true)
{
//插入获取验证码数据记录
$sql = "INSERT INTO " . $ecs->table('verify_code') . "(mobile, getip, verifycode, dateline, status) VALUES ('" . $mobile . "', '" . real_ip() . "', '$verifycode', '" . gmtime() ."', 4)";
$db->query($sql);
$result['error'] = 0;
$result['message'] = $_LANG['bind_mobile_verifycode_successed'];
die($json->encode($result));
}
else
{
$result['error'] = 5;
$result['message'] = $_LANG['bind_mobile_verifycode_failured'] . $ret;
die($json->encode($result));
}
}
?>