待发短信

在线客服
产品支持 短信宝客服
合作渠道 渠道合作
服务咨询

4001-021-502

工作时间

9:00-21:00

tpshop1.3.1商城系统替换接口

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>
                            <span>还没有短信宝账号?点击马上<a href="http://smsbao.com" target="_blank">免费注册</a></span>
                        </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);
        $this->api = 'http://api.smsbao.com/sms?';
    }
 
    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类

微信类

文章标签