待发短信

在线客服
产品支持 短信宝客服
合作渠道 渠道合作
服务咨询

4001-021-502

工作时间

9:00-21:00

DOYO管理系统短信插件开发

DOYO通用建站系统采用php+mysql开发,是免费的开源CMS建站、企业建站系统,便于二次开发,小编对于他比较了解,今天就以增加短信接口为例,教大家如何进行二次开发,使用的短信接口是我们短信宝短信群发平台的短信接口,我们短信宝短信群发平台非常稳定,发送速度快,注册就送测试短信,推荐大家使用。

进行开发插件,首先我们修改后台页面,打开项目/source/admin/template/sys.html文件,修改代码14行左右:

?
1
<ul class="switchs"><li id="s1">基本</li><li id="s2" class="c">上传</li><li id="s3" class="c">其他</li><li id="s4" class="c">伪静态</li><li id="s5" class="c">邮件</li><li id="s6" class="c">短信</li></ul>

在102行左右添加如下代码:

?
1
2
3
4
5
6
7
<div id="infos6" class="none">
    <?php $sendsms=unserialize($sysconfig['sendsms']); ?>
    <dl style="border:0;"><dd class="t">以下设置为短信发送配置,用于涉及发送短信功能使用<a href="http://www.smsbao.com">短信宝短信接口</a>,用于涉及发送短信功能使用,如“注册”“找回密码”等。</dd></dl>
    <dl><dt>短信宝帐号:</dt><dd><input name="sendsms[smskey]" type="text" class="int" value="<?php echo $sendsms['smskey'] ?>" style="width:200px;"/></dd></dl>
    <dl><dt>短信宝密码:</dt><dd><input name="sendsms[pass]" type="password" class="int" value="<?php echo $sendsms['pass'] ?>" style="width:200px;"/></dd></dl>
    <dl><dt>短信签名:</dt><dd><input name="sendsms[sign]" type="text" class="int" value="<?php echo $sendsms['sign'] ?>" style="width:200px;"/></dd><dd class="t">例如:DOYO</dd></dl>
    </div>

接下来我们修改保存短信配置文件,打开项目/source/admin/a_sys.php文件,修改 index 方法, 修改代码如下:

?
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
function index(){
                if($this->syArgs('run')==1){
                        $configfile='config.php';
                        $fp_tp=@fopen($configfile,"r");
                        $fp_txt=@fread($fp_tp,filesize($configfile));
                        @fclose($fp_tp);
                        $config=array('http_path','site_title','site_keywords','site_description','view_themes','site_html','site_html_dir','site_html_rules','site_html_index','cache_auto','cache_time','filetype','filesize','imgwater','imgwater_t','imgcaling','img_w','img_h','comment_audit','comment_user','rewrite_open','enable_gzip','enable_gzip_level');
                        foreach($config as $v){
                                if (strpos(',site_html,cache_auto,cache_time,filesize,imgwater,imgwater_t,imgcaling,img_w,img_h,comment_audit,comment_user,site_html_index,enable_gzip,enable_gzip_level,',$v)){
                                        $txt=$this->syArgs($v);if($v=='filesize'){$txt=$txt*1024;}
                                        if($v=='site_html'){
                                                if($GLOBALS['G_DY']['ext']['site_html']==1&&$txt==0)@unlink('index.html');
                                        }
                                        $fp_txt=preg_replace("/'".$v."' => .*?,/","'".$v."' => ".$txt.",",$fp_txt);
                                }else if($v=='filetype'){
                                        $fp_txt=preg_replace("/'".$v."' => '.*?',/","'".$v."' => '".strtolower($this->syArgs($v,1))."',",$fp_txt);
                                }else if($v=='site_html_rules'){
                                        if(stripos($this->syArgs($v,1),'[id]')===false&&stripos($this->syArgs($v,1),'[file]')===false){
                                        message_a("静态规则中[id]与[file]必须至少包含一个");
                                        }
                                        if(stripos($this->syArgs($v,1),'.')===false){
                                        message_a("静态规则中必须包含“.”和后缀名");
                                        }
                                        $fp_txt=preg_replace("/'site_html_rules' => '.*?',/","'site_html_rules' => '".$this->syArgs($v,1)."',",$fp_txt);
                                }else if($v=='site_html_dir'){
                                        if(preg_match("/^[a-zA-Z0-9_\/]*$/",$this->syArgs($v,1))==0)message_a("生成目录只能为英文、数字、下划线和/组成");
                                        if($this->syArgs($v,1)=='/'){
                                                $dir=$this->syArgs($v,1);
                                        }else if($this->syArgs($v,1)==''){
                                                $dir='html';
                                        }else{
                                                $dir=trim($this->syArgs($v,1),'/');
                                        }
                                        $fp_txt=preg_replace("/'".$v."' => '.*?',/","'".$v."' => '".strtolower($dir)."',",$fp_txt);
                                        
                                }else if($v=='site_html_rules'){
                                        if(preg_match("/^[a-zA-Z0-9_\.\[\]\/]*$/",$this->syArgs($v,1))==0)message_a("生成规则只能为英文、数字、下划线、点和/组成");
                                        if($this->syArgs($v,1)==''){
                                                $dir='[y]/[m]/[id].html';
                                        }else{
                                                $dir=trim($this->syArgs($v,1),'/');
                                        }
                                        $fp_txt=preg_replace("/'".$v."' => '.*?',/","'".$v."' => '".strtolower(trim($this->syArgs($v,1),'/'))."',",$fp_txt);
                                }else{
                                        $fp_txt=preg_replace("/'".$v."' => '.*?',/","'".$v."' => '".str_replace(array("\r\n","\n","\r"),'',$this->syArgs($v,1))."',",$fp_txt);
                                }
                        }
                        $fpt_tpl=@fopen($configfile,"w");
                        @fwrite($fpt_tpl,$fp_txt);
                        @fclose($fpt_tpl);
                        
                        $incfile='include/inc.php';
                        $inc_tp=@fopen($incfile,"r");
                        $inc_txt=@fread($inc_tp,filesize($incfile));
                        @fclose($inc_tp);
                        $inc=array('rewrite_open','rewrite_article','rewrite_article_type','rewrite_product','rewrite_product_type','rewrite_channel','rewrite_channel_type','rewrite_message_type','rewrite_special','rewrite_labelcus_custom','rewrite_dir');
                        foreach($inc as $v){
                                $vt=strtolower(trim($this->syArgs($v,1),'/'));
                                if(preg_match("/^[a-zA-Z0-9_\{\}\.\-\/]*$/",$vt)==0)message_a("伪静态规则只能包含英文、数字、下划线、点、中划线、{、}、/");
                                if($v=='rewrite_article'){
                                        if((stripos($vt,'{id}')===false&&stripos($vt,'{file}')===false)||stripos($vt,'{article}')===false){
                                        message_a("article规则中{id}与{file}必须至少包含一个,并且必须包含{article}");
                                        }
                                }
                                if($v=='rewrite_article_type'){
                                        if((stripos($vt,'{tid}')===false&&stripos($vt,'{file}')===false)||stripos($vt,'{page}')===false||stripos($vt,'{article}')===false||stripos($vt,'{type}')===false){
                                        message_a("article栏目规则中{tid}与{file}必须至少包含一个,并且必须包含{page}与{article}与{type}");
                                        }
                                }
                                if($v=='rewrite_product'){
                                        if((stripos($vt,'{id}')===false&&stripos($vt,'{file}')===false)||stripos($vt,'{product}')===false){
                                        message_a("product规则中{id}与{file}必须至少包含一个,并且必须包含{product}");
                                        }
                                }
                                if($v=='rewrite_product_type'){
                                        if((stripos($vt,'{tid}')===false&&stripos($vt,'{file}')===false)||stripos($vt,'{page}')===false||stripos($vt,'{product}')===false||stripos($vt,'{type}')===false){
                                        message_a("product栏目规则中{tid}与{file}必须至少包含一个,并且必须包含{page}与{product}与{type}");
                                        }
                                }
                                if($v=='rewrite_channel'){
                                        if((stripos($vt,'{id}')===false&&stripos($vt,'{file}')===false)||stripos($vt,'{channel}')===false||stripos($vt,'{molds}')===false){
                                        message_a("自定义频道规则中{id}与{file}必须至少包含一个,并且必须包含{molds}与{channel}");
                                        }
                                }
                                if($v=='rewrite_channel_type'){
                                        if((stripos($vt,'{tid}')===false&&stripos($vt,'{file}')===false)||stripos($vt,'{page}')===false||stripos($vt,'{channel}')===false||stripos($vt,'{type}')===false){
                                        message_a("自定义频道栏目规则中{tid}与{file}必须至少包含一个,并且必须包含{page}与{channel}与{type}");
                                        }
                                }
                                if($v=='rewrite_message_type'){
                                        if((stripos($vt,'{tid}')===false&&stripos($vt,'{file}')===false)||stripos($vt,'{page}')===false||stripos($vt,'{message}')===false||stripos($vt,'{type}')===false){
                                        message_a("message规则中{tid}与{file}必须至少包含一个,并且必须包含{page}与{message}与{type}");
                                        }
                                }
                                if($v=='rewrite_special'){
                                        if((stripos($vt,'{sid}')===false&&stripos($vt,'{file}')===false)||stripos($vt,'{page}')===false||stripos($vt,'{special}')===false){
                                        message_a("专题规则中{sid}与{file}必须至少包含一个,并且必须包含{page}与{special}");
                                        }
                                }
                                if($v=='rewrite_labelcus_custom'){
                                        if(stripos($vt,'{file}')===false){
                                        message_a("自定义页面规则中必须含有{file}");
                                        }
                                }
                                if($v=='rewrite_open'){
                                        $inc_txt=preg_replace("/'".$v."' => .*?,/","'".$v."' => ".$vt.",",$inc_txt);
                                }else{
                                        $inc_txt=preg_replace("/'".$v."' => '.*?',/","'".$v."' => '".$vt."',",$inc_txt);
                                }
                                if($v=='rewrite_dir'){
                                        if($vt==''){$vt='/';}else{$vt='/'.$vt.'/';}
                                        $inc_txt=preg_replace("/'".$v."' => .*?,/","'".$v."' => '".$vt."',",$inc_txt);
                                }
                        }
                        $inc_txt=preg_replace("/'mode' => '.*?',/","'mode' => '".$this->syArgs('mode',1)."',",$inc_txt);
                        $inc_txt=preg_replace("/'vercode' => .*?,/","'vercode' => ".$this->syArgs('vercode',1).",",$inc_txt);
                        $inc_tpl=@fopen($incfile,"w");
                        @fwrite($inc_tpl,$inc_txt);
                        @fclose($inc_tpl);
                        syDB('sysconfig')->update(array('name'=>'sendmail'),array('sets'=>serialize($this->syArgs('sendmail',2))));
                        syDB('sysconfig')->update(array('name'=>'sendsms'),array('sets'=>serialize($this->syArgs('sendsms',2))));
                        message_a("系统设置修改成功",'?c=a_sys');
                }
                $this->toptxt='系统设置';
                $this->d=$GLOBALS['G_DY']['ext'];
                $this->r=$GLOBALS['G_DY']['rewrite'];
                $this->inc=$GLOBALS['G_DY'];
                $s=syDB('sysconfig')->findAll();
                foreach($s as $v){$sysconfig[$v['name']]=$v['sets'];}
                $this->sysconfig=$sysconfig;
                $this->display("sys.html");
        }

接下来我们修改前台页面,打开项目/template/default/member/reg.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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>会员注册-{$GLOBALS['S']['title']}</title>
<link href="{$GLOBALS['skin']}style/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
var site_dir="{$GLOBALS['WWW']}";
</script>
{include="js.html"}
<script src="{$GLOBALS['WWW']}include/js/dyfrom.js" type="text/javascript"></script>
<script src="{$GLOBALS['WWW']}include/js/DatePicker/WdatePicker.js" type="text/javascript"></script>
<script type="text/javascript">
function postform(){
        value=$("#user").val();
        if(!dyfrom_null(value)||!dyfrom_max(value, 20)){
                alert('用户名不能为空,并且不能大于20个字符');return false;
        }
        if(dyfrom_ajax("{$GLOBALS['WWW']}index.php?c=member&a=rules","user="+value)=='false'){
                alert('用户名已被注册,请更换用户名');return false;
        }
        value=$("#pass1").val();
        if(!dyfrom_null(value)){
                alert('请输入密码');return false;
        }
        value=$("#pass2").val();
        if(!dyfrom_null(value)||!(value==$("#pass1").val())){
                alert('两次密码输入不同,请修改');return false;
        }
        value=$("#email").val();
        if(!dyfrom_email(value)){
                alert('请输入正确的email地址');return false;
        }
 
{if($GLOBALS['G_DY']['vercode']==1)}
        value=$("#vercode").val();
        if(dyfrom_ajax("{$GLOBALS['WWW']}index.php?c=ajax&a=vercode","vercode="+value)=='false'){
                alert('验证码输入错误');return false;
        }
{/if}
        return true;
}
</script>
 
</head>
 
<body>
{include="head.html"}
<div class="wpm list">
  <div class="tab11"></div>
  <div class="tab1 tab1b main">
    <div class="l">
      <div class="columnc"><h2>会员中心</h2></div>
      <div class="columncl">
      <a href="?c=member&a=reg&url={$backurl}" class="c">会员注册</a>
      <a href="?c=member&a=login&url={$backurl}">会员登录</a>
      </div>
    </div>
    <div class="r">
    <div class="content">
       <div class="position">当前位置:会员注册</div>
       <div class="member_f">
<form action="index.php?c=member&a=reg&go=1&url={$backurl}" method="post" onsubmit="return postform();">
       <dl><dt>用户名:</dt><dd><input type="text" name="user" id="user" class="inp" style="width:150px;"/></dd><dd class="m"></dd></dl>
       <dl><dt>密 码:</dt><dd><input type="password" name="pass1" id="pass1" class="inp" style="width:150px;"/></dd><dd class="m"></dd></dl>
       <dl><dt>确认密码:</dt><dd><input type="password" name="pass2" id="pass2" class="inp" style="width:150px;"/></dd><dd class="m"></dd></dl>
       <dl><dt>Email:</dt><dd><input type="text" name="email" id="email" class="inp" style="width:150px;"/></dd><dd class="m">重要,用于找回密码</dd></dl>
       {foreach $fields as $v}
       <dl><dt>{$v['name']}:</dt><dd>{$v['input']}</dd></dl>
       {/foreach}
{if($GLOBALS['G_DY']['vercode']==1)}     
       <dl><dt>验证码:</dt><dd><input type="text" name="vercode" id="vercode" class="inp" style="width:80px;"/></dd><dd><img src="{$GLOBALS['WWW']}include/vercode.php" id="vercodeimg" width="60" height="25" onclick="newvercode();" style="cursor:pointer;" /></dd><dd class="m"></dd></dl>
        <dl><dt>手机号码:</dt><dd><input type="text" name="mobile" id="pass2" class="inp" style="width:150px;"/></dd><dd class="m"><span class="sendcode" style="cursor: pointer;">获取验证码</span><p id="phone_err" class="errmsg" style="margin:5px 0 0 88px; color:red;"></p></dd></dl>
        <dl><dt>短信验证码:</dt><dd><input type="text" name="svcode" id="pass2" class="inp" style="width:150px;"/></dd><dd class="m"></dd></dl>
<script type="text/javascript">
setTimeout('newvercode()',1000);
function newvercode(){
        document.getElementById("vercodeimg").src="{$GLOBALS['WWW']}include/vercode.php?a="+Math.random();
}
</script>
{/if}
       <dl style="border:0;"><dt>&nbsp;</dt><dd><input type="submit" value="立即注册" class="btnbig" /></dd></dl>
</form>
       </div>
    </div>
    </div>
  </div>
  <div class="tab12 mban"></div>
</div>
 
 
 
<script>
    var time = 0; // 倒计时时间
    var res = null; // 倒计时资源,释放时使用
    var sendNode = null; // 发送的按钮节点
    var diffTime = "<?php echo $diff; ?>"; // 由php计算的时间差的结果。所以就算用户刷新页面,倒计时还是存在的。
 
    /**
     * 执行倒计时的方法
     */
    function sendTime() {
        clearTimeout(res); // 先清空一下倒计时资源。
        time--; // 倒计时时间递减。
 
        // 如果倒计时到达0时,则恢复按钮原来的内容
        if (time <= 0) {
            time = "获取验证码";
            sendNode.text(time);
            clearTimeout(res);
            time = 0;
            return;
        }
 
        // 倒计时的内容写到按钮里面
        sendNode.text("剩余" + time + "秒");
        res = setTimeout("sendTime()", 1000);
    }
 
    /**
     * 调用处
     */
    $(function() {
        sendNode = $(".sendcode"); // 获取发送的节点
        var flg = true; // 防止ajax重复提交的标记
 
        // 在页面加载时,先判断一下是否上次倒计时未完成,由php计算,防止页面刷新,覆盖掉倒计时。
        if ("" != diffTime) {
            time = parseInt(diffTime);
            sendTime();
        }
 
        /**
         * 点击发送短信,触发事件
         */
        sendNode.click(function() {
            // 如果当前倒计时结束,则收集表单数据,并ajax提交到服务端
 
            if (0 == time) {
                    value=$("#vercode").val();
                    if(dyfrom_ajax("{$GLOBALS['WWW']}index.php?c=ajax&a=vercode","vercode="+value)=='false'){
                      alert('验证码输入错误');return false;
                    }
 
                var phoneNum = $("input[name='mobile']").val();
 
                   var myreg=/^[1][3,4,5,7,8][0-9]{9}$/;  
                  if (!myreg.test(phoneNum)) {  
                      alert('手机号码不能为空或不正确'); 
                     return false;
                  }
                
 
                var data = { "mobile" : phoneNum};
                var err = "";
 
                if (flg == true) {
                    flg = false;
                    // ajax提交请求
                    $.ajax({
                        "url" : "index.php?c=member&a=reg&go=2",
                        "type" : "post",
                        "data" : data,
                        "dataType" : "json",
                        "success" : function (msg) {
                            $(".errmsg").text("");
 
                            if (msg == '0') {
 
                              time = 60;
                              sendTime();
                              alert('发送验证码成功!');
                                
                            } else {
 
                              alert('短信发送失败,原因:'+msg);
 
                            }
 
                                // 刷新图形验证码
                            flg = true;
                        }
                    });
                }
                return false;
            }
        });
    });
</script>
 
 
{include="bottom.html"}
</body>
</html>

继续修改找回密码页面,打开项目/template/default/member/password.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
201
202
203
204
205
206
207
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>找回密码-{$GLOBALS['S']['title']}</title>
<link href="{$GLOBALS['skin']}style/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
var site_dir="{$GLOBALS['WWW']}";
</script>
{include="js.html"}
<script src="{$GLOBALS['WWW']}include/js/dyfrom.js" type="text/javascript"></script>
<script type="text/javascript">
setTimeout('newvercode()',1000);
function newvercode(){
        document.getElementById("vercodeimg").src="{$GLOBALS['WWW']}include/vercode.php?a="+Math.random();
}
function postform(){
        value=$("#pass1").val();
        if(!dyfrom_null(value)){
                alert('请输入新密码');return false;
        }
        value=$("#pass2").val();
        if(!dyfrom_null(value)||!(value==$("#pass1").val())){
                alert('两次密码输入不同,请修改');return false;
        }
{if($GLOBALS['G_DY']['vercode']==1)}
        value=$("#vercode").val();
        if(dyfrom_ajax("{$GLOBALS['WWW']}index.php?c=ajax&a=vercode","vercode="+value)=='false'){
                alert(value);
                alert('验证码输入错误');return false;
        }
{/if}
        $("#reset").submit();
}
function retrieve(){
        $("#retrieve_go").html('<strong style="color:#F00; font-size:14px;">正在发送找回密码信息,请稍后...</strong>');
}
</script>
</head>
 
<body>
{include="head.html"}
<div class="wpm list">
  <div class="tab11"></div>
  <div class="tab1 tab1b main">
    <div class="l">
      <div class="columnc"><h2>会员中心</h2></div>
      <div class="columncl">
      <a href="?c=member&a=reg">会员注册</a>
      <a href="?c=member&a=login" class="c">会员登录</a>
      </div>
    </div>
    <div class="r">
    <div class="content">
       <div class="position">当前位置:找回密码</div>
       <div class="member_f">
{if($password)}
    <form action="index.php?c=member&a=reset_password&go=1" name="reset" id="reset" method="post">
    <input name="id" type="hidden" value="{$password['id']}" />
    <input name="token" type="hidden" value="{$password['token']}" />
        <dl><dt>用户名:</dt><dd>{$password['user']}</dd><dd class="m"></dd></dl>
        <dl><dt>新密码:</dt><dd><input type="password" name="pass1" id="pass1" class="inp" style="width:150px;"/></dd><dd class="m"></dd></dl>
        <dl><dt>确认密码:</dt><dd><input type="password" name="pass2" id="pass2" class="inp" style="width:150px;"/></dd><dd class="m"></dd></dl>
    {if($GLOBALS['G_DY']['vercode']==1)}
        <dl><dt>验证码:</dt><dd><input type="text" name="vercode" id="vercode" class="inp" style="width:80px;"/></dd><dd><img src="{$GLOBALS['WWW']}include/vercode.php" id="vercodeimg" width="60" height="25" style="cursor:pointer;" onclick="newvercode();" /></dd></dl>
    {/if}
    <dl style="border:0;"><dt>&nbsp;</dt><dd><input type="button" value="重置密码" class="btnbig" onclick="postform();" /></dd></dl>
    </form>
 
{else}
 
  <form action="index.php?c=member&a=retrieve_password&go=1" method="post" onsubmit="return retrieve()">
  <dl><dt class="emamobile" style="cursor: pointer;">邮箱</dt><dt class="emamobile" style="cursor: pointer;">手机</dt></dl>
        <dl class="email" style="display: none;"><dt>邮箱:</dt><dd><input type="text" name="email" class="inp" style="width:150px;"/></dd><dd class="m">输入您注册信息中的email地址</dd></dl>
  <dl class="mobile" style="display: block;"><dt>手机号码:</dt><dd><input type="text" name="mobile" class="inp" style="width:150px;"/></dd><dd class="m"><span class="sendcode" style="cursor: pointer;">获取验证码</span><p id="phone_err" class="errmsg" style="margin:5px 0 0 88px; color:red;"></p></dd></dl>
  <dl class="mobile" style="display: block;"><dt>短信验证码:</dt><dd><input type="text" name="svcode" class="inp" style="width:150px;"/></dd><dd class="m"></dd></dl>
 
  <dl><dt>用户名:</dt><dd><input type="text" name="user" class="inp"  style="width:150px;"/></dd><dd class="m">可不填写</dd></dl>
    {if($GLOBALS['G_DY']['vercode']==1)}
        <dl><dt>验证码:</dt><dd><input type="text" name="vercode" class="inp" id="vercode" style="width:80px;"/></dd><dd><img src="{$GLOBALS['WWW']}include/vercode.php" id="vercodeimg" width="60" height="25" style="cursor:pointer;" onclick="newvercode();" /></dd></dl>
    {/if}
    <dl style="border:0;"><dt>&nbsp;</dt><dd id="retrieve_go"><input type="submit" value="找回密码" class="btnbig" /></dd></dl>
    </form>
{/if}
       </div>
    </div>
    </div>
  </div>
  <div class="tab12 mban"></div>
</div>
 
<script>
  $('.emamobile').click(function(){
    var $this = $(this).html();
    if ($this == '手机') {
      $('.mobile').css('display','block');
      $('.email').css('display','none');
    }else{
      $('.mobile').css('display','none');
      $('.email').css('display','block');
    }
    
  })
</script>
 
<script>
    var time = 0; // 倒计时时间
    var res = null; // 倒计时资源,释放时使用
    var sendNode = null; // 发送的按钮节点
    var diffTime = "<?php echo $diff; ?>"; // 由php计算的时间差的结果。所以就算用户刷新页面,倒计时还是存在的。
 
    /**
     * 执行倒计时的方法
     */
    function sendTime() {
        clearTimeout(res); // 先清空一下倒计时资源。
        time--; // 倒计时时间递减。
 
        // 如果倒计时到达0时,则恢复按钮原来的内容
        if (time <= 0) {
            time = "获取验证码";
            sendNode.text(time);
            clearTimeout(res);
            time = 0;
            return;
        }
 
        // 倒计时的内容写到按钮里面
        sendNode.text("剩余" + time + "秒");
        res = setTimeout("sendTime()", 1000);
    }
 
    /**
     * 调用处
     */
    $(function() {
        sendNode = $(".sendcode"); // 获取发送的节点
        var flg = true; // 防止ajax重复提交的标记
 
        // 在页面加载时,先判断一下是否上次倒计时未完成,由php计算,防止页面刷新,覆盖掉倒计时。
        if ("" != diffTime) {
            time = parseInt(diffTime);
            sendTime();
        }
 
        /**
         * 点击发送短信,触发事件
         */
        sendNode.click(function() {
            // 如果当前倒计时结束,则收集表单数据,并ajax提交到服务端
 
            if (0 == time) {
            value=$("#vercode").val();
            if(dyfrom_ajax("{$GLOBALS['WWW']}index.php?c=ajax&a=vercode","vercode="+value)=='false'){
              alert(value);
              alert('验证码输入错误');return false;
            }
 
                var phoneNum = $("input[name='mobile']").val();
 
                   var myreg=/^[1][3,4,5,7,8][0-9]{9}$/;  
                  if (!myreg.test(phoneNum)) {  
                      alert('手机号码不能为空或不正确'); 
                     return false;
                  }
                
 
                var data = { "mobile" : phoneNum};
                var err = "";
 
                if (flg == true) {
                    flg = false;
                    // ajax提交请求
                    $.ajax({
                        "url" : "index.php?c=member&a=retrieve_password&go=2",
                        "type" : "post",
                        "data" : data,
                        "dataType" : "json",
                        "success" : function (msg) {
                            $(".errmsg").text("");
 
                            if (msg == '0') {
 
                              time = 60;
                              sendTime();
                              alert('发送验证码成功!');
                                
                            } else {
 
                              alert('短信发送失败,原因:'+msg);
 
                            }
 
                                // 刷新图形验证码
                            flg = true;
                        }
                    });
                }
                return false;
            }
        });
    });
</script>
 
{include="bottom.html"}
</body>
</html>

接下来修改注册和找回密码的控制代码,打开项目/source/member.php文件,修改retrieve_password方法和reg方法, 代码如下:

?
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
   function retrieve_password(){
 
                if ($this->syArgs("go") == 2) {
                        
                        $code = mt_rand(100000,999999);
                        $mobile $_POST['mobile'];
                        $content '您好,您正在进行找回密码操作验证码为:'.$code.',请不要告诉他人。';
 
                        $send = syClass('sysmsbao');
 
                        $request $send->sendsms($mobile,$content);
 
                        if ($request['code'] == '0') {
                                $_SESSION['smscode'] = $code;
 
                                echo $request['code'];exit;
                        }else{
                                echo $request['code'];exit;
                        }
                }
 
                if($this->syArgs("go")){
                        if($GLOBALS['G_DY']['vercode']==1){
                                if(!$this->syArgs("vercode",1)||md5(strtolower($this->syArgs("vercode",1)))!=$_SESSION['doyo_verify'])message("验证码错误");
                        }
                        $ok=false;
                        $user=$this->syArgs("user",1);
                        $email=$this->syArgs("email",1);
                        $mobile $this->syArgs('mobile',1);
 
                        if ($mobile) {
                                if ($user) {
                                        $conditions array('user' => $user,'mobile' => $mobile);
                                        $m = syDB('member')->find($conditions,null,'id,user,mobile');
                                        if(!$m){message("没有找到匹配的用户和手机号码,请确认用户名及手机号码输入正确。");}else{$ok=true;}
                                        
                                }else{
                                        $conditions array('mobile' => $mobile);
                                        $num = syDB('member')->findCount($conditions);
                                        if($num<1)message("没有找到匹配的用户和手机号,请确认用户名及手机号输入正确。");
                                        if($num>1)message("此手机号注册了多个账号,必须填写用户名才可找回密码。");
                                        if($num==1){$m = syDB('member')->find($conditions,null,'id,user,mobile');$ok=true;}
 
                                }
                        }
                        if($email){
                                if($user){
                                        $conditions array('user' => $user,'email' => $email);
                                        $m = syDB('member')->find($conditions,null,'id,user,email');
                                        if(!$m){message("没有找到匹配的用户和邮箱,请确认用户名及邮箱输入正确。");}else{$ok=true;}
                                }else{
                                        $conditions array('email' => $email);
                                        $num = syDB('member')->findCount($conditions);
                                        if($num<1)message("没有找到匹配的用户和邮箱,请确认用户名及邮箱输入正确。");
                                        if($num>1)message("此邮箱注册了多个账号,必须填写用户名才可找回密码。");
                                        if($num==1){$m = syDB('member')->find($conditions,null,'id,user,email');$ok=true;}
                                }
                        }
                        if($ok){
                                if($email){
                                        $http=get_domain();
                                        $subject=$http.'密码找回邮件';
                                        $token=md5($this->syArgs("vercode",1).md5(substr($m['pass'],mt_rand(1,10),mt_rand(10,20)).mt_rand(10000,99999)).$email.time());
                                        $url=$GLOBALS['WWW'].'index.php?c=member&a=reset_password&id='.$m['id'].'&token='.$token;
                                        $body='您在'.$GLOBALS['S']['title'].'提交了密码找回邮件,点击下面的链接进行密码重置:<a href="'.$http.$url.'" target="_blank">【点击此处进行密码重置】</a>,如果本次找回密码不是您亲自操作,请忽略本邮件。';
                                        $send=syClass('syphpmailer');
                                        $retrieve=$send->Send($email,$m['user'],$subject,$body);
                                        if(!$retrieve){
                                                message('邮件发送失败,请联系管理员。');
                                        }else{
                                                syDB('member')->update(array('id'=>$m['id']),array('token'=>$token,'tokentime'=>time()));
                                                message('密码已成功发送至您的邮箱,请点击邮件内容中的链接设置新密码,有效期3天。','?c=member');
                                        }
                                }
 
                                if ($mobile) {
 
                                        $code '123456';
                                        $mobile $_POST['mobile'];
                                        $content '您好,您的新密码为:'.$code.',请不要告诉他人。';
                                        $send = syClass('sysmsbao');
                                        $request $send->sendsms($mobile,$content);
                                        
                                        if ($request['code'] == '0') {
                                                syDB('member')->update(array('id'=>$m['id']),array('pass'=> md5(md5($code).$m['user'])));
                                                message('密码已成功发送至您的手机','?c=member');
 
                                        }else{
                                                message('短信发送失败,请联系管理员。');
 
                                        }
                                }
 
                        }
                }
                $this->display("member/password.html");
        }
        
reg 方法
 
        function reg(){
                $this->fields=fields_info(0,'member',1);
 
                if ($this->syArgs("go") == 2) {
 
                        $code = mt_rand(100000,999999);
                        $mobile $_POST['mobile'];
                        $content '您好您的注册验证码为:'.$code.',请不要告诉他人。';
 
                        $send = syClass('sysmsbao');
 
                        $request $send->sendsms($mobile,$content);
 
                        if ($request['code'] == '0') {
                                $_SESSION['smscode'] = $code;
 
                                echo $request['code'];exit;
                        }else{
                                echo $request['code'];exit;
                        }
 
                }
 
 
                if($this->syArgs("go")==1){
 
                        
                        if(!$this->syArgs('user',1))message("请输入用户名");
                        if(syDB('member')->find(array('user'=>$this->syArgs('user',1))))message("用户名已被注册,请更换");
                        if(!$this->syArgs('pass1',1))message("请输入密码");
                        if(!$this->syArgs('pass2',1))message("请输入确认密码");
                        if(!$this->syArgs('email',1))message("请输入Email");
                        if(!$this->syArgs('mobile',1))message("请输入mobile");
                        if(!$this->syArgs('svcode',1))message("请输入短信验证码");
                        if($this->syArgs('pass1',1)!=$this->syArgs('pass2',1))message("两次密码输入不一致");
                        if($GLOBALS['G_DY']['vercode']==1){
                        if(md5(strtolower($this->syArgs("vercode",1)))!=$_SESSION['doyo_verify']){message("验证码错误");}
                        }
                        if ($this->syArgs('svcode',1) != $_SESSION['smscode'] ) {
                                message("短信验证码错误");}
 
 
                        $newrow1 array(
                                'user' => $this->syArgs('user',1),
                                'pass' => md5(md5($this->syArgs("pass1",1)).$this->syArgs("user",1)),
                                'email' => $this->syArgs('email',1),
                                'mobile'=>$this->syArgs('mobile',1),
                                'gid' => 2,
                                'money' => 0,
                                'regtime' => time(),
                                'token' => '',
                        );
                        $newrow2 array();
                        $newrow2=array_merge($newrow2,$this->fields_args('member',0,1));
                        $newVerifier=$this->cu->syVerifier($newrow1);
                        if(false == $newVerifier){
                                $addnewrow=$this->cu->create($newrow1);
                                if($addnewrow==FALSE){message("注册失败,请重新注册");}
                                $arrays array(
                                        'aid' => $addnewrow,
                                );
                                $newrow2=array_merge($newrow2,$arrays);
                                syDB('member_field')->create($newrow2);
                                $_SESSION['member'] = array(
                                        'user' => $newrow1['user'],
                                        'id' => $addnewrow,
                                );
                                message("恭喜您,注册成功",$this->gourl);
                        }else{message_err($newVerifier);}
                }
                $this->display("member/reg.html");
        }

接下来我们增加接口代码,打开项目/include/ext新建一个文件 sysmsbao.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
<?php
 
if(!defined('APP_PATH')||!defined('DOYO_PATH')){exit('Access Denied');}
/**
* 短信宝短信接口
*/
class sysmsbao
{
        
        public function sendsms($mobile,$content)
        {
                $sms = syDB('sysconfig')->find(array('name'=>'sendsms'));
                $sms=unserialize($sms['sets']);
                $url 'http://api.smsbao.com/sms?u='.$sms['smskey'].'&p='.md5($sms['pass']).'&m='.$mobile.'&c=【'.$sms['sign'].'】'.$content;
 
                $request file_get_contents($url);
 
 
                if ($request == '0') {
                        return $data =array('code'=>$request);
                }else{
                        return $data array('code'=>$request);
                }
        }
}

最后我们需要一个增加数据库字段的文件,打开项目/source新建一个smsbao.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
<?php
if(!defined('APP_PATH')||!defined('DOYO_PATH')){exit('Access Denied');}
class smsbao extends syController
{        
        function __construct(){
                
        }
        function install(){
                header("Content-Type: text/html; charset=UTF-8");
                //短信宝配置
                $table_name_config=$GLOBALS['G_DY']['db']['prefix'].'sysconfig';
                $sql_config="INSERT INTO `{$table_name_config}`(name,sets) VALUES ('sendsms', '');";
                $res_config=syDB('sysconfig')->query($sql_config);
                //手机号码
                $table_name_member=$GLOBALS['G_DY']['db']['prefix'].'member';
                $sql_member="alter table {$table_name_member} add mobile char(11) comment '手机号码'";
                $res_member=syDB('sysconfig')->query($sql_member);
                if($res_config&&$res_member){
                        echo '短信宝插件安装成功,请删除source/smsbao.php';
                }else{
                        echo '安装失败';
                }
        }
}      

下面我们进行测试发送:

报备一下短信宝的VIP模板,这样就可以走短信宝的优质通道了,并且免审核了,短信内容3~5秒就可送达。
开源插件

最新更新

电商类

CMS类

微信类

文章标签