Edusoho網(wǎng)校系統(tǒng)是一套為企業(yè)、個人和教育機構(gòu)提供包括平臺、運營、內(nèi)容和營銷在內(nèi)的在線教育整體解決方案。完全的開源免費,開放API可定制性強。在網(wǎng)校教育中具有一定知名度,小編對他還是比較了解。今天就以替換短信接口為例告訴大家如何進行二次開發(fā),使用的短信接口是我們短信寶短信群發(fā)平臺的接口,我們短信寶短信群發(fā)平臺非常穩(wěn)定,發(fā)送速度快,注冊就送測試短信,推薦大家使用。
首先我們打開項目:\app\Resources\views\admin\system\auth.html.twig 在195行左右增加代碼
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
|
<div> <legend>短信寶配置</legend> <div class= "form-group" > <div class= "col-md-3 control-label" > <label for = "user_sms" >短信寶賬號</label> </div> <div class= "controls col-md-8" > <input type= "text" id= "user_sms" name= "user_sms" class= "form-control" value= "{{auth.user_sms}}" > </div> </div> <div class= "form-group" > <div class= "col-md-3 control-label" > <label for = "user_sms" >短信寶密碼</label> </div> <div class= "controls col-md-8" > <input type= "password" id= "pwd_sms" name= "pwd_sms" class= "form-control" value= "{{auth.pwd_sms}}" > </div> </div> <div class= "form-group" > <div class= "col-md-3 control-label" > <label for = "user_sms" >短信寶簽名</label> </div> <div class= "controls col-md-8" > <input type= "text" id= "sing_sms" name= "sing_sms" class= "form-control" value= "{{auth.sing_sms}}" > </div> </div> </div> </fieldset> |
打開項目:\src\AppBundle\Controller\Admin\UserSettingController.php 新增短信寶配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
$ default = array( 'register_mode' => 'closed' , 'email_enabled' => 'closed' , 'setting_time' => -1, 'email_activation_title' => '' , 'email_activation_body' => '' , 'welcome_enabled' => 'closed' , 'welcome_sender' => '' , 'welcome_methods' => array(), 'welcome_title' => '' , 'welcome_body' => '' , 'user_terms' => 'closed' , 'user_terms_body' => '' , 'privacy_policy' => 'closed' , 'privacy_policy_body' => '' , 'captcha_enabled' => 0, 'register_protective' => 'none' , 'nickname_enabled' => 0, 'avatar_alert' => 'none' , 'user_sms' => '填寫短信寶賬號' , 'pwd_sms' => '填寫短信寶密碼' , 'sing_sms' => '填寫短信寶簽名' , ); |
打開項目:\src\AppBundle\Controller\EduCloudController.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
|
private function sendSms(Request $request, $smsType) { $currentUser = $ this ->getCurrentUser(); $currentTime = time(); $to = $request->get( 'to' ); $errorMsg = $ this ->checkErrorMsg($currentUser, $currentTime, $smsType, $request); if (!empty($errorMsg)) { return array( 'error' => $errorMsg); } $description = $ this ->generateDescription($smsType); $smsCode = $ this ->generateSmsCode(); $statusStr = array( "0" => "短信發(fā)送成功" , "-1" => "參數(shù)不全" , "-2" => "服務(wù)器空間不支持,請確認(rèn)支持curl或者fsocket,聯(lián)系您的空間商解決或者更換空間!" , "30" => "密碼錯誤" , "40" => "賬號不存在" , "41" => "余額不足" , "42" => "帳戶已過期" , "43" => "IP地址限制" , "50" => "內(nèi)容含有敏感詞" ); $user = $ this ->setting( 'auth.user_sms' ); //短信平臺帳號 $pass = md5($ this ->setting( 'auth.pwd_sms' )); //短信平臺密碼 $sing = $ this ->setting( 'auth.sing_sms' ); $content= "【" .$sing. "】" .$description. '驗證碼為' .$smsCode; //要發(fā)送的短信內(nèi)容 $phone = $to; //要發(fā)送短信的手機號碼 $sendurl = $smsapi. "sms?u=" .$user. "&p=" .$pass. "&m=" .$phone. "&c=" .urlencode($content); $ret =file_get_contents($sendurl); $message = $statusStr[$ret]; if ($ret != 0 ) { return array( 'error' => sprintf( '發(fā)送失敗, %s' , $message)); } $result = []; $result[ 'to' ] = $to; $result[ 'smsCode' ] = $smsCode; $result[ 'userId' ] = $currentUser[ 'id' ]; if (0 != $currentUser[ 'id' ]) { $result[ 'nickname' ] = $currentUser[ 'nickname' ]; } $ this ->getLogService()->info( 'sms' , $smsType, sprintf( 'userId:%s,對%s發(fā)送用于%s的驗證短信%s' , $currentUser[ 'id' ], $to, $smsType, $smsCode), $result); $request->getSession()->set($smsType, array( 'to' => $to, 'sms_code' => $smsCode, 'sms_last_time' => $currentTime, )); if ($currentUser->isLogin()) { $key = $currentUser[ 'email' ]; } else { $key = $to.$request->getClientIp(); } $maxAllowance = $ this ->getRateLimiter($smsType, 6, 3600)->getAllow($key); return array( 'ACK' => 'ok' , 'allowance' => ($maxAllowance > 3) ? 0 : $maxAllowance); } |
好了經(jīng)過以上的添加,短信寶Edusoho_v8.34.3系統(tǒng)增加手機驗證就已經(jīng)安裝成功,可以正常使用了
報備一下短信寶的VIP模板,這樣就可以走短信寶的優(yōu)質(zhì)通道了,即便遇到敏感文字我們都不會人工審核,短信內(nèi)容3~5秒就可送達。
另外:我們已經(jīng)開發(fā)好完整的Edusoho_v8.34.3系統(tǒng)短信寶插件,點擊此鏈接 下載及查看安裝流程。
最新更新
電商類
CMS類
微信類