POSCMS是一款开源的跨平台网站内容管理系统,他是基于PHP+MYSQL开发的 ,是一套非常适合用做系统建站或者进行二次开发的程序核心,小编对他还是比较了解的,今天小编就以新增短信接口为例,给大家讲解一下如何进行二次开发,我们今天讲解的是3.5版本,使用的短信接口是我们短信宝短信群发平台的短信接口,我们短信宝短信群发平台的接口非常稳定,发送速度快,注册就送测试短信,推荐大家使用。
我们首先需要修改后台显示界面,打开项目\diy\dayrui\templates\admin\sms_index.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
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
{template nheader.html} < script type = "text/javascript" > $(function() { {if $data.uid && !$data.third} $.ajax({ type: "GET", dataType: "json", url: "{dr_url('api/sms_info')}&uid={$data.uid}&key={$data.key}", success: function(json) { eval(json.code); }, error: function(HttpRequest, ajaxOptions, thrownError) { alert('网络异常'); } }); {/if} {if $data.type == 0} $('.dr_0').show();$('.dr_1').hide();$('.dr_2').hide(); {else if $data.type == 1} $('.dr_1').show();$('.dr_0').hide();$('.dr_2').hide(); {else if $data.type == 2} $('.dr_2').show();$('.dr_1').hide();$('.dr_0').hide(); {/if} }); </ script > < form class = "form-horizontal" action = "" method = "post" id = "myform" name = "myform" > < div class = "page-bar" > < ul class = "page-breadcrumb mylink" > {$menu.link} < li > < a href = "{dr_help_url(108)}" target = "_blank" >< i class = "fa fa-book" ></ i > {fc_lang('在线帮助')}</ a > </ li > </ ul > < ul class = "page-breadcrumb myname" > {$menu.name} </ ul > < div class = "page-toolbar" > < div class = "btn-group pull-right" > < button type = "button" class = "btn green btn-sm btn-outline dropdown-toggle" data-toggle = "dropdown" aria-expanded = "false" data-hover = "dropdown" > {fc_lang('操作菜单')} < i class = "fa fa-angle-down" ></ i > </ button > < ul class = "dropdown-menu pull-right" role = "menu" > {loop $menu.quick $t} < li > < a href = "{$t.url}" >{$t.icon} {$t.name}</ a > </ li > {/loop} < li class = "divider" > </ li > < li > < a href = "javascript:window.location.reload();" > < i class = "icon-refresh" ></ i > {fc_lang('刷新页面')}</ a > </ li > </ ul > </ div > </ div > </ div > < h3 class = "page-title" > < small ></ small > </ h3 > < div class = "portlet light bordered myfbody" > < div class = "portlet-title" > < div class = "caption" > < span class = "caption-subject font-green sbold uppercase" >{fc_lang('账号设置')}</ span > </ div > </ div > < div class = "portlet-body" > < div class = "row" > < div class = "portlet-body form" > < div class = "form-group" > < label class = "col-md-2 control-label" style = "padding-top: 10px;" >{fc_lang('类型')}:</ label > < div class = "col-md-9" > < div class = "radio-list" > < label class = "radio-inline" >< input name = "data['type']" type = "radio" value = "0" onclick = "$('.dr_0').show();$('.dr_1').hide();$('.dr_2').hide();" {if $data.type == 0} checked = "checked" {/if} /> {fc_lang('官方接口')}</ label > < label class = "radio-inline" >< input name = "data['type']" type = "radio" value = "1" onclick = "$('.dr_1').show();$('.dr_0').hide();$('.dr_2').hide();" {if $data.type == 1} checked = "checked" {/if} /> {fc_lang('第三方接口')}</ label > < label class = "radio-inline" >< input name = "data['type']" type = "radio" value = "2" onclick = "$('.dr_2').show();$('.dr_0').hide();$('.dr_1').hide();" {if $data.type == 2} checked = "checked" {/if} /> {fc_lang('短信宝接口')}</ label > </ div > </ div > </ div > < div class = "form-group dr_0" > < label class = "col-md-2 control-label" >{fc_lang('申请教程')}:</ label > < div class = "col-md-9" > < div class = "form-control-static" >< label >< a href = "{SYS_HELP_URL}107.html" target = "_blank" >{SYS_HELP_URL}107.html</ a ></ label ></ div > </ div > </ div > < div class = "form-group dr_0" > < label class = "col-md-2 control-label" >SMS Uid:</ label > < div class = "col-md-9" > < label >< input class = "form-control" type = "text" name = "data[uid]" value = "{$data.uid}" ></ label > </ div > </ div > < div class = "form-group dr_0" > < label class = "col-md-2 control-label" >SMS Key:</ label > < div class = "col-md-9" > < input class = "form-control" type = "text" name = "data[key]" value = "{$data.key}" > </ div > </ div > {if $data.uid && !$data.third} < div class = "form-group dr_0" > < label class = "col-md-2 control-label" >{fc_lang('剩余短信')}:</ label > < div class = "col-md-9" > < div class = "form-control-static" id = "dr_sms" >....</ div > </ div > </ div > {/if} < div class = "form-group dr_1" > < label class = "col-md-2 control-label" >{fc_lang('申请教程')}:</ label > < div class = "col-md-9" > < div class = "form-control-static" >< label >< a href = "{SYS_HELP_URL}108.html" target = "_blank" >{SYS_HELP_URL}108.html</ a ></ label ></ div > </ div > </ div > < div class = "form-group dr_1" > < label class = "col-md-2 control-label" >{fc_lang('字段格式')}:</ label > < div class = "col-md-9" > < textarea class = "form-control" style = "height:120px" name = "data[third]" />{$data.third}</ textarea > </ div > </ div > < div class = "form-group dr_2" > < label class = "col-md-2 control-label" >{fc_lang('申请地址')}:</ label > < div class = "col-md-9" > < div class = "form-control-static" >< label >< a href = "http://www.smsbao.com/reg" target = "_blank" >http://www.smsbao.com/reg</ a ></ label ></ div > </ div > </ div > < div class = "form-group dr_2" > < label class = "col-md-2 control-label" >短信宝用户名:</ label > < div class = "col-md-9" > < input class = "form-control" type = "text" name = "data[smsbaouser]" value = "{$data.smsbaouser}" > </ div > </ div > < div class = "form-group dr_2" > < label class = "col-md-2 control-label" >短信宝密码:</ label > < div class = "col-md-9" > < input class = "form-control" type = "text" name = "data[smsbaopass]" value = "{$data.smsbaopass}" > </ div > </ div > < div class = "form-group " > < label class = "col-md-2 control-label" >{fc_lang('短信签名')}:</ label > < div class = "col-md-9" > < label >< input class = "form-control" type = "text" name = "data[note]" value = "{$data.note}" ></ label > < span class = "help-block" >保持在10个字符以内</ span > </ div > </ div > </ div > </ div > </ div > </ div > < div class = "myfooter" > < div class = "row" > < div class = "portlet-body form" > < div class = "form-body" > < div class = "form-actions" > < div class = "row" > < div class = "col-md-12 text-center" > < button type = "submit" class = "btn green" > < i class = "fa fa-save" ></ i > {fc_lang('保存')}</ button > </ div > </ div > </ div > </ div > </ div > </ div > </ div > </ form > {template nfooter.html} |
接着我们打开项目:\diy\dayrui\controllers\admin\Sms.php文件,替换index方法
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
|
public function index() { $file = CACHEPATH. 'config/sms.php' ; if (IS_POST) { $data = $this ->input->post( 'data' , true); $data [ 'type' ] = $data [ '0' ]; if ( strlen ( $data [ 'note' ]) > 30 ) { $this ->admin_msg(fc_lang( '短信签名超出了范围' )); } if ( $data [ '0' ] == '0' || $data [ '0' ] == '2' ) { unset( $data [ 'third' ]); } \Poscms\Service::L( 'dconfig' ); $size = $this ->dconfig ->file( $file ) ->note( '短信配置文件' ) ->space(8) ->to_require_one( $data ); if (! $size ) { $this ->admin_msg(fc_lang( '网站域名文件创建失败,请检查config目录权限' )); } $this ->system_log( '配置短信接口' ); // 记录日志 $this ->admin_msg(fc_lang( '操作成功,正在刷新...' ), dr_url( 'sms/index' ), 1); } $data = is_file ( $file ) ? require $file : array (); $this ->template->assign( array ( 'data' => $data , 'service' => $this ->service, )); $this ->template->display( 'sms_index.html' ); } |
最后我们打开项目:\diy\poscms\model\Member.php文件,替换sendsms方法,代码如下
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
|
public function sendsms( $mobile , $content ) { if (! $mobile || ! $content ) { return FALSE; } $file = CACHEPATH. 'config/sms.php' ; if (! is_file ( $file )) { return FALSE; } $config = require_once $file ; if ( $config [ 'type' ] == '0' ) { if ( is_file (COREPATH. 'helpers/sms_helper.php' )) { $this ->load->helper( 'sms' ); } if (function_exists( 'my_sms_send' )) { $result = my_sms_send( $mobile , $content , $config ); } else { return FALSE; } } elseif ( $config [ 'type' ] == '1' ) { $result = dr_catcher_data( 'http://sms.dayrui.com/index.php?uid=' . $config [ 'uid' ]. '&key=' . $config [ 'key' ]. '&mobile=' . $mobile . '&content=' . $content . '【' . $config [ 'note' ]. '】&domain=' .trim( str_replace ( 'http://' , '' , SITE_URL), '/' ). '&sitename=' .SITE_NAME); if (! $result ) { return FALSE; } $result = json_decode( $result , true); } elseif ( $config [ 'type' ] == '2' ){ $result = dr_catcher_data( 'http://api.smsbao.com/sms?u=' . $config [ 'smsbaouser' ]. '&p=' .md5( $config [ 'smsbaopass' ]). '&m=' . $mobile . '&c=【' . $config [ 'note' ]. '】' . $content ); if ( $result != 0) { return false; } else { $result = array ( 'status' => 'OK' , 'msg' => '发送成功' ); } } @ file_put_contents (CACHEPATH. 'sms_error.log' , date ( 'Y-m-d H:i:s' ). ' [' . $mobile . '] [' . $result [ 'msg' ]. '] (' . str_replace ( array ( chr (13), chr (10)), '' , $content ). ')' .PHP_EOL, FILE_APPEND); return $result ; } |
经过上面的替换,短信宝的短信平台已经替换成功了,可以正常使用了。进行测试发送:
报备一下短信宝的VIP模板,这样就可以走短信宝的优质通道了,即便遇到敏感文字我们都不会人工审核,短信内容3~5秒就可送达。
另外:我们已经开发好完整的POSCMS内容管理系统短信宝插件,点击此链接 下载及查看安装流程。
最新更新
电商类
CMS类
微信类