外賣人是一款基于PHP+MYSQL開發的一套外賣訂餐系統,有微信訂餐、wap訂餐、預定桌位等等多種外賣功能,是一款非常不錯的訂餐系統,小編今天就以替換短信接口為例帶大家進行二次開發,我們使用的短信接口是我們短信寶短信群發平臺的短信接口,我們短信寶短信群發平臺非常穩定,發送速度快,注冊就送測試短信,推薦大家使用。
下面我們進行接口替換,首先我們需要修改后臺模版文件,打開項目\templates\adminpage\other\smsset.html文件,將下列代碼進行覆蓋替換即可:
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}>短信設置<{/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%" >選擇短信發送類型</ 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 = "確認提交" class = "button" > </ form > </ div > </ div > </ div > <{/block}> |
接下來我們去修改短信發送接口,打開項目\class\phonecode.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
|
<?php /** * modify 2016-11-23 * @class 手機驗證碼 * @brief 促銷規則 */ class phonecode { private $mysql ; //數據庫連接 //短信主要類容 private $maincontent = array ( 0=> '用戶注冊,驗證碼:' , 1=> '登錄,驗證碼:' , 2=> '找回密碼,驗證碼:' , 3=> '更換手機,號驗證碼:' , 4=> '手機快捷登錄,驗證碼:' , 5=> '更換密碼,驗證碼:' , 6=> '下單,驗證碼:' , 7=> 'APP調用用戶登錄驗證' , 8=> '新綁定手機號' , 9=> '您好,尊敬的會員,驗證碼為:' , ); public $qianming ; //短信簽名 private $sendtype ; //驗證發送類型 private $typearray = array (0,1,2,3,4,5,6,7,8,9); //用戶檢測代碼 private $phone ; //手機號 private $limittime = 120; //短信有效時間 private $code ; //驗證碼; private $timelong = 0; //短信失效時間 private $errId ; //初始化函數 type 0.用戶注冊 1登錄驗證 2.找回密碼 3更換手機號 4手機快捷登錄 5更換密碼 //IFilter::act(IReq::get('phone')); //初始化 $mysql 數據庫連接 $sendtype 驗證碼類型= phone 接受手機號 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( '短信發送鏈接:' . $url ); $contentcccc = file_get_contents ( $url ); logwrite( '短信發送結果:' . $contentcccc ); } // public function sendcode(){ if (!IValidate::suremobi( $this ->phone)){ $this ->errId = '手機號格式錯誤' ; return false; } if (!in_array( $this ->sendtype, $this ->typearray)){ $this ->errId = '未定義的發送類型' ; 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 = '手機對應用戶不存在' ; 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 = '手機對應用戶不存在' ; 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 = '手機對應用戶不存在' ; 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 = '手機號對應用戶已存在' ; 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 = '手機號對應用戶已存在' ; 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 = '驗證碼還未失效'; $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 = '每天發送驗證碼不能超過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( '短信發送鏈接:' . $url ); $this ->timelong = $this ->limittime; logwrite( '短信發送結果:' . $contentcccc ); return true; } //校驗驗證碼是否有效 $Inputcode 校驗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 = '手機號格式錯誤' ; return false; } if (!in_array( $this ->sendtype, $this ->typearray)){ $this ->errId = '未定義的發送類型' ; return false; } if ( empty ( $Inputcode )){ $this ->errId = '未設置驗證碼' ; 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 = '驗證碼錯誤' ; return false; } $this ->code = $checkphone [ 'code' ]; return true; } else { $this ->errId = '驗證碼已失效' ; return false; } } else { $this ->errId = '該手機號未發送驗證碼' ; return false; } } public function getCode(){ return $this ->code; } public function getError() { return $this ->errId; } public function getTime(){ return $this ->timelong; } } ?> |
好了,經過以上的替換,短信寶的短信平臺已經替換成功了,我們去進行發送測試:
報備一下短信寶的VIP模板,這樣就可以走短信寶的優質通道了,并且免審核了,短信內容3~5秒就可送達。
另外:我們已經開發好完整的外賣人短信寶插件,點擊此鏈接 下載及查看安裝流程。
最新更新
電商類
CMS類
微信類