SHOPNR本地電商系統是一款簡單的外賣系統,他是基于PHP+MYSQL開發的,對于后期維護和二次開發比較容易,小編對這款系統還是比較了解的,今天小編就以短信接口替換為例,為大家講解一下如何進行二次開發,我們今天講解的是2.1.5版本,使用的短信接口是我們短信寶短信群發平臺的短信接口,我們短信寶短信群發平臺非常穩定,發送速度快,注冊就送測試短信,推薦大家使用。
我們首先修改后臺顯示界面,打開項目\App\shopadmin\Tpl\Config\index.html 文件,修改233~275左右代碼,修改為:
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
|
< div class = "am-panel am-panel-default" > < div class = "am-panel-hd" >短信接口</ div > < div class = "am-panel-bd" > < div class = "am-form-group" > < label class = "am-form-label inputname" >短信寶帳號:</ label > < div class = "inputbox" > < input type = "text" name = "sms_account" id = "doc-ipt-name-1" value = "{$site.sms_account}" > </ div > </ div > < div class = "am-form-group" > < label class = "am-form-label inputname" >短信寶密碼:</ label > < div class = "inputbox" > < input type = "password" name = "sms_password" id = "doc-ipt-name-1" value = "{$site.sms_password}" > </ div > </ div > < div class = "am-form-group" > < label class = "am-form-label inputname" >短信驗證:</ label > < div class = "inputbox" style = "margin-top: 10px;" > < input type = "radio" name = "is_sms_validate" value = '1' <eq name = "site.is_sms_validate" value = "1" >checked="checked"</ eq > > 開啟 < input type = "radio" name = "is_sms_validate" value = '0' <eq name = "site.is_sms_validate" value = "0" >checked="checked"</ eq >> 關閉< br /> < small >用戶注冊的時候,必須進行短信驗證;必須開通短信驗證,用戶才能找回密碼</ small > </ div > </ div > < div class = "am-form-group" > < label class = "am-form-label inputname" >短信訂單:</ label > < div class = "inputbox" style = "margin-top: 10px;" > < input type = "radio" name = "is_sms_order" value = '1' <eq name = "site.is_sms_order" value = "1" >checked="checked"</ eq >> 開啟 < input type = "radio" name = "is_sms_order" value = '0' <eq name = "site.is_sms_order" value = "0" >checked="checked"</ eq >> 關閉< br /> < small >用戶下單,會給商家和買家發送短信通知</ small > </ div > </ div > < div class = "am-form-group" > < label class = "am-form-label inputname" >賬戶短信:</ label > < div class = "inputbox" style = "margin-top: 10px;" > < input type = "radio" name = "is_sms_money" value = '1' <eq name = "site.is_sms_money" value = "1" >checked="checked"</ eq >> 開啟 < input type = "radio" name = "is_sms_money" value = '0' <eq name = "site.is_sms_money" value = "0" >checked="checked"</ eq >> 關閉< br /> < small >用戶賬號積分或者金額變動,會給會員發送短信通知</ small > </ div > </ div > < div class = "am-form-group" > < label class = "am-form-label inputname" >接單手機號:</ label > < div class = "inputbox" > < input type = "text" name = "get_tel" id = "doc-ipt-name-1" value = "{$site.get_tel}" > < small >必須填寫手機號,用來接收新訂單的短信通知。</ small > </ div > </ div > < div class = "am-form-group" > < label class = "am-form-label inputname" >短信簽名:</ label > < div class = "inputbox" > < input type = "text" name = "sms_sign" id = "doc-ipt-name-1" value = "{$site.sms_sign}" > < small >必須,如“【短信寶】” 3-8個字。</ small > </ div > </ div > < div class = "am-form-group" > < label class = "am-form-label inputname" > </ label > < div class = "inputbox" >< button type = "submit" class = "am-btn am-btn-primary" >保存修改</ button ></ div > </ div > </ div > </ div > |
接下來我們修改調用短信接口的文件,打開項目\Common\common.php文件,修改 send_message 方法, 代碼如下:
1
2
3
4
5
6
7
|
//短信發送 function send_message( $tel , $content ){ import( 'ORG.Util.smsbao.smsbao' ); $sendObj = new smsbao(C( "sms_account" ),C( "sms_password" )); $resultObj = $sendObj ->sendMessage( $tel ,C( 'sms_sign' ). $content ); } |
最后我們添加短信寶接口,打開項目\Framework\Library\ORG\Util 我們在Util下創建smsbao文件夾,在smsbao下創建smsbao.class.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
|
<?php /** php 環境須裝有curl模塊和json模塊才能正常使用該程序, 本頁面使用utf-8編碼,短信內容為utf-8編碼 **/ /** * 短信寶短信平臺 */ class smsbao { public function __construct( $username , $pass ) { $this ->u = $username ; $this ->p = md5( $pass ); } function sendMessage( $mobile , $content ) { if (function_exists( 'file_get_contents' )) { $ret = file_get_contents ( $url ); } else { $curl = curl_init(); curl_setopt( $curl , CURLOPT_URL, $url ); curl_setopt( $curl , CURLOPT_SSL_VERIFYPEER, false); curl_setopt( $curl , CURLOPT_SSL_VERIFYHOST, false); if (! empty ( $data )) { curl_setopt( $curl , CURLOPT_POST, 1); curl_setopt( $curl , CURLOPT_POSTFIELDS, $data ); } curl_setopt( $curl , CURLOPT_RETURNTRANSFER, 1); $ret = curl_exec( $curl ); curl_close( $curl ); return $info ; } } } |
好了,經過以上的替換,短信寶的短信平臺已經替換成功了,我們去進行發送測試:
報備一下短信寶的VIP模板,這樣就可以走短信寶的優質通道了,并且免審核了,短信內容3~5秒就可送達。
最新更新
電商類
CMS類
微信類