外賣人是一款基于PHP+MYSQL開(kāi)發(fā)的一套外賣訂餐系統(tǒng),有微信訂餐、wap訂餐、預(yù)定桌位等等多種外賣功能,是一款非常不錯(cuò)的訂餐系統(tǒng),小編今天就以替換短信接口為例帶大家進(jìn)行二次開(kāi)發(fā),我們使用的短信接口是我們短信寶短信群發(fā)平臺(tái)的短信接口,我們短信寶短信群發(fā)平臺(tái)非常穩(wěn)定,發(fā)送速度快,注冊(cè)就送測(cè)試短信,推薦大家使用。
下面我們進(jìn)行接口替換,首先我們需要修改后臺(tái)模版文件,打開(kāi)項(xiàng)目\templates\adminpage\other\smsset.html文件,將下列代碼進(jìn)行覆蓋替換即可:
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
|
<{extends file="<{$tempdir}>/public/admin.html"}> <{block name=extendjs}> < script type = "text/javascript" language = "javascript" src="<{$siteurl}>/templates/<{$tempdir}>/public/js/artdialog/plugins/iframeTools.js"></ script > <{/block}> <{block name=controlname}>短信設(shè)置<{/block}> <{block name=bodylist}> < div style = "width:auto;overflow-x:hidden;overflow-y:auto;" > < div id = "tagscontent" > < form method = "post" name = "form1" action = "<{ofunc type=url link=" /adminpage/other/module/smssetsave/datatype/json"}>" onsubmit="return subform('',this);"> < div > < table border = "0" cellspacing = "2" class = "list" name = "table" id = "table1" width = "100%" > < tbody > < tr onmouseover = "this.bgColor='#F5F5F5';" onmouseout = "this.bgColor='ffffff';" bgcolor = "#ffffff" > < td class = "left" width = "20%" >選擇短信發(fā)送類型</ td > < td > < select name = "smstype" id = "smstype" onchange = "doinfo();" > < option value = "2" selected >短信寶短信接口</ option > </ select > </ td > </ tr > </ tbody > </ table > < table border = "0" cellspacing = "2" cellpadding = "4" class = "list" name = "table" id = "table3" width = "100%" > < tbody > < tr onmouseover = "this.bgColor='#F5F5F5';" onmouseout = "this.bgColor='ffffff';" bgcolor = "#ffffff" > < td class = "left" >短信寶用戶名</ td > < td >< input type = "text" name = "sms86ac" id = "sms86ac" value="<{$sms86ac}>" class="skey" style="width:250px;"></ td > </ tr > < tr onmouseover = "this.bgColor='#F5F5F5';" onmouseout = "this.bgColor='ffffff';" bgcolor = "#ffffff" > < td class = "left" >短信寶密碼</ td > < td >< input type = "password" name = "sms86pd" id = "sms86pd" value="<{$sms86pd}>" class="skey" style="width:250px;"></ td > </ tr > </ tbody > </ table > </ div > < div class = "blank20" ></ div > < input type = "hidden" name = "tijiao" id = "tijiao" value = "do" class = "skey" style = "width:250px;" > < input type = "hidden" name = "saction" id = "saction" value = "siteset" class = "skey" style = "width:250px;" > < input type = "submit" value = "確認(rèn)提交" class = "button" > </ form > </ div > </ div > </ div > <{/block}> |
接下來(lái)我們?nèi)バ薷亩绦虐l(fā)送接口,打開(kāi)項(xiàng)目\class\phonecode.php文件,將下列代碼進(jìn)行覆蓋替換即可:
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
|
<?php /** * modify 2016-11-23 * @class 手機(jī)驗(yàn)證碼 * @brief 促銷規(guī)則 */ class phonecode { private $mysql ; //數(shù)據(jù)庫(kù)連接 //短信主要類容 private $maincontent = array ( 0=> '用戶注冊(cè),驗(yàn)證碼:' , 1=> '登錄,驗(yàn)證碼:' , 2=> '找回密碼,驗(yàn)證碼:' , 3=> '更換手機(jī),號(hào)驗(yàn)證碼:' , 4=> '手機(jī)快捷登錄,驗(yàn)證碼:' , 5=> '更換密碼,驗(yàn)證碼:' , 6=> '下單,驗(yàn)證碼:' , 7=> 'APP調(diào)用用戶登錄驗(yàn)證' , 8=> '新綁定手機(jī)號(hào)' , 9=> '您好,尊敬的會(huì)員,驗(yàn)證碼為:' , ); public $qianming ; //短信簽名 private $sendtype ; //驗(yàn)證發(fā)送類型 private $typearray = array (0,1,2,3,4,5,6,7,8,9); //用戶檢測(cè)代碼 private $phone ; //手機(jī)號(hào) private $limittime = 120; //短信有效時(shí)間 private $code ; //驗(yàn)證碼; private $timelong = 0; //短信失效時(shí)間 private $errId ; //初始化函數(shù) type 0.用戶注冊(cè) 1登錄驗(yàn)證 2.找回密碼 3更換手機(jī)號(hào) 4手機(jī)快捷登錄 5更換密碼 //IFilter::act(IReq::get('phone')); //初始化 $mysql 數(shù)據(jù)庫(kù)連接 $sendtype 驗(yàn)證碼類型= phone 接受手機(jī)號(hào) function __construct( $mysql , $type , $phone = '' ){ $this ->mysql = $mysql ; $this ->sendtype = $type ; $this ->phone = empty ( $phone )? intval (IFilter::act(IReq::get( 'phone' ))): $phone ; $msgqianming = '' ; $msgqianming = Mysite:: $app ->config[ 'msgqianming' ]; if ( ! empty ( $msgqianming ) ){ $this ->qianming = $msgqianming ; } else { $this ->qianming = Mysite:: $app ->config[ 'sitename' ]; } $this ->timelong = 0; //$this->tablepre = Mysite::$app->config['mobileapp']; } public function sendother( $msg ){ $contents = '【' . $this ->qianming. '】' . $msg ; $url = 'http://api.smsbao.com/sms?u=' .Mysite:: $app ->config[ 'sms86ac' ]. '&p=' .md5(Mysite:: $app ->config[ 'sms86pd' ]). '&m=' . $this ->phone. '&c=' .urlencode( $contents ); logwrite( '短信發(fā)送鏈接:' . $url ); $contentcccc = file_get_contents ( $url ); logwrite( '短信發(fā)送結(jié)果:' . $contentcccc ); } // public function sendcode(){ if (!IValidate::suremobi( $this ->phone)){ $this ->errId = '手機(jī)號(hào)格式錯(cuò)誤' ; return false; } if (!in_array( $this ->sendtype, $this ->typearray)){ $this ->errId = '未定義的發(fā)送類型' ; return false; } if ( $this ->sendtype == 2){ $checkmember = $this ->mysql->select_one( "select * from " .Mysite:: $app ->config[ 'tablepre' ]. "member where phone ='" . $this ->phone. "' order by uid desc limit 0,1" ); if ( empty ( $checkmember )){ $this ->errId = '手機(jī)對(duì)應(yīng)用戶不存在' ; return false; } } elseif ( $this ->sendtype == 3){ $checkmember = $this ->mysql->select_one( "select * from " .Mysite:: $app ->config[ 'tablepre' ]. "member where phone ='" . $this ->phone. "' order by uid desc limit 0,1" ); if ( empty ( $checkmember )){ $this ->errId = '手機(jī)對(duì)應(yīng)用戶不存在' ; return false; } } elseif ( $this ->sendtype == 4){ } elseif ( $this ->sendtype == 5){ $checkmember = $this ->mysql->select_one( "select * from " .Mysite:: $app ->config[ 'tablepre' ]. "member where phone ='" . $this ->phone. "' order by uid desc limit 0,1" ); if ( empty ( $checkmember )){ $this ->errId = '手機(jī)對(duì)應(yīng)用戶不存在' ; return false; } } elseif ( $this ->sendtype == 0){ $checkmember = $this ->mysql->select_one( "select * from " .Mysite:: $app ->config[ 'tablepre' ]. "member where phone ='" . $this ->phone. "' order by uid desc limit 0,1" ); if (! empty ( $checkmember )){ $this ->errId = '手機(jī)號(hào)對(duì)應(yīng)用戶已存在' ; return false; } } elseif ( $this ->sendtype == 8){ $checkmember = $this ->mysql->select_one( "select * from " .Mysite:: $app ->config[ 'tablepre' ]. "member where phone ='" . $this ->phone. "' order by uid desc limit 0,1" ); if (! empty ( $checkmember )){ $this ->errId = '手機(jī)號(hào)對(duì)應(yīng)用戶已存在' ; return false; } } $checkphone = $this ->mysql->select_one( "select * from " .Mysite:: $app ->config[ 'tablepre' ]. "mobileapp where phone ='" . $this ->phone. "' and type='" . $this ->sendtype. "' order by addtime desc limit 0,1" ); if (! empty ( $checkphone )){ //$checktime = time()-$this->limittime; if ( $checkphone [ 'addtime' ] > time()){ // $this->errId = '驗(yàn)證碼還未失效'; $this ->code = $checkphone [ 'code' ]; $this ->timelong = $checkphone [ 'addtime' ] - time(); return true; } } $mintime = strtotime ( date ( 'Y-m-d' ,time())); $checkcounts = $this ->mysql->counts( "select * from " .Mysite:: $app ->config[ 'tablepre' ]. "mobileapp where phone ='" . $this ->phone. "' and type='" . $this ->sendtype. "' and addtime > " . $mintime . " " ); if ( $checkcounts > 3){ $this ->errId = '每天發(fā)送驗(yàn)證碼不能超過(guò)3次' ; return false; } $this ->code = rand(1000,9999); $data [ 'phone' ] = $this ->phone; $data [ 'addtime' ] = time()+ $this ->limittime; $data [ 'code' ] = $this ->code; $data [ 'type' ] = $this ->sendtype; $this ->mysql->insert(Mysite:: $app ->config[ 'tablepre' ]. 'mobileapp' , $data ); $contents = '【' . $this ->qianming. '】' . $this ->maincontent[ $this ->sendtype]. $this ->code; $url = 'http://api.smsbao.com/sms?u=' .Mysite:: $app ->config[ 'sms86ac' ]. '&p=' .md5(Mysite:: $app ->config[ 'sms86pd' ]). '&m=' . $this ->phone. '&c=' .urlencode( $contents ); $contentcccc = file_get_contents ( $url ); logwrite( '短信發(fā)送鏈接:' . $url ); $this ->timelong = $this ->limittime; logwrite( '短信發(fā)送結(jié)果:' . $contentcccc ); return true; } //校驗(yàn)驗(yàn)證碼是否有效 $Inputcode 校驗(yàn)code public function checkcode( $Inputcode ){ # $checkcancode = Mysite:: $app ->config[ 'allowedcode' ]; $checkcancode = Mysite:: $app ->config[ 'regestercode' ]; if ( $this ->sendtype != 4){ if ( $checkcancode != 1){ return true; } } if (!IValidate::suremobi( $this ->phone)){ $this ->errId = '手機(jī)號(hào)格式錯(cuò)誤' ; return false; } if (!in_array( $this ->sendtype, $this ->typearray)){ $this ->errId = '未定義的發(fā)送類型' ; return false; } if ( empty ( $Inputcode )){ $this ->errId = '未設(shè)置驗(yàn)證碼' ; return false; } $checkphone = $this ->mysql->select_one( "select * from " .Mysite:: $app ->config[ 'tablepre' ]. "mobileapp where phone ='" . $this ->phone. "' and type='" . $this ->sendtype. "' order by addtime desc limit 0,1" ); if (! empty ( $checkphone )){ $checktime = time()- $this ->limittime; if ( $checkphone [ 'addtime' ] > $checktime ){ if ( $Inputcode != $checkphone [ 'code' ]){ $this ->errId = '驗(yàn)證碼錯(cuò)誤' ; return false; } $this ->code = $checkphone [ 'code' ]; return true; } else { $this ->errId = '驗(yàn)證碼已失效' ; return false; } } else { $this ->errId = '該手機(jī)號(hào)未發(fā)送驗(yàn)證碼' ; return false; } } public function getCode(){ return $this ->code; } public function getError() { return $this ->errId; } public function getTime(){ return $this ->timelong; } } ?> |
好了,經(jīng)過(guò)以上的替換,短信寶的短信平臺(tái)已經(jīng)替換成功了,我們?nèi)ミM(jìn)行發(fā)送測(cè)試:
報(bào)備一下短信寶的VIP模板,這樣就可以走短信寶的優(yōu)質(zhì)通道了,并且免審核了,短信內(nèi)容3~5秒就可送達(dá)。
另外:我們已經(jīng)開(kāi)發(fā)好完整的外賣人短信寶插件,點(diǎn)擊此鏈接 下載及查看安裝流程。
最新更新
電商類
CMS類
微信類