WSTMart電子商務系統是基于ThinkPHP5.0開發的B2B2C綜合電子商務系統,安裝此程序要確保PHP版本高于5.4,最好5.5(支持PHP7),因為是thinkphp框架,所以二開比較方便,注釋也清晰,小編對于此系統還是比較了解的,今天小編就以替換短信接口為例為大家講解一下如何進行二次開發,我們今天講解的是2.0版本,使用的短信接口是我們短信寶短信群發平臺的短信接口,我們短信寶短信群發平臺非常穩定,發送速度快,注冊就送測試短信,推薦大家使用。
進行接口替換我們首先進行修改短信配置界面,打開項目\wstmart\admin\view\sysconfigs\config1.html 文件,大約在41-77行左右,修改如下代碼:
|
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
|
<tr> <td colspan='2' class='head-ititle'>短信服務器設置</td> </tr> <tr> <th>開啟手機驗證:</th> <td> <label> <input type='radio' id='smsOpen1' name='smsOpen' class='ipt' value='1' {if $object['smsOpen']==1}checked{/if}/>是 </label> <label> <input type='radio' id='smsOpen0' name='smsOpen' class='ipt' value='0' {if $object['smsOpen']==0}checked{/if}/>否 </label> </td> </tr> <tr> <th>短信寶賬號:</th> <td><input type="text" id='smsKey' class='ipt' value="{$object['smsKey']}" maxLength='100'/> 還沒有帳號?點擊<a target='_blank' href='http://www.gjrencai.com/reg'>注冊</a></td> </tr> <tr> <th>短信寶密碼:</th> <td><input type="text" id='smsPass' class='ipt' value="{$object['smsPass']}" maxLength='100'/></td> </tr> <tr> <th>號碼每日發送數:</th> <td><input type="text" id='smsLimit' class='ipt' value="{$object['smsLimit']}" maxLength='100'/></td> </tr> <tr> <th>開啟短信發送驗證碼:</th> <td> <label> <input type='radio' id='smsVerfy1' class='ipt' name='smsVerfy' value='1' {if $object['smsVerfy']==1}checked{/if}/>是 </label> <label> <input type='radio' id='smsVerfy0' class='ipt' name='smsVerfy' value='0' {if $object['smsVerfy']==0}checked{/if}/>否 </label> </td> </tr> |
經過上面的替換,后臺顯示頁面就是短信寶的了,接下來我們去增加我們短信寶的接口代碼,打開項目\wstmart\common\common\function.php 文件,增加以下代碼:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
/** * 短信寶短信服務商 * @param string $phoneNumer 手機號碼 * @param string $content 短信內容 */function SmsbaoSMS($phoneNumer,$content){ $url = 'http://api.smsbao.com/sms?u='.WSTConf("CONF.smsKey").'&p='.md5(WSTConf("CONF.smsPass")).'&m='.$phoneNumer.'&c='.$content; $ch=curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//設置否輸出到頁面 curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30 ); //設置連接等待時間 curl_setopt($ch, CURLOPT_ENCODING, "gzip" ); $data=curl_exec($ch); curl_close($ch); return $data;} |
最后我們去修改調用接口的文件,打開項目\wstmart\common\model\LogSms.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
|
<?phpnamespace wstmart\common\model;/** * * 短信日志類 */class LogSms extends Base{ /** * 寫入并發送短訊記錄 */ public function sendSMS($smsSrc,$phoneNumber,$content,$smsFunc,$verfyCode){ $USER = session('WST_USER'); $userId = empty($USER)?0:$USER['userId']; $ip = request()->ip(); //檢測短信驗證碼驗證是否正確 if(WSTConf("CONF.smsVerfy")==1){ $smsverfy = input("post.smsVerfy"); $rs = WSTVerifyCheck($smsverfy); if(!$rs){ return WSTReturn("驗證碼不正確!",-2); } } //檢測是否超過每日短信發送數 $date = date('Y-m-d'); $smsRs = $this->field("count(smsId) counts,max(createTime) createTime") ->where(["smsPhoneNumber"=>$phoneNumber]) ->whereTime('createTime', 'between', [$date.' 00:00:00', $date.' 23:59:59'])->find(); if($smsRs['counts']>(int)WSTConf("CONF.smsLimit")){ return WSTReturn("請勿頻繁發送短信驗證!"); } if($smsRs['createTime'] !='' && ((time()-strtotime($smsRs['createTime']))<120)){ return WSTReturn("請勿頻繁發送短信驗證!"); } //檢測IP是否超過發短信次數 $ipRs = $this->field("count(smsId) counts,max(createTime) createTime") ->where(["smsIP"=>$ip]) ->whereTime('createTime', 'between', [$date.' 00:00:00', $date.' 23:59:59'])->find(); if($ipRs['counts']>(int)WSTConf("CONF.smsLimit")){ return WSTReturn("請勿頻繁發送短信驗證!"); } if($ipRs['createTime']!='' && ((time()-strtotime($ipRs['createTime']))<120)){ return WSTReturn("請勿頻繁發送短信驗證!"); } $code = SmsbaoSMS($phoneNumber,$content); $data = array(); $data['smsSrc'] = $smsSrc; $data['smsUserId'] = $userId; $data['smsPhoneNumber'] = $phoneNumber; $data['smsContent'] = $content; $data['smsReturnCode'] = $code; $data['smsCode'] = $verfyCode; $data['smsIP'] = $ip; $data['smsFunc'] = $smsFunc; $data['createTime'] = date('Y-m-d H:i:s'); $this->data($data)->save(); if(intval($code) == 0){ return WSTReturn("短信發送成功!",1); }else{ return WSTReturn("短信發送失敗!"); } }} |
好了,經過以上的替換,短信寶的短信平臺已經替換成功了,我們去進行發送測試:

報備一下短信寶的VIP模板,這樣就可以走短信寶的優質通道了,即便遇到敏感文字我們都不會人工審核,短信內容3~5秒就可送達。
另外:我們已經開發好完整的WSTMart電子商務系統短信寶插件,點擊此鏈接 下載及查看安裝流程。
最新更新
電商類
CMS類
微信類