BadouCMS是基于 ThinkPHP8+Layui 的开源网站管理系统,支持多语言、多模型、多条件搜索、内容权限、会员功能、文章评论、文章内链、百度推送、轮播图、多条件筛选、网站地图等。小编对这款软件还是比较了解的,小编今天就以V2.1.4新增短信接口为例为大家讲解一下如何进行二次开发,我们使用的短信接口是我们短信宝短信群发平台的短信接口,我们短信宝短信群发平台非常稳定,发送速度快,注册就送测试短信,推荐大家使用。
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类
微信类