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類
微信類