PbootCMS是全新内核且永久开源免费的PHP企业网站开发建设管理系统,是一套高效、简洁、 强悍的可免费商用的PHP CMS源码,能够满足各类企业网站开发建设的需要。系统采用简单到想哭的模板标签,只要懂HTML就可快速开发企业网站。小编对他还是比较了解的,今天小编就以留言模块新增短信接口为例,给大家讲解一下如何进行二次开发,我们今天讲解的是v3.2.4版本,使用的短信接口是我们短信宝短信群发平台的短信接口,我们短信宝短信群发平台的接口非常稳定,发送速度快,注册就送测试短信,推荐大家使用
1:打开项目:apps\admin\view\default\system\config.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
|
<ul class= "layui-tab-title" > <li class= "layui-this" lay-id= "t1" >基本配置</li> <li lay-id= "t2" >邮件通知</li> <li lay-id= "t3" >百度接口</li> <li lay-id= "t4" >WebAPI</li> <li lay-id= "t5" >图片水印</li> <li lay-id= "t6" >安全配置</li> <li lay-id= "t7" >URL规则</li> <li lay-id= "t8" >标题样式</li> <li lay-id= "t9" >会员配置</li> <li lay-id= "t10" >短信配置</li> </ul> <div class= "layui-tab-item" > <form action= "{url./admin/Config/index}" method= "post" class= "layui-form" > <input type= "hidden" name= "formcheck" value= "{$formcheck}" > <div class= "layui-form-item" > <label class= "layui-form-label" >是否开启</label> <div class= "layui-input-block" > <input type= "radio" name= "sms_status" value= "1" { if ([$configs.sms_status.value]==1)} checked= "checked" {/ if } title= "是" > <input type= "radio" name= "sms_status" value= "0" { if ([$configs.sms_status.value]==0)} checked= "checked" {/ if } title= "否" > </div> </div> <div class= "layui-form-item" > <label class= "layui-form-label" >短信宝账号</label> <div class= "layui-input-inline" > <input type= "text" name= "sms_account" value= "{$configs.sms_account.value}" placeholder= "请输入短信宝账号" class= "layui-input" > </div> </div> <div class= "layui-form-item" > <label class= "layui-form-label" >短信宝密码</label> <div class= "layui-input-inline" > <input type= "password" name= "sms_pwd" value= "{$configs.sms_pwd.value}" placeholder= "请输入短信宝密码" class= "layui-input" > </div> </div> <div class= "layui-form-item" > <label class= "layui-form-label" >短信宝签名</label> <div class= "layui-input-inline" > <input type= "text" name= "sms_signid" value= "{$configs.sms_signid.value}" placeholder= "请输入短信宝签名" class= "layui-input" > </div> </div> <div class= "layui-form-item" > <label class= "layui-form-label" >留言发送短信</label> <div class= "layui-input-block" > <input type= "radio" name= "message_send_sms" value= "1" { if ([$configs.message_send_sms.value]==1)} checked= "checked" {/ if } title= "启用" > <input type= "radio" name= "message_send_sms" value= "0" { if ([$configs.message_send_sms.value]==0)} checked= "checked" {/ if } title= "禁用" > </div> </div> <div class= "layui-form-item" > <label class= "layui-form-label" >表单发送短信</label> <div class= "layui-input-block" > <input type= "radio" name= "form_send_sms" value= "1" { if ([$configs.form_send_sms.value]==1)} checked= "checked" {/ if } title= "启用" > <input type= "radio" name= "form_send_sms" value= "0" { if ([$configs.form_send_sms.value]==0)} checked= "checked" {/ if } title= "禁用" > </div> </div> <div class= "layui-form-item" > <label class= "layui-form-label" >评论发送短信</label> <div class= "layui-input-block" > <input type= "radio" name= "comment_send_sms" value= "1" { if ([$configs.comment_send_sms.value]==1)} checked= "checked" {/ if } title= "启用" > <input type= "radio" name= "comment_send_sms" value= "0" { if ([$configs.comment_send_sms.value]==0)} checked= "checked" {/ if } title= "禁用" > </div> </div> <div class= "layui-form-item" > <label class= "layui-form-label" >信息接收手机号</label> <div class= "layui-input-inline" > <input type= "text" name= "sms_send_to" value= "{$configs.sms_send_to.value}" placeholder= "请输入信息接收手机号" class= "layui-input" > </div> </div> |
2:打开项目:apps\admin\controller\system\ConfigController.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
|
if ($_POST) { unset($_POST[ 'upload' ]); // 去除上传组件 if (isset($_POST[ 'sn' ])) { $_POST[ 'licensecode' ] = base64_encode(post( 'sn' ) . '/' . post( 'sn_user' )) . substr(post( 'sn' ), 1, 1); } foreach ($_POST as $key => $value) { if (! preg_match( '/^[\w\-]+$/' , $key)) { continue ; } $config = array( 'debug' , // 'sn', // 'sn_user', 'pagenum' , 'tpl_html_cache' , 'tpl_html_cache_time' , 'session_in_sitepath' ); if (in_array($key, $config)) { if ($key == 'tpl_html_cache_time' && ! $value) { $value = 900; } else { $value = post($key); } $ this ->modConfig($key, $value); } else { $ this ->modDbConfig($key); } } $ this ->log( '修改参数配置成功!' ); path_delete(RUN_PATH . '/config' ); // 清理缓存的配置文件 switch (post( 'submit' )) { case 'email' : success( '修改成功!' , url( '/admin/Config/index' . get_tab( 't2' ), false )); break ; case 'baidu' : success( '修改成功!' , url( '/admin/Config/index' . get_tab( 't3' ), false )); break ; case 'api' : success( '修改成功!' , url( '/admin/Config/index' . get_tab( 't4' ), false )); break ; case 'watermark' : success( '修改成功!' , url( '/admin/Config/index' . get_tab( 't5' ), false )); break ; case 'security' : success( '修改成功!' , url( '/admin/Config/index' . get_tab( 't6' ), false )); break ; case 'urlrule' : success( '修改成功!' , url( '/admin/Config/index' . get_tab( 't7' ), false )); break ; case 'pagetitle' : success( '修改成功!' , url( '/admin/Config/index' . get_tab( 't8' ), false )); break ; case 'member' : success( '修改成功!' , url( '/admin/Config/index' . get_tab( 't9' ), false )); break ; case 'upgrade' : success( '修改成功!' , url( '/admin/Upgrade/index' . get_tab( 't2' ), false )); break ; case 'sms' : success( '修改成功!' , url( '/admin/Config/index' . get_tab( 't10' ), false )); break ; default : success( '修改成功!' , url( '/admin/Config/index' , false )); } } |
3:打开项目:default\html\message.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
|
<div class= "form-group" > <label for = "mobile" >手 机</label> <div> <input type= "text" name= "mobile" required id= "mobile" placeholder= "请输入联系人手机" > <button id= "send-btn" onclick= "sendSms()" >发送验证码</button> </div> </div> <div class= "form-group" > <label for = "checkcode" >手机验证码</label> <div class= "row" > <div class= "col-6" > <input type= "text" name= "mobilecode" required id= "mobilecode" class= "form-control" placeholder= "请输入手机验证码" > </div> </div> </div> <script> function sendSms() { // 倒计时60秒 var countdown = 60; var btn = document.getElementById( "send-btn" ); let checkcode = $( "#checkcode" ).val(); let mobile = $( "#mobile" ).val(); $.ajax({ type: 'get' , url: '?member/msgSms' , dataType: 'json' , data: { mobile: mobile, checkcode: checkcode }, success: function (response, status) { console.log(response) if (response.code){ btn.disabled = true ; btn.innerHTML = countdown + "秒后重发" ; btn.style.color = 'black' ; var timer = setInterval( function () { countdown -= 1; console.log(countdown) if (countdown <= 0) { clearInterval(timer); btn.disabled = false ; btn.innerHTML = "发送验证码" ; } else { btn.innerHTML = countdown + "秒后重发" ; } }, 1000); alert( "短信发送成功" ); } else { alert(response.data); $( '.codeimg' ).click(); //更新验证码 } }, error: function (xhr,status,error){ alert( '返回数据异常!' ); } }); return false ; } </script> |
4:打开项目:\home\controller\MemberController.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
|
//留言发送短信 public function msgSms(){ if ($ this ->config( 'message_status' ) === '0' ) { error( '系统已经关闭留言功能,请到后台开启再试!' ); } if (time() - session( 'lastsms' ) < 60) { alert_back( '您提交太频繁了,请稍后再试!' ); } // 需登录 if ($ this ->config( 'message_rqlogin' ) && ! session( 'pboot_uid' )) { if (! ! $backurl = $_SERVER[ 'HTTP_REFERER' ]) { alert_location( "请先注册登录后再留言!" , Url::home( 'member/login' , null , "backurl=" . urlencode($backurl))); } else { alert_location( "请先注册登录后再留言!" , Url::home( 'member/login' )); } } // 验证码验证 $checkcode = strtolower(get( 'checkcode' , 'var' )); if ($ this ->config( 'message_check_code' ) !== '0' ) { if (! $checkcode) { alert_back( '验证码不能为空!' ); } if ($checkcode != session( 'checkcode' )) { alert_back( '验证码错误!' ); } } $mobile = get( 'mobile' ); if (!preg_match( '/^1[3-9]\d{9}$/' , $mobile)) { alert_back( '手机号码格式错误!' ); } $code = mt_rand(1000,9999); session( 'mobilecode' , $code); // $mail_subject = "【" . CMSNAME . "】您的验证码为" . $code . "请注意查收!" ; $res = sendsms($ this ->config(),$mobile,$mail_subject); if ($res){ session( 'lastsms' , time()); //记录最后一次发送短信 alert_location( '发送成功!' , '-1' , 1); } } |
5:打开项目:apps\home\controller\MessageController.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
|
public function index() { if ($_POST) { if ($ this ->config( 'message_status' ) === '0' ) { error( '系统已经关闭留言功能,请到后台开启再试!' ); } if (time() - session( 'lastsub' ) < 10) { alert_back( '您提交太频繁了,请稍后再试!' ); } // 需登录 if ($ this ->config( 'message_rqlogin' ) && ! session( 'pboot_uid' )) { if (! ! $backurl = $_SERVER[ 'HTTP_REFERER' ]) { alert_location( "请先注册登录后再留言!" , Url::home( 'member/login' , null , "backurl=" . urlencode($backurl))); } else { alert_location( "请先注册登录后再留言!" , Url::home( 'member/login' )); } } // 验证码验证 // $checkcode = strtolower(post('checkcode', 'var')); // if ($this->config('message_check_code') !== '0') { // if (! $checkcode) { // alert_back('验证码不能为空!'); // } // // if ($checkcode != session('checkcode')) { // alert_back('验证码错误!'); // } // } //短信验证码校验 $mobilecode = strtolower(post( 'mobilecode' , 'var' )); if (! $mobilecode) { alert_back( '验证码不能为空!' ); } if ($mobilecode != session( 'mobilecode' )) { alert_back( '短信验证码错误!' ); } // 读取字段 if (! $form = $ this ->model->getFormField(1)) { alert_back( '留言表单不存在任何字段,请核对后重试!' ); } // 接收数据 $mail_body = '' ; foreach ($form as $value) { $field_data = post($value->name); if (is_array($field_data)) { // 如果是多选等情况时转换 $field_data = implode( ',' , $field_data); } $field_data = preg_replace_r( '/pboot:if/i' , '' , $field_data); if ($value->required && ! $field_data) { alert_back($value->description . '不能为空!' ); } else { $data[$value->name] = $field_data; $mail_body .= $value->description . ':' . $field_data . '<br>' ; } } $status = $ this ->config( 'message_verify' ) === '0' ? 1 : 0; // 设置额外数据 if ($data) { $data[ 'acode' ] = get_lg(); $data[ 'user_ip' ] = ip2long(get_user_ip()); $data[ 'user_os' ] = get_user_os(); $data[ 'user_bs' ] = get_user_bs(); $data[ 'recontent' ] = '' ; $data[ 'status' ] = $status; $data[ 'create_user' ] = 'guest' ; $data[ 'update_user' ] = 'guest' ; $data[ 'uid' ] = session( 'pboot_uid' ); } if ($ this ->model->addMessage($data)) { session( 'lastsub' , time()); // 记录最后提交时间 $ this ->log( '留言提交成功!' ); if ($ this ->config( 'message_send_mail' ) && $ this ->config( 'message_send_to' )) { $mail_subject = "【" . CMSNAME . "】您有新的" . $value->form_name . "信息,请注意查收!" ; $mail_body .= '<br>来自网站 ' . get_http_url() . ' (' . date( 'Y-m-d H:i:s' ) . ')' ; sendmail($ this ->config(), $ this ->config( 'message_send_to' ), $mail_subject, $mail_body); } alert_location( '提交成功!' , '-1' , 1); } else { $ this ->log( '留言提交失败!' ); alert_back( '提交失败!' ); } } else { alert_back( '提交失败,请使用POST方式提交!' ); } } } |
6:打开项目:\core\function\helper.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
|
// 发送短信 function sendsms(array $config, $to, $content) { $statusStr = array( "0" => "短信发送成功" , "-1" => "参数不全" , "-2" => "服务器空间不支持,请确认支持curl或者fsocket,联系您的空间商解决或者更换空间!" , "30" => "密码错误" , "40" => "账号不存在" , "41" => "余额不足" , "42" => "帐户已过期" , "43" => "IP地址限制" , "50" => "内容含有敏感词" ); if (! $to || ! $content) { return false ; } if ($config[ 'sms_status' ] == 0){ alert_back( '短信暂未开启' ); } if (! isset($config[ 'sms_status' ]) || ! isset($config[ 'sms_pwd' ]) || ! isset($config[ 'sms_signid' ])) { alert_back( '短信发送参数配置有误' ); } $user = $config[ 'sms_account' ]; $pass = md5($config[ 'sms_pwd' ]); $content = "【" . $config[ 'sms_signid' ] . "】" .$content; $phone = $to; // 替换空格 $sendurl = $smsapi. "sms?u=" .$user. "&p=" .$pass. "&m=" .$phone. "&c=" .urlencode($content); $res =file_get_contents($sendurl) ; if ($res == 0) { return true ; } else { alert_back( '短信发送失败,' . $statusStr[$res]); } } |
经过上面的替换,短信宝的短信平台已经替换成功了,可以正常使用了。进行测试发送:
报备一下短信宝的VIP模板,这样就可以走短信宝的优质通道了,即便遇到敏感文字我们都不会人工审核,短信内容3~5秒就可送达。
另外:我们已经开发好完整的PbootCMS_V3.2.4系统留言模块短信宝插件,点击此链接 下载及查看安装流程
最新更新
电商类
CMS类
微信类