TPshop是用thinkphp開發(fā)的一款免費(fèi)開源電商系統(tǒng),二次開發(fā)非常方便,代碼清晰簡(jiǎn)潔。系統(tǒng)支持多語言版本,操作簡(jiǎn)單,安全穩(wěn)定,是廣大用戶二次開發(fā)的最佳選擇,我以替換短信接口為例,一步一步的手把手教大家開發(fā)過程,我們做演示的短信平臺(tái)是我們短信寶短信群發(fā)平臺(tái),我們短信寶短信平臺(tái)非常穩(wěn)定,短信發(fā)送速度快,注冊(cè)就送測(cè)試短信,推大家使用。
首先我們要更換后臺(tái)的顯示界面文件。打開模版文件,替換一下模版文件。打開項(xiàng)目/application/admin/view/system/sms.html文件,修改代碼26~85行,代碼如下:
|
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
|
<form method="post" id="handlepost" action="{:U('System/handle')}"> <div class="tab-content" style="padding:20px 0px;"> <div class="tab-pane active" id="tab_tongyong"> <table class="table table-bordered"> <tbody> <tr> <td class="col-sm-2">短信寶用戶名:</td> <td class="col-sm-8"> <input type="text" class="form-control" name="sms_appkey" value="{$config.sms_appkey}" > <span id="err_attr_name" style="color:#F00;display:none;"></span> </td> </tr> <tr> <td>短信寶密碼:</td> <td> <input type="password" class="form-control" name="sms_secretKey" value="{$config.sms_secretKey}" > </td> </tr> <tr> <td>短信簽名:</td> <td> <input type="text" class="form-control" placeholder="tpshop" name="sms_product" value="{$config.sms_product}"> </td> </tr> <tr style="display:none;"> <td>短信模板ID:</td> <td> <input type="text" class="form-control" name="sms_templateCode" value="{$config.sms_templateCode}" placeholder="例如SMS_12885853" > </td> </tr> <tr> <td>注冊(cè)啟用短信:</td> <td> <input type="radio" class="" name="regis_sms_enable" <if condition="$config['regis_sms_enable'] eq 1">checked</if> value="1" >是 <input type="radio" class="" name="regis_sms_enable" <if condition="$config['regis_sms_enable'] eq 0">checked</if> value="0" >否 </td> </tr> <tr> <td>短信碼超時(shí)時(shí)間:</td> <td> <select name="sms_time_out"> <option value="60" <if condition="$config['sms_time_out'] eq 60">selected="selected"</if>>1分鐘 </option> <option value="120"<if condition="$config['sms_time_out'] eq 120">selected="selected"</if>>2分鐘 </option> <option value="300"<if condition="$config['sms_time_out'] eq 300">selected="selected"</if>>5分鐘 </option> <option value="600"<if condition="$config['sms_time_out'] eq 600">selected="selected"</if>>10分鐘 </option> <option value="1200"<if condition="$config['sms_time_out'] eq 1200">selected="selected"</if>>20分鐘 </option> <option value="1800"<if condition="$config['sms_time_out'] eq 1800">selected="selected"</if>>30分鐘 </option> </select> </td> </tr> </tbody> <tfoot> <tr> <td> </td> <td><input type="hidden" name="inc_type" value="{$inc_type}"></td> <td class="text-right"><input class="btn btn-primary" type="button" onclick="adsubmit()" value="保存"></td> </tr> </tfoot> </table> </div> </div></form> |
經(jīng)過替換之后,所有的顯示都變成短信寶短信平臺(tái)的了,第一步完成。接下來替換發(fā)送短信的接口文件,項(xiàng)目/application/common/common/common.php文件,250~276行。修改發(fā)送短信代碼,代碼如下:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
/** * 發(fā)送短信 * @param $mobile 手機(jī)號(hào)碼 * @param $content 內(nèi)容 * @return bool*/function sendSMS($mobile,$content){ require(APP_PATH.'Common/Util/Sms.class.php'); $config = F('sms','',TEMP_PATH); $smsbao=Vendor('smsbao.smsbao'); $sms_content="【".$config['sms_product']."】".'您的注冊(cè)驗(yàn)證碼為:'.$content.'。如非本人操作,請(qǐng)忽略。'; if (empty($config['sms_appkey']) || empty($config['sms_secretKey'])) { return false; } $smsbao_c=new Sms($config['sms_appkey'],$config['sms_secretKey']); $res=$smsbao_c->sendSms($mobile,$sms_content); if($res=='0'){ return true; }else{ return false; }} |
最后我們需要在項(xiàng)目/application/common/util/建一個(gè)文件,取名為Sms.class.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
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
|
<?php/** * Created by Green Studio. * File: File.class.php * User: Timothy Zhang * Date: 14-1-31 * Time: 下午2:53 */class Sms{ private $username; private $password; private $api; private $errNo = array( "0" => "短信發(fā)送成功", "-1" => "參數(shù)不全", "-2" => "服務(wù)器空間不支持,請(qǐng)確認(rèn)支持curl或者fsocket,聯(lián)系您的空間商解決或者更換空間!", "30" => "密碼錯(cuò)誤", "40" => "賬號(hào)不存在", "41" => "余額不足", "42" => "帳戶已過期", "43" => "IP地址限制", "50" => "內(nèi)容含有敏感詞" ); public function __construct($username, $password) { $this->username = $username; $this->password = md5($password); } public function getError($no) { return $this->errNo[$no]; } public function sendSms($mobile, $sms_content) { if (empty($mobile) || empty($sms_content)) { return false; } $sms_content = urlencode($sms_content); $sendUrl = $this->api . 'u=' . $this->username . '&p=' . $this->password . '&m='.$mobile . '&c=' . $sms_content; $sendNo = file_get_contents($sendUrl); if (!$sendNo=='0') { return $this->getError($sendNo); }else{ return '0'; } }} |
經(jīng)過上面的替換,短信寶的短信平臺(tái)已經(jīng)替換成功了,可以正常使用了。進(jìn)行測(cè)試發(fā)送:

報(bào)備一下短信寶的VIP模板,這樣就可以走短信寶的優(yōu)質(zhì)通道了,并且免審核了,短信內(nèi)容3~5秒就可送達(dá)。
最新更新
電商類
CMS類
微信類