待发短信

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

4001-021-502

工作时间

9:00-18:00

帝国CMSV_7.5新增功能模块手机登录

帝国CMS是基于B/S结构,安全、稳定、强大、灵活的网站管理系统.还提供了系统扩展框架。小编对这款系统还比较了解,今天就以增加手机登录为例为大家讲解一下如何进行二次开发,我们今天讲解的是7.5版本,使用的短信接口是我们短信宝短信群发平台的短信接口,我们短信宝短信群发平台非常稳定,发送速度快,注册就送测试短信,推荐大家使用!

需求介绍:手机验证码登陆,未注册手机号自动创建一个帐号

首先打开项目:\e\template\member\login.php 在74行左右新增手机快捷登录

?
1
2
3
4
5
6
7
8
    <tr bgcolor="#FFFFFF">
      <td height="25">&nbsp;</td>
      <td height="25">
          <input type="submit" name="Submit" value=" 登 录 ">&nbsp;&nbsp;&nbsp;
          <input type="button" name="button" value="马上注册" onclick="parent.location.href='../register/<?=$tobind?'?tobind=1':''?>';">
          <a style="cursor:pointer;"  onclick="parent.location.href='../mobilelogin'">手机号快捷登录</a>
      </td>
    </tr>

打开项目:\e\template\member\ 新增个mobilelogin.php

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
if(!defined('InEmpireCMS'))
{
    exit();
}
?>
<?php
$public_diyr['pagetitle']='会员登录';
$url="<a href=../../../>首页</a>&nbsp;>&nbsp;<a href=../cp/>会员中心</a>&nbsp;>&nbsp;会员登录";
require(ECMS_PATH.'e/template/incfile/header.php');
?>
<script src="/js/jquery.min-1.7.2.js"></script>
<br>
  <table width="500" border="0" align="center" cellpadding="3" cellspacing="1" class="tableborder">
      <form name="userloginform" method="POST" action="../doaction.php">
          <input type=hidden name=ecmsfrom value="<?=ehtmlspecialchars($_GET['from'])?>">
          <input type=hidden name=enews value="userloginform">
          <input name="groupid" type="hidden" id="groupid" value="<?=$groupid?>">
          <input name="tobind" type="hidden" id="tobind" value="<?=$tobind?>">
          <tr class="header">
              <td height="25" colspan="2"><div align="center">手机号快捷登录<?=$tobind?' (绑定账号)':''?></div></td>
          </tr>
 
 
          <tr bgcolor="#FFFFFF">
              <td height="25">手机</td>
              <td><input name="phone" type="text" id="phone" size="38"></td>
          </tr>
          <?php
          if($public_r['loginkey_ok'])
          {
          ?>
          <tr bgcolor="#FFFFFF">
              <td height="25">验证码:</td>
              <td height="25">
                  <table width="100%" border="0" cellspacing="0" cellpadding="0">
                      <tr>
                          <td width="52"><input name="key" type="text" id="key" size="6">
                          </td>
                          <td id="loginshowkey"><a href="#EmpireCMS" onclick="edoshowkey('loginshowkey','login','<?=$public_r['newsurl']?>');" title="点击显示验证码">点击显示验证码</a></td>
                      </tr>
                  </table>
              </td>
          </tr>
         <?php
          }
          ?>
          <tr>
              <td height="25" bgcolor="#FFFFFF"> <div align='left'>认证码</div></td>
              <td height="25" bgcolor="#FFFFFF"> <input name='rzm' type='text' id='rzm' maxlength='30'>
                  *<input  type="button" style="font-size: 12px; height: 22px; line-height: 19px;" value="发送验证码" onclick="sendrzm()" id="sendag"  ></td>
          </tr>
          <tr bgcolor="#FFFFFF">
              <td height="25">&nbsp; </td>
              <td height="25"> <input type="submit" name="button" value="登录"></td>
          </tr>
      </form>
  </table>
<SCRIPT language=javascript>
    <!--
    var secs = 120;
    function sendrzm(){
        var tel=$("#phone").val();
        <?
        if($public_r['loginkey_ok'])
        {
        ?>
        if($('#key').val()==''||$('#key').val().length<4){
            alert('请先填写图形验证码');
            return false;
        }
        <?
        }
        ?>
        if($.trim(tel)==''||$.trim(tel).length!=11){
            alert('请填写正确的手机号码');
        }else{
            $.getJSON('/e/member/doaction.php?enews=Loginsend&phone=' + tel ,
                function(data) {
                    if(data.d=='2'){
                        alert(data.n);
                    }else{
                        document.userloginform.sendag.disabled=true;
                        for(i=1;i<=secs;i++) {
                            window.setTimeout("update(" + i + ")", i * 1000);
                        }
                    }
 
 
                });
        }
    }
    function update(num) {
        if(num == secs) {
            document.userloginform.sendag.value ="重新发送认证码";
            document.userloginform.sendag.disabled=false;
        }
        else {
            printnr = secs-num;
            document.userloginform.sendag.value = "(" + printnr +")重新发送认证码";
        }
    }
    //-->
</SCRIPT>
<br>
<?php
require(ECMS_PATH.'e/template/incfile/footer.php');
?>

打开项目:\e\member\ 新增mobilelogin目录 以及子文件loginjs.php和index.php

loginjs.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
<?php
require("../../class/connect.php");
if(!defined('InEmpireCMS'))
{
    exit();
}
eCheckCloseMods('member');//关闭模块
$myuserid=(int)getcvar('mluserid');
$r=array();
$mhavelogin=0;
if($myuserid)
{
    include("../../class/db_sql.php");
    include("../../member/class/user.php");
    include("../../data/dbcache/MemberLevel.php");
    $link=db_connect();
    $empire=new mysqlquery();
    $mhavelogin=1;
    //数据
    $myusername=RepPostVar(getcvar('mlusername'));
    $myrnd=RepPostVar(getcvar('mlrnd'));
    $qcklgr=qCheckLoginAuthstr();
    if(!$qcklgr['islogin'])
    {
        EmptyEcmsCookie();
        $mhavelogin=0;
    }
    else
    {
        $r=$empire->fetch1("select ".eReturnSelectMemberF('userid,username,groupid,userfen,money,userdate,havemsg,checked')." from ".eReturnMemberTable()." where ".egetmf('userid')."='$myuserid' and ".egetmf('rnd')."='$myrnd' limit 1");
        if(empty($r[userid])||$r[checked]==0)
        {
            EmptyEcmsCookie();
            $mhavelogin=0;
        }
    }
    //会员等级
    if(empty($r[groupid]))
    {$groupid=eReturnMemberDefGroupid();}
    else
    {$groupid=$r[groupid];}
    $groupname=$level_r[$groupid]['groupname'];
    //点数
    $userfen=$r[userfen];
    //余额
    $money=$r[money];
    //天数
    $userdate=0;
    if($r[userdate])
    {
        $userdate=$r[userdate]-time();
        if($userdate<=0)
        {$userdate=0;}
        else
        {$userdate=round($userdate/(24*3600));}
    }
    //是否有短消息
    $havemsg="";
    if($r[havemsg])
    {
        $havemsg="<a href='".$public_r['newsurl']."e/member/msg/' target=_blank><font color=red>您有新消息</font></a>";
    }
    //$myusername=$r[username];
}
if($mhavelogin==1)
{
?>
document.write("&raquo;&nbsp;<font color=red><b><?=$myusername?></b></font>&nbsp;&nbsp;<a href=\"/e/member/my/\" target=\"_parent\"><?=$groupname?></a>&nbsp;<?=$havemsg?>&nbsp;<a href=\"/e/space/?userid=<?=$myuserid?>\" target=_blank>我的空间</a>&nbsp;&nbsp;<a href=\"/e/member/msg/\" target=_blank>短信息</a>&nbsp;&nbsp;<a href=\"/e/member/fava/\" target=_blank>收藏夹</a>&nbsp;&nbsp;<a href=\"/e/member/cp/\" target=\"_parent\">控制面板</a>&nbsp;&nbsp;<a href=\"/e/member/doaction.php?enews=exit&ecmsfrom=9\" onclick=\"return confirm(\'确认要退出?\');\">退出</a>");
<?php
    db_close();
    $empire=null;
}
else
{
?>
document.write("<form name=login method=post action=\"/e/member/doaction.php\">    <input type=hidden name=enews value=login>    <input type=hidden name=ecmsfrom value=9>    用户名:<input name=\"username\" type=\"text\" class=\"inputText\" size=\"16\" />&nbsp;    密码:<input name=\"password\" type=\"password\" class=\"inputText\" size=\"16\" />&nbsp;    <input type=\"submit\" name=\"Submit\" value=\"登陆\" class=\"inputSub\" />&nbsp;    <input type=\"button\" name=\"Submit2\" value=\"注册\" class=\"inputSub\" onclick=\"window.open(\'/e/member/register/\');\" /></form>");
<?php
}
?>

index.php新增代码

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?php
require('../../class/connect.php');
require("../../class/db_sql.php");
require('../../member/class/user.php');
$link=db_connect();
$empire=new mysqlquery();
$editor=1;
eCheckCloseMods('member');//关闭模块
$tobind=(int)$_GET['tobind'];
if($ecms_config['member']['loginurl'])
{
    Header("Location:".$ecms_config['member']['loginurl']);
    exit();
}
//导入模板
require(ECMS_PATH.'e/template/member/mobilelogin.php');
db_close();
$empire=null;
?>

打开项目:\e\member\class\member_loginfun.php 在146行增加mlogin方法

?
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
function mlogin($add){
    global $empire,$dbtbpre,$public_r,$ecms_config;
    if($ecms_config['member']['loginurl'])
    {
        Header("Location:".$ecms_config['member']['loginurl']);
        exit();
    }
    $dopr=1;
    if($_POST['prtype'])
    {
        $dopr=9;
    }
    $username=trim($add['phone']);
    $password=trim($add['phone']);
    if(!$username||!$password)
    {
        printerror("EmptyLogin","history.go(-1)",$dopr);
    }
    $tobind=(int)$add['tobind'];
    //验证码
    $keyvname='checkloginkey';
    if($public_r['loginkey_ok'])
    {
        ecmsCheckShowKey($keyvname,$add['key'],$dopr);
    }
    $username=RepPostVar($username);
    $password=RepPostVar($password);
    //手机验证码
    $tel=$add['phone'];
    $rzm=$add['rzm'];
    C_sjrl($tel,$rzm);
    $num=0;
    $zrc=$empire->fetch1("select userid from {$dbtbpre}enewsmemberadd where phone='$tel'  limit 1");
    $r=$empire->fetch1("select ".eReturnSelectMemberF('*')." from ".eReturnMemberTable()." where ".egetmf('userid')."='$zrc[0]' limit 1");
    if(!$r['userid'])
    {
        require "member_registerfun.php";
        $user_groupid=eReturnMemberDefGroupid();
        $groupid=(int)$add['groupid'];
        $groupid=empty($groupid)?$user_groupid:$groupid;
        CheckMemberGroupCanReg($groupid);
        //注册时间
        $lasttime=time();
        $registertime=eReturnAddMemberRegtime();
        $rnd=make_password(20);//产生随机密码
        $userkey=eReturnMemberUserKey();
        //密码
        $truepassword=$password;
        $salt=eReturnMemberSalt();
        $password=eDoMemberPw($password,$salt);
        $email '';
        //审核
        $checked=ReturnGroupChecked($groupid);
        if($checked&&$public_r['regacttype'])
        {
            $checked=0;
        }
        $checked=(int)$checked;
        //验证附加表必填项
        $mr['add_filepass']=ReturnTranFilepass();
        $member_r array(",truename,mycall,phone,oicq,msn,homepage,userpic,address,zip,saytext",",'','',".$add[phone].",'','','','','','',''" );
        //IP
        $regip=egetip();
        $regipport=egetipport();
 
        $sql=$empire->query("insert into ".eReturnMemberTable()."(".eReturnInsertMemberF('username,password,rnd,email,registertime,groupid,userfen,userdate,money,zgroupid,havemsg,checked,salt,userkey').") values('$username','$password','$rnd','$email','$registertime','$groupid','$public_r[reggetfen]','0','0','0','0','$checked','$salt','$userkey');");
        //取得userid
        $userid=$empire->lastid();
        //附加表
        $addr=$empire->fetch1("select * from {$dbtbpre}enewsmemberadd where userid='$userid'");
        if(!$addr['userid'])
        {
            $spacestyleid=ReturnGroupSpaceStyleid($groupid);
            $sql1=$empire->query("insert into {$dbtbpre}enewsmemberadd(userid,spacestyleid,regip,lasttime,lastip,loginnum,regipport,lastipport".$member_r[0].") values('$userid','$spacestyleid','$regip','$lasttime','$regip','1','$regipport','$regipport'".$member_r[1].");");
        }
        //更新附件
        UpdateTheFileOther(6,$userid,$mr['add_filepass'],'member');
        ecmsEmptyShowKey($keyvname);//清空验证码
        //绑定帐号
        if($tobind)
        {
            MemberConnect_BindUser($userid);
        }
        if($sql)
        {
            //审核
            if($checked==0)
            {
                $location=DoingReturnUrl("../../",$_POST['ecmsfrom']);
                printerror("RegisterSuccessCheck",$location,1);
            }
            $logincookie=0;
            if($ecms_config['member']['regcookietime'])
            {
                $logincookie=time()+$ecms_config['member']['regcookietime'];
            }
            $r=$empire->fetch1("select ".eReturnSelectMemberF('*')." from ".eReturnMemberTable()." where ".egetmf('userid')."='$userid' limit 1");
            $set1=esetcookie("mlusername",$username,$logincookie);
            $set2=esetcookie("mluserid",$userid,$logincookie);
            $set3=esetcookie("mlgroupid",$groupid,$logincookie);
            $set4=esetcookie("mlrnd",$rnd,$logincookie);
            //验证符
            qGetLoginAuthstr($userid,$username,$rnd,$groupid,$logincookie);
            //登录附加cookie
            AddLoginCookie($r);
            $location="../member/cp/";
            $returnurl=getcvar('returnurl');
            if($returnurl&&!strstr($returnurl,"e/member/iframe")&&!strstr($returnurl,"e/member/register")&&!strstr($returnurl,"enews=exit"))
            {
                $location=$returnurl;
            }
            $set5=esetcookie("returnurl","");
            //易通行系统
            DoEpassport('reg',$userid,$username,$truepassword,$salt,$email,$groupid,$registertime);
            $location=DoingReturnUrl($location,$_POST['ecmsfrom']);
            printerror("RegisterSuccess",$location,1);
        }
        else
        {printerror("DbError","history.go(-1)",1);}
    }
    else{
        if($r['checked']==0)
        {
            if($public_r['regacttype']==1)
            {
                printerror('NotCheckedUser','../member/register/regsend.php',1);
            }
            else
            {
                printerror('NotCheckedUser','',1);
            }
        }
        //绑定帐号
        if($tobind)
        {
            MemberConnect_BindUser($r['userid']);
        }
        $rnd=make_password(20);//取得随机密码
        //默认会员组
        if(empty($r['groupid']))
        {
            $r['groupid']=eReturnMemberDefGroupid();
        }
        $r['groupid']=(int)$r['groupid'];
        $lasttime=time();
        //IP
        $lastip=egetip();
        $lastipport=egetipport();
        $usql=$empire->query("update ".eReturnMemberTable()." set ".egetmf('rnd')."='$rnd',".egetmf('groupid')."='$r[groupid]' where ".egetmf('userid')."='$r[userid]'");
        $empire->query("update {$dbtbpre}enewsmemberadd set lasttime='$lasttime',lastip='$lastip',loginnum=loginnum+1,lastipport='$lastipport' where userid='$r[userid]'");
        //设置cookie
        $lifetime=(int)$add['lifetime'];
        $logincookie=0;
        if($lifetime)
        {
            $logincookie=time()+$lifetime;
        }
        $set1=esetcookie("mlusername",$username,$logincookie);
        $set2=esetcookie("mluserid",$r['userid'],$logincookie);
        $set3=esetcookie("mlgroupid",$r['groupid'],$logincookie);
        $set4=esetcookie("mlrnd",$rnd,$logincookie);
        //验证符      qGetLoginAuthstr($r['userid'],$username,$rnd,$r['groupid'],$logincookie);
        //登录附加cookie
        AddLoginCookie($r);
        $location="../member/cp/";
        $returnurl=getcvar('returnurl');
        if($returnurl)
        {
            $location=$returnurl;
        }
        if(strstr($_SERVER['HTTP_REFERER'],"e/member/iframe"))
        {
            $location="../member/iframe/";
        }
        if(strstr($location,"enews=exit")||strstr($location,"e/member/register")||strstr($_SERVER['HTTP_REFERER'],"e/member/register"))
        {
            $location="../member/cp/";
            $_POST['ecmsfrom']='';
        }
        ecmsEmptyShowKey($keyvname);//清空验证码
        $set6=esetcookie("returnurl","");
        if($set1&&$set2)
        {
            //易通行系统      DoEpassport('login',$r['userid'],$username,$password,$r['salt'],$r['email'],$r['groupid'],$r['registertime']);
            $location=DoingReturnUrl($location,$_POST['ecmsfrom']);
            printerror("LoginSuccess",$location,$dopr);
        }
        else
        {
            printerror("NotCookie","history.go(-1)",$dopr);
        }
    }
}

打开项目:\e\class\connect.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
//登录发送手机验证码
function F_rzml($tel){
    global $empire,$dbtbpre,$public_r;
 
 
    $ism=is_mobile($tel);
    if($ism == 2)
    {
        G_return("手机号码为空或者错误!");
    }
    $time=time();
    //识别码
    $gzwc=RepPostVar(getcvar('gzwrl'));
    $zr=$empire->fetch1("select * from {$dbtbpre}rz where bsm='$gzwc' and sj='$tel'  limit 1");
    if($zr['id']){
        //验证次数
        if($zr['c']>10)
        {
            G_return("该号码已多次接收不了验证码,建议更换手机重新注册!");
        }
        //验证间隔时间
        $gtime2=$zr['t']+60*2;
        if($time<$gtime2)
        {
            G_return("发送过程中,手机接收验证码需要1-2分钟,请耐心等待!");
        }
        $rm=no_make_password(6);
        $content=$rm;
        $fh=api_sendsms($tel,$content);
        if($fh){
            $sql=$empire->query("update {$dbtbpre}rz set t='$time',rzm='$rm',c=c+1 where id='$zr[id]'");
            $logincookie=$time+3600*2;
            $set1=esetcookie("gzwrz",$gzwc,$logincookie);
            G_return("验证码已发送成功,请查收!",1);
        }else{
            G_return("发送失败,请联系管理员!");
        }
    }else{
        $rm=no_make_password(6);
        $content=$rm;
        $fh=api_sendsms($tel,$content);
        if($fh){
            $gzwc=make_password(20);
            $sql=$empire->query("insert into {$dbtbpre}rz(bsm,rzm,sj,t,c) values('$gzwc','$rm','$tel','$time','1');");
            $logincookie=$time+3600*2;
            $set1=esetcookie("gzwrl",$gzwc,$logincookie);
            G_return("验证码已发送成功,请查收!",1);
        }else{
            G_return("发送失败,请联系管理员!");
        }
    }
}

打开项目:\e\member\doaction.php 在66行新增下代码

?
1
2
3
4
elseif($enews=="userloginform")//手机快捷登录
{
    mlogin($_POST);
}

好了经过以上的添加,短信宝手机功能模块就已经安装成功,可以正常使用了

报备一下短信宝的VIP模板,这样就可以走短信宝的优质通道了,即便遇到敏感文字我们都不会人工审核,短信内容3~5秒就可送达。

另外:我们已经开发好完整的帝国CMS系统短信宝插件,点击此链接 下载及查看安装流程。

 
开源插件
文章标签