Lecms 是一款轻量级网站内容管理系统,简洁精干。程序框架采用懒加载、分布式服务器的设计,每张表都可有自己的DB服务器群和CACHE服务器(群),单表能承受亿级数据。内置多种SEO设置,对网站URL路径设置自由度极高,可自由灵活设置网站的URL,让你的网站在搜索引擎中获得好的收录排名。小编对他还是比较了解的,今天小编就以新增短信接口为例,给大家讲解一下如何进行二次开发,我们今天讲解的是v3.0.3版本,使用的短信接口是我们短信宝短信群发平台的短信接口,我们短信宝短信群发平台的接口非常稳定,发送速度快,注册就送测试短信,推荐大家使用
1:打开项目:admin\control\admin_control.class.php 新增短信设置路由
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
$menu[ 'menuInfo' ][ 'setting' ] = array( 'title' => lang( 'setting' ), 'icon' => 'fa fa-cogs' , 'href' => '' , 'target' => '_self' , 'child' =>array( array( 'title' => lang( 'basic_setting' ), 'href' => 'index.php?setting-index' , 'icon' => 'fa fa-cog' , 'target' => '_self' ), array( 'title' => lang( 'seo_setting' ), 'href' => 'index.php?setting-seo' , 'icon' => 'fa fa-life-ring' , 'target' => '_self' ), array( 'title' => lang( 'link_setting' ), 'href' => 'index.php?setting-link' , 'icon' => 'fa fa-link' , 'target' => '_self' ), array( 'title' => lang( 'user_setting' ), 'href' => 'index.php?setting-user' , 'icon' => 'fa fa-user-circle' , 'target' => '_self' ), array( 'title' => lang( 'attach_setting' ), 'href' => 'index.php?setting-attach' , 'icon' => 'fa fa-paperclip' , 'target' => '_self' ), array( 'title' => lang( 'image_setting' ), 'href' => 'index.php?setting-image' , 'icon' => 'fa fa-file-image-o' , 'target' => '_self' ), array( 'title' => lang( 'comment_setting' ), 'href' => 'index.php?setting-comment' , 'icon' => 'fa fa-comments-o' , 'target' => '_self' ), array( 'title' => lang( 'email_setting' ), 'href' => 'index.php?setting-email' , 'icon' => 'fa fa-envelope' , 'target' => '_self' ), array( 'title' => '短信设置' , 'href' => 'index.php?setting-sms' , 'icon' => 'fa fa-envelope' , 'target' => '_self' ), array( 'title' => lang( 'other_setting' ), 'href' => 'index.php?setting-other' , 'icon' => 'fa fa-info' , 'target' => '_self' ), ), ); |
2:打开项目:admin\view\default 新增setting_sms.htm短信配置文件
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
|
{inc:header.htm} <div class= "layui-card" > <div class= "layui-card-header" >短信设置</div> <div class= "layui-card-body" > <form id= "form" class= "layui-form" action= "index.php?setting-sms-ajax-1" method= "post" > <div class= "layui-form-item" > <label class= "layui-form-label required" >短信开关</label> <div class= "layui-input-block" > {$input[open_sms]} </div> </div> <div class= "layui-form-item" > <label class= "layui-form-label required" >短信宝账号</label> <div class= "layui-input-inline" > {$input[sms_user]} <a href= "http://console.smsbao.com/#/register" target= "_blank" style= "color: red" class= "mt-2 small" >还没有短信宝账号? 点击注册 </a> </div> </div> <div class= "layui-form-item" > <label class= "layui-form-label required" >短信宝密码</label> <div class= "layui-input-inline" > {$input[sms_pwd]} </div> </div> <div class= "layui-form-item" > <label class= "layui-form-label required" >短信宝签名</label> <div class= "layui-input-inline" > {$input[sms_sign]} </div> </div> <div class= "layui-form-item" > <label class= "layui-form-label" >短信模板</label> <div class= "layui-input-inline" > {$input[sms_template]} </div> </div> {hook:admin_setting_email_after.htm} <div class= "layui-form-item" > <div class= "layui-input-block" > <button class= "layui-btn" lay-submit lay-filter= "form" >{lang:submit}</button> </div> </div> </form> </div> </div> <script type= "text/javascript" > layui.use( 'form' , function (){ var form = layui.form; //监听提交 form.on( 'submit(form)' , function (){ adminAjax.submit( "#form" ); }); }); </script> </body> </html> |
3:打开项目:\admin\control\setting_control.class.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
|
//短信设置 public function sms(){ // hook admin_setting_control_email_before.php if (empty($_POST)) { version_compare(PHP_VERSION, '5.5.0' , '>' ) || $ this ->message(0, lang( 'php_version_5_5' ), '' , 1000); $cfg = $ this ->kv->xget( 'cfg' ); $input = array(); $arr = array(1=>lang( 'open' ), 0=>lang( 'close' )); $input[ 'open_sms' ] = form::get_radio_layui( 'open_sms' , $arr, $cfg[ 'open_sms' ]); $input[ 'sms_user' ] = form::get_text( 'sms_user' , $cfg[ 'sms_user' ], '' , 'lay-verify="required"' ); $input[ 'sms_pwd' ] = form::get_password( 'sms_pwd' , $cfg[ 'sms_pwd' ], '' , 'lay-verify="required"' ); $input[ 'sms_sign' ] = form::get_text( 'sms_sign' , $cfg[ 'sms_sign' ], '' , 'lay-verify="required"' ); $input[ 'sms_template' ] = form::get_text( 'sms_template' , $cfg[ 'sms_template' ]); // hook admin_setting_control_email_after.php $ this ->assign( 'input' , $input); $ this ->assign( 'cfg' , $cfg); $ this ->display(); } else { $ this ->kv->xset( 'open_sms' , (int) R( 'open_sms' , 'P' ), 'cfg' ); $ this ->kv->xset( 'sms_user' , R( 'sms_user' , 'P' ), 'cfg' ); $ this ->kv->xset( 'sms_pwd' , R( 'sms_pwd' , 'P' ), 'cfg' ); $ this ->kv->xset( 'sms_sign' , R( 'sms_sign' , 'P' ), 'cfg' ); $ this ->kv->xset( 'sms_template' , R( 'sms_template' , 'P' ), 'cfg' ); // hook admin_setting_control_email_post_after.php $ this ->kv->save_changed(); $ this ->runtime-> delete ( 'cfg' ); E(0, lang( 'edit_sucessfully' )); } } |
4:打开项目:\view\default\user\register.htm 注册页面添加手机验证
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
|
{ if :$cfg[open_user_register_vcode]} <div class= "form-group" > <label for = "vcode" class= "col-sm-4 control-label" >{lang:vcode}</label> <div class= "col-sm-4" > <input class= "form-control" id= "vcode" type= "text" name= "vcode" value= "" placeholder= "{lang:vcode}" autocomplete= "off" > </div> <div class= "col-sm-4" > <img src= "index.php?user-vcode-name-registervcode.html" alt= "{lang:vcode}" onclick= "this.src='index.php?user-vcode-name-registervcode-r-'+Math.random();" id= "vcodeimg" style= "width: 100%;" /> </div> </div> {/ if } { if :$cfg[open_sms]} <div class= "form-group" > <label for = "mobile" class= "col-sm-4 control-label" >手机号</label> <div class= "col-sm-8" > <input class= "form-control" id= "mobile" type= "text" name= "mobile" value= "" placeholder= "请输入手机号" autocomplete= "off" > </div> </div> <div class= "form-group" > <label for = "smscode" class= "col-sm-4 control-label" >短信验证码</label> <div class= "col-sm-4" > <input class= "form-control" id= "smscode" type= "text" name= "smscode" value= "" placeholder= "短信验证码" autocomplete= "off" > </div> <div class= "col-sm-4" > <input id= "sendmobilecode" class= "btn btn-primary btn-sm ml-3 " lay-submit lay-filter= "sendSms" type= "button" value= "获取验证码" > </div> </div> {/ if } <script type= "text/javascript" > layui.use([ 'form' ], function () { var form = layui.form, layer = layui.layer, $ = layui.$; form.on( 'submit(form)' , function (data) { data = data.field; if (data.username == '' ) { layer.msg( '{lang:please_input_username}' , {icon: 5}); return false ; } else if (data.password == '' ) { layer.msg( '{lang:please_input_password}' , {icon: 5}); return false ; } else if (data.repassword == '' ) { layer.msg( '{lang:please_input_confirm_password}' , {icon: 5}); return false ; } else if (data.mobile == '' ) { layer.msg( '请填写手机号' , {icon: 5}); return false ; } else if (data.smscode == '' ) { layer.msg( '请填写短信验证码' , {icon: 5}); return false ; } else if (data.password != data.repassword){ layer.msg( '{lang:pwd_inconsistent}' , {icon: 5}); return false ; } $.post( "index.php?user-register-ajax-1" ,data, function (res){ if (res.status){ var icon = 1; } else { var icon = 5; } layer.msg(res.message, {icon: icon}); if (res.status) setTimeout( function (){ location.href= "{$_http_referer}" ; }, 1000); return false ; }, 'json' ); return false ; }); $( '#sendmobilecode' ).on( 'click' , function (){ var mobile = $( '#mobile' ).val() var vcode = $( '#vcode' ).val() if (mobile == '' ){ layer.msg( '请填写手机号' ); return false ; } $.post( "index.php?user-sendsms-ajax-1" ,{mobile: mobile,vcode:vcode,type:1}, function (res){ if (res.status){ var icon = 1; } else { var icon = 5; } layer.msg(res.message, {icon: icon}); return false ; }, 'json' ); }); }); </script> |
5:打开项目:view\default\user 新增短信忘记密码页面
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
|
<!DOCTYPE html> <html> <head> <meta charset= "utf-8" > <title>{$cfg[titles]}</title> <meta name= "viewport" content= "width=device-width, initial-scale=1.0, user-scalable=no" > <meta name= "renderer" content= "webkit" > <link rel= "shortcut icon" type= "image/x-icon" href= "{$cfg[webdir]}favicon.ico" /> <link rel= "stylesheet" href= "{$cfg[tpl]}user/css/frontend.min.css" media= "all" > <link rel= "stylesheet" href= "{$cfg[tpl]}user/css/user.css" media= "all" > <!-- HTML5 shim, for IE6-8 support of HTML5 elements. All other JS at the end of file. --> <!--[ if lt IE 9]> <script src= "{$cfg[tpl]}user/js/html5shiv.js" ></script> <script src= "{$cfg[tpl]}user/js/respond.min.js" ></script> <![endif]--> <script src= "{$cfg[webdir]}static/js/jquery.js" charset= "utf-8" ></script> <!-- <script src= "https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/js/bootstrap.min.js" integrity= "sha384-aJ21OjlMXNL5UyIl/XNwTMqvzeRMZH2w8c5cRVpzpU8Y5bApTppSuUkhZXN0VxHd" crossorigin= "anonymous" ></script>--> </head> <body> <nav class= "navbar navbar-white navbar-fixed-top" role= "navigation" > <div class= "container" > <div class= "navbar-header" > <button type= "button" class= "navbar-toggle" data-toggle= "collapse" data-target= "#header-navbar" > <span class= "sr-only" >{lang:toggle}</span> <span class= "icon-bar" ></span> <span class= "icon-bar" ></span> <span class= "icon-bar" ></span> </button> <a class= "navbar-brand" href= "{$cfg[weburl]}" >{$cfg[webname]}</a> </div> <div class= "collapse navbar-collapse" id= "header-navbar" > <ul class= "nav navbar-nav navbar-right" > <li><a href= "{$cfg[weburl]}" title= "{$cfg[webname]}" >{lang:home}</a></li> </ul> </div> </div> </nav> <main class= "content" > <div id= "content-container" class= "container" > <div class= "user-section login-section" > <div class= "logon-tab clearfix" > <a class= "active" title= "{lang:forget_password}" rel= "nofollow" >{lang:forget_password}</a>{ if :$cfg[open_user_login]}<a href= "{$login_url}" title= "{lang:login}" rel= "nofollow" >{lang:login}</a>{/ if } </div> <div class= "login-main" > <form id= "login-form" class= "form-horizontal layui-form" action= "index.php?user-forget.html" method= "post" > <input type= "hidden" name= "FORM_HASH" value= "{$C[FORM_HASH]}" /> <div class= "form-group" > <label for = "username" class= "col-sm-4 control-label" >{lang:username}</label> <div class= "col-sm-8" > <input class= "form-control" id= "username" type= "text" name= "username" value= "" placeholder= "{lang:please_input_username}" autocomplete= "off" > </div> </div> <div class= "form-group" > <label for = "mobile" class= "col-sm-4 control-label" >手机号</label> <div class= "col-sm-8" > <input class= "form-control" id= "mobile" type= "text" name= "mobile" value= "" placeholder= "请输入手机号" autocomplete= "off" > </div> </div> <div class= "form-group" > <label for = "smscode" class= "col-sm-4 control-label" >短信验证码</label> <div class= "col-sm-4" > <input class= "form-control" id= "smscode" type= "text" name= "smscode" value= "" placeholder= "短信验证码" autocomplete= "off" > </div> <div class= "col-sm-4" > <input id= "sendmobilecode" class= "btn btn-primary btn-sm ml-3 " lay-submit lay-filter= "sendSms" type= "button" value= "获取验证码" > </div> </div> <div class= "form-group" > <label for = "vcode" class= "col-sm-4 control-label" >{lang:vcode}</label> <div class= "col-sm-4" > <input class= "form-control" id= "vcode" type= "text" name= "vcode" value= "" placeholder= "{lang:vcode}" autocomplete= "off" > </div> <div class= "col-sm-4" > <img src= "index.php?user-vcode-name-forgetvcode.html" alt= "{lang:vcode}" onclick= "this.src='index.php?user-vcode-name-forgetvcode-r-'+Math.random();" id= "vcodeimg" style= "width: 100%;" /> </div> </div> <div class= "form-group" > <label for = "password" class= "col-sm-4 control-label" >{lang:new_password}</label> <div class= "col-sm-8" > <input class= "form-control" id= "password" type= "text" name= "password" value= "" placeholder= "{lang:new_password}" autocomplete= "off" > </div> </div> <div class= "form-group" > <label for = "repassword" class= "col-sm-4 control-label" >{lang:confirm_new_password}</label> <div class= "col-sm-8" > <input class= "form-control" id= "repassword" type= "text" name= "repassword" value= "" placeholder= "{lang:confirm_new_password}" autocomplete= "off" > </div> </div> <div class= "form-group" > <label class= "col-sm-3 control-label" ></label> <div class= "col-sm-9" > <button type= "submit" class= "btn btn-primary btn-lg btn-block" lay-submit lay-filter= "form" >提交</button> </div> </div> {hook:user_user_forget_after.htm} </form> </div> </div> </div> </main> <footer class= "footer" style= "clear:both" > <p class= "copyright" >Copyright © {php}echo date( 'Y' );{/php} {$cfg[webname]} All Rights Reserved.</p> </footer> <script src= "{$cfg[webdir]}static/layui/lib/layui-v2.6.3/layui.js" charset= "utf-8" ></script> <script type= "text/javascript" > layui.use([ 'form' ], function () { var form = layui.form, layer = layui.layer, $ = layui.$; form.on( 'submit(form)' , function (data) { data = data.field; if (data.username == '' ) { layer.msg( '{lang:please_input_username}' , {icon: 5}); return false ; } else if (data.mobile == '' ) { layer.msg( '手机号为空' , {icon: 5}); return false ; } else if (data.vcode == '' ) { layer.msg( '{lang:vcode_no_empty}' , {icon: 5}); return false ; } else { $.post( "index.php?user-mobileforget-ajax-1" ,data, function (res){ if (res.status){ var icon = 1; } else { var icon = 5; } layer.msg(res.message, {icon: icon}); if (res.status) setTimeout( function (){ location.href= "{$_http_referer}" ; }, 1000); return false ; }, 'json' ); return false ; } }); $( '#sendmobilecode' ).on( 'click' , function (){ var mobile = $( '#mobile' ).val() var vcode = $( '#vcode' ).val() if (mobile == '' ){ layer.msg( '请填写手机号' ); return false ; } $.post( "index.php?user-sendsms-ajax-1" ,{mobile: mobile,vcode:vcode,type:2}, function (res){ if (res.status){ var icon = 1; } else { var icon = 5; } layer.msg(res.message, {icon: icon}); return false ; }, 'json' ); }); }); </script> </body> </html> |
6:打开项目:lecms\control\user_control.class.php 大概45行修改忘记密码跳转链接
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
|
function __construct() { parent::__construct(); $dis_action = array( 'login' , 'register' , 'forget' , 'resetpwd' ); //登录后禁止访问的action // hook user_control_construct_dis_action_after.php if ( !isset($ this ->_cfg[ 'open_user' ]) || empty($ this ->_cfg[ 'open_user' ]) ){ //未开启用户功能 $ this ->message(0, lang( 'open_user_0' ), $ this ->_cfg[ 'weburl' ]); }elseif ( $ this ->_uid && in_array($_GET[ 'action' ], $dis_action)){ $ this ->message(0, lang( 'logged' ), $ this ->cms_content->user_url( 'index' , 'my' )); } //来路 $ this ->_http_referer = user_http_referer(array(), $ this ->_cfg[ 'weburl' ]); $ this ->assign( '_http_referer' , $ this ->_http_referer); //忘记密码链接 if (isset($ this ->_cfg[ 'open_sms' ])){ $forget_pwd_url = $ this ->cms_content->user_url( 'mobileforget' , 'user' ); } else { $forget_pwd_url = $ this ->cms_content->user_url( 'forget' , 'user' ); } $ this ->assign( 'forget_pwd_url' , $forget_pwd_url); // hook user_control_construct_after.php } |
7:打开项目:lecms\control\user_control.class.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
|
public function register() { if ( !isset($ this ->_cfg[ 'open_user_register' ]) || empty($ this ->_cfg[ 'open_user_register' ]) ){ $ this ->message(0, lang( 'register_close' ), $ this ->_cfg[ 'weburl' ]); } if (empty($_POST)) { $ this ->_cfg[ 'titles' ] = lang( 'register' ). '_' .$ this ->_cfg[ 'webname' ]; $ this ->_var[ 'topcid' ] = -1; $ this ->assign( 'cfg' , $ this ->_cfg); $ this ->assign( 'cfg_var' , $ this ->_var); // hook user_control_register_after.php $GLOBALS[ 'run' ] = &$ this ; $_ENV[ '_theme' ] = &$ this ->_cfg[ 'theme' ]; $ this ->display( 'user/register.htm' ); }elseif(form_submit()) { // hook user_control_register_post_before.php $user = &$ this ->user; $username = R( 'username' , 'P' ); $password = R( 'password' , 'P' ); $repassword = R( 'repassword' , 'P' ); if ($message = $user->check_username($username)) { $ this ->message(0, $message); }elseif($message = $user->check_password($password)){ $ this ->message(0, $message); }elseif ($password != $repassword){ $ this ->message(0, lang( 'pwd_inconsistent' )); } //开启了注册验证码 if ( !empty($ this ->_cfg[ 'open_user_register_vcode' ]) ){ $vcode = R( 'vcode' , 'P' ); empty($vcode) && $ this ->message(0, lang( 'vcode_no_empty' )); if ($vcode != _SESSION( 'registervcode' )){ $ this ->message(0, lang( 'vcode_error' )); } } //开启了短信验证码 if (!empty($ this ->_cfg[ 'open_sms' ])){ $sess_mobile = _SESSION( 'user_create_mobile' ); $sess_code = _SESSION( 'user_create_code' ); $mobile = R( 'mobile' , 'P' ); $smscode = R( 'smscode' , 'P' ); if (!preg_match( '/^1[3-9]\d{9}$/' , $mobile)){ $ this ->message(0, '手机号有误' ); } if (empty($sess_code)) $ this ->message(0, '请点击获取验证码' ); if (empty($sess_mobile)) $ this ->message(0, '请点击获取验证码' ); if ($mobile != $sess_mobile) $ this ->message(0, lang( '验证码不正确' )); if ($smscode != $sess_code) $ this ->message(0, lang( '验证码不正确' )); } // hook user_control_register_post_check_after.php if ($user->get_user_by_username($username)){ $ this ->message(0, lang( 'username_is_exists' )); } $salt = random(16, 3, '0123456789abcdefghijklmnopqrstuvwxyz' ); // 增加破解难度 $password = md5(md5($password).$salt); $ip = ip2long($_ENV[ '_ip' ]); $data = array( 'username' =>$username, 'password' =>$password, 'salt' =>$salt, 'groupid' =>11, //注册用户 'author' =>$username, 'regip' =>$ip, 'regdate' =>$_ENV[ '_time' ], 'mobile' =>isset($mobile) ? $mobile : '' , ); // hook user_control_register_post_data_after.php $uid = $user->create($data); if ($uid){ // hook user_control_register_post_create_success_after.php // 写入 cookie $userauth = str_auth( "$uid\t$data[username]\t$data[password]\t$data[groupid]" , 'ENCODE' ); _setcookie( 'userauth' , $userauth, 0, '' , '' , false , true ); // 更新登录信息 $updata[ 'uid' ] = $uid; $updata[ 'loginip' ] = ip2long($ip); $updata[ 'logindate' ] = $_ENV[ '_time' ]; $updata[ 'logins' ] = 1; $user->update($updata); $ this ->message(1, lang( 'register_successfully' ), $ this ->_http_referer); } else { $ this ->message(0, lang( 'register_failed' )); } } else { $ this ->message(0, lang( 'form_invalid' )); } } |
8:当前项目下新增短信发送
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
|
public function sendsms(){ if (!$_POST){ $ this ->message(0, 'error' ); } if (isset($_SESSION[ 'countdown' ]) && time()<($_SESSION[ 'countdown' ]+60)) { $ this ->message(0, '请求频繁' ); } $mobile = R( 'mobile' , 'P' ); if (empty($ this ->_cfg[ 'open_sms' ])){ $ this ->message(0, '短信未开启' ); } if (!preg_match( '/^1[3-9]\d{9}$/' , $mobile)) { $ this ->message(0, '手机号错误' ); } //应该都请求 if ( !empty($ this ->_cfg[ 'open_user_register_vcode' ]) ){ $vcode = R( 'vcode' , 'P' ); empty($vcode) && $ this ->message(0, lang( 'vcode_no_empty' )); $key = (R( 'type' , 'P' )==1)? 'registervcode' : 'forgetvcode' ; if ($vcode != _SESSION($key)){ $ this ->message(0, lang( 'vcode_error' )); } } $code = rand(100000, 999999); $_SESSION[ 'user_create_mobile' ] = $mobile; $_SESSION[ 'user_create_code' ] = $code; $statusStr = array( "0" => "短信发送成功" , "-1" => "参数不全" , "-2" => "服务器空间不支持,请确认支持curl或者fsocket,联系您的空间商解决或者更换空间!" , "30" => "密码错误" , "40" => "账号不存在" , "41" => "余额不足" , "42" => "帐户已过期" , "43" => "IP地址限制" , "50" => "内容含有敏感词" ); $user = $ this ->_cfg[ 'sms_user' ]; //短信平台帐号 $pass = md5($ this ->_cfg[ 'sms_pwd' ]); //短信平台密码 $content= '【' .$ this ->_cfg[ 'sms_sign' ]. '】' .str_replace( '{$code}' ,$code,$ this ->_cfg[ 'sms_template' ]); //要发送的短信内容 $phone = $mobile; //要发送短信的手机号码 $sendurl = $smsapi. "sms?u=" .$user. "&p=" .$pass. "&m=" .$phone. "&c=" .urlencode($content); $result =file_get_contents($sendurl) ; if ( '0' === $result) { $_SESSION[ 'countdown' ] = time(); $ this ->message(1, '发送成功' ); } else { $ this ->message(0, '发送失败' .$statusStr[$result]); } } |
9:当前项目下新增手机号找回密码
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
|
//手机号找回密码 public function mobileforget(){ if ( !isset($ this ->_cfg[ 'open_user_reset_password' ]) || empty($ this ->_cfg[ 'open_user_reset_password' ])){ $ this ->message(0, lang( 'password_recovery_disabled' )); }elseif(empty($ this ->_cfg[ 'open_sms' ]) ){ $ this ->message(0, '短信未开启' ); } if (empty($_POST)) { $ this ->_cfg[ 'titles' ] = lang( 'forget_password' ). '_' .$ this ->_cfg[ 'webname' ]; $ this ->_var[ 'topcid' ] = -1; $ this ->assign( 'cfg' , $ this ->_cfg); $ this ->assign( 'cfg_var' , $ this ->_var); // hook user_control_forget_after.php $GLOBALS[ 'run' ] = &$ this ; $_ENV[ '_theme' ] = &$ this ->_cfg[ 'theme' ]; $ this ->display( 'user/mobile_forget_password.htm' ); } else { $username = R( 'username' , 'P' ); $mobile = R( 'mobile' , 'P' ); $vcode = R( 'vcode' , 'P' ); // hook user_control_forget_post_data_after.php if (empty($username) || empty($mobile) || empty($vcode)){ $ this ->message(0, '用户名和验证码和手机号都不能为空' ); } if (!preg_match( '/^1[3-9]\d{9}$/' , $mobile)) { $ this ->message(0, '手机号错误' ); } if ($vcode != _SESSION( 'forgetvcode' )){ $ this ->message(0, lang( 'vcode_error' )); } $data = $ this ->user->get_user_by_username($username); if ( empty($data) ){ $ this ->message(0, lang( 'no_this_user' )); } else { if ( $data[ 'mobile' ] != $mobile){ $ this ->message(0, lang( '该用户没有绑定手机号或者手机号错误' )); } $sess_mobile = _SESSION( 'user_create_mobile' ); $sess_code = _SESSION( 'user_create_code' ); $mobile = R( 'mobile' , 'P' ); $smscode = R( 'smscode' , 'P' ); $password = R( 'password' , 'P' ); $repassword = R( 'repassword' , 'P' ); if (empty($sess_code)) $ this ->message(0, '请点击获取验证码' ); if (empty($sess_mobile)) $ this ->message(0, '请点击获取验证码' ); if ($mobile != $sess_mobile) $ this ->message(0, lang( '验证码不正确' )); if ($smscode != $sess_code) $ this ->message(0, lang( '验证码不正确' )); $user = &$ this ->user; if ($message = $user->check_username($username)) { $ this ->message(0, $message); }elseif($message = $user->check_password($password)){ $ this ->message(0, $message); }elseif ($password != $repassword){ $ this ->message(0, lang( 'pwd_inconsistent' )); } $salt = random(16, 3, '0123456789abcdefghijklmnopqrstuvwxyz' ); // 增加破解难度 $password = md5(md5($password).$salt); $updata = array( 'uid' =>$data[ 'uid' ], 'password' =>$password, 'salt' =>$salt ); if ( $user->update($updata) ){ $ this ->message(1, lang( 'reset_password_successfully' )); } else { $ this ->message(0, lang( 'reset_password_failed' )); } } } } |
经过上面的替换,短信宝的短信平台已经替换成功了,可以正常使用了。进行测试发送:
报备一下短信宝的VIP模板,这样就可以走短信宝的优质通道了,即便遇到敏感文字我们都不会人工审核,短信内容3~5秒就可送达。
另外:我们已经开发好完整的LeCMS_V3.0.3系统短信宝插件,点击此链接 下载及查看安装流
最新更新
电商类
CMS类
微信类