待发短信

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

4001-021-502

工作时间

9:00-21:00

五指cms网站管理系统新增短信宝短信接口

五指CMS是国内新一代、能够实现跨屏管理的网站内容管理系统,是国内家后台管理界面全部采用HTML5+CSS3技术的内容管理系统(CMS),该系统采用了PHP5+MYSQL做为技术基础进行开发。采用了面向对象的编程方式,多层架构设计,模块化的开发方式。系统功能易于扩展,易于二次开发,支持站群。今天小编就已替换短信接口为例为大家讲解一下如何进行二次开发,我们讲解的是v4.1.0版本,使用的短信接口是我们短信宝短信群发平台的接口,我们短信宝短信群发平台非常稳定,发送速度快,注册就送测试短信,推荐大家使用。

首先我们更换后台显示界面,打开项目\coreframe\app\sms\admin\template\setting.tpl.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
<?php defined('IN_WZ') or exit('No direct script access allowed');?>
<?php
include $this->template('header','core');
?>
<body class="body pxgridsbody">
<section class="wrapper">
    <div class="row">
        <div class="col-lg-12">
            <section class="panel">
                <?php echo $this->menu($GLOBALS['_menuid']);?>
                <div class="panel-body">
                    <form class="form-horizontal tasi-form" method="post" action="">
                        <div class="form-group">
                            <label class="col-sm-2 col-xs-4 control-label">短信宝用户名</label>
                            <div class="col-lg-3 col-sm-4 col-xs-4 input-group">
                                <input type="text" class="form-control" name="form[sms_uid]"  value="<?php echo output($setting,'sms_uid');?>" placeholder="">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 col-xs-4 control-label">短信宝密码</label>
                            <div class="col-lg-3 col-sm-4 col-xs-4 input-group">
                                <input type="password" class="form-control" name="form[sms_pid]" value="<?php echo output($setting,'sms_pid');?>">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 col-xs-4 control-label">短信签名</label>
                            <div class="col-lg-3 col-sm-4 col-xs-4 input-group">
                                <input type="text" class="form-control" name="form[sms_passwd]" value="<?php echo output($setting,'sms_passwd');?>">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-2 col-xs-4 control-label"></label>
                                <div class="col-lg-3 col-sm-4 col-xs-4 input-group">
                                    <input class="btn btn-info col-sm-12 col-xs-12" type="submit" name="submit" value="提交">
                                </div>
                        </div>
                    </form>
                </div>
 
            </section>
        </div>
    </div>
    <!-- page end--><div class="alert alert-success fade in">
        <strong>短信购买:</strong> 支持全国电信、移动、联通手机用户。购买地址 <a href="http://www.smsbao.com" target="_blank">http://www.smsbao.com</a>    </div>
</section>
<script src="<?php echo R;?>js/bootstrap.min.js"></script>
<script src="<?php echo R;?>js/jquery.nicescroll.js" type="text/javascript"></script>
<script src="<?php echo R;?>js/pxgrids-scripts.js"></script>

其次我们修改短信发送类,打开项目\coreframe\app\sms\libs\class\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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
<?php
defined('IN_WZ'or exit('No direct script access allowed');
/**
 * 短信API
 */
class WUZHI_sms {
    public $uid;
    public $statuscode;
    private $sms_uid,$sms_pid,$sms_key,$smsapi_url;
    
    /**
     
     * 初始化接口类
     * @param int $uid 用户id
     * @param int $sms_pid 产品id
     * @param string $sms_key 密钥
     */
    public function __construct() {
        $this->smsapi_url = 'http://api.smsbao.com/sms?';
        $sms_config = get_cache('sms_config','sms');
        $this->sms_uid = $sms_config['sms_uid'];
        $this->sms_pid = $sms_config['sms_pid'];
        $this->sms_key = $sms_config['sms_passwd'];
    }
        
    /**
     
     * 获取短信产品列表信息
     */
    public function get_price() {
        return [];
    }
    
    /**
     
     * 获取短信产品购买地址
     */
    public function get_buyurl($productid = 0) {
        return [];
    }
 
    /**
     * 获取短信剩余条数和限制短信发送ip
     */
    public function get_smsinfo() {
        return [];
    }  
 
    /**
     * 获取充值记录
     */
    public function get_buyhistory() {
        return [];        
    }
 
    /**
     * 获取消费记录
     * @param int $page 页码
     */
    public function get_payhistory($page=1) {
        return [];    
    }
 
    /**
     * 发送短信
     *
     * @param string $mobile
     * @param string $content
     * @param string $tplid
     * @param string $send_time
     * @param int $return_code
     * @return mixed
     */
    public function send_sms($mobile=''$content='',$tplid ''$send_time =''$return_code = 0) {
        //短信发送状态
        $status $this->_sms_status();
        if(is_array($mobile)){
            $mobile = implode(","$mobile);
        }
        /*if(strtolower(CHARSET)=='utf-8') {
            $send_content = iconv('utf-8','gbk',$content);
        }else{
            $send_content = $content;
        }*/
        //$send_content = $content;
        //$send_time = strtotime($send_time);
        //短信模板
        $sitelist = get_cache('sitelist');
        $siteid intval($GLOBALS['siteid']);
        $sms_param=explode('||'$content);
        if($tplid==269){
            //发送优惠券信息,尊敬的用户,五指CMS优惠券为:sss,截止日期为:2016-12-1,请登录www.h1jk.cn及时使用!
            $tpl="尊敬的用户您好,恭喜你获得优惠券,卡号为:%s,截止日期为:%s,请及时使用,请登录".$sitelist[$siteid]['url']s;
            $sms_content=sprintf($tpl,$sms_param[0],$sms_param[1]);
        }elseif($tplid==222){
            //您的预约卡信息如下:<br>卡号:{$r['card_no']} <br> 密码:{$card_password}<br>
            $tpl="您的预约卡信息如下:卡号:%s, 密码:%s!";
            $sms_content=sprintf($tpl,$content);
        }else{
            //验证码
            $tpl="您的验证码为:%s,请不要告诉他人。";
            $sms_content=sprintf($tpl,$sms_param[0],$sms_param[1]);
        }
        $data array(
            'u' => $this->sms_uid,
            'p' => md5($this->sms_pid),
            'c' => "【".$this->sms_key."】".$sms_content,
            'm' => $mobile,
        );
        $send_res=file_get_contents($this->smsapi_url.http_build_query($data));
        
        //echo $this->smsapi_url.http_build_query($data);
        return $send_res;
    }
        
    /**
     
     * 获取远程内容
     * @param $timeout 超时时间
     */
    public function getinfo($timeout=30) {
        
        $this->setting = array(
                            'sms_uid'=>$this->sms_uid,
                            'sms_pid'=>$this->sms_pid,
                            'sms_passwd'=>$this->sms_key,
                            );
                                    
        $this->param = array_merge($this->param, $this->setting);
        
        $url $this->smsapi_url.http_build_query($this->param);
        $stream = stream_context_create(array('http' => array('timeout' => $timeout)));
        return @file_get_contents($url, 0, $stream);
    }
    
    /**
     *  post数据
     *  @param string $url     post的url
     *  @param int $limit      返回的数据的长度
     *  @param string $post        post数据,字符串形式username='dalarge'&password='123456'
     *  @param string $cookie  模拟 cookie,字符串形式username='dalarge'&password='123456'
     *  @param string $ip      ip地址
     *  @param int $timeout        连接超时时间
     *  @param bool $block     是否为阻塞模式
     *  @return string          返回字符串
     */
    
    private function _post($url$limit = 0, $post ''$cookie ''$ip ''$timeout = 30, $block = true) {
        $return '';
        $matches parse_url($url);
        $host $matches['host'];
        $path $matches['path'] ? $matches['path'].($matches['query'] ? '?'.$matches['query'] : '') : '/';
        $port = !empty($matches['port']) ? $matches['port'] : 80;
        $siteurl = URL();
        if($post) {
            $out "POST $path HTTP/1.1\r\n";
            $out .= "Accept: */*\r\n";
            $out .= "Referer: ".$siteurl."\r\n";
            $out .= "Accept-Language: zh-cn\r\n";
            $out .= "Content-Type: application/x-www-form-urlencoded\r\n";
            $out .= "User-Agent: $_SERVER[HTTP_USER_AGENT]\r\n";
            $out .= "Host: $host\r\n" ;
            $out .= 'Content-Length: '.strlen($post)."\r\n" ;
            $out .= "Connection: Close\r\n" ;
            $out .= "Cache-Control: no-cache\r\n" ;
            $out .= "Cookie: $cookie\r\n\r\n" ;
            $out .= $post ;
        else {
            $out "GET $path HTTP/1.1\r\n";
            $out .= "Accept: */*\r\n";
            $out .= "Referer: ".$siteurl."\r\n";
            $out .= "Accept-Language: zh-cn\r\n";
            $out .= "User-Agent: $_SERVER[HTTP_USER_AGENT]\r\n";
            $out .= "Host: $host\r\n";
            $out .= "Connection: Close\r\n";
            $out .= "Cookie: $cookie\r\n\r\n";
        }
        $fp = @fsockopen(($ip $ip $host), $port$errno$errstr$timeout);
        if(!$fpreturn '';
    
        stream_set_blocking($fp$block);
        stream_set_timeout($fp$timeout);
        @fwrite($fp$out);
        $status = stream_get_meta_data($fp);
    
        if($status['timed_out']) return '';  
        while (!feof($fp)) {
            if(($header = @fgets($fp)) && ($header == "\r\n" ||  $header == "\n"))  break;            
        }
        
        $stop = false;
        while(!feof($fp) && !$stop) {
            $data fread($fp, ($limit == 0 || $limit > 8192 ? 8192 : $limit));
            $return .= $data;
            if($limit) {
                $limit -= strlen($data);
                $stop $limit <= 0;
            }
        }
        @fclose($fp);
        
        //部分虚拟主机返回数值有误,暂不确定原因,过滤返回数据格式
        $return_arr explode("\n"$return);
        if(isset($return_arr[1])) {
            $return = trim($return_arr[1]);
        }
        unset($return_arr);
        
        return $return;
    }
 
    /**
     
     * 接口短信状态
     */
    private function _sms_status() {
        $array array(
            '0'=>'发送成功',
            "-1" => "参数不全",
            "-2" => "服务器空间不支持,请确认支持curl或者fsocket,联系您的空间商解决或者更换空间!",
            "30" => "密码错误",
            "40" => "账号不存在",
            "41" => "余额不足",
            "42" => "帐户已过期",
            "43" => "IP地址限制",
            "50" => "内容含有敏感词",
        );
        return $array;
    }
    
}
?>

最后修改发送短信文件,打开项目\coreframe\app\sms\sms.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
defined('IN_WZ'or exit('No direct script access allowed');
/**
 * 发送短信验证码
 */
class sms{
    public function __construct() {
        $this->db = load_class('db');
    }
 
    /**
     * 发送短信(手机短信验证码、图片验证码)
     */
    public function sendsms() {
        //验证 页面验证码是否正确
        //插入相关信息
        /**
        1、使用安全图片验证码(网站)
        2、单IP的请求次数限定 (网站)(APP)
        3、单用户动态短信请求间隔时长限制(网站)(APP)
        4、  同一手机号次数限定 (网站)(APP)
         */
        $config = get_cache('sms_config','sms');
        $uid = get_cookie('_uid');
        $mobile $GLOBALS['mobile'];
        if(!preg_match('/^(?:13\d{9}|15[0|1|2|3|5|6|7|8|9]\d{8}|17[0|1|2|3|5|6|7|8|9]\d{8}|18[0|1|2|3|5|6|7|8|9]\d{8}|14[5|7]\d{8})$/',$mobile)) {
            exit('201');
        }
        $checkcode $GLOBALS['checkcode'];
        if($checkcode==''exit('202');
        load_class('session');
        if(strtolower($_SESSION['code']) != strtolower($checkcode)) exit('202');
        $_SESSION['code'] = '';
 
        $endtime = SYS_TIME-120;
 
        if($_SESSION['et'] && $_SESSION['et']>$endtime) {
            if($config['sms_uid']!='test') {
                exit('204');
            }
        else {
            $_SESSION['et'] = SYS_TIME;
        }
        if(isset($GLOBALS['isreg']) && $GLOBALS['isreg']) {//是否为注册,验证手机是否已注册
            $reg_data $this->db->get_one('member'array('mobile' => $mobile),'uid');
            if($reg_data) {
                exit('206');
            }
        }
        $posttime = SYS_TIME-86400;
        $ip = get_ip();
        $where "`ip`='$ip' AND `posttime`>$posttime";
        $num $this->db->count_result('sms_checkcode',$where);
        if($num>200 && $config['sms_uid']!='test') {//单IP 24小时内最大请求次数限定
            exit('203');
        }
 
        //单用户动态短信请求间隔时长限制 ,根据手机号码判断是否为一个用户
        $where "`mobile`='$mobile'";
        $r $this->db->get_one('sms_checkcode',$where'*', 0,'id DESC' );
 
        if($r['posttime']>$endtime && $config['sms_uid']!='test') {//120 秒之内连续请求
            exit('204');
        }
 
 
        //同一手机号次数限定
        $where "`mobile`='$mobile' AND `posttime`>=$posttime";
        $num $this->db->count_result('sms_checkcode',$where);
        if($num>200 && $config['sms_uid']!='test') {//同一手机号次数限定 24小时内最大请求次数限定
            exit('205');
        }
//验证通过
 
        $sendsms = load_class('sms','sms');
        if($config['sms_uid']!='test') {
            $code = rand(1000,9999);
        else {
            $code = 1111;
        }
 
        $formdata array();
        $formdata['mobile'] = $mobile;
        $formdata['uid'] = $uid;
        $formdata['posttime'] = SYS_TIME;
        $formdata['code'] = $code;
        $formdata['ip'] = $ip;
        $this->db->insert('sms_checkcode'$formdata);
        if($config['sms_uid']!='test') {
            $returnstr $sendsms->send_sms($mobile$code, 1); //发送短信
            if($returnstr==0) {
                exit('0');
            else {
                echo $returnstr;
            }
        else {
            exit('0');
        }
    }
}
?>

好了,经过以上的替换,短信宝的短信平台已经替换成功了,我们去进行发送测试:

报备一下短信宝的VIP模板,这样就可以走短信宝的优质通道了,并且免审核了,短信内容3~5秒就可送达。

另外:我们已经开发好完整的五指cms网站管理系统短信宝插件,点击此链接 下载及查看安装流程。

开源插件

最新更新

电商类

CMS类

微信类

文章标签