zzzphp是一款开源的跨平台网站内容管理系统,他是基于PHP+MYSQL开发的 ,是一套非常适合用做系统建站或者进行二次开发的程序核心,小编对他还是比较了解的,今天小编就以新增短信接口为例,给大家讲解一下如何进行二次开发,我们今天讲解的是1.7.0版本,使用的短信接口是我们短信宝短信群发平台的短信接口,我们短信宝短信群发平台的接口非常稳定,发送速度快,注册就送测试短信,推荐大家使用。
首先打开项目:\admin\template\systemedit.tpl 修改一下代码
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
|
<div class = "show-[c:smsmark]" id= "showsms" > <div class = "form-group" > <label class = "col-sm-2 control-label" >短信宝账号</label> <div class = "col-sm-4" > <input type= "text" value= "[c:smsid]" name= "smsid" id= "smsid" class = "form-control" > </div> <span class = "help-block m-b-none" ><i class = "fa fa-info-circle" ></i>还没有注册账号<a href= "http://www.smsbao.com/register.jhtml" style= "border-top-color: #d21a31" >立即注册</a> </span> </div> <div class = "form-group" > <label class = "col-sm-2 control-label" >密码</label> <div class = "col-sm-4" > <input type= "text" value= "[c:smspw]" name= "smspw" id= "smspw" class = "form-control" > </div> <span class = "help-block m-b-none" ><i class = "fa fa-info-circle" ></i> 32位字母数字组合</span> </div> <div class = "form-group" > <label class = "col-sm-2 control-label" >短信宝签名</label> <div class = "col-sm-4" > <input type= "text" value= "[c:smsing]" name= "smsing" id= "smsing" class = "form-control" > </div> <div class = "form-group" > <label class = "col-sm-2 control-label" >注册短信验证</label> <div class = "col-sm-1" > <input type= "checkbox" name= "regsendsms" value= "1" class = "js-switch" { $check_onoff [c regsendsms], "checked" }> <span class = "help-block m-b-none" >开启</span> </div> <label class = "col-sm-2 control-label" >找回密码验证</label> <div class = "col-sm-1" > <input type= "checkbox" name= "forgetsendsms" value= "1" class = "js-switch" { $check_onoff [c forgetsendsms], "checked" } > <span class = "help-block m-b-none" >开启</span> </div> </div> <div class = "form-group" > <label class = "col-sm-2 control-label" >测试短信配置</label> <div class = "col-sm-2" > <input type= "text" id= "testphone" name= "testphone" placeholder= "手机号" class = "form-control" > </div> <div class = "col-sm-4" > <button type= "button" class = "btn btn-info" id= "trysms" ><i class = "fa fa-commenting" ></i> 发送测试短信</button> </div> </div> <div class = "form-group" > <label class = "col-sm-2 control-label" >余额</label> <div class = "col-sm-2" > <input type= "button" class = "btn btn-outline btn-danger" id= "smsnum" value= "查询" > </div> </div> <div class = "form-group" > <label class = "col-sm-2 control-label" >发送记录</label> <div class = "col-sm-2" > <button type= "button" onClick= "opennew('../plugins/sms/sms_list.php')" class = "btn btn-outline btn-success" >查看发送记录</button> </div> </div> </div> </div> |
打开项目:\admin\save.php 修改代码
1
2
3
4
5
6
7
8
9
|
$smsmark =getform( 'smsmark' , 'post' ); $smsid =getform( 'smsid' , 'post' ); $smspw =getform( 'smspw' , 'post' ); $smsing =getform( 'smsing' , 'post' ); //if (strlen($smsid)<5 || strlen($smspw)<32) $smsmark=0; 'smsmark' => $smsmark , 'smsid' => $smsid , 'smspw' => $smspw , 'smsing' => $smsing , |
打开项目:\inc\zzz_main.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
|
function send_smsBao( $mobile , $content ){ if ( conf( 'smsmark' ) == 0 ) exit ; $t0 = time(); $t1 = get_session( 'smstime' ); $t2 = 59 - ( $t0 - $t1 ); $ip = ip(); if ( $t2 > 0 ) die ( '0请等待' . $t2 . '秒再尝试' ); if ( empty ( $_SESSION [ 'code' ] ) ) die ( '0警报:正在尝试刷短信,已通知管理员并将你加入黑名单。' ); $prevtime = strtotime ( db_select( 'sms' , 'smsaddtime' , array ( 'smsip' => $ip ), array ( 'id' => 'desc' ) ) ); $t3 = $t0 - $prevtime ; if ( $t3 < 60 ) die ( '0请不要尝试连续请求!' ); $smsid = conf( 'smsid' ); $smspw = md5(conf( 'smspw' )); $smsing = conf( 'smsing' ); $content = '【' . $smsing . '】' . $content ; $sendurl = $url . "sms?u=" . $smsid . "&p=" . $smspw . "&m=" . $mobile . "&c=" .urlencode( $content ); $result = file_get_contents ( $sendurl ); switch ( $result ) { case "0" : $tempstr = "1发送成功" ; break ; case "-1" : $tempstr = "0参数不全" ; break ; case "-2" : $tempstr = "0服务器空间不支持,请确认支持curl或者fsocket,联系您的空间商解决或者更换空间!" ; break ; case "30" : $tempstr = "密码错误" ; break ; case "40" : $tempstr = "0账号不存在" ; break ; case "-5" : $tempstr = "0内容过长" ; break ; case "41" : $tempstr = "0余额不足" ; break ; case "42" : $tempstr = "0帐户已过期" ; break ; case "43" : $tempstr = "0IP地址限制" ; break ; case "50" : $tempstr = "0内容含有敏感词" ; break ; default : $tempstr = "0未知错误" ; } set_session( 'smstime' , $t0 ); db_exec( "insert into [dbpre]sms(smsmobile,smscontent,smsip,smsaddtime,smsbackinfo,smsonoff,smsid,smspw)values('" . $mobile . "','" . $content . "','" . $ip . "','" . date ( 'Y-m-d H:i:s ' ) . "' , '" . $tempstr . "' ," . cleft( $tempstr , 0, 1 ) . ",'" . $smsid . "','" . hidestr( $smspw , 8 ) . "')" ); return $tempstr ; } |
打开项目:\plugins\sms\sms.php 修改下其中代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
function try_sms(){ $mobile = getform( "mobile" , 'post' ); return send_smsBao( $mobile , '这是一条测试短信,您的验证码是1234。' ); } function sendcode(){ $smsphone =getform( "phonenum" , "both" ); $smscode = randname(4, 'num' ); $smsdata =send_smsBao( $smsphone , "验证码为" . $smscode . ",有效期10分钟,请不要把验证码泄露给其他人。" ); set_session( "smscode" , $smscode ); set_session( "smsphone" , $smsphone ); echo $smsdata ; } |
打开项目:\plugins\sms\sms.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
|
function sendCode(obj){ var phonenum = $( "#phonenum" ).val(); if (phonenum.length !=11){ layer.open({content: '请先填写正确的手机号!' }); $( "#phonenum" ).blur() return false; } if ( $( "#imgcode" ).length > 0 ) { var code = $( "#imgcode" ).val(); if (code.length!=4){ layer.open({content: '请先填写图形验证码' }); $( "#imgcode" ).blur() return false; } else { $.post( "/zzzphp/plugins/sms/sms.php?act=getcode" , function (imgcode){ if (imgcode!=code){ layer.open({content: '请填写正确的验证码!' }); $( "#imgcode" ).blur() } }); } } var result = isPhoneNum(); if (result) { $.post( "/zzzphp/plugins/sms/sms.php?act=sendcode&phonenum=" + phonenum, function (data) { var act = data.substring(0, 1); var info = data.substring(1); if (act == 1) { addCookie( "secondsremained" , 60, 60); //添加cookie记录,有效时间60s settime(obj); //开始倒计时 } else if (act == 0) { layer.open({ content: info }) }; }); } } |
打开项目:\config\zzz_config.php 添加一下短信配置代码
1
2
3
4
5
6
7
8
|
//短信 'smsmark' => '1' , //短信开关 'smsid' => '' , //短信接口账号 'smspw' => '' , //短信接口密码 'smsing' => '' , 'regsendsms' => '1' , //注册发送验证码 'forgetsendsms' => '1' , //忘记密码发送验证码 'plugurl' => 'zzzcms.com' , //授权域名,只填写主域名即可,不加www |
经过上面的替换,短信宝的短信平台已经替换成功了,可以正常使用了。
报备一下短信宝的VIP模板,这样就可以走短信宝的优质通道了,即便遇到敏感文字我们都不会人工审核,短信内容3~5秒就可送达。
另外:我们已经开发好完整的zzzPhp系统短信宝插件,点击此链接 下载及查看安装流程。
最新更新
电商类
CMS类
微信类