YzmCMS是一款轻量级开源内容管理系统,它采用OOP(面向对象)方式自主开发的框架。基于PHP+Mysql架构,并采用MVC框架式开发的一款高效开源的内容管理系统,便于进行二次开发,小编对这款软件还是比较了解的,小编今天就给大家讲解一下YzmCMS_v5.1版本的短信宝接口替换流程,我们使用的短信接口是我们短信宝短信群发平台的短信接口,我们短信宝短信群发平台非常稳定,发送速度快,注册就送测试短信,推荐大家使用。
首先我们打开项目:application\admin\view\system_set.html文件,替换227~307行代码:
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
|
< div class = "tabCon" > < div class = "row cl" > <label class = "form-label col-xs-4 col-sm-2" >短信宝用户名:</label> < div class = "formControls col-xs-8 col-sm-9" > <input type= "text" name= "smsbao_user" value= "<?php echo $data[" smsbao_user "];?>" class = "input-text" style= "width:50%" > </ div > </ div > < div class = "row cl" > <label class = "form-label col-xs-4 col-sm-2" >短信宝密码:</label> < div class = "formControls col-xs-8 col-sm-9" > <input type= "text" name= "smsbao_pass" value= "<?php echo $data[" smsbao_pass "];?>" class = "input-text" style= "width:50%" > </ div > </ div > < div class = "row cl" > <label class = "form-label col-xs-4 col-sm-2" >短信签名:</label> < div class = "formControls col-xs-8 col-sm-9" > <input type= "text" name= "smsbao_sign" value= "<?php echo $data[" smsbao_sign "];?>" class = "input-text" style= "width:50%" > </ div > </ div > </ div > </ div > < div class = "row cl" > < div class = "col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-2" > <input type= "submit" class = "btn btn-primary radius" name= "dosubmit" value= " 保存 " > <input type= "reset" class = "btn btn-default radius" value= " 取消 " > </ div > </ div > </form> </ div > <?php include $ this ->admin_tpl( 'footer' );?> <script type= "text/javascript" > function check_all(){ var reg = /^http(.+)\/$/; if ($( "input[name='site_name']" ).val()== '' ){ layer.alert( '站点名称不能为空!' ); return false ; } if (!reg.test($( "input[name='site_url']" ).val())){ return false ; } if ($( "input[name='pic_wid']" ).val()== '' || isNaN($( "input[name='pic_wid']" ).val())){ layer.alert( '缩略图宽度只能为数字!' ); return false ; } if ($( "input[name='pic_hei']" ).val()== '' || isNaN($( "input[name='pic_hei']" ).val())){ layer.alert( '缩略图高度只能为数字!' ); return false ; } if ($( "input[name='upload_maxsize']" ).val()== '' || isNaN($( "input[name='upload_maxsize']" ).val())){ layer.alert( '允许上传附件大小只能为数字!' ); return false ; } if ($( "input[name='watermark_name']" ).val()== '' ){ layer.alert( '水印图片名称不能为空!' ); return false ; } return true ; } function test_mail() { var mail_to = $( "input[name='mail_to']" ).val(); if (mail_to == '' ){ layer.alert( '请输入邮件测试地址!' ); return false ; } $.ajax({ type: 'POST' , url: '<?php echo U(' public_test_mail ');?>' , data: "mail_to=" +mail_to, success: function (msg) { layer.alert(msg); } }) } $(function(){ $.Huitab( "#tab_system .tabBar span" , "#tab_system .tabCon" , "current" , "click" , "<?php echo isset($_GET['tab']) ? intval($_GET['tab']) : '0'?>" ); }); </script> |
接着我们打开项目:application\member\view\member_set.html文件,替换为以下代码:
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
|
<? php include $this->admin_tpl('meta', 'admin');?> < title >会员中心设置 - YzmCMS内容管理系统</ title > </ head > < body > < nav class = "breadcrumb" >< i class = "Hui-iconfont" ></ i > 首页 < span class = "c-gray en" >></ span > 会员管理 < span class = "c-gray en" >></ span > 会员中心设置 < a class = "btn btn-success radius r" style = "line-height:1.6em;margin-top:3px" href = "javascript:location.replace(location.href);" title = "刷新" >< i class = "Hui-iconfont" ></ i ></ a ></ nav > < div class = "page-container" > < form class = "form form-horizontal" method = "post" action="<?php echo U('admin/system_manage/save');?>" onsubmit="return check_all()"> < div id = "tab_system" class = "HuiTab" > < div class = "tabBar cl" >< span >基本设置</ span >< span >其他设置</ span ></ div > < div class = "tabCon" > < div class = "row cl" > < label class = "form-label col-xs-4 col-sm-2" >是否开启会员注册:</ label > < div class = "formControls col-xs-8 col-sm-9" > < label class = "label_radio" >< input name = "member_register" type = "radio" <?php echo $data["member_register"]? 'checked' : '' ?> value="1"> 开启</ label > < label class = "label_radio" >< input name = "member_register" type = "radio" <?php echo $data["member_register"]? '' : 'checked' ?> value="0"> 关闭</ label > </ div > </ div > < div class = "row cl" > < label class = "form-label col-xs-4 col-sm-2" >新会员注册邮件验证:</ label > < div class = "formControls col-xs-8 col-sm-9" > < label class = "label_radio" >< input name = "member_email" type = "radio" <?php echo $data["member_email"]? 'checked' : '' ?> value="1"> 开启</ label > < label class = "label_radio" >< input name = "member_email" type = "radio" <?php echo $data["member_email"]? '' : 'checked' ?> value="0"> 关闭</ label > < span style = "color:#888" > [需填写邮箱配置,且开启后会员注册审核功能无效]</ span > </ div > / div > < div class = "row cl" > < label class = "form-label col-xs-4 col-sm-2" >新会员注册短信验证:</ label > < div class = "formControls col-xs-8 col-sm-9" > < label class = "label_radio" >< input name = "member_mobile" type = "radio" <?php echo $data["member_mobile"]? 'checked' : '' ?> value="1"> 开启</ label > < label class = "label_radio" >< input name = "member_mobile" type = "radio" <?php echo $data["member_mobile"]? '' : 'checked' ?> value="0"> 关闭</ label > < span style = "color:#888" > [需填写短信配置,且开启后会员注册审核功能无效]</ span > </ div > </ div > < div class = "row cl" > < label class = "form-label col-xs-4 col-sm-2" >会员注册需要管理员审核:</ label > < div class = "formControls col-xs-8 col-sm-9" > < label class = "label_radio" >< input name = "member_check" type = "radio" <?php echo $data["member_check"]? 'checked' : '' ?> value="1"> 开启</ label > < label class = "label_radio" >< input name = "member_check" type = "radio" <?php echo $data["member_check"]? '' : 'checked' ?> value="0"> 关闭</ label > </ div > </ div > < div class = "row cl" > < label class = "form-label col-xs-4 col-sm-2" >是否开启会员登录验证码:</ label > < div class = "formControls col-xs-8 col-sm-9" > < label class = "label_radio" >< input name = "member_yzm" type = "radio" <?php echo $data["member_yzm"]? 'checked' : '' ?> value="1"> 开启</ label > < label class = "label_radio" >< input name = "member_yzm" type = "radio" <?php echo $data["member_yzm"]? '' : 'checked' ?> value="0"> 关闭</ label > </ div > </ div > < div class = "row cl" > < label class = "form-label col-xs-4 col-sm-2" >新会员默认积分:</ label > < div class = "formControls col-xs-8 col-sm-9" > < input type = "text" name = "member_point" value = "<?php echo $data[" member_point"];?>" class="input-text" style="width:30%"> < span style = "color:red" > [积分=经验,区别在于积分可以通过消费减少,经验只增不减,下同]</ span > </ div > </ div > < div class = "row cl" > < label class = "form-label col-xs-4 col-sm-2" >每日登陆奖励积分:</ label > < div class = "formControls col-xs-8 col-sm-9" > < input type = "text" name = "login_point" value = "<?php echo $data[" login_point"];?>" class="input-text" style="width:30%"> </ div > </ div > < div class = "row cl" > < label class = "form-label col-xs-4 col-sm-2" >发布评论奖励积分:</ label > < div class = "formControls col-xs-8 col-sm-9" > < input type = "text" name = "comment_point" value = "<?php echo $data[" comment_point"];?>" class="input-text" style="width:30%"> </ div > </ div > < div class = "row cl" > < label class = "form-label col-xs-4 col-sm-2" >投稿奖励积分:</ label > < div class = "formControls col-xs-8 col-sm-9" > < input type = "text" name = "publish_point" value = "<?php echo $data[" publish_point"];?>" class="input-text" style="width:30%"> </ div > </ div > </ div > < div class = "tabCon" > < div class = "row cl" > < label class = "form-label col-xs-4 col-sm-2" >QQ登录 App ID:</ label > < div class = "formControls col-xs-8 col-sm-9" > < input type = "text" name = "qq_app_id" value = "<?php echo $data[" qq_app_id"];?>" class="input-text" style="width:50%"> </ div > </ div > < div class = "row cl" > < label class = "form-label col-xs-4 col-sm-2" >QQ登录 App key:</ label > < div class = "formControls col-xs-8 col-sm-9" > < input type = "text" name = "qq_app_key" value = "<?php echo $data[" qq_app_key"];?>" class="input-text" style="width:50%"> </ div > </ div > < div class = "row cl" > < label class = "form-label col-xs-4 col-sm-2" >QQ登录 回调地址:</ label > < div class = "formControls col-xs-8 col-sm-9" > < input type = "text" name = "callback" readonly value="<?php echo U('member/other/qq_login');?>" class="input-text" style="width:50%"> </ div > </ div > </ div > </ div > < div class = "row cl" > < div class = "col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-2" > < input type = "submit" class = "btn btn-primary radius" name = "dosubmit" value = " 保存 " > < input type = "reset" class = "btn btn-default radius" value = " 取消 " > </ div > </ div > </ form > </ div > <? php include $this->admin_tpl('footer', 'admin');?> < script type = "text/javascript" > function check_all(){ if($("input[name='member_point']").val()=='' || isNaN($("input[name='member_point']").val())){ layer.msg('新会员默认积分只能为数字!'); return false; } if($("input[name='login_point']").val()=='' || isNaN($("input[name='login_point']").val())){ layer.msg('每日登陆奖励积分只能为数字!'); return false; } if($("input[name='comment_point']").val()=='' || isNaN($("input[name='comment_point']").val())){ layer.msg('发布评论奖励积分只能为数字!'); return false; } if($("input[name='login_point']").val()=='' || isNaN($("input[name='login_point']").val())){ layer.msg('投稿奖励积分只能为数字!'); return false; } return true; } $(function(){ $.Huitab("#tab_system .tabBar span","#tab_system .tabCon","current","click","<? php echo isset($_GET['tab']) ? intval($_GET['tab']) : '0'?>"); }); </ script > </ body > </ html > |
接着打开项目:application\member\view\default\register.html文件,替换为以下代码:
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" > <html> <head> <meta http-equiv= "Content-Type" content= "text/html; charset=utf-8" > <title>会员注册</title> <link href= "{STATIC_URL}css/member_login.css" rel= "stylesheet" type= "text/css" /> <script type= "text/javascript" src= "{STATIC_URL}js/jquery-1.8.2.min.js" ></script> <script type= "text/javascript" src= "{STATIC_URL}plugin/layer/3.0.1/layer.js" ></script> <script type= "text/javascript" src= "{STATIC_URL}js/register.js" ></script> <meta name= "description" content= "yzmcms会员注册" /> </head> <body> < div class = "w880 main" > < div class = "main_left" > <p class = "logo" ><a href= "{SITE_URL}" ><img src= "{STATIC_URL}images/logo.png" ></a></p> <p>已经有帐号?<a href= "{U('login')}" >点击登录</a></p> <p>使用合作网站登录</p> <p><a href= "{U('member/other/qq_login')}" target= "_blank" class = "qq_login" >腾讯QQ登陆</a></p> </ div > < div class = "main_right" > < div class = "login" >会员注册</ div > < div class = "form2" > <form action= "" method= "post" onsubmit= "return checkall()" > <ul> <li><label>用户名</label><input type= "text" class = "input" name= "username" id= "username" placeholder= "请输入用户名" value= "" ></li> <li><label>电子邮箱</label><input type= "text" class = "input" name= "email" id= "email" placeholder= "请输入电子邮箱" value= "" ></li> <li><label>密码</label><input type= "password" class = "input" name= "password" id= "password" placeholder= "请输入密码" value= "" ></li> <li><label>确认密码</label><input type= "password" class = "input" name= "password2" id= "password2" placeholder= "请输入确认密码" value= "" ></li> <li><label>验证码</label><input type= "text" class = "input code" name= "code" id= "code" placeholder= "请输入验证码" ><img src= "{U('api/index/code')}" onclick= "this.src=this.src+'?'" class = "codeimg" title= "看不清,换一张" ></li> <li><label>手机号码:</label><input type= "text" class = "input" name= "mobile" id= "mobile" value= "" ></li> { if $config[ 'member_mobile' ] == 1} <li><label>手机验证:</label><input type= "text" class = "input code" name= "mobile_code" value= "" id= "mobile_code" > <b class = "huoqu" style= "height: 28px; width: 120px;cursor: pointer;" >获取验证码</b></li> {/ if } <li><input type= "submit" class = "submit" name= "dosubmit" value= "同意以下协议并注册" ></li> <li><input type= "checkbox" checked= "checked" value= "1" id= "agree" name= "agree" /> <a onclick= "show_protocol()" href= "javascript:void(0);" >点击阅读注册协议</a></li> </ul> </form> </ div > </ div > </ div > < div class = 'clearfix' ></ div > < div class = "footer" > <p>Powered by <a href= "http://www.yzmcms.com" target= "_blank" >{YZMCMS_SOFTNAME}</a> © 2014-2018 版权所有</p> </ div > <script type= "text/javascript" > function checkname(){ var res = false ; if ($( "#username" ).val() != '' ){ $.ajax({ type: "post" , url: "{U('public_checkname')}" , dataType: "html" , async: false , data: "username=" +$( '#username' ).val(), beforeSend: function(){ $( "#dosubmit" ).attr({ disabled: "disabled" }); }, success: function(msg){ if (msg == '1' ){ $( "#dosubmit" ).removeAttr( "disabled" ); res = true ; } else if (msg == '-1' ){ layer.msg( '用户名已存在' , {icon:2, time : 1000}); } else if (msg == '0' ){ layer.msg( '用户名格式不正确' , {icon:2, time : 1000}); } else { layer.msg( '未知错误' , {icon:2, time : 1000}); } } }); return res; } else { layer.msg( '用户名不能为空' , {icon:2, time : 1000}); return res; } } function checkemail(){ var reg = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(.[a-zA-Z0-9_-])+/; var res = false ; if (reg.test($( "#email" ).val())){ $.ajax({ type: "post" , url: "{U('public_checkemail')}" , dataType: "html" , async: false , data: "email=" +$( '#email' ).val(), beforeSend: function(){ $( "#dosubmit" ).attr({ disabled: "disabled" }); }, success: function(msg){ if (msg == '1' ){ $( "#dosubmit" ).removeAttr( "disabled" ); res = true ; } else if (msg == '-1' ){ layer.msg( '电子邮箱已存在' , {icon:2, time : 1000}); } else if (msg == '0' ){ layer.msg( '电子邮箱格式不正确' , {icon:2, time : 1000}); } else { layer.msg( '未知错误' , {icon:2, time : 1000}); } } }); return res; } else { layer.msg( '电子邮箱格式不正确' , {icon:2, time : 1000}); return res; } } function show_protocol(){ layer.open({ type: 1, title: '会员注册协议' , skin: 'layui-layer-rim' , area: [ '550px' , '320px' ], content: '<div style="margin:15px 20px"><p >1、在本站注册的会员,必须遵守《互联网电子公告服务管理规定》,不得在本站发表诽谤他人,侵犯他人隐私,侵犯他人知识产权,传播病毒,政治言论,商业讯息等信息。</p><br><p>2、在所有在本站发表的文章,本站都具有最终编辑权,并且保留用于印刷或向第三方发表的权利,如果你的资料不齐全,我们将有权不作任何通知使用你在本站发布的作品。</p><br><p>3、在登记过程中,您将选择注册名和密码。注册名的选择应遵守法律法规及社会公德。您必须对您的密码保密,您将对您注册名和密码下发生的所有活动承担责任。</p></div>' }); } </script> <script type= "text/javascript" > var time = 0; var res = null; function sendTime(){ clearTimeout(res); // 先清空一下倒计时资源。 time --; // 倒计时时间递减。 // 如果倒计时到达0时,则恢复按钮原来的内容 if ( time <= 0) { time = "获取验证码" ; $( '.huoqu' ).text( time ); clearTimeout(res); time = 0; return ; } // 倒计时的内容写到按钮里面 $( '.huoqu' ).text( "剩余" + time + "秒" ); res = setTimeout( "sendTime()" , 1000); } $(function(){ var flg = true ; $( '.huoqu' ).on( 'click' ,function(){ console. log (123); var mobile = $( "#mobile" ).val(); var code = $( "#code" ).val(); var reg = /^1[3,4,5,7,8]\d{9}$/; var ret = false ; if (code == '' ) {layer.msg( '请填写验证码' ); return ret;} if (!reg.test(mobile)) {layer.msg( '手机号码不正确' ); return ret;} if (0 == time ) { var data = { "code" : code, "mobile" : mobile}; var err = "" ; if (flg == true ) { flg = false ; // ajax提交请求 $.ajax({ type: "post" , url: "{U('public_checksms')}" , dataType: "html" , async: false , data: data, beforeSend: function(){ $( "#dosubmit" ).attr({ disabled: "disabled" }); }, success: function(msg){ if (msg == '0' ){ time = 60; sendTime(); layer.msg( '短信发送成功!' ); ret = true ; } else if (msg == '1' ){ layer.msg( '验证码不正确' ); } else if (msg == '2' ){ layer.msg( '短信配置不正确' ); } else { layer.msg(msg); } } }); } $( '.codeimg' ).click(); return ret; } }) }) </script> </body> </html> |
接着在项目:application\member\view\default\目录下新建名为:reset_mobile.html文件
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
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> < html > < head > < meta http-equiv = "Content-Type" content = "text/html; charset=utf-8" > < title >会员中心-通过手机找回密码</ title > < link href = "{STATIC_URL}css/member_reset.css" rel = "stylesheet" type = "text/css" /> < meta name = "description" content = "通过手机找回密码" /> </ head > < body > < div class = "w1" > < div class = "w980 head" > < div class = "right" >< a href = "{SITE_URL}" >回到首页</ a ></ div > < a href = "{U('member/index/register')}" class = "current" >注册</ a > 欢迎登录 </ div > </ div > <!--主要内容--> < div class = "main" > < h1 >通过手机找回密码</ h1 > < div class = "main_left" > < div class = "title" > < span >步骤:1. 确认账号 > 2.安全验证 > 3. 重置密码 > 4. 成功</ span > </ div > < div class = "form" > {if $_SESSION['step'] == 1} < form method = "post" action = "" > < ul > < li >用户名:< input type = "text" placeholder = "用户名" required name = "username" class = "input" /></ li > < li >验证码:< input type = "text" placeholder = "验证码" required name = "code" class = "input code" />< img src = "{U('api/index/code')}" onclick = "this.src=this.src+'?'" class = "codeimg" title = "看不清,换一张" ></ li > < li >< input type = "submit" name = "dosubmit" value = "下一步" class = "submit" > < a href = "{U('init')}" >重新选择验证方式</ a ></ li > </ ul > </ form > {elseif $_SESSION['step'] == 2} < form method = "post" action = "" > < ul > < li >< span class = "red" >我们已将校验码发送至您绑定的手机号< strong style = "color:#333;" >{$_SESSION['mobile']} </ strong >,请在下方输入完成验证</ span ></ li > < li >短信校验码:< input type = "text" placeholder = "短信校验码" required name = "mobile_code" class = "input code" /></ li > < li >< input type = "submit" name = "dosubmit" value = "下一步" class = "submit" > < a onclick = "history.go(-1)" href = "javascript:void(0)" >上一步</ a ></ li > </ ul > </ form > {else} < form method = "post" action = "" onsubmit = "return checkall()" > < ul > < li >< span class = "red" >验证成功,请重新设定您的密码:</ span ></ li > < li > 新密码:< input type = "password" placeholder = "新密码" required name = "password" id = "password" class = "input" /></ li > < li >确认新密码:< input type = "password" placeholder = "确认新密码" required name = "password2" id = "password2" class = "input" /></ li > < li >< input type = "submit" name = "dosubmit" value = "下一步" class = "submit" ></ li > </ ul > </ form > {/if} </ div > </ div > < div class = "main_right" > < p >已经有了账号?</ p > < p >请直接登录</ p > < br > < p >< a href = "{U('member/index/login')}" class = "button" >登录</ a ></ p > </ div > </ div > < script > function checkall(){ var password = document.getElementById("password").value; var password2 = document.getElementById("password2").value; if(password.length < 6){ alert('密码不能低于6位!'); return false; } if(password != password2){ alert('两次密码不一致!'); return false; } } </ script > <!--网站底部--> < div class = "footer" > < p >Powered by < a href = "http://www.yzmcms.com" target = "_blank" >{YZMCMS_SOFTNAME}</ a > © 2014-2018 版权所有</ p > </ div > </ body > </ html > |
接着我们打开项目:application\member\controller\index.class.php文件,替换register方法
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
|
/** * 会员注册 */ public function register(){ $config = get_config(); //检查是否允许新会员注册 if ( $config [ 'member_register' ] == 0) showmsg( '管理员关闭了新会员注册!' , 'stop' ); if (isset( $_SESSION [ '_userid' ]) && $_SESSION [ '_userid' ]){ showmsg(L( 'login_success' ), U( 'member/index/init' ), 1); } if (isset( $_POST [ 'dosubmit' ])){ if ( empty ( $_SESSION [ 'code' ]) || strtolower ( $_POST [ 'code' ]) != $_SESSION [ 'code' ]){ $_SESSION [ 'code' ] = '' ; showmsg(L( 'code_error' ), '' , 1); } if ( empty ( $_SESSION [ 'mobile_code' ]) || strtolower ( $_POST [ 'mobile_code' ]) != $_SESSION [ 'mobile_code' ]) { $_SESSION [ 'mobile_code' ] = '' ; showmsg(L( '手机验证码不正确' ), '' ,1); } $_SESSION [ 'code' ] = '' ; $member = D( 'member' ); $data = array (); $data [ 'username' ] = isset( $_POST [ 'username' ]) && is_username( $_POST [ 'username' ]) ? trim( $_POST [ 'username' ]) : showmsg(L( 'user_name_format_error' )); $data [ 'password' ] = isset( $_POST [ 'password' ]) && is_password( $_POST [ 'password' ]) ? trim( $_POST [ 'password' ]) : showmsg(L( 'password_format_error' )); $data [ 'email' ] = isset( $_POST [ 'email' ]) && is_email( $_POST [ 'email' ]) ? trim( $_POST [ 'email' ]) : showmsg(L( 'mail_format_error' )); $data [ 'mobile' ] = isset( $_POST [ 'mobile' ]) && is_mobile( $_POST [ 'mobile' ]) ? trim( $_POST [ 'mobile' ]) : showmsg(L( '手机号不正确' )); $result = $member ->where( array ( 'username' => $_POST [ 'username' ]))->find(); if ( $result ) showmsg(L( 'user_already_exists' )); $result = $member ->where( array ( 'email' => $_POST [ 'email' ]))->find(); if ( $result ) showmsg( "邮箱已存在!" ); $result = $member ->where( array ( 'mobile' => $_POST [ 'mobile' ]))->find(); if ( $result ) showmsg( "手机已存在" ); $data [ 'nickname' ] = $data [ 'username' ]; $data [ "password" ] = password( $data [ 'password' ]); $data [ 'regdate' ] = $data [ 'lastdate' ] = SYS_TIME; $data [ 'regip' ] = $data [ 'lastip' ] = getip(); $data [ 'groupid' ] = '1' ; $data [ 'amount' ] = '0.00' ; $data [ 'point' ] = $data [ 'experience' ] = $config [ 'member_point' ]; //经验和积分 $data [ 'status' ] = ( $config [ 'member_check' ] || $config [ 'member_email' ]) ? 0 : 1; $data [ 'userid' ] = $member ->insert( $data , true); if (! $data [ 'userid' ]) showmsg( "注册失败!" ); D( 'member_detail' )->insert( $data , true, false); //插入附表 if ( $config [ 'member_email' ]){ //是否需要邮件验证 $mail_code = $_SESSION [ 'mail_code' ] = md5(microtime(true). $data [ 'userid' ]); $_SESSION [ 'userid' ] = $data [ 'userid' ]; $url = SITE_URL. "index.php?m=member&c=index&a=register&mail_code=$mail_code&userid={$data['userid']}&verify=1" ; $message = '请点击邮箱验证地址:<a href="' . $url . '">' . $url . '</a>' ; $res = sendmail( $data [ 'email' ], '会员邮箱验证' , $message ); if (! $res ) showmsg( '邮件发送失败,请联系网站管理员!' , 'stop' ); showmsg( '我们已将邮件发送到您的邮箱,请尽快完成验证!' ); } elseif ( $config [ 'member_check' ]){ //是否需要管理员审核 showmsg( '注册成功,由于管理员开启审核机制,请耐心等待!' ); } $_SESSION [ '_userid' ] = $data [ 'userid' ]; $_SESSION [ '_username' ] = $data [ 'username' ]; set_cookie( '_userid' , $data [ 'userid' ]); set_cookie( '_username' , $data [ 'username' ]); set_cookie( '_nickname' , $data [ 'username' ]); set_cookie( '_groupid' , $data [ 'groupid' ]); showmsg( '注册成功!' , U( 'member/index/init' ), 1); } else { if (! empty ( $_GET [ 'verify' ])) { $mail_code = isset( $_GET [ 'mail_code' ]) ? trim( $_GET [ 'mail_code' ]) : showmsg(L( 'illegal_operation' )); $userid = isset( $_GET [ 'userid' ]) ? intval ( $_GET [ 'userid' ]) : showmsg(L( 'illegal_operation' )); if (isset( $_SESSION [ 'mail_code' ]) && $mail_code == $_SESSION [ 'mail_code' ] && $userid == $_SESSION [ 'userid' ]){ unset( $_SESSION [ 'mail_code' ], $_SESSION [ 'userid' ]); D( 'member' )->update( array ( 'status' => 1, 'email_status' => 1), array ( 'userid' => $userid )); showmsg( '邮箱验证成功!' , U( 'member/index/login' ), 2); } else { showmsg( '验证失败,可能是验证时间已过期!' , U( 'member/index/register' )); } } include template( 'member' , 'register' ); } } public function public_checksms(){ if ( empty ( $_SESSION [ 'code' ]) || strtolower ( $_POST [ 'code' ]) != $_SESSION [ 'code' ]){ $_SESSION [ 'code' ] = '' ; echo 1; exit ; } $_SESSION [ 'code' ] = '' ; $mobile = $_POST [ 'mobile' ]; $result = sendsms( $mobile ); echo $result ; } |
接着打开项目:application\member\controller\reset.class.php文件,增加reset_mobile方法
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
|
public function reset_mobile(){ session_start(); $_SESSION [ 'step' ] = isset( $_SESSION [ 'step' ]) ? $_SESSION [ 'step' ] : 1; if ( $_SESSION [ 'step' ]==1 && isset( $_POST [ 'dosubmit' ])) { if ( empty ( $_SESSION [ 'code' ]) || strtolower ( $_POST [ 'code' ]) != $_SESSION [ 'code' ]){ $_SESSION [ 'code' ] = '' ; showmsg(L( 'code_error' ), '' , 1); } $data = $this ->_check( $_POST [ 'username' ]); if ( empty ( $data [ 'mobile' ])) showmsg( '您没有绑定手机,请选择其他方式找回密码!' , 'stop' ); $ret = sendsms( $data [ 'mobile' ]); if ( $ret != 0) { showmsg( '短信发送失败,请联系网站管理员!' ); } $_SESSION [ 'mobile' ] = $data [ 'mobile' ]; $_SESSION [ 'userid' ] = $data [ 'userid' ]; $_SESSION [ 'emc_times' ] = 5; $_SESSION [ 'step' ] = 2; } elseif ( $_SESSION [ 'step' ] ==2 && isset( $_POST [ 'dosubmit' ])){ if ( $_SESSION [ 'emc_times' ]== '' || $_SESSION [ 'emc_times' ]<=0){ $_SESSION [ 'step' ] = 1; showmsg( "验证次数超过5次,请重新获取短信验证码!" ); } if (! empty ( $_SESSION [ 'mobile_code' ]) && strtolower ( $_POST [ 'mobile_code' ]) == strtolower ( $_SESSION [ 'mobile_code' ])){ unset( $_SESSION [ 'emc_times' ]); $_SESSION [ 'step' ] = 3; } else { $_SESSION [ 'emc_times' ] = $_SESSION [ 'emc_times' ]-1; showmsg( '短信校验码错误!' , '' ,1); } } else if ( $_SESSION [ 'step' ]==3 && isset( $_POST [ 'dosubmit' ])){ if (!isset( $_POST [ 'password' ]) || !is_password( $_POST [ 'password' ])) showmsg(L( 'password_format_error' )); D( 'member' )->update( array ( 'password' => password( $_POST [ 'password' ])), array ( 'userid' => $_SESSION [ 'userid' ])); unset( $_SESSION [ 'step' ], $_SESSION [ 'code' ], $_SESSION [ 'mobile_code' ], $_SESSION [ 'mobile' ], $_SESSION [ 'userid' ]); showmsg( '更新密码成功!' , U( 'member/index/login' )); } include template( 'member' , 'reset_mobile' ); } |
接着我们在项目common\function\system.func.php文件中增加sendsms发送短信方法
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
function sendsms( $mobile ) { $config = get_config(); $user = $config [ 'smsbao_user' ]; $pass = $config [ 'smsbao_pass' ]; $sign = $config [ 'smsbao_sign' ]; if ( empty ( $user ) && empty ( $pass ) && empty ( $sign )) { return 2; } $code = rand(1000,9999); $content = '【' . $sign . '】您的验证码为:' . $code . '请妥善保存!' ; $result = file_get_contents ( $url ); if ( $result == 0) { $_SESSION [ 'mobile_code' ] = $code ; return '0' ; } else { return $result ; } } |
最后我们在项目根目录下创建smsbao_install.php文件及smsbao.sql文件,来安装短信宝信息
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
|
<?php header( "Content-type:text/html;charset=utf-8" ); $config = include ( './common/config/config.php' ); $conn = mysqli_connect( $config [ 'db_host' ], $config [ 'db_user' ], $config [ 'db_pwd' ], $config [ 'db_name' ]); $newsql = sreadfile( "smsbao.sql" ); $sqls = explode ( ";" , $newsql ); foreach ( $sqls as $sql ) { if ( empty ( $sql )) { continue ; } if (! $con = $con = mysqli_query( $conn , $sql )) { echo "执行sql语句成功" .mysqli_error( $conn ); exit (); } } echo "<h4>YzmCMS短信宝短信插件安装成功,请删除此文件。</h4>" ; function sreadfile( $filename ){ $content = '' ; if (function_exists( 'file_get_contents' )) { @ $content = file_get_contents ( $filename ); } else { if (@ $fp = fopen ( $filename , 'r' )) { @ $content = fread ( $fp , filesize ( $filename )); @fclose( $fp ); } } return $content ; } |
1
2
3
4
5
|
INSERT INTO `yzm_config` (`id`, `name`, `type`, `title`,`value`,`status`) VALUES ( '' , 'smsbao_user' , '1' , '短信宝用户名' , '0' , '1' ); INSERT INTO `yzm_config` (`id`, `name`, `type`, `title`,`value`,`status`) VALUES ( '' , 'smsbao_pass' , '1' , '短信宝密码' , '0' , '1' ); INSERT INTO `yzm_config` (`id`, `name`, `type`, `title`,`value`,`status`) VALUES ( '' , 'smsbao_sign' , '1' , '短信宝用户名' , '0' , '1' ); INSERT INTO `yzm_config` (`id`, `name`, `type`, `title`,`value`,`status`) VALUES ( '' , 'member_mobile' , '3' , '新会员注册是否需要短信验证' , '0' , '1' ); ALTER TABLE `yzm_member` ADD COLUMN `mobile` char(11) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL COMMENT '手机号码' AFTER `loginnum`; |
经过上面的替换,短信宝的短信平台已经替换成功了,可以正常使用了。进行测试发送:
报备一下短信宝的VIP模板,这样就可以走短信宝的优质通道了,即便遇到敏感文字我们都不会人工审核,短信内容3~5秒就可送达。
另外:我们已经开发好完整的yzmCMS短信宝插件,点击此链接 下载及查看安装流程。
最新更新
电商类
CMS类
微信类