CRMEB知识付费系统是西安众邦科技旗下的具有自主知识产权的在线教育知识付费系统。系统基于ThinkPhp5.0+layui+Vue开发,功能包含在线直播、付费视频、付费音频、付费阅读、会员系统、分销系统、拼团活动、直播带货、直播打赏、商城系统等。今天小编就以新增短信接口为例,给大家讲解一下如何进行二次开发,使用的短信接口是我们短信宝短信群发平台的短信接口,我们短信宝短信群发平台的接口非常稳定,发送速度快,注册就送测试短信,推荐大家使用。
首先执行以下SQL增加短信宝配置参数字典
|
1
2
3
4
5
6
|
UPDATE `eb_system_config` SET `parameter`='1=阿里云短信平台\n2=crmeb短信平台\n3=>短信宝' WHERE (`menu_name`='sms_platform_selection');UPDATE `eb_system_menus` SET `menu_name`='短信宝配置' WHERE (`id`=501);INSERT INTO `eb_system_config_tab` ( `id`, `title`, `eng_title`, `status`, `info`, `icon`, `type`) VALUES( '999', '短信宝配置', 'smsbao', 1, 0, 'sun-o', 5);INSERT INTO `eb_system_config` ( `menu_name`, `type`, `input_type`, `config_tab_id`, `parameter`, `upload_type`, `required`, `width`, `high`, `value`, `info`, `desc`, `sort`, `status`) VALUES( 'smsbao_user', 'text', 'input', 999, NULL, NULL, NULL, 100, NULL, '\"\"', '短信宝账号', '短信宝账号', 0, 1),( 'smsbao_apiKey', 'text', 'input', 999, NULL, NULL, NULL, 100, NULL, '\"\"', '短信宝APIKEY', '短信宝APIKEY', 0, 1); |
接着打开项目application\wap\controller\AuthApi.php文件,替换code方法:
|
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
|
public function code($phone = '') { $name = "is_phone_code" . $phone; if ($phone == '') return JsonService::fail('请输入手机号码!'); $time = Session::get($name, 'wap'); if ($time < time() + 60) Session::delete($name, 'wap'); if (Session::has($name, 'wap') && $time < time()) return JsonService::fail('您发送验证码的频率过高,请稍后再试!'); $code = AliMessageService::getVerificationCode(); SmsCode::set(['tel' => $phone, 'code' => md5('is_phone_code' . $code), 'last_time' => time() + 300, 'uid' => $this->uid]); Session::set($name, time() + 60, 'wap'); $smsHandle = new Sms(); $sms_platform_selection = SystemConfigService::get('sms_platform_selection'); $smsSignName = SystemConfigService::get('smsSignName');//短信签名 $smsTemplateCode = SystemConfigService::get('smsTemplateCode');//短信模板ID if ($sms_platform_selection == 1) { if (!$smsSignName || !$smsTemplateCode) return JsonService::fail('系统后台短信没有配置,请稍后在试!'); $res = AliMessageService::sendmsg($phone, $code); }else if ($sms_platform_selection == 3) { if (!$smsSignName || !$smsTemplateCode) return JsonService::fail('系统后台短信没有配置,请稍后在试!'); $smsbaoHandle = new Smsbao(); $res = $smsbaoHandle->send($phone, $smsTemplateCode, ['code' => $code]); } else { $res = $smsHandle->send($phone, $smsTemplateCode, ['code' => $code]); } if ($res) { return JsonService::successful('发送成功', $res); } else { return JsonService::fail('发送失败!'); } } |
接着在extend\service\sms\storage目录下 新增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
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
<?phpnamespace service\sms\storage;use basic\BaseSms;use service\AccessTokenServeService;use think\exception\ValidateException;use think\Config;use service\SystemConfigService;class Smsbao{ private $account = ""; private $sercet = ""; private $signName = ""; public function __construct() { $this->account = SystemConfigService::get('smsbao_user'); $this->sercet = SystemConfigService::get('smsbao_apiKey'); $this->signName = SystemConfigService::get('smsSignName'); } /** * 发送短信 * @param $phone * @param $template * @param $param * @return bool|string */ public function send($phone, $templateId='', $data = []) { $statusStr = array( "0" => "短信发送成功", "-1" => "参数不全", "-2" => "服务器空间不支持,请确认支持curl或者fsocket,联系您的空间商解决或者更换空间!", "30" => "密码错误", "40" => "账号不存在", "41" => "余额不足", "42" => "帐户已过期", "43" => "IP地址限制", "50" => "内容含有敏感词" ); if (!$phone) { throw new ValidateException('手机号不能为空'); } if (is_null( $templateId)) { throw new ValidateException('模版ID不存在'); } $search = array_map(function($key) { return '{$' . $key . '}'; // 将键转换为 {key} 形式 }, array_keys($data)); $replace = array_values($data); // 替换内容为数组的值 // 执行替换 $content = str_replace($search, $replace, $templateId); $content = '【'.$this->signName.'】'.$content; $sendurl = $smsapi."sms?u=".$this->account."&p=".$this->sercet."&m=".$phone."&c=".urlencode($content); $result = $this->fetchContent($sendurl,'POST','') ; if ($result != '0') { return [ 'data' =>'发送成功', 'Code' =>'OK', 'Message' =>'OK' ]; }else{ throw new ValidateException($statusStr[$result]); } } private function fetchContent($url, $method, $body) { $ch = curl_init(); if($method == 'POST') { curl_setopt($ch, CURLOPT_POST, 1);//post提交方式 curl_setopt($ch, CURLOPT_POSTFIELDS, $body); } else { $url .= '?'.$body; } curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_TIMEOUT, 5); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, array( "x-sdk-client" => "php/2.0.0" )); if(substr($url, 0,5) == 'https') { curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); } $rtn = curl_exec($ch); if($rtn === false) { // 大多由设置等原因引起,一般无法保障后续逻辑正常执行, // 所以这里触发的是E_USER_ERROR,会终止脚本执行,无法被try...catch捕获,需要用户排查环境、网络等故障 trigger_error("[CURL_" . curl_errno($ch) . "]: " . curl_error($ch), E_USER_ERROR); } curl_close($ch); return $rtn; }} |
好了经过以上的添加,短信宝的短信平台已经替换成功了,可以正常使用了

报备一下短信宝的VIP模板,这样就可以走短信宝的优质通道了,即便遇到敏感文字我们都不会人工审核,短信内容3~5秒就可送达。
另外:我们已经开发好完整的CRMEB知识付费系统短信宝插件,点击此链接 下载及查看安装流程。
最新更新
电商类
CMS类
微信类