YzmCMS是一款轻量级开源内容管理系统,它采用OOP(面向对象)方式自主开发的框架。基于PHP+Mysql架构,并采用MVC框架式开发的一款高效开源的内容管理系统,可运行在Linux、Windows、MacOSX、Solaris等各种平台上。便于进行二次开发,小编对这款软件还是比较了解的,小编今天就以新增短信接口为例为大家讲解一下如何进行二次开发,我们使用的短信接口是我们短信宝短信群发平台的短信接口,我们短信宝短信群发平台非常稳定,发送速度快,注册就送测试短信,推荐大家使用。
打开项目:\application\admin\view\system_set.html 增加短信宝页面代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
<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> |
打开项目:\application\member\view\member_set.html 在18行增加以下代码
1
2
3
4
5
6
7
8
|
<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> |
打开项目:\application\member\view\member_add.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
|
<form method= "post" onsubmit= "return dosub(this)" > <ul> <li><label><span class= "c-red" >*</span>用户名:</label><input type= "text" class= "input" name= "username" value= "" onblur= "get_nickname()" ></li> <li><label><span class= "c-red" >*</span>密码:</label><input type= "text" class= "input" name= "password" value= "" ></li> <li><label>昵称:</label><input type= "text" class= "input" name= "nickname" value= "" ></li> <li><label><span class= "c-red" >*</span>邮箱:</label><input type= "email" class= "input" name= "email" value= "" >><span class= "c-red" >*</span>手机号码:</label><input type= "mobile" class= "input" name= "mobile" value= "" ></li> <li><label><span class= "c-red" >*</span>会员组:</label> <span class= "span_input" ><select name= "groupid" style= "margin-left:0px;" > <?php foreach($member_group as $val){ echo '<option value="' .$val[ 'groupid' ]. '">' .$val[ 'name' ]. '</option>' ; } ?> </select> <span class= "c-red" >*会员组别影响到经验</span></span> </li> <li><label><span class= "c-red" >*</span>积分:</label><input type= "text" class= "input" name= "point" value= "0" ></li> <li><label>vip会员:</label> <span class= "span_input" title= "vip会员可以免积分查看付费内容" >是否为vip会员 <input name= "vip" value= "1" type= "checkbox" > 过期时间 <input type= "text" class= "input-text laydate-icon" style= "width:175px;height:30px;" name= "overduedate" value= "" onclick= "laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss'})" ></span> </li> <li><input type= "hidden" name= "dosubmit" value= "1" > <input class= "dosubmit w_120 btn-primary radius" type= "submit" value= "提交" > <input class= "btn w_120 btn-default radius" type= "button" value= "取消" onclick= "yzmcms_close()" > </li> </ul> </form> |
打开项目:\application\member\view\default\register.html 注册页面添加手机号
1
2
3
4
|
<li><label>手机号码:</label><input type= "text" class= "input" name= "mobile" id= "mobile" value= "" ></li> { if $config[ 'member_mobile' ] == 1} <li><input type= "text" class= "input code" name= "mobile_code" value= "" id= "mobile_code" > <b class= "huoqu" style= "height: 28px; width: 120px;cursor: pointer;display: inline-block;margin-top: 10px;" >获取验证码</b></li> {/ if } |
打开项目:\application\member\view\default\register.html 同时最后也添加js代码、
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
|
<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 (){ 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}; console.log(data); 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 (data){ data = JSON.parse(data) if (data.status === 1){ time = 60; sendTime(); layer.msg( '短信发送成功!' ); ret = true ; } else { layer.msg(data.message); window.location.reload(); } } }); } $( '.codeimg' ).click(); return ret; } }) }) </script> |
打开项目:\application\member\controller\index.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
|
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 (is_ajax()){ // $this->_check_code($_POST['code']); if (empty($_SESSION[ 'mobile_code' ]) || strtolower($_POST[ 'mobile_code' ]) != $_SESSION[ 'mobile_code' ]) { $_SESSION[ 'mobile_code' ] = '' ; return_json(array( 'status' =>0, 'message' => '手机验证码不正确' )); } $member = D( 'member' ); $data = array(); $data[ 'username' ] = isset($_POST[ 'username' ]) && is_username($_POST[ 'username' ]) ? trim($_POST[ 'username' ]) : return_json(array( 'status' =>0, 'message' =>L( 'user_name_format_error' ))); $data[ 'password' ] = isset($_POST[ 'password' ]) && is_password($_POST[ 'password' ]) ? trim($_POST[ 'password' ]) : return_json(array( 'status' =>0, 'message' =>L( 'password_format_error' ))); $data[ 'email' ] = isset($_POST[ 'email' ]) && is_email($_POST[ 'email' ]) ? trim($_POST[ 'email' ]) : return_json(array( 'status' =>0, 'message' =>L( 'mail_format_error' ))); $data[ 'mobile' ] = isset($_POST[ 'mobile' ]) && is_mobile($_POST[ 'mobile' ]) ? trim($_POST[ 'mobile' ]) : return_json(array( 'status' =>0, 'message' => '手机号不正确' )); $result = $member->field( 'userid' )->where(array( 'username' =>$_POST[ 'username' ]))->find(); if ($result) return_json(array( 'status' =>0, 'message' => '该用户名已注册!' )); $result = $member->field( 'userid' )->where(array( 'email' =>$_POST[ 'email' ]))->find(); if ($result) return_json(array( 'status' =>0, 'message' => '该邮箱已注册!' )); $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' ]) return_json(array( 'status' =>0, 'message' => '注册失败!' )); D( 'member_detail' )->insert($data, true , false ); //插入附表 if ($config[ 'member_email' ]){ //需要邮件验证 $mail_code = string_auth($data[ 'userid' ]. '|' .SYS_TIME, 'ENCODE' , make_auth_key( 'email' )); $url = U( 'member/index/register' , array( 'mail_code' =>$mail_code, 'verify' =>1)); $email_tpl = APP_PATH.ROUTE_M.DIRECTORY_SEPARATOR. 'view' .DIRECTORY_SEPARATOR.(defined( 'MODULE_THEME' ) ? MODULE_THEME : C( 'site_theme' )).DIRECTORY_SEPARATOR. 'email_register_message.html' ; $message = is_file($email_tpl) ? file_get_contents($email_tpl) : return_json(array( 'status' =>0, 'message' => '邮件模板不存在,请联系网站管理员!' )); $message = str_replace(array( '{site_name}' , '{url}' , '{username}' , '{email}' ), array(get_config( 'site_name' ),$url,$data[ 'username' ],$data[ 'email' ]), $message); $res = sendmail($data[ 'email' ], '会员注册邮箱验证' , $message); if (!$res) return_json(array( 'status' =>0, 'message' => '邮件发送失败,请联系网站管理员!' )); return_json(array( 'status' =>1, 'message' => '我们已将邮件发送到您的邮箱,请尽快完成验证!' , 'url' =>U( 'member/index/login' ))); }elseif($config[ 'member_check' ]){ //需要管理员审核 return_json(array( 'status' =>1, 'message' => '注册成功,由于管理员开启审核机制,请耐心等待!' , 'url' =>U( 'member/index/login' ))); } $_SESSION[ '_userid' ] = $data[ 'userid' ]; $_SESSION[ '_username' ] = $data[ 'username' ]; set_cookie( '_userid' , $data[ 'userid' ], 0, true ); set_cookie( '_username' , $data[ 'username' ], 0, true ); set_cookie( '_groupid' , $data[ 'groupid' ], 0, true ); set_cookie( '_nickname' , $data[ 'username' ]); return_json(array( 'status' =>1, 'message' => '注册成功!' , 'url' =>U( 'member/index/init' ))); } else { if (!empty($_GET[ 'verify' ])) { $mail_code = isset($_GET[ 'mail_code' ]) ? trim($_GET[ 'mail_code' ]) : showmsg(L( 'illegal_operation' ), 'stop' ); $code_res = string_auth($mail_code, 'DECODE' , make_auth_key( 'email' )); $code_arr = explode( '|' , $code_res); $userid = isset($code_arr[0]) ? intval($code_arr[0]) : showmsg(L( 'illegal_operation' ), 'stop' ); $time = isset($code_arr[1]) ? $code_arr[1] : showmsg(L( 'illegal_operation' ), 'stop' ); if ($time+1800 > SYS_TIME){ 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' ); } } |
打开项目:\application\member\controller\reset.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
|
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 增加发送类
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
|
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_json(array( 'status' =>0, 'message' => '短信配置错误' )); } $code = rand(1000,9999); $content = '【' .$sign. '】您的验证码为:' .$code. '请妥善保存!' ; $result = file_get_contents($url); if ($result == 0) { $_SESSION[ 'mobile_code' ] = $code; setcache($mobile, time(),60); return_json(array( 'status' =>1, 'message' => '发送成功' )); } else { return_json(array( 'status' =>0, 'message' => '发送失败' )); } } function resetsms($mobile) { $config = get_config(); $user = $config[ 'smsbao_user' ]; $pass = $config[ 'smsbao_pass' ]; $sign = $config[ 'smsbao_sign' ]; if (empty($user) && empty($pass) && empty($sign)) { return 1; } $code = rand(1000,9999); $content = '【' .$sign. '】您的验证码为:' .$code. '请妥善保存!' ; $result = file_get_contents($url); if ($result == 0) { $_SESSION[ 'mobile_code' ] = $code; return 0; } else { return 1; } |
打开项目:\application\member\view\default\reset_type.html 增加手机找回密码的方式
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
<div class= "main" > <h1>请选择密码找回方式</h1> <div class= "main_left" > <div class= "reset_type" > <span>1.</span>通过手机找回密码 <a href= "{U('reset_mobile')}" >立即找回</a> </div> <div class= "reset_type" > <span>1.</span>通过电子邮箱找回密码 <a href= "{U('reset_email')}" >立即找回</a> </div> <div class= "reset_type" > <span>2.</span>通过安全问题找回密码 <a href= "{U('reset_problem')}" >立即找回</a> </div> </div> |
好了,经过以上的替换,短信宝的短信平台已经替换成功了,可以正常使用了。我们进行测试发送。
报备一下短信宝的VIP模板,这样就可以走短信宝的优质通道了,即便遇到敏感文字我们都不会人工审核,短信内容3~5秒就可送达。
另外:我们已经开发好完整的YzmCMS_V7.1系统短信宝插件,点击此链接 下载及查看安装流程。
最新更新
电商类
CMS类
微信类