微擎是一款免费开源的公众平台管理系统,基于web2.0技术架构,他有很多的扩展模块,二次开发也非常方便,微课堂是微擎应用市场一套针对知识付费和在线教育的模块,打破传统课堂,在线视频学习 内置优惠券营销功能,小编对他还是很了解,今天小编就以替换短信接口为例告诉大家如何进行二次开发,我们讲解的是v2版本,使用的短信接口是我们短信宝短信群发平台的接口,我们短信宝短信群发平台非常稳定,发送速度快,注册就送测试短信,推荐大家使用
1:打开项目:addons\fy_lessonv2\template\web\setting\sms.html 修改大概46行
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
|
<div class= "qcloud-sms" { if $sms[ 'type' ]!=2}style= "display:none;" {/ if }> <div class= "form-group" > <label class= "col-xs-12 col-sm-3 col-md-2 control-label" >短信宝账号</label> <div class= "col-sm-9" > <input type= "text" name= "sms[qcloud][appid]" class= "form-control" value= "{$sms[qcloud][appid]}" > <span class= "help-block" ><a style= "color: red;" target= "_blank" href= "https://smsbao.com/reg" >还没有账号?点击申请</a> </span> </div> </div> <div class= "form-group" > <label class= "col-xs-12 col-sm-3 col-md-2 control-label" >短信宝密码</label> <div class= "col-sm-9" > <input type= "text" name= "sms[qcloud][appkey]" class= "form-control" value= "{$sms[qcloud][appkey]}" > </div> </div> <div class= "form-group" > <label class= "col-xs-12 col-sm-3 col-md-2 control-label" >短信宝签名</label> <div class= "col-sm-9" > <input type= "text" name= "sms[qcloud][sign]" class= "form-control" value= "{$sms[qcloud][sign]}" > </div> </div> <div class= "form-group" > <label class= "col-xs-12 col-sm-3 col-md-2 control-label" >短信验证码模版</label> <div class= "col-sm-9" > <input type= "text" name= "sms[qcloud][template_id]" class= "form-control" value= "{$sms[qcloud][template_id]}" > <span class= "help-block" >短信模版申请示例:您的短信验证码是:${code},请不要告诉任何人。</span> </div> </div> </div> |
2:打开项目:addons\fy_lessonv2\inc\common\ 新增SmsbaoSMS.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
|
<?php class SmsbaoSMS{ /** * 执行发送短信 * $sms 短信配置信息 * $mobile 接收手机号码 * $templateId 模版ID * $data 发送参数 **/ public function sendSMS($sms, $mobile, $templateId, $data){ $content = sprintf($templateId,$data[ 'code' ]); $user = $sms[ 'appid' ]; //短信平台帐号 $pass = md5($sms[ 'appkey' ]); //短信平台密码 $content=$content; //要发送的短信内容 $phone = $mobile; //要发送短信的手机号码 $sendurl = $smsapi. "sms?u=" .$user. "&p=" .$pass. "&m=" .$phone. "&c=" .urlencode($content); $result =file_get_contents($sendurl); return $result; } } |
3:打开项目:addons\fy_lessonv2\inc\common\SendSMS.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
|
public function sendCode(){ if (!(preg_match( "/1\d{10}/" ,$ this ->mobile))){ $data = array( 'code' => -1, 'msg' => '您输入的手机号码有误' ); $ this ->resultJson($data); } $param[ 'code' ] = strval(rand(1234,9999)); $_SESSION[ 'mobile_record' ] = $ this ->mobile; $_SESSION[ 'mobile_code' ] = $param[ 'code' ]; if ($ this ->smsConfig[ 'type' ]==1){ require_once dirname(__FILE__). '/AliyunSMS.php' ; $aliyunSMS = new AliyunSMS(); $sms = $ this ->smsConfig[ 'aliyun' ]; $output = $aliyunSMS->sendSMS($sms, $ this ->mobile, $sms[ 'template_id' ], $param); $result = json_decode(json_encode($output), true ); if ($result[ 'Code' ]== 'OK' ){ $data = array( 'code' => 0, 'msg' => '验证码发送成功' , 'result' => $result ); } else { $data = array( 'code' => -1, 'msg' => $result[ 'Message' ], ); } $ this ->resultJson($data); } elseif($ this ->smsConfig[ 'type' ]==2){ $statusStr = array( "0" => "短信发送成功" , "-1" => "参数不全" , "-2" => "服务器空间不支持,请确认支持curl或者fsocket,联系您的空间商解决或者更换空间!" , "30" => "密码错误" , "40" => "账号不存在" , "41" => "余额不足" , "42" => "帐户已过期" , "43" => "IP地址限制" , "50" => "内容含有敏感词" ); require_once dirname(__FILE__). '/SmsbaoSMS.php' ; $SmsbaoSMS = new SmsbaoSMS(); $sms = $ this ->smsConfig[ 'qcloud' ]; $output = $SmsbaoSMS->sendSMS($sms, $ this ->mobile, $sms[ 'template_id' ], $param); if ($output== '0' ){ $data = array( 'code' => 0, 'msg' => '验证码发送成功' , 'result' => $output ); } else { $data = array( 'code' => -1, 'msg' => $output[$statusStr], ); } $ this ->resultJson($data); } } |
经过上面的替换,短信宝的短信平台已经替换成功了,可以正常使用了。进行测试发送:
报备一下短信宝的VIP模板,这样就可以走短信宝的优质通道了,即便遇到敏感文字我们都不会人工审核,短信内容3~5秒就可送达。
另外:我们已经开发好完整的微课堂v2系统短信宝插件,点击此链接 下载及查看安装流程。
最新更新
电商类
CMS类
微信类