PHPCMS V9采用PHP5+MYSQL做為技術(shù)基礎(chǔ)進行開發(fā)。V9采用OOP(面向?qū)ο螅┓绞竭M行基礎(chǔ)運行框架搭建。模塊化開發(fā)方式做為功能開發(fā)形式。框架易于功能擴展,代碼維護,優(yōu)秀的二次開發(fā)能力,可滿足所有網(wǎng)站的應(yīng)用需求。今天我就來帶大家來做一次替換短信接口的工作。
我們短信寶的平臺極其穩(wěn)定,而且短信發(fā)送速度相當(dāng)快捷,驗證碼和訂單通知在3~5秒就能收到,用戶體驗非常好,推薦大家使用。
接下來我就來說一下開發(fā)步驟:
1. 首先,我們先更換后臺的顯示界面文件。打開模板文件,替換一下模板文件。打開項目/phpcms/modules/sms/templates/index.tpl.php,替換的代碼從12行~86行,代碼如下圖所示:
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
|
< div class = "explain-col search-form" > 短信模塊默認使用< a href = "http://www.gjrencai.com" target = "_blank" style = "font-weight:bold;color:red;" >短信寶</ a >接口, 還沒有短信寶賬戶,請點擊< a href = "http://smsbao.com/reg" target = "_blank" style = "font-weight:bold;color:red;" >免費注冊</ a >, 短信寶客服熱線:400-716-3021,或聯(lián)系短信寶< a href = "http://wpa.b.qq.com/cgi/wpa.php?ln=1&key=XzkzODA0NjAyMV8yNTU0MzFfNDAwMDA5MDQ2NV8yXw" target = "_blank" style = "font-weight:bold;color:red;" >在線客服</ a > </ br > 說明:欲購買1W條以上的短信套餐以及包月套餐用戶,請咨詢< a href = "http://wpa.b.qq.com/cgi/wpa.php?ln=1&key=XzkzODA0NjAyMV8yNTU0MzFfNDAwMDA5MDQ2NV8yXw" target = "_blank" style = "font-weight:bold;color:red;" >在線客服</ a > </ br > 備注:短信寶官網(wǎng)(http://www.gjrencai.com),短信寶技術(shù)交流群:188145230 </ div > </ form > < div class = "btn text-l" > < span class = "font-fixh green" >您當(dāng)前賬戶為:<? php echo $this->smsapi->userid?>,短信寶賬戶剩余短信條數(shù):<? php echo $smsinfo_arr?></ span > </ div >< br > < br > < table width = "100%" cellspacing = "0" > < thead > < tr > < th width = "5%" align = "center" ><? php echo L('product_id')?></ th > < th width = "20%" align = "left" ><? php echo L('product_name')?></ th > < th width = "30%" align = "left" ><? php echo L('product_description')?></ th > < th width = "10%" align = "left" ><? php echo L('totalnum')?></ th > < th width = "10%" align = "left" ><? php echo L('give_away')?></ th > < th width = "10%" align = "left" ><? php echo L('product_price').L('yuan')?></ th > < th width = "10%" align = "left" ><? php echo L('buy')?></ th > </ tr > </ thead > < tbody > < tr > < td width = "10%" align = "center" >1</ td > < td width = "10%" align = "left" >50條短信</ td > < td width = "10%" align = "left" >50條短信</ td > < td width = "10%" align = "left" >50</ td > < td width = "10%" align = "left" >0</ td > < td width = "10%" align = "left" >5</ td > < td width = "10%" align = "left" >< a href = "http://smsbao.com/member/product/list.jhtml" target = "_blank" >購買</ a ></ td > </ tr > < tr > < td width = "10%" align = "center" >2</ td > < td width = "10%" align = "left" >500條短信</ td > < td width = "10%" align = "left" >500條短信</ td > < td width = "10%" align = "left" >500</ td > < td width = "10%" align = "left" >0</ td > < td width = "10%" align = "left" >40</ td > < td width = "10%" align = "left" >< a href = "http://smsbao.com/member/product/list.jhtml" target = "_blank" >購買</ a ></ td > </ tr > < tr > < td width = "10%" align = "center" >3</ td > < td width = "10%" align = "left" >2000條短信</ td > < td width = "10%" align = "left" >2000條短信</ td > < td width = "10%" align = "left" >2000</ td > < td width = "10%" align = "left" >0</ td > < td width = "10%" align = "left" >150</ td > < td width = "10%" align = "left" >< a href = "http://smsbao.com/member/product/list.jhtml" target = "_blank" >購買</ a ></ td > </ tr > < tr > < td width = "10%" align = "center" >4</ td > < td width = "10%" align = "left" >5000條短信</ td > < td width = "10%" align = "left" >5000條短信</ td > < td width = "10%" align = "left" >5000</ td > < td width = "10%" align = "left" >0</ td > < td width = "10%" align = "left" >375</ td > < td width = "10%" align = "left" >< a href = "http://smsbao.com/member/product/list.jhtml" target = "_blank" >購買</ a ></ td > </ tr > < tr > < td width = "10%" align = "center" >5</ td > < td width = "10%" align = "left" >10000條短信</ td > < td width = "10%" align = "left" >10000條短信</ td > < td width = "10%" align = "left" >10000</ td > < td width = "10%" align = "left" >0</ td > < td width = "10%" align = "left" >700</ td > < td width = "10%" align = "left" >< a href = "http://smsbao.com/member/product/list.jhtml" target = "_blank" >購買</ a ></ td > </ tr > </ tbody > </ table > |
打開項目/phpcms/modules/sms/templates/sms_sent.tpl.php,替換的代碼從35行~53行,代碼如下圖所示:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
< form name = "dosubmit" action = "?m=sms&c=sms&a=sms_sent" method = "post" id = "myform" > < table width = "100%" class = "table_form" > < tr > < td width = "120" >發(fā)送號碼 < font color = "#C0C0C0" >(每行一個號碼)</ font ></ td > < td >< textarea name = "mobile" ></ textarea ></ td > </ tr > < tr ></ br > < tr > < td width = "120" >發(fā)送內(nèi)容 < font color = "#C0C0C0" >(短信群發(fā)內(nèi)容)</ font ></ td > < td >< textarea name = "msg" ></ textarea ></ td > </ tr > </ table > < div class = "bk15" ></ div > < input name = "dosubmit" type = "submit" value="<?php echo L('submit')?>" class="button" id="dosubmit"> </ form > |
打開項目/phpcms/modules/sms/templates/sms_setting.tpl.php,替換的代碼從7行~32行,代碼如下圖所示:
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
|
< form name = "myform" action = "?m=sms&c=sms&a=sms_setting" method = "post" id = "myform" > < table width = "100%" class = "table_form" > < tr > < td width = "120" ><? php echo L('sms_enable')?></ td > < td > < input name = "setting[sms_enable]" value = "1" type = "radio" id = "sms_enable" <?php if($this->sms_setting[sms_enable] == 1) {?>checked<? php }?>> <? php echo L('open')?> < input name = "setting[sms_enable]" value = "0" type = "radio" id = "sms_enable" <?php if($this->sms_setting[sms_enable] == 0) {?>checked<? php }?>> <? php echo L('close')?> </ td > </ tr > < tr > < td width = "120" >短信寶用戶名 < font color = "#C0C0C0" ></ font ></ td > < td > < input type = "text" name = "setting[userid]" size = "20" placeholder = "填寫你在短信寶注冊的用戶名" value="<?php echo $this->sms_setting[userid]?>" id="userid"> </ td > </ tr > < tr > < td width = "120" >短信寶密碼 < font color = "#C0C0C0" ></ font ></ td > < td > < label > < input type = "input" id = "sms_key" name = "setting[sms_key]" value="<?php echo $this->sms_setting[sms_key]?>" size="50"> < input type = "hidden" name = "pc_hash" value="<?php echo $_GET['pc_hash'];?>" size="50"> </ label > </ td > </ tr > < tr > < td width = "120" >短信簽名 < font color = "#C0C0C0" ></ font ></ td > < td > < input type = "text" name = "setting[productid]" size = "20" placeholder = "填寫你所發(fā)送短信的簽名" value="<?php echo $this->sms_setting[productid]?>" id="productid"> </ td > </ tr > </ table > < div class = "bk15" ></ div > < input name = "dosubmit" type = "submit" value="<?php echo L('submit')?>" class="button" id="dosubmit"> </ form > |
經(jīng)過替換后,所有的顯示都變成短信寶短信平臺的了。第一步完成。接下來替換發(fā)送短信的業(yè)務(wù)代碼。修改項目/phpcms/modules/sms/functions/global.func.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
|
<?php function sms_status( $status = 0, $return_array = 0) { $array = array ( '0' => '發(fā)送成功' , '30' => '密碼錯誤' , '40' => '賬號不存在' , '41' => '余額不足' , '42' => '帳號過期' , '43' => 'IP地址限制' , '50' => '內(nèi)容含有敏感詞' , '51' => '手機號碼不正確' , '-1' => '參數(shù)不全' ); return $return_array ? $array : $array [ $status ]; } function checkmobile( $mobilephone ) { $mobilephone = trim( $mobilephone ); if (preg_match( "/^13[0-9]{1}[0-9]{8}$|15[01236789]{1}[0-9]{8}$|18[01236789]{1}[0-9]{8}$/" , $mobilephone )){ return $mobilephone ; } else { return false; } } function get_smsnotice( $type = '' ) { $url = isset( $_SERVER [ 'HTTP_HOST' ]) ? $_SERVER [ 'HTTP_HOST' ] : '' ; $urls = base64_decode ( 'aHR0cDovL3Ntcy5waHBpcC5jb20vYXBpLnBocD9vcD1zbXNub3RpY2UmdXJsPQ==' ). $url . "&type=" . $type ; $content = pc_file_get_contents( $urls ,5); if ( $content ) { $content = json_decode( $content ,true); if ( $content [ 'status' ]==1) { return strtolower (CHARSET)== 'gbk' ?iconv( 'utf-8' , 'gbk' , $content [ 'msg' ]) : $content [ 'msg' ]; } } $urls = base64_decode ( 'aHR0cDovL3Ntcy5waHBjbXMuY24vYXBpLnBocD9vcD1zbXNub3RpY2UmdXJsPQ==' ). $url . "&type=" . $type ; $content = pc_file_get_contents( $urls ,3); if ( $content ) { $content = json_decode( $content ,true); if ( $content [ 'status' ]==1) { return strtolower (CHARSET)== 'gbk' ?iconv( 'utf-8' , 'gbk' , $content [ 'msg' ]) : $content [ 'msg' ]; } } return '<font color="red">短信通服務(wù)器無法訪問!您將無法使用短信通服務(wù)!</font>' ; } function sendsms( $mobile , $send_txt , $tplid = 1, $id_code = '' , $siteid =1) { pc_base::load_app_class( 'smsapi' , 'sms' , 0); //引入smsapi類 $sms_setting = getcache( 'sms' , 'sms' ); $sms_uid = $sms_setting [ $siteid ][ 'userid' ]; //短信接口用戶ID $sms_pid = $sms_setting [ $siteid ][ 'productid' ]; //產(chǎn)品ID $sms_passwd = $sms_setting [ $siteid ][ 'sms_key' ]; //32位密碼 $smsapi = new smsapi( $sms_uid , $sms_pid , $sms_passwd ); //初始化接口類 $mobile = explode ( ',' , $mobile ); $code = $smsapi ->send_sms( $mobile , $send_txt , 0, CHARSET, $id_code , $tplid ,1); //發(fā)送短信 if ( $code ==0) { return 0; } else { return sms_status( $code ,1); } } |
修改項目/phpcms/modules/sms/classes/smsapi.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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
|
<?php /** * 短信平臺API接口類 */ class smsapi { public $userid ; public $statuscode ; private $productid , $sms_key , $smsapi_url ; /** * * 初始化接口類 * @param int $userid 用戶id * @param int $productid 產(chǎn)品id * @param string $sms_key 密鑰 */ public function __construct( $userid = '' , $productid = '' , $sms_key = '' ) { $this ->userid = $userid ; $this ->productid = $productid ; $this ->sms_key = $sms_key ; } /** * * 獲取短信產(chǎn)品列表信息 */ public function get_price() { $this ->param = array ( 'op' => 'sms_get_productlist' ); $res = $this ->pc_file_get_contents(); return ! empty ( $res ) ? json_decode( $res , 1) : array (); } /** * * 獲取短信產(chǎn)品購買地址 */ public function get_buyurl( $productid = 0) { } public function show_qf_url() { return $this ->smsapi_url. 'u=' . $this ->userid. '&p=' .md5( $this ->sms_key). '&m={mobile}&c=【' . $this ->productid. '】{content}' ; } /** * 獲取短信剩余條數(shù)和限制短信發(fā)送ip */ public function get_smsinfo() { $post = 'u=' . $this ->userid. '&p=' .md5( $this ->sms_key); $retArr = split( "\n" , $ret ); $balanceArr = split( "," , $retArr [1]); $balance = $retArr [0] == 0 ? $balanceArr [1] : $ret ; return $balance ; } /** * 獲取充值記錄 */ public function get_buyhistory() { $this ->param = array ( 'op' => 'sms_get_paylist' ); $res = $this ->pc_file_get_contents(); return ! empty ( $res ) ? json_decode( $res , 1) : array (); } /** * 獲取消費記錄 * @param int $page 頁碼 */ public function get_payhistory( $page =1) { $this ->param = array ( 'op' => 'sms_get_report' , 'page' => $page ); $res = $this ->pc_file_get_contents(); return ! empty ( $res ) ? json_decode( $res , 1) : array (); } /** * 獲取短信api幫助 */ public function get_sms_help() { $this ->param = array ( 'op' => 'sms_help' , 'page' => $page ); $res = $this ->pc_file_get_contents(); return ! empty ( $res ) ? json_decode( $res , 1) : array (); } /** * * 批量發(fā)送短信 * @param array $mobile 手機號碼 * @param string $content 短信內(nèi)容 * @param datetime $send_time 發(fā)送時間 * @param string $charset 短信字符類型 gbk / utf-8 * @param string $id_code 唯一值 、可用于驗證碼 */ public function send_sms( $mobile = '' , $content = '' , $send_time = '' , $charset = 'gbk' , $id_code = '' , $tplid = '' , $return_code = 0) { //短信發(fā)送狀態(tài) $status = $this ->_sms_status(); $content = safe_replace( $content ); $send_content = $content ; $send_time = strtotime ( $send_time ); $smsapi_senturl = $this ->smsapi_url. 'op=sms_service_new' ; foreach ( $mobile as $key => $val ){ $data = array ( 'p' => md5( $this ->sms_key), 'u' => $this ->userid, 'charset' => CHARSET, 'c' => urlencode( '【' . $this ->productid. '】' . $send_content ), 'm' => $val , 'send_time' => $send_time , 'tplid' => $tplid , ); $post = '' ; foreach ( $data as $k => $v ) { $post .= $k . '=' . $v . '&' ; } $return = $this ->_post( $smsapi_senturl , 0, $post ); //增加到本地數(shù)據(jù)庫 $sms_report_db = pc_base::load_model( 'sms_report_model' ); $send_userid = param::get_cookie( '_userid' ) ? intval (param::get_cookie( '_userid' )) : 0; $ip = ip(); $new_content = $content ; if ( $return == '0' ) { $sms_report_db ->insert( array ( 'mobile' => $val , 'posttime' =>SYS_TIME, 'id_code' => $id_code , 'send_userid' => $send_userid , 'status' => $this ->statuscode, 'msg' => $new_content , 'return_id' => $return , 'ip' => $ip )); } else { $sms_report_db ->insert( array ( 'mobile' => $val , 'posttime' =>SYS_TIME, 'send_userid' => $send_userid , 'status' => '-2' , 'msg' => $new_content , 'ip' => $ip )); } if ( $this ->statuscode==0) { $barr = explode ( ':' , $arr [1]); if ( $barr [0]== 'KEY' ) { return '短信已提交,請等待審批!審批時間為:9:00-18:00。 法定假日不審批!如需幫助,請聯(lián)系phpcms.cn官網(wǎng)!' ; } } //end } } /** * * 獲取遠程內(nèi)容 * @param $timeout 超時時間 */ public function pc_file_get_contents( $timeout =30) { $this ->setting = array ( 'u' => $this ->userid, 'p' =>md5( $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ù)的長度 * @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 連接超時時間 * @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 = $this ->_get_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 ); //部分虛擬主機返回數(shù)值有誤,暫不確定原因,過濾返回數(shù)據(jù)格式 $return_arr = explode ( "\n" , $return ); if (isset( $return_arr [1])) { $return = trim( $return_arr [1]); } unset( $return_arr ); return $return ; } /** * 獲取當(dāng)前頁面完整URL地址 */ private function _get_url() { $sys_protocal = isset( $_SERVER [ 'SERVER_PORT' ]) && $_SERVER [ 'SERVER_PORT' ] == '443' ? 'https://' : 'http://' ; $php_self = $_SERVER [ 'PHP_SELF' ] ? $this ->_safe_replace( $_SERVER [ 'PHP_SELF' ]) : $this ->_safe_replace( $_SERVER [ 'SCRIPT_NAME' ]); $path_info = isset( $_SERVER [ 'PATH_INFO' ]) ? $this ->_safe_replace( $_SERVER [ 'PATH_INFO' ]) : '' ; $relate_url = isset( $_SERVER [ 'REQUEST_URI' ]) ? $this ->_safe_replace( $_SERVER [ 'REQUEST_URI' ]) : $php_self .(isset( $_SERVER [ 'QUERY_STRING' ]) ? '?' . $this ->_safe_replace( $_SERVER [ 'QUERY_STRING' ]) : $path_info ); return $sys_protocal .(isset( $_SERVER [ 'HTTP_HOST' ]) ? $_SERVER [ 'HTTP_HOST' ] : '' ). $relate_url ; } /** * 安全過濾函數(shù) * * @param $string * @return string */ private function _safe_replace( $string ) { $string = str_replace ( '%20' , '' , $string ); $string = str_replace ( '%27' , '' , $string ); $string = str_replace ( '%2527' , '' , $string ); $string = str_replace ( '*' , '' , $string ); $string = str_replace ( '"' , '"' , $string ); $string = str_replace ( "'" ,'', $string ); $string = str_replace ( '"' , '' , $string ); $string = str_replace ( ';' , '' , $string ); $string = str_replace ( '<' , '<' , $string ); $string = str_replace ( '>' , '>' , $string ); $string = str_replace ( "{" , '' , $string ); $string = str_replace ( '}' , '' , $string ); $string = str_replace ( '\\' , '' , $string ); return $string ; } /** * * 接口短信狀態(tài) */ private function _sms_status() { pc_base::load_app_func( 'global' , 'sms' ); return sms_status(0,1); } } ?> |
修改項目/api/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
|
<?php defined( 'IN_PHPCMS' ) or exit ( 'No permission resources.' ); /** * 短信發(fā)送接口 */ $sms_report_db = pc_base::load_model( 'sms_report_model' ); $session_storage = 'session_' .pc_base::load_config( 'system' , 'session_storage' ); pc_base::load_sys_class( $session_storage ); if ( empty ( $_SESSION [ 'code' ])) exit ( '-100' ); if ( empty ( $_GET [ 'session_code' ]) || preg_match( '/^([a-zA-Z0-9])$/i' , $_GET [ 'session_code' ]) || $_SESSION [ 'code' ]!= $_GET [ 'session_code' ]) exit ( '-101' ); if (isset( $_GET [ 'mobile' ]) && ! empty ( $_GET [ 'mobile' ])) { $mobile = $_GET [ 'mobile' ]; } else { $mobile = $_SESSION [ 'mobile' ]; } $_SESSION [ 'code' ] = '' ; if (!isset( $_SESSION [ 'csms' ])) { $_SESSION [ 'csms' ] = 0; } elseif ( $_SESSION [ 'csms' ] > 3) { exit ( '-1' ); } $_SESSION [ 'csms' ] += 1; $siteid = get_siteid() ? get_siteid() : 1 ; $sms_setting = getcache( 'sms' , 'sms' ); if (!preg_match( '/^1[3-9]\d{9}$/' , $mobile )) exit ( 'mobile phone error' ); $posttime = SYS_TIME-86400; $where = "`mobile`='$mobile' AND `posttime`>'$posttime'" ; $num = $sms_report_db -> count ( $where ); if ( $num > 3) { exit ( '-1' ); //當(dāng)日發(fā)送短信數(shù)量超過限制 3 條 } //同一IP 24小時允許請求的最大數(shù) $allow_max_ip = 10; //正常注冊相當(dāng)于 10 個人 $ip = ip(); $where = "`ip`='$ip' AND `posttime`>'$posttime'" ; $num = $sms_report_db -> count ( $where ); if ( $num >= $allow_max_ip ) { exit ( '-3' ); //當(dāng)日單IP 發(fā)送短信數(shù)量超過 $allow_max_ip } if ( intval ( $sms_setting [ $siteid ][ 'sms_enable' ]) == 0) exit ( '-99' ); //短信功能關(guān)閉 $sms_uid = $sms_setting [ $siteid ][ 'userid' ]; //短信接口用戶ID $sms_pid = $sms_setting [ $siteid ][ 'productid' ]; //產(chǎn)品ID $sms_passwd = $sms_setting [ $siteid ][ 'sms_key' ]; //32位密碼 $posttime = SYS_TIME-600; $rs = $sms_report_db ->get_one( "`mobile`='$mobile' AND `posttime`>'$posttime'" ); if ( $rs [ 'id_code' ]) { $id_code = $rs [ 'id_code' ]; } else { $id_code = random(6); //唯一嗎,用于擴展驗證 } //$send_txt = '尊敬的用戶您好,您在'.$sitename.'的注冊驗證碼為:'.$id_code.',驗證碼有效期為5分鐘。'; $send_txt = $id_code ; $send_userid = intval ( $_GET [ 'send_userid' ]); //操作者id pc_base::load_app_class( 'smsapi' , 'sms' , 0); //引入smsapi類 $smsapi = new smsapi( $sms_uid , $sms_pid , $sms_passwd ); //初始化接口類 //$smsapi->get_price(); //獲取短信剩余條數(shù)和限制短信發(fā)送的ip地址 $mobile = explode ( ',' , $mobile ); $tplid = 1; $id_code = random(6); //唯一嗎,用于擴展驗證 $send_txt = '尊敬的用戶您好,您的注冊驗證碼為:' . $id_code . ',驗證碼有效期為5分鐘。' ; $content = safe_replace( $send_txt ); $sent_time = intval ( $_POST [ 'sendtype' ]) == 2 && ! empty ( $_POST [ 'sendtime' ]) ? trim( $_POST [ 'sendtime' ]) : date ( 'Y-m-d H:i:s' ,SYS_TIME); $smsapi ->send_sms( $mobile , $send_txt , $sent_time , CHARSET, $id_code , $tplid ); //發(fā)送短信 echo 0; ?> |
好了,經(jīng)過以上的替換,短信寶的短信平臺已經(jīng)替換成功了,可以正常使用了。我們進行測試發(fā)送。
ok,測試成功。是不是很方便呀。大家動手試一下吧。
報備一下短信寶的VIP模板,這樣就可以走優(yōu)質(zhì)通道了,并且免審核了,短信內(nèi)容3~5秒就可送達。
最新更新
電商類
CMS類
微信類