微擎是一款免费开源的公众平台管理系统,基于web2.0技术架构,他有很多的扩展模块,二次开发也非常方便,小编对于这套系统还是比较了解的,今天小编就以微擎_1.8版本的替换短信接口为例告诉大家如何进行二次开发,使用的短信接口是我们短信宝短信群发平台的接口,我们短信宝短信群发平台非常稳定,发送速度快,注册就送测试短信,推荐大家使用。
首先我们打开项目:\web\themes\default\system\user-setting.html 文件,添加以下代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
{if $do == 'sms'} < div id = "sms" > < div class = "form-group" > < label class = "col-sm-2 control-label" style = "text-align:left;" >短信宝账号</ label > < div class = "col-sm-8" > < input type = "text" name = "sms_name" class = "form-control" value = "{$settings['sms_name']}" /> < span class = "help-block" >没有短信宝账号?点击< a class = "btn btn-primary span3" target = "_blank" href = "http://www.smsbao.com" >免费注册</ a ></ span > </ div > </ div > < div class = "form-group" > < label class = "col-sm-2 control-label" style = "text-align:left;" >短信宝密码</ label > < div class = "col-sm-8" > < input type = "password" name = "sms_password" class = "form-control" value = "{$settings['sms_password']}" /> </ div > </ div > < div class = "form-group" > < label class = "col-sm-2 control-label" style = "text-align:left;" >短信签名</ label > < div class = "col-sm-8" > < input type = "text" name = "sms_sign" class = "form-control" value = "{$settings['sms_sign']}" /> </ div > </ div > </ div > {/if} |
接着在项目:\web\themes\default\system\user-setting-header.html文件中添加以下代码
1
|
< li {if $do == 'sms'} class = "active" {/if}>< a href="{php echo url('system/usersetting', array('do' => 'sms'))}">短信配置</ a ></ li > |
接着打开项目:\web\source\system\usersetting.ctrl.php 文件替换8~28行代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
$dos = array ( 'login' , 'binding' , 'sms' ); $do = in_array( $do , $dos ) ? $do : 'login' ; $settings = $_W [ 'setting' ][ 'copyright' ]; if ( empty ( $settings ) || ! is_array ( $settings )) { $settings = array (); } else { $settings [ 'slides' ] = iunserializer( $settings [ 'slides' ]); } if ( $do == 'sms' ) { $_W [ 'page' ][ 'title' ] = '短信配置' ; if (checksubmit( 'submit' )) { $settings [ 'sms_name' ] = $_GPC [ 'sms_name' ]; $settings [ 'sms_password' ] = $_GPC [ 'sms_password' ]; $settings [ 'sms_sign' ] = $_GPC [ 'sms_sign' ]; setting_save( $settings , 'copyright' ); itoast( '更新设置成功!' , '' , 'success' ); } } |
最后我们打开项目:\framework\model\cloud.mod.php 文件,替换cloud_sms_send方法
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
|
function cloud_sms_send( $mobile , $content , $postdata = array (), $custom_sign = '' ) { global $_W ; if (!preg_match( '/^1\d{10}$/' , $mobile ) || empty ( $content )) { return error(1, '发送短信失败, 原因: 手机号错误或内容为空.' ); } if ( empty ( $_W [ 'uniacid' ])) { $sms_info = cloud_sms_info(); $balance = empty ( $sms_info [ 'sms_count' ]) ? 0 : $sms_info [ 'sms_count' ]; if (! empty ( $custom_sign )) { $sign = $custom_sign ; } } else { $row = pdo_get( 'uni_settings' , array ( 'uniacid' => $_W [ 'uniacid' ]), array ( 'notify' )); $row [ 'notify' ] = @iunserializer( $row [ 'notify' ]); $config = $row [ 'notify' ][ 'sms' ]; $balance = intval ( $config [ 'balance' ]); $sign = $config [ 'signature' ]; } if ( empty ( $sign )) { $sign = '短信宝' ; } //判断剩余条数 if ( $balance <1){ return error(-1, '短信发送失败, 原因:余额不足' ); } //短信宝账号 // $smsbao_info=pdo_get('uni_settings' , array('uniacid' => $_W['uniacid']), array('copyright')); //$smsbao_info=setting_load($key = 'copyright'); $sms_param [ 'u' ]= $_W [ 'setting' ][ 'copyright' ][ 'sms_name' ]; $sms_param [ 'p' ]=md5( $_W [ 'setting' ][ 'copyright' ][ 'sms_password' ]); $sms_param [ 'm' ]= $mobile ; $sms_param [ 'c' ]= "【" . $_W [ 'setting' ][ 'copyright' ][ 'sms_sign' ]. "】" . $content ; $statusStr = array ( "0" => "短信发送成功" , "-1" => "参数不全" , "-2" => "服务器空间不支持,请确认支持curl或者fsocket,联系您的空间商解决或者更换空间!" , "30" => "密码错误" , "40" => "账号不存在" , "41" => "余额不足" , "42" => "帐户已过期" , "43" => "IP地址限制" , "50" => "内容含有敏感词" ); if (trim( $response )!= '0' ) { return error( $response , '短信发送失败, 原因:' . $statusStr [ $response ]); } if (trim( $response )== '0' ) { if (! empty ( $_W [ 'uniacid' ])) { $row [ 'notify' ][ 'sms' ][ 'balance' ] = $row [ 'notify' ][ 'sms' ][ 'balance' ] - 1; if ( $row [ 'notify' ][ 'sms' ][ 'balance' ] < 0) { $row [ 'notify' ][ 'sms' ][ 'balance' ] = 0; } pdo_update( 'uni_settings' , array ( 'notify' => iserializer( $row [ 'notify' ])), array ( 'uniacid' => $_W [ 'uniacid' ])); uni_setting_save( 'notify' , $row [ 'notify' ]); } } return true; } |
经过上面的替换,短信宝的短信平台已经替换成功了,可以正常使用了。进行测试发送:
报备一下短信宝的VIP模板,这样就可以走短信宝的优质通道了,即便遇到敏感文字我们都不会人工审核,短信内容3~5秒就可送达。
另外:我们已经开发好完整的微擎系统短信宝插件,点击此链接 下载及查看安装流程。
最新更新
电商类
CMS类
微信类