五指CMS是國(guó)內(nèi)新一代、能夠?qū)崿F(xiàn)跨屏管理的網(wǎng)站內(nèi)容管理系統(tǒng),是國(guó)內(nèi)家后臺(tái)管理界面全部采用HTML5+CSS3技術(shù)的內(nèi)容管理系統(tǒng)(CMS),該系統(tǒng)采用了PHP5+MYSQL做為技術(shù)基礎(chǔ)進(jìn)行開發(fā)。采用了面向?qū)ο蟮木幊谭绞剑鄬蛹軜?gòu)設(shè)計(jì),模塊化的開發(fā)方式。系統(tǒng)功能易于擴(kuò)展,易于二次開發(fā),支持站群。今天小編就已替換短信接口為例為大家講解一下如何進(jìn)行二次開發(fā),我們講解的是v4.1.0版本,使用的短信接口是我們短信寶短信群發(fā)平臺(tái)的接口,我們短信寶短信群發(fā)平臺(tái)非常穩(wěn)定,發(fā)送速度快,注冊(cè)就送測(cè)試短信,推薦大家使用。
首先我們更換后臺(tái)顯示界面,打開項(xiàng)目\coreframe\app\sms\admin\template\setting.tpl.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
|
<? php defined('IN_WZ') or exit('No direct script access allowed');?> <? php include $this->template('header','core'); ?> < body class = "body pxgridsbody" > < section class = "wrapper" > < div class = "row" > < div class = "col-lg-12" > < section class = "panel" > <? php echo $this->menu($GLOBALS['_menuid']);?> < div class = "panel-body" > < form class = "form-horizontal tasi-form" method = "post" action = "" > < div class = "form-group" > < label class = "col-sm-2 col-xs-4 control-label" >短信寶用戶名</ label > < div class = "col-lg-3 col-sm-4 col-xs-4 input-group" > < input type = "text" class = "form-control" name = "form[sms_uid]" value="<?php echo output($setting,'sms_uid');?>" placeholder=""> </ div > </ div > < div class = "form-group" > < label class = "col-sm-2 col-xs-4 control-label" >短信寶密碼</ label > < div class = "col-lg-3 col-sm-4 col-xs-4 input-group" > < input type = "password" class = "form-control" name = "form[sms_pid]" value="<?php echo output($setting,'sms_pid');?>"> </ div > </ div > < div class = "form-group" > < label class = "col-sm-2 col-xs-4 control-label" >短信簽名</ label > < div class = "col-lg-3 col-sm-4 col-xs-4 input-group" > < input type = "text" class = "form-control" name = "form[sms_passwd]" value="<?php echo output($setting,'sms_passwd');?>"> </ div > </ div > < div class = "form-group" > < label class = "col-sm-2 col-xs-4 control-label" ></ label > < div class = "col-lg-3 col-sm-4 col-xs-4 input-group" > < input class = "btn btn-info col-sm-12 col-xs-12" type = "submit" name = "submit" value = "提交" > </ div > </ div > </ form > </ div > </ section > </ div > </ div > <!-- page end--> < div class = "alert alert-success fade in" > < strong >短信購買:</ strong > 支持全國(guó)電信、移動(dòng)、聯(lián)通手機(jī)用戶。購買地址 < a href = "http://www.gjrencai.com" target = "_blank" >http://www.gjrencai.com</ a > </ div > </ section > < script src="<?php echo R;?>js/bootstrap.min.js"></ script > < script src="<?php echo R;?>js/jquery.nicescroll.js" type="text/javascript"></ script > < script src="<?php echo R;?>js/pxgrids-scripts.js"></ script > |
其次我們修改短信發(fā)送類,打開項(xiàng)目\coreframe\app\sms\libs\class\sms.class.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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
|
<?php defined( 'IN_WZ' ) or exit ( 'No direct script access allowed' ); /** * 短信API */ class WUZHI_sms { public $uid ; public $statuscode ; private $sms_uid , $sms_pid , $sms_key , $smsapi_url ; /** * * 初始化接口類 * @param int $uid 用戶id * @param int $sms_pid 產(chǎn)品id * @param string $sms_key 密鑰 */ public function __construct() { $sms_config = get_cache( 'sms_config' , 'sms' ); $this ->sms_uid = $sms_config [ 'sms_uid' ]; $this ->sms_pid = $sms_config [ 'sms_pid' ]; $this ->sms_key = $sms_config [ 'sms_passwd' ]; } /** * * 獲取短信產(chǎn)品列表信息 */ public function get_price() { return []; } /** * * 獲取短信產(chǎn)品購買地址 */ public function get_buyurl( $productid = 0) { return []; } /** * 獲取短信剩余條數(shù)和限制短信發(fā)送ip */ public function get_smsinfo() { return []; } /** * 獲取充值記錄 */ public function get_buyhistory() { return []; } /** * 獲取消費(fèi)記錄 * @param int $page 頁碼 */ public function get_payhistory( $page =1) { return []; } /** * 發(fā)送短信 * * @param string $mobile * @param string $content * @param string $tplid * @param string $send_time * @param int $return_code * @return mixed */ public function send_sms( $mobile = '' , $content = '' , $tplid = '' , $send_time = '' , $return_code = 0) { //短信發(fā)送狀態(tài) $status = $this ->_sms_status(); if ( is_array ( $mobile )){ $mobile = implode( "," , $mobile ); } /*if(strtolower(CHARSET)=='utf-8') { $send_content = iconv('utf-8','gbk',$content); }else{ $send_content = $content; }*/ //$send_content = $content; //$send_time = strtotime($send_time); //短信模板 $sitelist = get_cache( 'sitelist' ); $siteid = intval ( $GLOBALS [ 'siteid' ]); $sms_param = explode ( '||' , $content ); if ( $tplid ==269){ //發(fā)送優(yōu)惠券信息,尊敬的用戶,五指CMS優(yōu)惠券為:sss,截止日期為:2016-12-1,請(qǐng)登錄www.h1jk.cn及時(shí)使用! $tpl = "尊敬的用戶您好,恭喜你獲得優(yōu)惠券,卡號(hào)為:%s,截止日期為:%s,請(qǐng)及時(shí)使用,請(qǐng)登錄" . $sitelist [ $siteid ][ 'url' ]s; $sms_content =sprintf( $tpl , $sms_param [0], $sms_param [1]); } elseif ( $tplid ==222){ //您的預(yù)約卡信息如下:<br>卡號(hào):{$r['card_no']} <br> 密碼:{$card_password}<br> $tpl = "您的預(yù)約卡信息如下:卡號(hào):%s, 密碼:%s!" ; $sms_content =sprintf( $tpl , $content ); } else { //驗(yàn)證碼 $tpl = "您的驗(yàn)證碼為:%s,請(qǐng)不要告訴他人。" ; $sms_content =sprintf( $tpl , $sms_param [0], $sms_param [1]); } $data = array ( 'u' => $this ->sms_uid, 'p' => md5( $this ->sms_pid), 'c' => "【" . $this ->sms_key. "】" . $sms_content , 'm' => $mobile , ); $send_res = file_get_contents ( $this ->smsapi_url.http_build_query( $data )); //echo $this->smsapi_url.http_build_query($data); return $send_res ; } /** * * 獲取遠(yuǎn)程內(nèi)容 * @param $timeout 超時(shí)時(shí)間 */ public function getinfo( $timeout =30) { $this ->setting = array ( 'sms_uid' => $this ->sms_uid, 'sms_pid' => $this ->sms_pid, 'sms_passwd' => $this ->sms_key, ); $this ->param = array_merge ( $this ->param, $this ->setting); $url = $this ->smsapi_url.http_build_query( $this ->param); $stream = stream_context_create( array ( 'http' => array ( 'timeout' => $timeout ))); return @ file_get_contents ( $url , 0, $stream ); } /** * post數(shù)據(jù) * @param string $url post的url * @param int $limit 返回的數(shù)據(jù)的長(zhǎng)度 * @param string $post post數(shù)據(jù),字符串形式username='dalarge'&password='123456' * @param string $cookie 模擬 cookie,字符串形式username='dalarge'&password='123456' * @param string $ip ip地址 * @param int $timeout 連接超時(shí)時(shí)間 * @param bool $block 是否為阻塞模式 * @return string 返回字符串 */ private function _post( $url , $limit = 0, $post = '' , $cookie = '' , $ip = '' , $timeout = 30, $block = true) { $return = '' ; $matches = parse_url ( $url ); $host = $matches [ 'host' ]; $path = $matches [ 'path' ] ? $matches [ 'path' ].( $matches [ 'query' ] ? '?' . $matches [ 'query' ] : '' ) : '/' ; $port = ! empty ( $matches [ 'port' ]) ? $matches [ 'port' ] : 80; $siteurl = URL(); if ( $post ) { $out = "POST $path HTTP/1.1\r\n" ; $out .= "Accept: */*\r\n" ; $out .= "Referer: " . $siteurl . "\r\n" ; $out .= "Accept-Language: zh-cn\r\n" ; $out .= "Content-Type: application/x-www-form-urlencoded\r\n" ; $out .= "User-Agent: $_SERVER[HTTP_USER_AGENT]\r\n" ; $out .= "Host: $host\r\n" ; $out .= 'Content-Length: ' . strlen ( $post ). "\r\n" ; $out .= "Connection: Close\r\n" ; $out .= "Cache-Control: no-cache\r\n" ; $out .= "Cookie: $cookie\r\n\r\n" ; $out .= $post ; } else { $out = "GET $path HTTP/1.1\r\n" ; $out .= "Accept: */*\r\n" ; $out .= "Referer: " . $siteurl . "\r\n" ; $out .= "Accept-Language: zh-cn\r\n" ; $out .= "User-Agent: $_SERVER[HTTP_USER_AGENT]\r\n" ; $out .= "Host: $host\r\n" ; $out .= "Connection: Close\r\n" ; $out .= "Cookie: $cookie\r\n\r\n" ; } $fp = @ fsockopen (( $ip ? $ip : $host ), $port , $errno , $errstr , $timeout ); if (! $fp ) return '' ; stream_set_blocking( $fp , $block ); stream_set_timeout( $fp , $timeout ); @fwrite( $fp , $out ); $status = stream_get_meta_data( $fp ); if ( $status [ 'timed_out' ]) return '' ; while (! feof ( $fp )) { if (( $header = @ fgets ( $fp )) && ( $header == "\r\n" || $header == "\n" )) break ; } $stop = false; while (! feof ( $fp ) && ! $stop ) { $data = fread ( $fp , ( $limit == 0 || $limit > 8192 ? 8192 : $limit )); $return .= $data ; if ( $limit ) { $limit -= strlen ( $data ); $stop = $limit <= 0; } } @fclose( $fp ); //部分虛擬主機(jī)返回?cái)?shù)值有誤,暫不確定原因,過濾返回?cái)?shù)據(jù)格式 $return_arr = explode ( "\n" , $return ); if (isset( $return_arr [1])) { $return = trim( $return_arr [1]); } unset( $return_arr ); return $return ; } /** * * 接口短信狀態(tài) */ private function _sms_status() { $array = array ( '0' => '發(fā)送成功' , "-1" => "參數(shù)不全" , "-2" => "服務(wù)器空間不支持,請(qǐng)確認(rèn)支持curl或者fsocket,聯(lián)系您的空間商解決或者更換空間!" , "30" => "密碼錯(cuò)誤" , "40" => "賬號(hào)不存在" , "41" => "余額不足" , "42" => "帳戶已過期" , "43" => "IP地址限制" , "50" => "內(nèi)容含有敏感詞" , ); return $array ; } } ?> |
最后修改發(fā)送短信文件,打開項(xiàng)目\coreframe\app\sms\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
|
<?php defined( 'IN_WZ' ) or exit ( 'No direct script access allowed' ); /** * 發(fā)送短信驗(yàn)證碼 */ class sms{ public function __construct() { $this ->db = load_class( 'db' ); } /** * 發(fā)送短信(手機(jī)短信驗(yàn)證碼、圖片驗(yàn)證碼) */ public function sendsms() { //驗(yàn)證 頁面驗(yàn)證碼是否正確 //插入相關(guān)信息 /** 1、使用安全圖片驗(yàn)證碼(網(wǎng)站) 2、單IP的請(qǐng)求次數(shù)限定 (網(wǎng)站)(APP) 3、單用戶動(dòng)態(tài)短信請(qǐng)求間隔時(shí)長(zhǎng)限制(網(wǎng)站)(APP) 4、 同一手機(jī)號(hào)次數(shù)限定 (網(wǎng)站)(APP) */ $config = get_cache( 'sms_config' , 'sms' ); $uid = get_cookie( '_uid' ); $mobile = $GLOBALS [ 'mobile' ]; if (!preg_match( '/^(?:13\d{9}|15[0|1|2|3|5|6|7|8|9]\d{8}|17[0|1|2|3|5|6|7|8|9]\d{8}|18[0|1|2|3|5|6|7|8|9]\d{8}|14[5|7]\d{8})$/' , $mobile )) { exit ( '201' ); } $checkcode = $GLOBALS [ 'checkcode' ]; if ( $checkcode == '' ) exit ( '202' ); load_class( 'session' ); if ( strtolower ( $_SESSION [ 'code' ]) != strtolower ( $checkcode )) exit ( '202' ); $_SESSION [ 'code' ] = '' ; $endtime = SYS_TIME-120; if ( $_SESSION [ 'et' ] && $_SESSION [ 'et' ]> $endtime ) { if ( $config [ 'sms_uid' ]!= 'test' ) { exit ( '204' ); } } else { $_SESSION [ 'et' ] = SYS_TIME; } if (isset( $GLOBALS [ 'isreg' ]) && $GLOBALS [ 'isreg' ]) { //是否為注冊(cè),驗(yàn)證手機(jī)是否已注冊(cè) $reg_data = $this ->db->get_one( 'member' , array ( 'mobile' => $mobile ), 'uid' ); if ( $reg_data ) { exit ( '206' ); } } $posttime = SYS_TIME-86400; $ip = get_ip(); $where = "`ip`='$ip' AND `posttime`>$posttime" ; $num = $this ->db->count_result( 'sms_checkcode' , $where ); if ( $num >200 && $config [ 'sms_uid' ]!= 'test' ) { //單IP 24小時(shí)內(nèi)最大請(qǐng)求次數(shù)限定 exit ( '203' ); } //單用戶動(dòng)態(tài)短信請(qǐng)求間隔時(shí)長(zhǎng)限制 ,根據(jù)手機(jī)號(hào)碼判斷是否為一個(gè)用戶 $where = "`mobile`='$mobile'" ; $r = $this ->db->get_one( 'sms_checkcode' , $where , '*' , 0, 'id DESC' ); if ( $r [ 'posttime' ]> $endtime && $config [ 'sms_uid' ]!= 'test' ) { //120 秒之內(nèi)連續(xù)請(qǐng)求 exit ( '204' ); } //同一手機(jī)號(hào)次數(shù)限定 $where = "`mobile`='$mobile' AND `posttime`>=$posttime" ; $num = $this ->db->count_result( 'sms_checkcode' , $where ); if ( $num >200 && $config [ 'sms_uid' ]!= 'test' ) { //同一手機(jī)號(hào)次數(shù)限定 24小時(shí)內(nèi)最大請(qǐng)求次數(shù)限定 exit ( '205' ); } //驗(yàn)證通過 $sendsms = load_class( 'sms' , 'sms' ); if ( $config [ 'sms_uid' ]!= 'test' ) { $code = rand(1000,9999); } else { $code = 1111; } $formdata = array (); $formdata [ 'mobile' ] = $mobile ; $formdata [ 'uid' ] = $uid ; $formdata [ 'posttime' ] = SYS_TIME; $formdata [ 'code' ] = $code ; $formdata [ 'ip' ] = $ip ; $this ->db->insert( 'sms_checkcode' , $formdata ); if ( $config [ 'sms_uid' ]!= 'test' ) { $returnstr = $sendsms ->send_sms( $mobile , $code , 1); //發(fā)送短信 if ( $returnstr ==0) { exit ( '0' ); } else { echo $returnstr ; } } else { exit ( '0' ); } } } ?> |
好了,經(jīng)過以上的替換,短信寶的短信平臺(tái)已經(jīng)替換成功了,我們?nèi)ミM(jìn)行發(fā)送測(cè)試:
報(bào)備一下短信寶的VIP模板,這樣就可以走短信寶的優(yōu)質(zhì)通道了,并且免審核了,短信內(nèi)容3~5秒就可送達(dá)。
另外:我們已經(jīng)開發(fā)好完整的五指cms網(wǎng)站管理系統(tǒng)短信寶插件,點(diǎn)擊此鏈接 下載及查看安裝流程。
最新更新
電商類
CMS類
微信類