TPshop是用thinkphp開發的一款免費開源電商系統,二次開發非常方便,代碼清晰簡潔。系統支持多語言版本,操作簡單,安全穩定,是廣大用戶二次開發的最佳選擇,我以替換短信接口為例,一步一步的手把手教大家開發過程,我們做演示的短信平臺是我們短信寶短信群發平臺,我們短信寶短信平臺非常穩定,短信發送速度快,注冊就送測試短信,推大家使用。
首先我們要更換后臺的顯示界面文件。打開模版文件,替換一下模版文件。打開項目/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>注冊啟用短信:</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>短信碼超時時間:</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> |
經過替換之后,所有的顯示都變成短信寶短信平臺的了,第一步完成。接下來替換發送短信的接口文件,項目/application/common/common/common.php文件,250~276行。修改發送短信代碼,代碼如下:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
/** * 發送短信 * @param $mobile 手機號碼 * @param $content 內容 * @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']."】".'您的注冊驗證碼為:'.$content.'。如非本人操作,請忽略。'; 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; }} |
最后我們需要在項目/application/common/util/建一個文件,取名為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" => "短信發送成功", "-1" => "參數不全", "-2" => "服務器空間不支持,請確認支持curl或者fsocket,聯系您的空間商解決或者更換空間!", "30" => "密碼錯誤", "40" => "賬號不存在", "41" => "余額不足", "42" => "帳戶已過期", "43" => "IP地址限制", "50" => "內容含有敏感詞" ); 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'; } }} |
經過上面的替換,短信寶的短信平臺已經替換成功了,可以正常使用了。進行測試發送:

報備一下短信寶的VIP模板,這樣就可以走短信寶的優質通道了,并且免審核了,短信內容3~5秒就可送達。
最新更新
電商類
CMS類
微信類