TPshop是用thinkphp開發(fā)的一款免費開源網(wǎng)店系統(tǒng),二次開發(fā)非常方便,代碼清晰簡潔,通俗易懂,豐富的插件和多套模板支持,易擴(kuò)展,是目前國內(nèi)首家最為完善的開源商城系統(tǒng)。系統(tǒng)支持多語言版本,操作簡單,安全穩(wěn)定,是廣大用戶二次開發(fā)的最佳選擇,小編今天就以新增短信接口為例為大家講解一下如何進(jìn)行二次開發(fā),我們使用的短信接口是我們短信寶短信群發(fā)平臺的短信接口,我們短信寶短信群發(fā)平臺非常穩(wěn)定,發(fā)送速度快,注冊就送測試短信,推薦大家使用。
首先我們打開項目:\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: //重新組裝發(fā)送內(nèi)容, 將變量內(nèi)容組裝成: 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; } |
接著增加發(fā)送短信的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
|
/** * 發(fā)送短信(短信寶) * @param $mobile 手機(jī)號碼 * @param $code 驗證碼 * @return bool 短信發(fā)送成功返回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); } } |
好了,經(jīng)過以上的替換,短信寶的短信平臺已經(jīng)替換成功了,可以正常使用了。我們進(jìn)行測試發(fā)送。

報備一下短信寶的VIP模板,這樣就可以走短信寶的優(yōu)質(zhì)通道了,即便遇到敏感文字我們都不會人工審核,短信內(nèi)容3~5秒就可送達(dá)。
另外:我們已經(jīng)開發(fā)好完整的TPshop商城系統(tǒng)短信寶插件,點擊此鏈接 下載及查看安裝流程。
最新更新
電商類
CMS類
微信類