PbootCMS是全新內(nèi)核且永久開源免費(fèi)的PHP企業(yè)網(wǎng)站開發(fā)建設(shè)管理系統(tǒng),是一套高效、簡潔、 強(qiáng)悍的可免費(fèi)商用的PHP CMS源碼,能夠滿足各類企業(yè)網(wǎng)站開發(fā)建設(shè)的需要。系統(tǒng)采用簡單到想哭的模板標(biāo)簽,只要懂HTML就可快速開發(fā)企業(yè)網(wǎng)站。小編對他還是比較了解的,今天小編就以新增短信接口為例,給大家講解一下如何進(jìn)行二次開發(fā),我們今天講解的是v3.1.2版本,使用的短信接口是我們短信寶短信群發(fā)平臺的短信接口,我們短信寶短信群發(fā)平臺的接口非常穩(wěn)定,發(fā)送速度快,注冊就送測試短信,推薦大家使用
1:打開項目:apps\admin\view\default\system\config.html 增加短信設(shè)置頁面
|
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
|
<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> |
2:打開相同項目:apps\admin\view\default\system\config.html 修改大概在707行
|
1
2
3
4
5
6
7
8
9
|
<div class="layui-form-item"> <label class="layui-form-label">會員注冊驗證碼</label> <div class="layui-input-block"> <input type="radio" name="register_check_code" value="0" {if([$configs.register_check_code.value]=='0')} checked="checked" {/if} title="禁用"> <input type="radio" name="register_check_code" value="1" {if([$configs.register_check_code.value]=='1'||[$configs.register_check_code.value]=='')} checked="checked" {/if} title="普通驗證碼"> <input type="radio" name="register_check_code" value="2" {if([$configs.register_check_code.value]=='2')} checked="checked" {/if} title="郵箱驗證碼"> <input type="radio" name="register_check_code" value="3" {if([$configs.register_check_code.value]=='3')} checked="checked" {/if} title="短信驗證碼"> </div> </div> |
3:打開項目: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
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
|
public function index() { if (! ! $action = get('action')) { switch ($action) { case 'sendemail': $rs = sendmail($this->config(), get('to'), '【' . CMSNAME . '】測試郵件', '歡迎您使用' . CMSNAME . '網(wǎng)站開發(fā)管理系統(tǒng)!'); if ($rs === true) { alert_back('測試郵件發(fā)送成功!'); } else { error('發(fā)送失?。? . $rs); } break; } } // 修改參數(shù)配置 if ($_POST) { unset($_POST['upload']); // 去除上傳組件 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('修改參數(shù)配置成功!'); 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)); } } $configs = $this->model->getList(); $configs['debug']['value'] = $this->config('debug'); $configs['sn']['value'] = $this->config('sn'); $configs['sn_user']['value'] = $this->config('sn_user'); $configs['session_in_sitepath']['value'] = $this->config('session_in_sitepath'); $configs['pagenum']['value'] = $this->config('pagenum'); $configs['url_type']['value'] = $this->config('url_type'); $configs['tpl_html_cache']['value'] = $this->config('tpl_html_cache'); $configs['tpl_html_cache_time']['value'] = $this->config('tpl_html_cache_time'); $this->assign('configs', $configs); $this->assign('groups', model('admin.member.MemberGroup')->getSelect()); $this->display('system/config.html'); } |
4:打開項目:apps\home\controller\ParserController.php 修改大概143行
|
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
|
public function parserSingleLabel($content) { $content = str_replace('{pboot:ucenter}', Url::home('member/ucenter'), $content); // 用戶中心 if (! ! $url = get("backurl")) { // 獲取會跳地址 $content = str_replace('{pboot:login}', Url::home('member/login', null, "backurl=" . urlencode($url)), $content); // 登錄地址 } else { $content = str_replace('{pboot:login}', Url::home('member/login'), $content); // 登錄地址 } $content = str_replace('{pboot:register}', Url::home('member/register'), $content); // 注冊地址 $content = str_replace('{pboot:isregister}', Url::home('member/isRegister'), $content); // 檢查是否注冊地址 $content = str_replace('{pboot:umodify}', Url::home('member/umodify'), $content); // 修改資料地址 $content = str_replace('{pboot:logout}', Url::home('member/logout'), $content); // 推出登錄 $content = str_replace('{pboot:upload}', Url::home('member/upload'), $content); // 上傳資料 if (strpos($content, '{pboot:sendemail}')) { session('sendemail', true); // 避免非法外部提交 $content = str_replace('{pboot:sendemail}', Url::home('member/sendEmail'), $content); // 上傳資料 } else { session('sendemail', false); } if (strpos($content, '{pboot:sendsms}')) { session('sendsms', true); // 避免非法外部提交 $content = str_replace('{pboot:sendsms}', Url::home('member/sendSms'), $content); // 發(fā)送短信 } else { session('sendsms', false); } $content = str_replace('{pboot:islogin}', session('pboot_uid') ? 1 : 0, $content); // 是否登錄 if (strpos($content, '{pboot:mustlogin}') !== false) { $content = str_replace('{pboot:mustlogin}', '', $content); if (! session('pboot_uid')) { // 沒有經(jīng)登錄 if ($this->config('login_no_wait')) { location(Url::home('member/login', null, "backurl=" . urlencode(get_current_url()))); } else { error('您的權(quán)限不足,無法瀏覽本頁面!', Url::home('member/login', null, "backurl=" . urlencode(get_current_url()))); } } } $content = str_replace('{pboot:msgaction}', Url::home('message'), $content); // 留言提交路徑 $content = str_replace('{pboot:scaction}', Url::home('search'), $content); // 搜索提交路徑 $content = str_replace('{pboot:msgcodestatus}', $this->config('message_check_code') === '0' ? 0 : 1, $content); // 是否開留言啟驗證碼 $content = str_replace('{pboot:formcodestatus}', $this->config('form_check_code') === '0' ? 0 : 1, $content); // 是否開啟表單驗證碼 $content = str_replace('{pboot:checkcode}', CORE_DIR . '/code.php', $content); // 驗證碼路徑 $content = str_replace('{pboot:lgpath}', Url::get('home/Do/area'), $content); // 多語言切換前置路徑,如{pboot:lgpath}?lg=cn $content = str_replace('{pboot:appid}', $this->config('api_appid'), $content); // API認(rèn)證用戶 $content = str_replace('{pboot:timestamp}', time(), $content); // 認(rèn)證時間戳 $content = str_replace('{pboot:signature}', md5(md5($this->config('api_appid') . $this->config('api_secret') . time())), $content); // API認(rèn)證密鑰 $content = str_replace('{pboot:httpurl}', get_http_url(), $content); // 當(dāng)前訪問的域名地址 $content = str_replace('{pboot:pageurl}', get_current_url(), $content); // 當(dāng)前頁面的地址 $content = str_replace('{pboot:registercodestatus}', $this->config('register_check_code') === '0' ? 0 : ($this->config('register_check_code') ?: 1), $content); // 是否開啟注冊驗證碼 $content = str_replace('{pboot:logincodestatus}', $this->config('login_check_code') === '0' ? 0 : 1, $content); // 是否開啟評論驗證碼 $content = str_replace('{pboot:commentcodestatus}', $this->config('comment_check_code') === '0' ? 0 : 1, $content); // 是否開啟評論驗證碼 $content = str_replace('{pboot:commentaction}', Url::home('comment/add', null, "contentid={content:id}"), $content); // 評論提交路徑 $content = str_replace('{pboot:mycommentpage}', Url::home('comment/my'), $content); // 我的評論 $content = str_replace('{pboot:registerstatus}', $this->config('register_status') === '0' ? 0 : 1, $content); // 是否開啟注冊 $content = str_replace('{pboot:loginstatus}', $this->config('login_status') === '0' ? 0 : 1, $content); // 是否開啟登錄 $content = str_replace('{pboot:commentstatus}', $this->config('comment_status') === '0' ? 0 : 1, $content); // 是否開啟評論 // 記錄蜘蛛爬行 if ($this->config('spiderlog') !== '0') { if ($this->config('tpl_html_cache')) { // 緩存時插入script,否則直接執(zhí)行 $spidercode = "<script src='" . Url::home('Spider', null, 'url=' . URL) . "' async='async'></script>"; $content = preg_replace('/(<\/body>)/i', $spidercode . "\n$1", $content); } else { $spider = new SpiderController(URL); $spider->index(); } } return $content; } |
5:打開項目:template\default\html\member\register.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
|
<div class="container pages"> {include file=comm/position.html} <!-- 用戶注冊 --> <div class="row"> <div class="col-lg-3"></div> <div class="col-12 col-lg-6"> <form class="my-4" onsubmit="return register(this);"> {pboot:if({pboot:registercodestatus}==3)} <div class="form-group"> <label for="username">手機(jī)號</label> <input type="text" name="username" required id="username" onblur="isRegister()" class="form-control" placeholder="請輸入登錄賬號"> <div id="usernote"></div> </div> {else} <div class="form-group"> <label for="username">賬 號</label> <input type="text" name="username" required id="username" onblur="isRegister()" class="form-control" placeholder="請輸入登錄賬號"> <div id="usernote"></div> </div> {/pboot:if} <div class="form-group"> <label for="nickname">昵 稱</label> <input type="text" name="nickname" required id="nickname" class="form-control" placeholder="請輸入賬號昵稱"> </div> <div class="form-group"> <label for="password">密 碼</label> <input type="password" name="password" required id="password" class="form-control" placeholder="請輸入登錄密碼"> </div> <div class="form-group"> <label for="rpassword">確認(rèn)密碼</label> <input type="password" name="rpassword" required id="rpassword" class="form-control" placeholder="請再次輸入登錄密碼"> </div> {pboot:if({pboot:registercodestatus}==1)} <div class="form-group"> <label for="checkcode">驗證碼</label> <div class="row"> <div class="col-6"> <input type="text" name="checkcode" required id="checkcode" class="form-control" placeholder="請輸入驗證碼"> </div> <div class="col-6"> <img title="點(diǎn)擊刷新" style="height:33px;" id="codeimg" src="{pboot:checkcode}" onclick="this.src='{pboot:checkcode}?'+Math.round(Math.random()*10);" /> </div> </div> </div> {/pboot:if} {pboot:if({pboot:registercodestatus}==2)} <div class="form-group"> <label for="checkcode">郵箱驗證碼</label> <div class="row"> <div class="col-6"> <input type="text" name="checkcode" required id="checkcode" class="form-control" placeholder="請輸入驗證碼"> </div> <div class="col-6"> <span class="btn btn-info mb-2" onclick="sendEmail();">發(fā)送</span> </div> </div> </div> {/pboot:if} {pboot:if({pboot:registercodestatus}==3)} <div class="form-group"> <label for="checkcode">手機(jī)驗證碼</label> <div class="row"> <div class="col-6"> <input type="text" name="checkcode" required id="checkcode" class="form-control" placeholder="請輸入驗證碼"> </div> <div class="col-6"> <span class="btn btn-info mb-2" onclick="sendSms();">發(fā)送</span> </div> </div> </div> {/pboot:if} <div class="form-group"> <button type="submit" class="btn btn-info mb-2">立即注冊</button> <span class="text-secondary ml-3">已有賬號?<a href="{pboot:login}">馬上登錄</a></span> </div> </form> </div> <div class="col-lg-3"></div> </div> </div> |
6:打開項目:apps\home\controller\MemberController.php 增加注冊模塊短信發(fā)送函數(shù)
|
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
|
public function sendSms() { $to = post('to'); if ($this->config('register_check_code') != 3) { json(0, '發(fā)送失敗,后臺配置非短信驗證碼模式!'); } if (! preg_match('/^1[0-9]{10}$/', $to)) { json(0, '賬號格式不正確,請輸入正確的手機(jī)號碼!'); } if (! session('sendsms')) { json(0, '非法提交發(fā)送短信!'); } if (time() - session('lastsendsms') < 60) { json(0, '您提交太頻繁了,請稍后再試!'); } // 檢查手機(jī)注冊 if ($this->model->checkUsername("usermobile='$to' OR username='$to'")) { json(0, '您輸入的手機(jī)號已被注冊!'); } $rs = false; if ($to) { $code = create_code(4); session('checkcode', strtolower($code)); $mail_body = "您的驗證碼為:" . $code; $rs = sendsms($this->config(), $to, $mail_body); } if ($rs === true) { session('lastsendsms', time()); // 記錄最后提交時間 json(1, '發(fā)送成功!'); } else { json(0, '發(fā)送失敗,' . $rs); } } |
7:打開項目:core\function\helper.php 增加短信寶發(fā)送接口
|
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 sendsms(array $config, $to, $content){ $statusStr = array( "0" => "短信發(fā)送成功", "-1" => "參數(shù)不全", "-2" => "服務(wù)器空間不支持,請確認(rèn)支持curl或者fsocket,聯(lián)系您的空間商解決或者更換空間!", "30" => "密碼錯誤", "40" => "賬號不存在", "41" => "余額不足", "42" => "帳戶已過期", "43" => "IP地址限制", "50" => "內(nèi)容含有敏感詞" ); 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('短信發(fā)送參數(shù)配置有誤'); } $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 { error('短信發(fā)送失敗,' . $statusStr[$res]); }} |
經(jīng)過上面的替換,短信寶的短信平臺已經(jīng)替換成功了,可以正常使用了。進(jìn)行測試發(fā)送:
報備一下短信寶的VIP模板,這樣就可以走短信寶的優(yōu)質(zhì)通道了,即便遇到敏感文字我們都不會人工審核,短信內(nèi)容3~5秒就可送達(dá)。
另外:我們已經(jīng)開發(fā)好完整的PbootCMS_V3.1.2注冊模塊系統(tǒng)短信寶插件,點(diǎn)擊此鏈接?下載及查看安裝流程。
最新更新
電商類
CMS類
微信類