POSCMS是一款開源的跨平臺網站內容管理系統,他是基于PHP+MYSQL開發的 ,是一套非常適合用做系統建站或者進行二次開發的程序核心,小編對他還是比較了解的,今天小編就以新增短信接口為例,給大家講解一下如何進行二次開發,我們今天講解的是3.2版本,使用的短信接口是我們短信寶短信群發平臺的短信接口,我們短信寶短信群發平臺的接口非常穩定,發送速度快,注冊就送測試短信,推薦大家使用。
我們首先需要修改后臺顯示界面,打開項目\cache\templates\diy.dayrui.templates.admin.sms_index.html.cache.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
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
|
<? php if ($fn_include = $this->_include("nheader.html")) include($fn_include); ?> < script type = "text/javascript" > $(function() { <? php if ($data['uid']) { ?> $.getScript("<? php echo $service; ?>?c=check&uid=<? php echo $data['uid']; ?>&key=<? php echo $data['key']; ?>"); <? php } if ($data['type'] == 0) { ?> $('.dr_0').show();$('.dr_1').hide();$('.dr_2').hide(); <? php } elseif ($data['type'] == 1) { ?> $('.dr_1').show();$('.dr_0').hide();$('.dr_2').hide(); <? php } else {?> $('.dr_2').show();$('.dr_1').hide();$('.dr_0').hide(); <? php } ?> }); </ script > < form class = "form-horizontal" action = "" method = "post" id = "myform" name = "myform" > < div class = "page-bar" > < ul class = "page-breadcrumb mylink" > <? php echo $menu['link']; ?> < li > < a href="<?php echo dr_help_url(108); ?>" target="_blank">< i class = "fa fa-book" ></ i > <? php echo fc_lang('在線幫助'); ?></ a > </ li > </ ul > < ul class = "page-breadcrumb myname" > <? php echo $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" > <? php echo fc_lang('操作菜單'); ?> < i class = "fa fa-angle-down" ></ i > </ button > < ul class = "dropdown-menu pull-right" role = "menu" > <? php if (is_array($menu['quick'])) { $ count =count($menu['quick']);foreach ($menu['quick'] as $t) { ?> < li > < a href="<?php echo $t['url']; ?>"><? php echo $t['icon']; echo $t['name']; ?></ a > </ li > <? php } } ?> < li class = "divider" > </ li > < li > < a href = "javascript:window.location.reload();" > < i class = "icon-refresh" ></ i > <? php echo 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" ><? php echo 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;" ><? php echo 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();" <?php if ($data['type'] == 0) { ?>checked="checked"<? php } ?> /> <? php echo 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();" <?php if ($data['type'] == 1) { ?>checked="checked"<? php } ?> /> <? php echo 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();" <?php if ($data['type'] == 2) { ?>checked="checked"<? php } ?> /> <? php echo fc_lang('短信寶接口'); ?></ label > </ div > </ div > </ div > < div class = "form-group dr_0" > < label class = "col-md-2 control-label" ><? php echo fc_lang('申請教程'); ?>:</ label > < div class = "col-md-9" > < div class = "form-control-static" >< label >< a href = "http://help.dayrui.com/107.html" target = "_blank" >http://help.dayrui.com/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="<?php echo $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="<?php echo $data['key']; ?>" > </ div > </ div > <? php if ($data['uid']) { ?> < div class = "form-group dr_0" > < label class = "col-md-2 control-label" ><? php echo fc_lang('剩余短信'); ?>:</ label > < div class = "col-md-9" > < div class = "form-control-static" id = "dr_sms" >....</ div > </ div > </ div > <? php } ?> < div class = "form-group dr_1" > < label class = "col-md-2 control-label" ><? php echo fc_lang('申請教程'); ?>:</ label > < div class = "col-md-9" > < div class = "form-control-static" >< label >< a href = "http://help.dayrui.com/108.html" target = "_blank" >http://help.dayrui.com/108.html</ a ></ label ></ div > </ div > </ div > < div class = "form-group dr_1" > < label class = "col-md-2 control-label" ><? php echo fc_lang('字段格式'); ?>:</ label > < div class = "col-md-9" > < textarea class = "form-control" style = "height:120px" name = "data[third]" /><? php echo $data['third']; ?></ textarea > </ div > </ div > < div class = "form-group dr_2" > < label class = "col-md-2 control-label" ><? php echo fc_lang('申請地址'); ?>:</ label > < div class = "col-md-9" > < div class = "form-control-static" >< label >< a href = "http://www.gjrencai.com/reg" target = "_blank" >http://www.gjrencai.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[smsbaokey]" value="<?php echo $data['smsbaokey']; ?>" > </ 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="<?php echo $data['smsbaopass']; ?>" > </ div > </ div > < div class = "form-group " > < label class = "col-md-2 control-label" ><? php echo fc_lang('短信簽名'); ?>:</ label > < div class = "col-md-9" > < label >< input class = "form-control" type = "text" name = "data[note]" value="<?php echo $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 > <? php echo fc_lang('保存'); ?></ button > </ div > </ div > </ div > </ div > </ div > </ div > </ div > </ form > <? php if ($fn_include = $this->_include("nfooter.html")) include($fn_include); ?> |
顯示界面修改完成后,我們去修改接口配置文件,打開項目\diy\dayrui\controllers\admin\Sms.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
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
|
<?php if (!defined( 'BASEPATH' )) exit ( 'No direct script access allowed' ); /* v3.1.0 */ class Sms extends M_Controller { /** * 構造函數 */ public function __construct() { parent::__construct(); $this ->template->assign( 'menu' , $this ->get_menu_v3( array ( fc_lang( '賬號設置' ) => array ( 'admin/sms/index' , 'envelope' ), fc_lang( '發送短信' ) => array ( 'admin/sms/send' , 'send' ), fc_lang( '發送日志' ) => array ( 'admin/sms/log' , 'calendar' ), ))); } /** * 賬號 */ public function index() { $file = WEBPATH. 'config/sms.php' ; if (IS_POST) { $data = $this ->input->post( 'data' , true); // var_dump($data);exit; if ( strlen ( $data [ 'note' ]) > 30 ) { $this ->admin_msg(fc_lang( '短信簽名超出了范圍' )); } if ( $_POST [ 'type' ] == '0' || $_POST [ 'type' ] == '2' ) { unset( $data [ 'third' ]); } $this ->load->library( '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' ); } /** * 發送 */ public function send() { $file = WEBPATH. 'config/sms.php' ; if (! is_file ( $file )) { $this ->admin_msg(fc_lang( '您還沒有配置短信賬號呢' )); } $this ->template->display( 'sms_send.html' ); } /** * 發送 */ public function ajaxsend() { $file = WEBPATH. 'config/sms.php' ; if (! is_file ( $file )) { exit (dr_json(0, fc_lang( '您還沒有配置短信賬號呢' ))); } $data = $this ->input->post( 'data' , true); if ( strlen ( $data [ 'content' ]) > 150) { exit (dr_json(0, fc_lang( '短信內容過長,不得超過70個漢字' ))); } $mobile = $data [ 'mobile' ]; if ( $data [ 'mobiles' ] && ! $data [ 'mobile' ]) { $mobile = str_replace ( array (PHP_EOL, chr (13), chr (10)), ',' , $data [ 'mobiles' ]); $mobile = str_replace ( ',,' , ',' , $mobile ); $mobile = trim( $mobile , ',' ); } if (substr_count( $mobile , ',' ) > 40) { exit (dr_json(0, fc_lang( '群發一次不得超過40個,數量過多時請分批發送' ))); } $this ->system_log( '發送系統短信' ); // 記錄日志 $result = $this ->member_model->sendsms( $mobile , $data [ 'content' ]); if ( $result === FALSE) { exit (dr_json(0, '#0' .fc_lang( '發送失敗' ))); } else { exit (dr_json( $result [ 'status' ], $result [ 'msg' ])); } } /** * 日志 */ public function log() { if (IS_POST) { @unlink(WEBPATH. 'cache/sms_error.log' ); exit (dr_json(1, fc_lang( '操作成功,正在刷新...' ))); } $data = $list = array (); $file = @ file_get_contents (WEBPATH. 'cache/sms_error.log' ); if ( $file ) { $data = explode (PHP_EOL, $file ); $data = $data ? array_reverse ( $data ) : array (); unset( $data [0]); $page = max(1, (int) $this ->input->get( 'page' )); $limit = ( $page - 1) * SITE_ADMIN_PAGESIZE; $i = $j = 0; foreach ( $data as $v ) { if ( $i >= $limit && $j < SITE_ADMIN_PAGESIZE) { $list [] = $v ; $j ++; } $i ++; } } $total = count ( $data ); $this ->template->assign( array ( 'list' => $list , 'total' => $total , 'pages' => $this ->get_pagination(dr_url( 'sms/log' ), $total ) )); $this ->template->display( 'sms_log.html' ); } } |
接下來我們去修改接口發送文件,打開項目\diy\module\member\models\Member_model.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
|
/** * 短信發送 * * @param string $mobile * @param string $content * @return bool */ public function sendsms( $mobile , $content ) { if (! $mobile || ! $content ) { return FALSE; } $file = WEBPATH. 'config/sms.php' ; if (! is_file ( $file )) { return FALSE; } $config = require_once $file ; if ( $config [ 'type' ] == '0' ) { $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); } else { $result = dr_catcher_data( 'http://api.smsbao.com/sms?u=' . $config [ 'smsbaokey' ]. '&p=' .md5( $config [ 'smsbaopass' ]). '&m=' . $mobile . '&c=【' . $config [ 'note' ]. '】' . $content ); if ( $result != 0) { return false; } else { $result = array ( 'status' => 'OK' , 'msg' => '發送成功' ); } } @ file_put_contents (WEBPATH. 'cache/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秒就可送達。
最新更新
電商類
CMS類
微信類