TPshop是用thinkphp開發的一款免費開源網店系統,二次開發非常方便,代碼清晰簡潔,通俗易懂,豐富的插件和多套模板支持,易擴展,是目前國內首家最為完善的開源商城系統。小編今天就以3.5.3版本新增短信接口為例為大家講解一下如何進行二次開發,我們使用的短信接口是我們短信寶短信群發平臺的短信接口,我們短信寶短信群發平臺非常穩定,發送速度快,注冊就送測試短信,推薦大家使用。
首先打開項目:\application\admin\view\system\sms.html文件,替換35行左右代碼
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
|
< dd class = "opt" > < select name = "sms_platform" id = "sms_platform" > < option value = "1" <if condition = "$config[sms_platform] eq 1" >selected="selected"</ if >>阿里云</ option > < option value = "2" <if condition = "$config[sms_platform] eq 2" >selected="selected"</ if >>天瑞云</ option > < option value = "3" <if condition = "$config[sms_platform] eq 3" >selected="selected"</ if >>短信寶</ option > </ select > < p class = "notic" >短信平臺選擇</ p > </ dd > </ dl > < dl class = "row" > < dt class = "tit" > < label for = "sms_appkey" >短信平臺[appkey]</ label > </ dt > < dd class = "opt" > < input id = "sms_appkey" name = "sms_appkey" value = "{$config.sms_appkey}" class = "input-txt" type = "text" /> < p class = "notic" >短信平臺配置appkey/keyid/短信寶用戶名</ p > < p class = "notic" >短信寶的用戶名,還未注冊短信寶的用戶請點擊< a href = "http://www.gjrencai.com" target = "_blank" >免費注冊</ a ></ p > </ dd > </ dl > < dl class = "row" > < dt class = "tit" > < label for = "sms_secretKey" >短信平臺[secretKey]</ label > </ dt > < dd class = "opt" > < input id = "sms_secretKey" name = "sms_secretKey" value = "{$config.sms_secretKey}" class = "input-txt" type = "text" /> < p class = "notic" >短信平臺配置secretKey/短信寶密碼</ p > </ dd > </ dl > < dl class = "row" > < dt class = "tit" > < label for = "sms_product" >公司名/品牌名/產品名</ label > </ dt > < dd class = "opt" > < input id = "sms_product" name = "sms_product" value = "{$config.sms_product}" class = "input-txt" type = "text" /> < p class = "notic" >公司名/品牌名/產品名</ p > </ dd > </ dl > |
接著打開項目:\application\admin\view\sms_template\_sms_template.html文件,替換85~115行代碼
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
|
function checkForm(){ var smsSign = $( "#addEditSmsTemplate" ).find( "input[name='sms_sign']" ).val(); //短信簽名 var smsTplCode = $( "#addEditSmsTemplate" ).find( "input[name='sms_tpl_code']" ).val(); //模板ID var tplContent = $( "#addEditSmsTemplate" ).find( "textarea[name='tpl_content']" ).val(); //模板內容 var sendscene = $( "#send_scene option:selected" ).val(); if ($.trim(smsSign) == '' ) { $( "#err_sms_sign" ).show(); return false ; } if ($.trim(tplContent) == '' ) { $( "#err_tpl_content" ).show(); return false ; } if (sendscene == -1){ $( "#err_send_scene" ).show(); return false ; } $( '#addEditSmsTemplate' ).submit(); } |
最后打開項目:\application\common\logic\SmsLogic.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
|
/** * 發送短信(短信寶) * @param $mobile 手機號碼 * @param $code 驗證碼 * @return bool 短信發送成功返回true失敗返回false */ private function sendSmsBySmsbao( $mobile , $smsSign , $smsParam , $templateCode , $msg ) { $user = $this ->config[ 'sms_appkey' ]; $pass = $this ->config[ 'sms_secretKey' ]; $url = 'http://api.smsbao.com/sms?u=' . $user . '&p=' .md5( $pass ). '&m=' . $mobile . '&c=【' . $smsSign . '】' . $msg ; if (function_exists( 'file_get_contents' )) { $ret = file_get_contents ( $url ); } else { $ch = curl_init(); $timeout = 5; curl_setopt( $ch , CURLOPT_URL, $url ); curl_setopt( $ch , CURLOPT_RETURNTRANSFER, 1); curl_setopt( $ch , CURLOPT_CONNECTTIMEOUT, $timeout ); $ret = curl_exec( $ch ); curl_close( $ch ); } if ( $ret == 0) { return array ( 'status' => 1, 'msg' => $ret ); } else { return array ( 'status' => -1, 'msg' => $ret ); } } |
好了,經過以上的替換,短信寶的短信平臺已經替換成功了,可以正常使用了。我們進行測試發送。
報備一下短信寶的VIP模板,這樣就可以走短信寶的優質通道了,即便遇到敏感文字我們都不會人工審核,短信內容3~5秒就可送達。
另外:我們已經開發好完整的TPshop商城系統短信寶插件,點擊此鏈接 下載及查看安裝流程。
最新更新
電商類
CMS類
微信類