BadouCMS是基于 ThinkPHP8+Layui 的開源網(wǎng)站管理系統(tǒng),支持多語(yǔ)言、多模型、多條件搜索、內(nèi)容權(quán)限、會(huì)員功能、文章評(píng)論、文章內(nèi)鏈、百度推送、輪播圖、多條件篩選、網(wǎng)站地圖等。小編對(duì)這款軟件還是比較了解的,小編今天就以V2.1.4新增短信接口為例為大家講解一下如何進(jìn)行二次開發(fā),我們使用的短信接口是我們短信寶短信群發(fā)平臺(tái)的短信接口,我們短信寶短信群發(fā)平臺(tái)非常穩(wěn)定,發(fā)送速度快,注冊(cè)就送測(cè)試短信,推薦大家使用。
1.首先執(zhí)行插件sql語(yǔ)句
|
1
2
3
4
5
6
|
/**表名前綴根據(jù)自身要求進(jìn)行修改**/INSERT INTO `bd_config` (`name`, `group`, `title`, `tip`, `type`, `value`, `content`, `rule`, `extend`, `allow_del`, `weigh`) VALUES ( 'sms_gateways', 'sms', '短信服務(wù)商', '', 'radio', 0, '[\"\\u77ed\\u4fe1\\u5b9d\"]', '', '', 1, 9);INSERT INTO `bd_config` ( `name`, `group`, `title`, `tip`, `type`, `value`, `content`, `rule`, `extend`, `allow_del`, `weigh`) VALUES ('sms_smsbao_sign_name', 'sms', '短信簽名', '', 'string', '', '', '', '', 1, 8);INSERT INTO `bd_config` ( `name`, `group`, `title`, `tip`, `type`, `value`, `content`, `rule`, `extend`, `allow_del`, `weigh`) VALUES ('sms_smsbao_username', 'sms', '短信寶賬號(hào)', '', 'string', '', '', '', '', 1, 7);INSERT INTO `bd_config` ( `name`, `group`, `title`, `tip`, `type`, `value`, `content`, `rule`, `extend`, `allow_del`, `weigh`) VALUES ('sms_smsbao_apikey', 'sms', '短信寶APIKEY', '', 'string', '', '', '', '', 1, 6);INSERT INTO `bd_config` ( `name`, `group`, `title`, `tip`, `type`, `value`, `content`, `rule`, `extend`, `allow_del`, `weigh`) VALUES ('sms_smsbao_template', 'sms', '短信模板', '', 'array','[{"key":"register","value":"您的驗(yàn)證碼是{code}"},{"key":"resetpwd","value":"您的驗(yàn)證碼是{code}"},{"key":"changepwd","value":"您的驗(yàn)證碼是{code}"},{"key":"changemobile","value":"您的驗(yàn)證碼是{code}"},{"key":"profile","value":"您的驗(yàn)證碼是{code}"},{"key":"mobilelogin","value":"您的驗(yàn)證碼是{code}"},{"key":"bind","value":"您的驗(yàn)證碼是{code}"}]', '', 'required', '', 1, 5); |
2.接著在modules\smsbao目錄下新增Smsbao.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
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
|
<?phpnamespace modules\smsbao;use think\facade\Event;class Smsbao{ /** * 應(yīng)用初始化時(shí)調(diào)用 * @return array */ public function AppInit() { Event::listen('sms_send', function ($params) { $result = true; try { $sms_sign = get_sys_config('sms_smsbao_sign_name'); $user = get_sys_config('sms_smsbao_username'); $apikey = get_sys_config('sms_smsbao_apikey'); $template = get_sys_config('sms_smsbao_template'); $template = json_decode($template, true); $template = array_column($template, 'value', 'key'); $template = $template[$params['event']]; $phone = $params['mobile']; $TemplateContent = str_replace('{code}', $params['code'], $template); $content='【'.$sms_sign.'】'.$TemplateContent; $sendurl = $smsapi."sms?u=".$user."&p=".$apikey."&m=".$phone."&c=".urlencode($content); $res = file_get_contents($sendurl); if (0 === $res) { return true; }else { return true; } } catch (PHPMailerException $e) { $result = false; } return $result; }); Event::listen('sms_notice', function ($params) { $result = true; try { $sms_sign = get_sys_config('sms_smsbao_sign_name'); $user = get_sys_config('sms_smsbao_username'); $apikey = get_sys_config('sms_smsbao_apikey'); $template = get_sys_config('sms_smsbao_template'); $template = json_decode($template, true); $template = array_column($template, 'value', 'key'); $template = $template[$params['event']]; $phone = $params['mobile']; $TemplateContent = str_replace('{code}', $params['code'], $template); $content='【'.$sms_sign.'】'.$TemplateContent; $sendurl = $smsapi."sms?u=".$user."&p=".$apikey."&m=".$phone."&c=".urlencode($content); $res = file_get_contents($sendurl); if (0 === $res) { return true; }else { return false; } } catch (PHPMailerException $e) { $result = false; } return $result; }); }} |
經(jīng)過(guò)上面的替換,短信寶的短信平臺(tái)已經(jīng)替換成功了,可以正常使用了。進(jìn)行測(cè)試發(fā)送:

報(bào)備一下短信寶的VIP模板,這樣就可以走短信寶的優(yōu)質(zhì)通道了,即便遇到敏感文字我們都不會(huì)人工審核,短信內(nèi)容3~5秒就可送達(dá)。
另外:我們已經(jīng)開發(fā)好完整的BadouCMS短信寶插件,點(diǎn)擊此鏈接?下載及查看安裝流
最新更新
電商類
CMS類
微信類