TPshop是用thinkphp開發的一款免費開源網店系統,二次開發非常方便,代碼清晰簡潔,通俗易懂,豐富的插件和多套模板支持,易擴展,是目前國內首家最為完善的開源商城系統。系統支持多語言版本,操作簡單,安全穩定,是廣大用戶二次開發的最佳選擇,小編今天就以新增短信接口為例為大家講解一下如何進行二次開發,我們使用的短信接口是我們短信寶短信群發平臺的短信接口,我們短信寶短信群發平臺非常穩定,發送速度快,注冊就送測試短信,推薦大家使用。
首先我們打開項目:\application\admin\view\system\sms.html文件,替換45~73行左右的代碼
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
|
< dl class = "row" > < dt class = "tit" > < label for = "sms_platform" >選擇短信平臺</ label > </ dt > < dd class = "opt" > < select name = "sms_platform" id = "sms_platform" > < option value = "1" <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 > |
接著打開項目:\application\common\logic\SmsLogic.php文件,替換realSendSms方法
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
|
private function realSendSms( $mobile , $smsSign , $smsParam , $templateCode , $msg ) { $type = (int) $this ->config[ 'sms_platform' ] ?: 0; switch ( $type ) { case 0: $result = $this ->sendSmsByAlidayu( $mobile , $smsSign , $smsParam , $templateCode ); break ; case 1: $result = $this ->sendSmsByAliyun( $mobile , $smsSign , $smsParam , $templateCode ); break ; case 2: //重新組裝發送內容, 將變量內容組裝成: 13800138006##張三格式 foreach ( $smsParam as $k => $v ){ $contents [] = $v ; } $content = implode( $contents , "##" ); $result = $this ->sendSmsByCloudsp( $mobile , $smsSign , $content , $templateCode ); break ; case 3: $result = $this ->sendSmsBySmsbao( $mobile , $smsSign , $smsParam , $templateCode , $msg ); break ; default : $result = [ 'status' => -1, 'msg' => '不支持的短信平臺' ]; } return $result ; } |
接著增加發送短信的sendSmsBySmsbao方法
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
|
/** * 發送短信(短信寶) * @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' ]; 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類
微信類