前段時間小編為大家介紹了php云人才的短信插件開發,最近有許多人找到小編說php云人才更新到4.5版本了,之前的短信插件無法使用了,小編最近也整理了一下,下面帶著大家一起進行新版本的替換,我們使用的短信接口是我們短信寶短信群發平臺的短信接口,我們短信寶短信平臺十分穩定,發送速度快,注冊就送測試短信,推薦大家使用。
下面我們進行開發,第一步我們需要修改后臺短信配置文件,打開項目\app\template\admin\admin_msg_config.htm文件,將以下代碼進行替換覆蓋:
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
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> < html > < head > < meta http-equiv = "Content-Type" content = "text/html;charset=utf-8" > < meta http-equiv = "Pragma" content = "no-cache" /> < meta http-equiv = "Cache-Control" content = "no-cache" /> < meta http-equiv = "Expires" content = "0" /> < link href = "images/reset.css?v={yun:}$config.cachecode{/yun}" rel = "stylesheet" type = "text/css" /> < link href = "images/system.css?v={yun:}$config.cachecode{/yun}" rel = "stylesheet" type = "text/css" /> < link href = "images/table_form.css?v={yun:}$config.cachecode{/yun}" rel = "stylesheet" type = "text/css" /> < script src = "{yun:}$config.sy_weburl{/yun}/js/jquery-1.8.0.min.js?v={yun:}$config.cachecode{/yun}" ></ script > < script src = "js/admin_public.js?v={yun:}$config.cachecode{/yun}" language = "javascript" ></ script > < link href = "{yun:}$config.sy_weburl{/yun}/js/layui/css/layui.css?v={yun:}$config.cachecode{/yun}" rel = "stylesheet" > < script src = "{yun:}$config.sy_weburl{/yun}/js/layui/layui.js?v={yun:}$config.cachecode{/yun}" language = "javascript" ></ script > < script src = "{yun:}$config.sy_weburl{/yun}/js/layui/phpyun_layer.js?v={yun:}$config.cachecode{/yun}" ></ script > < title >后臺管理</ title > </ head > < body class = "body_ifm" > < div class = "infoboxp" > < div class = "admin_new_tip" > < a href = "javascript:;" class = "admin_new_tip_close" ></ a > < a href = "javascript:;" class = "admin_new_tip_open" style = "display:none;" ></ a > < div class = "admin_new_tit" >< i class = "admin_new_tit_icon" ></ i >操作提示</ div > < div class = "admin_new_tip_list_cont" > < div class = "admin_new_tip_list" >請先注冊帳戶 短信內容支持長短信,最多300個字,64個字按一條短信計費。</ div > </ div > </ div > < div class = "clear" ></ div > < div style = "height:10px;" ></ div > < div class = "main_tag" > < div class = "tag_box" > < div > < form action = "" method = "post" class = "layui-form" > < table width = "100%" class = "table_form" > < tr > < th width = "200" bgcolor = "#f0f6fb" >< span class = "admin_bold" >參數說明</ span ></ th > < td bgcolor = "#f0f6fb" >< span class = "admin_bold" >參數值</ span ></ td > </ tr > < tr class = "admin_table_trbg" > < th width = "200" >是否開啟:</ th > < td > < div class = "layui-form-item" > < div class = "layui-input-block" > < div class = "layui-input-inline" > < 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" title = "開啟" > < 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" title = "關閉" > </ div > </ div > </ div > </ 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" /> </ tr > < tr class = "admin_table_trbg" > < th width = "200" >KEY:</ 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" /> </ tr > < tr class = "admin_table_trbg" > < th width = "200" >短信寶用戶名:</ th > < td >< input type = "text" class = "input-text tips_class" name = "smsbao_user" id = "smsbao_user" value = "{yun:}$config.smsbao_user{/yun}" size = "50" maxlength = "255" ></ td > </ tr > < tr class = "admin_table_trbg" > < th width = "200" >短信寶密碼:</ th > < td >< input type = "password" class = "input-text tips_class" name = "smsbao_pass" id = "smsbao_pass" value = "{yun:}$config.smsbao_pass{/yun}" size = "50" maxlength = "255" ></ td > </ tr > < tr class = "admin_table_trbg" > < th width = "200" >短信寶簽名:</ th > < td >< input type = "text" class = "input-text tips_class" name = "smsbao_sign" id = "smsbao_sign" value = "{yun:}$config.smsbao_sign{/yun}" size = "50" maxlength = "255" ></ td > </ tr > < tr > < th width = "200" >單次號碼量:</ 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" >最小數為1。</ span ></ td > </ tr > < tr class = "admin_table_trbg" > < th width = "200" >同一IP一天發送短信:</ 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" >同一手機號一天發送短信:</ 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" />條</ td > </ tr > < tr class = "admin_table_trbg" > < th width = "200" >購買短信:</ th > < td >< div class = "yun_admin_divh" >< a href = "http://www.gjrencai.com/" target = "_blank" style = " color:#CC3300; text-decoration:underline; " > 購買短信地址</ a ></ div ></ td > </ tr > < tr > < th width = "160" >剩余短信數量:</ th > < td >< input class = "input-text input_text_rp" type = "text" name = "rest_msgnum" id = "rest_msgnum" value = "0" disabled = "disabled" />條</ td > </ tr > < tr > < th width = "160" >天眼查數量:</ th > < td >< input class = "input-text input_text_rp" type = "text" name = "rest_businessnum" id = "rest_businessnum" value = "0" disabled = "disabled" />條</ td > </ tr > < tr > < td colspan = "2" align = "center" >< input class = "layui-btn layui-btn-normal" id = "config" type = "button" name = "msgconfig" value = "提交" /> < input class = "layui-btn layui-btn-normal" type = "reset" value = "重置" /></ td > </ tr > </ table > < input type = "hidden" id = "pytoken" name = "pytoken" value = "{yun:}$pytoken{/yun}" > </ form > </ div > </ div > </ div > < script > layui.use(['layer', 'form'], function(){ var layer = layui.layer ,form = layui.form ,$ = layui.$; }); $(function(){ $("#config").click(function(){ if ($("#sy_msguser").val() == '' || $("#sy_msgkey").val() == '' || $("#sy_msgpw").val() == '') { alert('請填寫賬戶、密碼、KEY'); return false; } $.post("index.php?m=msgconfig&c=save",{ config : $("#config").val(), sy_msguser : $("#sy_msguser").val(), sy_msg_isopen : $("input[name=sy_msg_isopen]:checked").val(), sy_msgkey :$("#sy_msgkey").val(), smsbao_user:$("#smsbao_user").val(), smsbao_pass:$("#smsbao_pass").val(), smsbao_sign:$("#smsbao_sign").val(), pytoken : $("#pytoken").val(), sy_msgpw : $("#sy_msgpw").val(), sy_msgsendnum : $("#sy_msgsendnum").val(), ip_msgnum : $("#ip_msgnum").val(), moblie_msgnum : $("#moblie_msgnum").val(), integral_msg_proportion : $("#integral_msg_proportion").val() },function(data,textStatus){ config_msg(data); }); }); $.post("index.php?m=msgconfig&c=get_businessnum",{pytoken : $("#pytoken").val(),msguser : $("#sy_msguser").val()},function(data){ data = eval('('+data+')'); if(data){ $("#rest_businessnum").val(data.businessnum); } }); $.post("index.php?m=msgconfig&c=get_restnum",{pytoken : $("#pytoken").val(),smsbao_user : $("#smsbao_user").val(),smsbao_pass : $("#smsbao_pass").val()},function(data){ if(data){ $("#rest_msgnum").val(data); } }); }) </ script > </ div > </ body > </ html > |
接下來我們去修改接口代碼文件,打開項目\app\model\notice.model.php文件,我們修改sendSMS和postSMS方法,修改代碼為:
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
|
private function postSMS( $type = "msgsend" , $data = '' ){ $data [ 'content' ] = str_replace ( array ( " " , " " , "\t" , "\n" , "\r" ), array ( "" , "" , "" , "" , "" ), $data [ 'content' ]); $url .= '?u=' . $data [ 'uid' ]. '&p=' .md5( $data [ 'pwd' ]). '&m=' . $data [ 'mobile' ]. '&c=【' . $data [ 'key' ]. '】' . $data [ 'content' ]; 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 ; } public function sendSMS( $data ) { if (! $this ->config[ "sy_msguser" ] || ! $this ->config[ "sy_msgpw" ] || ! $this ->config[ "sy_msgkey" ]|| $this ->config[ 'sy_msg_isopen' ]!= '1' ){ return array ( 'status' => -1, 'msg' => "還沒有配置短信,請聯系管理員!" ); } $data [ 'mobile' ] = $data [ 'moblie' ] ? $data [ 'moblie' ] : $data [ 'mobile' ]; if ( $this ->_isKey( 'mobile' , $data ) == fasle || CheckMoblie( $data [ 'mobile' ]) == false){ return array ( 'status' => -1, 'msg' => '手機號錯誤' ); } if ( $this ->_isKey( 'content' , $data ) == fasle || $data [ 'content' ] == "" ){ return array ( 'status' => -1, 'msg' => '短信內容為空' ); } $msguser = $this ->config[ "smsbao_user" ]; $msgpw = strtolower ( $this ->config[ "smsbao_pass" ]); $msgkey = $this ->config[ "smsbao_sign" ]; $time = $data [ 'time' ] ? $data [ 'time' ] : '' ; $mid = $data [ 'mid' ] ? $data [ 'mid' ] : '' ; $row = array ( 'uid' => $msguser , 'pwd' => $msgpw , 'key' => $msgkey , 'mobile' => $data [ 'mobile' ], 'content' => $data [ 'content' ], 'time' => $time , 'mid' => $mid ); $re = $this ->postSMS( "msgsend" , $row ); $sql_data [ "uid" ] = $data [ 'uid' ]; $sql_data [ "name" ] = $data [ 'name' ]; $sql_data [ "cuid" ] = $data [ 'cuid' ]; $sql_data [ 'cname' ] = $data [ 'cname' ] ? $data [ 'cname' ] : '系統' ; $sql_data [ "moblie" ] = $data [ 'mobile' ]; $sql_data [ "ctime" ] = time(); $sql_data [ "content" ] = $data [ 'content' ]; if (trim( $re ) == '0' ){ include_once ( 'warning.model.php' ); $warning = new warning_model( $this ->db, $this ->def, array ( 'uid' => $this ->uid, 'username' => $this ->username, 'usertype' => $this ->usertype)); $warning ->warning(5); $sql_data [ 'state' ]= "0" ; $sql_data [ 'ip' ]=fun_ip_get(); $sqlResult = $this ->insert_into( "moblie_msg" , $sql_data ); return array ( 'status' => 1, 'msg' => "發送成功!" ); } else { $sql_data [ "state" ] = $re ; $this ->insert_into( "moblie_msg" , $sql_data ); include (CONFIG_PATH. "db.data.php" ); if ( $arr_data [ 'msgreturn' ][ $re ]){ return array ( 'status' => -1, 'msg' => "發送失敗!狀態:" . $arr_data [ 'msgreturn' ][ $re ]); } else { return array ( 'status' => -1, 'msg' => "發送失敗!狀態:" . $re ); } } } |
經過上面的替換,短信寶的短信平臺已經替換成功了,可以正常使用了。進行測試發送:
報備一下短信寶的VIP模版,這樣就可以走短信寶的優質通道,并且免審核了,短信內容3~5秒就可送達。
另外:我們已經開發好完整的PHP云人才系統短信寶插件,點擊此鏈接 下載及查看安裝流程。
最新更新
電商類
CMS類
微信類