海洋cms是一套专为不同需求的站长而设计的视频点播系统,灵活,方便,人性化设计简单易用是最大的特色。采用PHP+MYSQL架构,原生PHP代码带来卓越的访问速度和负载能力免去您的后顾之优。今天小编就以新增短信接口为例,给大家讲解一下如何进行二次开发,使用的短信接口是我们短信宝短信群发平台的短信接口,我们短信宝短信群发平台的接口非常稳定,发送速度快,注册就送测试短信,推荐大家使用
1:打开项目:\data\admin目录下边创建 sms.php ,代码如下
1
|
<?php $smsbao_user = "短信宝用户名" ; $smsbao_pass = "短信宝密码" ; $smsbao_sign = "短信宝签名" ; ?> |
2:打开项目系统的核心目录如:/sgmtnc(每个项目核心目录名可能不一样)增加admin_sms.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
|
<?php header( 'Content-Type:text/html;charset=utf-8' ); require_once(dirname(__FILE__). "/config.php" ); CheckPurview(); if ($action== "set" ) { $weburl= $_POST[ 'smsbao_user' ]; $token = $_POST[ 'smsbao_pass' ]; $token = $_POST[ 'smsbao_sign' ]; $open=fopen( "../data/admin/sms.php" , "w" ); $str= '<?php ' ; $str.= '$smsbao_user = "' ; $str.="$smsbao_user "; $str.='" ; '; $str.= '$smsbao_pass = "' ; $str.="$smsbao_pass "; $str.='" ; '; $str.= '$smsbao_sign = "' ; $str.="$smsbao_sign "; $str.='" ; '; $str.= " ?>" ; fwrite($open,$str); fclose($open); ShowMsg( "成功保存设置!" , "admin_sms.php" ); exit; } ?> <!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>短信设置</title> <link href= "img/style.css" rel= "stylesheet" type= "text/css" /> <link href= "img/style.css" rel= "stylesheet" type= "text/css" /> <script src= "js/common.js" type= "text/javascript" ></script> <script src= "js/main.js" type= "text/javascript" ></script> </head> <body> <script type= "text/JavaScript" > if (parent.$( 'admincpnav' )) parent.$( 'admincpnav' ).innerHTML= '后台首页 » 管理员 » 短信设置' ;</script> <div class= "r_main" > <div class= "r_content" > <div class= "r_content_1" > <form action= "admin_sms.php?action=set" method= "post" > <table width= "100%" border= "0" cellpadding= "0" cellspacing= "0" class= "tb_style" > <tbody><tr class= "thead" > <td colspan= "5" class= "td_title" >短信设置</td> </tr> <tr> <td width= "80%" align= "left" height= "30" class= "td_border" > <?php require_once( "../data/admin/sms.php" ); ?> 短信宝用户名:<input name= "smsbao_user" value= "<?php echo $smsbao_user;?>" > </td> </tr> <tr> <td width= "80%" align= "left" height= "30" class= "td_border" > 短信宝密码:<input name= "smsbao_pass" value= "<?php echo $smsbao_pass;?>" > </td> </tr> <tr> <td width= "80%" align= "left" height= "30" class= "td_border" > 短信宝签名:<input name= "smsbao_sign" value= "<?php echo $smsbao_sign;?>" > </td> </tr> <tr> <td width= "90%" align= "left" height= "30" class= "td_border" > * 如果修改无效,请检查/data/admin/sms.php文件权限是否可写。 </td> </tr> <tr> <td width= "10%" align= "left" height= "30" class= "td_border" > <input type= "submit" value= "确 认" class= "btn" > </td> </tr> </tbody></table> </form> </div> </div> </div> <?php viewFoot(); ?> </body> </html> |
3:当前目录同时打开inc_menu.php 大概166行 增加短信设置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
'system' =>array ( 'link' => "admin_config.php" , 0=> "系统" , 1=> "<a target='I2' href='admin_config.php'>网站设置</a>" , 2=> "" , 3=> "<a target='I2' href='admin_config_mark.php'>图片水印设置</a>" , 4=> "<a target='I2' href='admin_datarelate.php?action=ftppic'>远程图片设置</a>" , 5=> "" , 6=> "<a target='I2' href='admin_player.php'>播放器设置</a>" , 7=> "<a target='I2' href='../js/player/dmplayer/admin/'>弹幕播放管理</a>" , 8=> "<a target='I2' href='admin_player.php?action=boardsource'>播放来源管理</a>" , 9=> "<a target='I2' href='admin_playerdown.php?action=boardsource'>下载来源管理</a>" , 10=> "" , 11=> "<a target='I2' href='admin_manager.php'>系统账号管理</a>" , 12=> "<a target='I2' href='admin_vcode.php'>后台登陆验证码</a>" , 13=> "<a target='I2' href='admin_isapi.php'>资源库API设置</a>" , 14=> "<a target='I2' href='admin_ip.php'>后台IP安全设置</a>" , 15=> "<a target='I2' href='admin_weixin.php'>微信公众号设置</a>" , 16=> "<a target='I2' href='admin_smtp.php'>邮件服务器设置</a>" , 17=> "<a target='I2' href='admin_sms.php'>短信设置</a>" , ), |
4:打开项目:\templets\default\html\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
|
<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.val(time); clearTimeout(res); time = 0; return ; } // 倒计时的内容写到按钮里面 sendNode.val( "剩余" + time + "秒" ); res = setTimeout( "sendTime()" , 1000); } /** * 调用处 */ $( function () { sendNode = $( "#get_code" ); // 获取发送的节点 var flg = true ; // 防止ajax重复提交的标记 // 在页面加载时,先判断一下是否上次倒计时未完成,由php计算,防止页面刷新,覆盖掉倒计时。 /** * 点击发送短信,触发事件 */ sendNode.on( "click" , function () { // 如果当前倒计时结束,则收集表单数据,并ajax提交到服务端 if (0 == time) { var phoneNum = $( "input[name='nickname']" ).val(); var myreg=/^[1][3,4,5,7,8][0-9]{9}$/; if (!myreg.test(phoneNum)) { alert( '手机号码不能为空或不正确' ); return false ; } if ( true ) {} var code = $( "input[name='validate']" ).val(); var data = { "code" : code, "phone" : phoneNum, "Obtain" : 1}; var err = "" ; if (flg == true ) { flg = false ; // ajax提交请求 $.ajax({ "url" : "reg.php" , "type" : "post" , "data" : data, "dataType" : "json" , "success" : function (msg) { $( ".errmsg" ).text( "" ); console.log(msg); if (msg == '发送成功' ) { time = 60; sendTime(); alert( "发送验证码成功!" ); } else { alert( '短信发送失败,原因' +msg); } // 刷新图形验证码 $( "#code_img" ).click(); flg = true ; } }); } return false ; } }); }); </script> |
5:打开项目:/reg.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
|
if ($_POST[ 'Obtain' ] == '1' ) { $mobile = $_POST[ 'phone' ]; $code = $_POST[ 'code' ]; $phone= "/^[1][3,4,5,7,8][0-9]{9}$/" ; if (!preg_match($phone,$mobile)||!$mobile) { echo json_encode( "手机号不正确" ); exit(); } if ($cfg_feedback_ck== '1' ) { $code = empty($code) ? '' : strtolower(trim($code)); if ($code== '' || $code != $svali) { ResetVdValue(); echo json_encode( "验证码不正确" ); exit(); } } $pcode = rand(00000,99999); require_once( "data/admin/sms.php" ); $url = 'http://api.smsbao.com/sms?u=' .$smsbao_user. '&p=' .md5($smsbao_pass). '&m=' .$mobile. '&c=【' .$smsbao_sign. '】您的验证码为' .$pcode. '请妥善保存!' ; // $ret = file_get_contents($url); $ret = 0; if ($ret == 0) { echo json_encode( '发送成功' ); $_SESSION[ 'pcode' ] = $pcode; exit; } else { echo json_encode( '发送失败' .$ret); exit; } } |
6:当前文件同时修改对应的html 大概234行
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
function viewRegister() { $mystr= "<ul>" . "<form id=\"f_Activation\" action=\"/" .$GLOBALS[ 'cfg_cmspath' ]. "reg.php?action=reg\" method=\"post\">" . "<li><input type=\"input\" name=\"m_user\" id=\"m_user\" autofocus class=\"form-control\" placeholder=\"用户名\" /></li>" . "<li><input type=\"password\" name=\"m_pwd\" class=\"form-control\" placeholder=\"密码\" /></li>" . "<li><input type=\"password\" name=\"m_pwd2\" class=\"form-control\" placeholder=\"确认密码\" /></li>" . "<li><input type=\"text\" name=\"email\" class=\"form-control\" placeholder=\"邮箱地址\" /></li>" . "<li><img id=\"vdimgck\" src=\"./include/vdimgck.php\" alt=\"看不清?点击更换\" align=\"absmiddle\" class=\"pull-right\" style='width:70px; height:32px;' onClick=\"this.src=this.src+'?'\"/><input type=\"text\" name=\"validate\" id=\"vdcode\" placeholder=\"验证码\" style='width:50%;text-transform:uppercase;' class=\"form-control\" /> </li>" . "<li style='display: flex;'><input type=\"text\" name=\"nickname\" id=\"phone\" placeholder=\"手机号\" style='width:50%;text-transform:uppercase;' class=\"form-control\" /> <input style='width: 30%;margin-left: 60px' class=\"pull-right btn btn-block btn-info\" value='获取验证码' id=\"get_code\"></li>" . "<li><input type=\"input\" name=\"mcode\" id=\"mcode\" autofocus class=\"form-control\" placeholder=\"短信验证码\" /></li>" . "<li><input type=\"submit\" value=\"注册\" class=\"btn btn-block btn-warning\"/></li>" . "<li class=\"text-center\"><a class=\"text-muted\" href=\"./login.php\">已有账号,直接登录?</a></li>" . "</form>" . "</ul>" ; return $mystr; } |
经过上面的替换,短信宝的短信平台已经替换成功了,可以正常使用了。进行测试发送:
报备一下短信宝的VIP模板,这样就可以走短信宝的优质通道了,即便遇到敏感文字我们都不会人工审核,短信内容3~5秒就可送达。
另外:我们已经开发好完整的海洋CMS V13.2系统短信宝插件,点击此链接 下载及查看安装流
最新更新
电商类
CMS类
微信类