大商創,是一款功能強大的B2B2C多用戶商城系統,二次開發進行功能擴展很方便,代碼清晰簡潔,通俗易懂。我以替換接口為例為大家詳細講解如何進行二次開發,我們使用的短信接口是我們短信寶短信群發平臺的短信接口,我們短信寶短信平臺非常穩定,短信發送速度快,注冊就送測試短信,推大家使用。
進行接口替換,首先我們要替換后臺的模版文件,打開項目文件(/admin/templates/huyi_configure_list.dwt、/admin/templates/alidayu_configure_list.dwt、/admin/templates/alitongxin_configure_list.dwt),都修改11~28行,修改為如下代碼:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
< div class = "explanation" id = "explanation" > < div class = "ex_tit" > < i class = "sc_icon" ></ i >< h4 >操作提示</ h4 >< span id = "explanationZoom" title = "收起提示" ></ span > {if $open eq 1} < div class = "view-case" > < div class = "view-case-tit" >< i ></ i >查看教程</ div > < div class = "view-case-info" > </ div > </ div > {/if} </ div > < ul > < li class = "li_color" >注意:目前短信寶和阿里大魚的短信模板是一致的,請慎重操作添加、編輯和刪除.</ li > < li >列表頁展示所有短信配置模板的信息列表。</ li > < li >每條信息可以進行編輯和刪除操作。</ li > </ ul > </ div > |
經過替換后所有的頁面都變成我們短信寶的了,第一步完成。接下來替換短信發送的接口代碼,打開項目\includes\cls_sms.php文件,修改sms、send這兩個方法,修改代碼為:
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
|
function sms() { /* 由于要包含init.php,所以這兩個對象一定是存在的,因此直接賦值 */ $this ->sms_name = $GLOBALS [ '_CFG' ][ 'sms_ecmoban_user' ]; $this ->sms_password = $GLOBALS [ '_CFG' ][ 'sms_ecmoban_password' ]; $this ->sms_sign = $GLOBALS [ '_CFG' ][ 'shop_name' ]; } // 發送短消息 function send( $phones , $msg = '' , $send_date = '' , $send_num = 1, $sms_type = '' , $version = '1.0' , & $sms_error = '' , $mobile_code = '' ) { if ( $GLOBALS [ '_CFG' ][ 'sms_type' ] == 0) { /* 檢查發送信息的合法性 */ $contents = $this ->get_contents( $phones , $msg ); if (! $contents ) { return false; } /* 獲取API URL */ if ( count ( $contents ) > 1) { foreach ( $contents as $key => $val ) { $post_data = 'u=' . $this ->sms_name . '&p=' . $this ->sms_password . '&m=' . $val [ 'phones' ] . '&c=【' . $this ->sms_sign. '】' . rawurlencode( $val [ 'content' ]); //密碼可以使用明文密碼或使用32位MD5加密 $get = file_get_contents ( $sms_url . $post_data ); $gets [ 'code' ]= $get ; $gets [ 'msg' ]= '發送成功' ; sleep(1); } } else { $post_data = 'u=' . $this ->sms_name . '&p=' . $this ->sms_password . '&m=' . $contents [0][ 'phones' ] . '&c=【' . $this ->sms_sign. '】' . rawurlencode( $contents [0][ 'content' ]); $get = file_get_contents ( $sms_url . $post_data ); $gets [ 'code' ] = $get ; $gets [ 'msg' ] = '發送成功' ; } //print_r($gets);exit; //開啟調試模式 if ( $get == '0' ) { return true; } else { $statusStr = array ( "0" => "短信發送成功" , "-1" => "參數不全" , "-2" => "服務器空間不支持,請確認支持curl或者fsocket,聯系您的空間商解決或者更換空間!" , "30" => "密碼錯誤" , "40" => "賬號不存在" , "41" => "余額不足" , "42" => "帳戶已過期" , "43" => "IP地址限制" , "50" => "內容含有敏感詞" ); $sms_error = $phones . $statusStr [ "$get" ]; $this ->logResult( $sms_error ); return false; } } else if ( $GLOBALS [ '_CFG' ][ 'sms_type' ] >=1) { $msg = $this ->get_usser_sms_msg( $msg ); //阿里大魚短信接口 if (! empty ( $msg [ 'sms_value' ])){ $smsParams = array ( 'mobile_phone' => $phones , 'code' => $msg [ 'code' ] ); $send_time = $msg [ 'sms_value' ]; } else { $smsParams = array ( 'mobile_phone' => $phones , 'code' => $msg [ 'code' ], 'product' => $msg [ 'product' ] ); $send_time = 'sms_signin' ; } $result = sms_ali( $smsParams , $send_time ); //阿里大魚短信變量傳值,發送時機傳值 $resp = $GLOBALS [ 'ecs' ]->ali_yu( $result ); if ( $resp ->code == 0){ return true; } else { if ( $resp ->sub_msg){ $sms_error = $phones . $resp ->sub_msg; } else { $sms_error = $phones . ":" . $resp ->msg; } $this ->logResult( $sms_error ); return false; } } } |
修改配置文件,打開項目/languages/zh_cn/admin/common.php文件,修改470行左右,修改代碼如下:
1
|
$_LANG [ 'huyi_configure' ] = '短信寶短信' ; |
打開項目/languages/zh_cn/admin/shop_config.php文件,修改85、206~208行左右,修改代碼如下:
1
2
3
4
|
85 $_LANG [ 'cfg_range' ][ 'sms_type' ][ '0' ] = '短信寶' ; 206 $_LANG [ 'cfg_name' ][ 'sms_ecmoban_user' ] = '短信寶短信接口用戶名' ; 207 $_LANG [ 'cfg_name' ][ 'sms_ecmoban_password' ] = '短信寶短信接口密碼' ; 208 $_LANG [ 'cfg_name' ][ 'sms_sign' ] = '短信簽名' ; |
pc端的我們已經替換成功了,我們進行手機端的替換,打開項目\mobile\app\helpers\base_helper.php文件,修改send_sms方法,修改代碼為:
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
|
function send_sms( $mobile , $send_time = '' , $content ) { $sms_type = [ 'ihuyi' , 'alidayu' , 'aliyun' ]; $config = array ( 'driver' => 'sms' , 'driverConfig' => array ( 'sms_type' => $sms_type [ $GLOBALS [ '_CFG' ][ 'sms_type' ]], // 短信類型對應 $sms_type 數組索引 'ihuyi' => array ( 'sms_name' => $GLOBALS [ '_CFG' ][ 'sms_ecmoban_user' ], 'sms_password' => $GLOBALS [ '_CFG' ][ 'sms_ecmoban_password' ], 'sms_sign' => $GLOBALS [ '_CFG' ][ 'shop_name' ] ), 'alidayu' => array ( 'ali_appkey' => $GLOBALS [ '_CFG' ][ 'ali_appkey' ], 'ali_secretkey' => $GLOBALS [ '_CFG' ][ 'ali_secretkey' ] ), 'aliyun' => array ( 'access_key_id' => $GLOBALS [ '_CFG' ][ 'access_key_id' ], 'access_key_secret' => $GLOBALS [ '_CFG' ][ 'access_key_secret' ] ) ) ); // 發送消息 $sms = new \App\Notifications\Send( $config ); if ( $sms ->push( $mobile , $send_time , $content ) === true) { return true; } else { return $sms ->getError(); } } |
接下來修改發送的接口類,打開項目\mobile\app\modules\notifications\sms\driver\Ihuyi.php文件,修改以下代碼:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
private function send() { foreach ( $this ->phones as $mobile ) { $post_data = array ( 'u' => $this ->config[ 'sms_name' ], 'p' => $this ->config[ 'sms_password' ], 'm' => $mobile , 'c' => '【' . $this ->config[ 'sms_sign' ]. '】' . $this ->content ); $res = Http::doPost( $this ->sms_api, $post_data ); //print_r($data);exit; //開啟調試模式 TODO 此處暫時只能發送一次 if ( $data [ 'SubmitResult' ][ 'code' ] == 0) { return true; } else { $this ->errorInfo = $data [ 'SubmitResult' ][ 'msg' ]; logResult( $this ->errorInfo, 'sms' ); return false; } } } |
經過上面的替換,短信寶的短信平臺已經替換成功了,可以正常使用了。進行測試發送:
報備一下短信寶的VIP模版,這樣就可以走短信寶的優質通道,并且免審核了,短信內容3~5秒就可送達。
最新更新
電商類
CMS類
微信類