BadouCMS是基于 ThinkPHP8+Layui 的開源網站管理系統,支持多語言、多模型、多條件搜索、內容權限、會員功能、文章評論、文章內鏈、百度推送、輪播圖、多條件篩選、網站地圖等。小編對這款軟件還是比較了解的,小編今天就以V2.2.0新增短信接口為例為大家講解一下如何進行二次開發,我們使用的短信接口是我們短信寶短信群發平臺的短信接口,我們短信寶短信群發平臺非常穩定,發送速度快,注冊就送測試短信,推薦大家使用。
1.首先執行插件sql語句
|
1
2
3
4
5
6
|
/**表名前綴根據自身要求進行修改**/INSERT INTO `bd_config` (`name`, `group`, `title`, `tip`, `type`, `value`, `content`, `rule`, `extend`, `allow_del`, `weigh`) VALUES ( 'sms_gateways', 'sms', '短信服務商', '', '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', '短信寶賬號', '', '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":"您的驗證碼是{code}"},{"key":"resetpwd","value":"您的驗證碼是{code}"},{"key":"changepwd","value":"您的驗證碼是{code}"},{"key":"changemobile","value":"您的驗證碼是{code}"},{"key":"profile","value":"您的驗證碼是{code}"},{"key":"mobilelogin","value":"您的驗證碼是{code}"},{"key":"bind","value":"您的驗證碼是{code}"}]', '', 'required', '', 1, 5); |
2.接著在modules\smsbao目錄下新增Smsbao.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
|
<?phpnamespace modules\smsbao;use think\facade\Event;class Smsbao{ /** * 應用初始化時調用 * @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; }); }} |
經過上面的替換,短信寶的短信平臺已經替換成功了,可以正常使用了。進行測試發送:

報備一下短信寶的VIP模板,這樣就可以走短信寶的優質通道了,即便遇到敏感文字我們都不會人工審核,短信內容3~5秒就可送達。
另外:我們已經開發好完整的BadouCMS短信寶插件,點擊此鏈接?下載及查看安裝流
最新更新
電商類
CMS類
微信類