海盜云商是采用PHP+MySQL方式運行的開源電子商務網店程序。輕架構,高效率簡易開發,助你快速搭建并輕松管理網店站點,便于二次開發,小編對于這款產品還是比較了解的,今天就以替換短信接口為例,一步一步的帶領大家如何進行二次開發,我們使用的短信接口是我們短信寶短信群發平臺的短信接口,我們短信寶短信群發平臺非常穩定,發送速度快。注冊就送測試短信,推薦大家使用。
進行接口替換我們首先需要修改后臺模版文件,打開項目/system/module/notify/library/driver/sms/config.xml,修改代碼如下:
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
|
<? xml version = "1.0" encoding = "ISO-8859-1" ?> < root > < item id = "code" > <![CDATA[sms]]> </ item > < item id = "name" > <![CDATA[短信寶通知系統]]> </ item > < item id = "description" > <![CDATA[包含手機注冊驗證、找回密碼、余額變動通知、充值成功短信通知、訂單發貨短信通知、確認訂單短信通知、付款成功短信通知、下單成功短信通知]]> </ item > < item id = "dataline" > <![CDATA[2015-05-25 14:57:09]]> </ item > < item id = "version" > <![CDATA[1.0]]> </ item > < item id = "sort" > <![CDATA[2]]> </ item > < item id = "ignore" > <![CDATA[email_validate,goods_arrival]]> </ item > < item id = "vars" > < item id = "sms_name" > < item id = "name" > <![CDATA[短信寶用戶名]]> </ item > < item id = "type" > <![CDATA[text]]> </ item > < item id = "value" > <![CDATA[]]> </ item > < item id = "tips" > <![CDATA[請填寫在短信寶注冊的用戶名,尚未注冊短信寶的,請點擊 <a href='http://www.gjrencai.com' target='_blank'><strong>免費注冊</strong></a> ]]> </ item > </ item > < item id = "sms_pwd" > < item id = "name" > <![CDATA[短信寶賬戶密碼]]> </ item > < item id = "type" > <![CDATA[password]]> </ item > < item id = "value" > <![CDATA[]]> </ item > < item id = "tips" > <![CDATA[請填寫短信寶賬戶密碼 ]]> </ item > </ item > < item id = "sms_sign" > < item id = "name" > <![CDATA[短信簽名]]> </ item > < item id = "type" > <![CDATA[text]]> </ item > < item id = "value" > <![CDATA[]]> </ item > < item id = "tips" > <![CDATA[設置短信簽名如,一般為3-8個字符,如:海盜云商 ]]> </ item > </ item > </ item > </ root > |
接下來我們修改模版文件,打開項目/system/module/notify/library/driver/sms/template.inc.php文件,修改代碼為:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
<p class = "notice" >您正在編輯 <em id= "content-label" class = "text-main" >loading</em> 通知模板 </p> <?php foreach ( $hooks as $tk => $tv ):?> <div id= 'edit_<?php echo $tk?>' style= "display: none;" > <div class = "form-group" > <span class = "label" ></span> <div class = "" > <input type= 'text' name= '<?php echo $tk?>[template_id]' class = 'input hd-input' value= '<?php echo trim($template[' template '][$tk][' template_id '])?>' /> </div> </div> </div> <?php endforeach ;?> |
修改配置模版的代碼文件,打開項目/system/module/notify/control/admin_control.class.php文件中的,template方法,代碼如下:
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
|
/* 配置模板 */ public function template() { $notify = $this ->service->fetch_by_code( $_GET [ 'code' ]); $hooks = array ( 'after_register' => '注冊成功' , 'register_validate' => '注冊驗證' , 'mobile_validate' => '手機驗證' , 'email_validate' => '郵箱驗證' , 'forget_pwd' => '找回密碼' , 'money_change' => '余額變動' , 'recharge_success' => '充值成功' , 'order_delivery' => '訂單發貨' , 'confirm_order' => '確認訂單' , 'pay_success' => '付款成功' , 'create_order' => '下單成功' , 'goods_arrival' => '商品到貨' , ); //$replace = $this->service->template_replace(); $ignore = explode ( ',' , $notify [ 'ignore' ]); foreach ( $ignore as $k => $v ) { unset( $hooks [ $v ]); } if (checksubmit( 'dosubmit' )) { $template = array (); $enabled = array (); foreach ( $hooks as $k => $v ) { $template [ $k ] = str_replace ( $replace , array_keys ( $replace ), $_GET [ $k ]); } $enabled = $_GET [ 'enabled' ]; $_GET [ 'template' ] = unit::json_encode( $template ); $_GET [ 'enabled' ] = json_encode( $enabled ); $_GET [ 'name' ] = $notify [ 'name' ]; $result = $this ->temlage_service->update( $_GET ); if ( $result === false) showmessage( $this ->temlage_service->error); showmessage(lang( 'upload_message_success' , 'notify/language' ),url( 'index' )); } else { $template = $this ->temlage_service->fetch_by_code( $_GET [ 'code' ]); foreach ( $template [ 'template' ] as $k => $temp ) { $template [ 'template' ][ $k ] = str_replace ( array_keys ( $replace ), $replace , $temp ); } //單獨處理短信 if ( $_GET [ 'code' ] == 'sms' ){ $cloud = $this ->load->service( 'admin/cloud' ); $data = $cloud ->getsmstpl(); $template = $data [ 'result' ] ? array_merge ( $template , $data [ 'result' ]) : $template ; $sms_num = $cloud ->getsmsnum(); $this ->load->librarys( 'View' )->assign( 'sms_num' , $sms_num ); } $this ->load->librarys( 'View' )->assign( 'notify' , $notify )->assign( 'hooks' , $hooks )->assign( 'replace' , $replace )->assign( 'ignore' , $ignore )->assign( 'template' , $template )->display( 'notify_template' ); } } |
接下來我們需要修改發送隊列文件,打開項目/library/queue.class.php文件,修改add方法,代碼為:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
/* 加入隊列 */ public function add( $type = 'email' , $method , $params , $sort = 100) { $params = ( is_array ( $params ) && ! empty ( $params )) ? json_encode( $params ) : $params ; $data = array ( 'type' => $type , 'method' => $method , 'params' => $params , 'dateline' => TIMESTAMP, 'sort' => (int) $sort ); model( 'notify/queue' , 'service' )->config( $data )->send(); return true; } |
最后我們修改短信接口文件,打開項目/module/notify/library/driver/sms/sms.class.php,修改send方法,代碼為:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
public function send(){ $params = array (); $param = array (); $params [ 'tpl_id' ] = $this ->sms[ 'tpl_id' ]; $param [ 'm' ] = $this ->sms[ 'mobile' ]; $params [ 'tpl_vars' ] = $this ->sms[ 'tpl_vars' ]; $params [ 'sms_sign' ] = $this ->config[ 'configs' ][ 'sms_sign' ]; $param [ 'u' ] = $this ->config[ 'configs' ][ 'sms_name' ]; $param [ 'p' ] = MD5( $this ->config[ 'configs' ][ 'sms_pwd' ]); $tpl_vals =[]; foreach ( $params [ 'tpl_vars' ] as $key => $val ){ $new_key = '{' . $key . '}' ; $tpl_vals [ $new_key ]= $val ; } $param [ 'c' ]= "【{$params['sms_sign']}】" . strtr ( $params [ 'tpl_id' ], $tpl_vals ); $send = ( $r == '0' ) ? TRUE : FALSE; return $this ->_notify( $send ); } |
好了,經過以上的替換,短信寶的短信平臺已經替換成功了,可以正常使用了。進行發送測試:
報備一下短信寶的VIP模板,這樣就可以走短信寶的優質通道了,并且免審核了,短信內容3~5秒就可送達。
最新更新
電商類
CMS類
微信類