前段時(shí)間小編為大家介紹了php云人才的短信插件開發(fā),今天發(fā)現(xiàn)php云人才的版本升級(jí)了,短信接口也需要重新替換了,所以寫了這一篇4.3版本的短信插件開發(fā),使用的短信接口還是我們短信寶短信群發(fā)平臺(tái)的接口,我們短信寶短信群發(fā)平臺(tái)穩(wěn)定可靠,速度也很快,注冊(cè)就送免費(fèi)測(cè)試條數(shù)。
首先我們要更換后臺(tái)的顯示界面文件。打開模版文件,替換一下模版文件。打開項(xiàng)目/app/template/admin/admin_msg_config.html,都修改代碼35~83行,修改代碼如下:
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
|
< form action = "" method = "post" > < table width = "100%" class = "table_form" > < tr > < th width = "200" >參數(shù)說明:</ th > < td >參數(shù)值</ td > </ tr > < tr class = "admin_table_trbg" > < th width = "200" >是否開啟:</ th > < td > < input id = "sy_msg_isopen_1" type = "radio" {yun:}if $config.sy_msg_isopen=='1'{/yun} checked = "" {yun:}/if{/yun} value = "1" name = "sy_msg_isopen" > < label for = "sy_msg_isopen_1" >開啟</ label > < input id = "sy_msg_isopen_2" type = "radio" {yun:}if $config.sy_msg_isopen!='1'{/yun} checked = "" {yun:}/if{/yun} value = "2" name = "sy_msg_isopen" > < label for = "sy_msg_isopen_2" >關(guān)閉</ label > </ td > </ tr > < tr class = "admin_table_trbg" > < th width = "200" >短信寶用戶名:</ th > < td >< input class = "input-text tips_class" type = "text" name = "sy_msguser" id = "sy_msguser" value = "{yun:}$config.sy_msguser{/yun}" size = "30" maxlength = "255" /> </ td > </ tr > < tr > < th width = "200" >短信寶密碼:</ th > < td >< input class = "input-text tips_class" type = "password" name = "sy_msgpw" id = "sy_msgpw" value = "{yun:}$config.sy_msgpw{/yun}" size = "30" maxlength = "255" /> </ td > </ tr > < tr class = "admin_table_trbg" > < th width = "200" >短信簽名:</ th > < td >< input class = "input-text tips_class" type = "text" name = "sy_msgkey" id = "sy_msgkey" value = "{yun:}$config.sy_msgkey{/yun}" size = "50" maxlength = "255" /> < span class = "admin_web_tip" >短信的簽名,3-8個(gè)字符</ span ></ td > </ tr > < tr > < th width = "200" >單次號(hào)碼量:</ th > < td >< input class = "input-text input_text_rp" type = "text" name = "sy_msgsendnum" id = "sy_msgsendnum" value = "{yun:}$config.sy_msgsendnum{/yun}" size = "30" maxlength = "255" />條 < span class = "admin_web_tip" >最小數(shù)為1。</ span ></ td > </ tr > < tr class = "admin_table_trbg" > < th width = "200" >同一IP一天發(fā)送短信:</ th > < td >< input class = "input-text input_text_rp" type = "text" name = "ip_msgnum" id = "ip_msgnum" value = "{yun:}$config.ip_msgnum{/yun}" size = "30" maxlength = "255" />條</ td > </ tr > < tr > < th width = "160" >同一手機(jī)號(hào)一天發(fā)送短信:</ th > < td >< input class = "input-text input_text_rp" type = "text" name = "moblie_msgnum" id = "moblie_msgnum" value = "{yun:}$config.moblie_msgnum{/yun}" size = "30" maxlength = "255" />條 < span class = "admin_web_tip" >同一手機(jī)號(hào)日上限為5條</ span ></ td > </ tr > < tr class = "admin_table_trbg" > < th width = "200" >購(gòu)買短信:</ th > < td >< a href = "http://www.gjrencai.com" target = "_blank" style = " color:#CC3300; text-decoration:underline; " > 購(gòu)買短信地址</ a ></ td > </ tr > < tr > < td colspan = "2" align = "center" >< input class = "admin_submit4" id = "config" type = "button" name = "msgconfig" value = "提交" /> < input class = "admin_submit4" type = "reset" value = "重置" /></ td > </ tr > </ table > < input type = "hidden" id = "pytoken" name = "pytoken" value = "{yun:}$pytoken{/yun}" > </ form > |
經(jīng)過替換后后臺(tái)顯示頁(yè)面是我們短信寶的了,下面我們進(jìn)行修改短信發(fā)送接口類,打開項(xiàng)目/app/public/common.php,修改sendSMS和postSMS這兩個(gè)方法,修改代碼如下:
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
|
function sendSMS( $uid , $pwd , $key , $mobile , $content , $time = '' , $mid = '' , $info = array ()){ $data_msg [ "uid" ]= $info [ 'uid' ]; $data_msg [ "name" ]= $info [ 'name' ]; $data_msg [ "cuid" ]= $info [ 'cuid' ]; if ( $info [ 'cname' ]){ $data_msg [ "cname" ]= $info [ 'cname' ]; } else { $data_msg [ "cname" ]= "系統(tǒng)" ; } $data_msg [ "moblie" ]= $mobile ; $data_msg [ "ctime" ]=time(); $data_msg [ "content" ]= $content ; $data = array ( 'u' => $uid , 'p' =>md5( strtolower ( $pwd )), 'key' => $key , 'm' => $mobile , 'c' =>iconv( 'GB2312' , 'UTF-8' , '【' . $key . '】' . $content ), 'time' => $time , 'mid' => $mid ); $re = $this ->postSMS( "msgsend" , $data ); $this ->warning( '5' ); if (trim( $re ) == '0' ){ $data_msg [ 'state' ]= "1" ; $data_msg [ 'ip' ]=fun_ip_get(); $this ->MODEL()->insert_into( "moblie_msg" , $data_msg ); return "發(fā)送成功!" ; } else { $result = array ( "-1" => "參數(shù)不全" , "30" => '用戶名密碼錯(cuò)誤' , "40" => '賬號(hào)不存在' , "41" => '余額不足' , "42" => '賬號(hào)過期' , "43" => 'IP地址限制' , "50" => '內(nèi)容含有敏感詞' , "51" => '手機(jī)號(hào)碼不正確' ); $data_msg [ "state" ]= "0" ; $this ->MODEL()->insert_into( "moblie_msg" , $data_msg ); if ( $result [ $re ]){ return "發(fā)送失??!狀態(tài):" . $result [ $re ]; } else { return "發(fā)送失敗!狀態(tài):" . $re ; } } } function postSMS( $type = "msgsend" , $data = '' ){ $data [ 'content' ] = str_replace ( array ( " " , " " , "\t" , "\n" , "\r" ), array ( "" , "" , "" , "" , "" ), $data [ 'content' ]); $url .= '?u=' . $data [ 'u' ]. '&p=' . $data [ 'p' ]. '&m=' . $data [ 'm' ]. '&c=' . $data [ 'c' ]. '&time=' . $data [ 'time' ]. '' ; if (function_exists( 'file_get_contents' )){ $file_contents = file_get_contents ( $url ); } else { $ch = curl_init(); $timeout = 5; curl_setopt ( $ch , CURLOPT_URL, $url ); curl_setopt ( $ch , CURLOPT_RETURNTRANSFER, 1); curl_setopt ( $ch , CURLOPT_CONNECTTIMEOUT, $timeout ); $file_contents = curl_exec( $ch ); curl_close( $ch ); } return $file_contents ; } |
經(jīng)過上面的替換,短信寶的短信平臺(tái)已經(jīng)替換成功了,可以正常使用了。進(jìn)行測(cè)試發(fā)送:
報(bào)備一下短信寶的VIP模版,這樣就可以走短信寶的優(yōu)質(zhì)通道,并且免審核了,短信內(nèi)容3~5秒就可送達(dá)。
最新更新
電商類
CMS類
微信類