Edusoho网校系统是一套为企业、个人和教育机构提供包括平台、运营、内容和营销在内的在线教育整体解决方案。完全的开源免费,开放API可定制性强。在网校教育中具有一定知名度,小编对他还是比较了解。今天就以替换短信接口为例告诉大家如何进行二次开发,使用的短信接口是我们短信宝短信群发平台的接口,我们短信宝短信群发平台非常稳定,发送速度快,注册就送测试短信,推荐大家使用。
首先我们打开项目:\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 新增短信发送
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" => "短信发送成功" , "-1" => "参数不全" , "-2" => "服务器空间不支持,请确认支持curl或者fsocket,联系您的空间商解决或者更换空间!" , "30" => "密码错误" , "40" => "账号不存在" , "41" => "余额不足" , "42" => "帐户已过期" , "43" => "IP地址限制" , "50" => "内容含有敏感词" ); $user = $ this ->setting( 'auth.user_sms' ); //短信平台帐号 $pass = md5($ this ->setting( 'auth.pwd_sms' )); //短信平台密码 $sing = $ this ->setting( 'auth.sing_sms' ); $content= "【" .$sing. "】" .$description. '验证码为' .$smsCode; //要发送的短信内容 $phone = $to; //要发送短信的手机号码 $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( '发送失败, %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发送用于%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); } |
好了经过以上的添加,短信宝Edusoho_v8.34.3系统增加手机验证就已经安装成功,可以正常使用了
报备一下短信宝的VIP模板,这样就可以走短信宝的优质通道了,即便遇到敏感文字我们都不会人工审核,短信内容3~5秒就可送达。
另外:我们已经开发好完整的Edusoho_v8.34.3系统短信宝插件,点击此链接 下载及查看安装流程。
最新更新
电商类
CMS类
微信类