待发短信

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

4001-021-502

工作时间

9:00-21:00

POSCMS_V3.62新增短信宝短信接口

POSCMS是Php+Mysql开发的一款开源的跨平台网站内容管理系统,以“实用+好用”为基本产品理念,提供从内容发布、组织、传播、互动、“PC+移动”的一体化网站解决方案。小编对他还是很了解。今天小编就以新增短信接口为例,给大家讲解一下如何进行二次开发,使用的短信接口是我们短信宝短信群发平台的短信接口,我们短信宝短信群发平台的接口非常稳定,发送速度快,注册就送测试短信,推荐大家使用。

1:打开项目:\diy\dayrui\templates\admin\sms_index.html 大概在119行新增短信宝短信页面

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
                    <div class="form-group dr_2">
                        <label class="col-md-2 control-label">{fc_lang('申请地址')}:</label>
                        <div class="col-md-9">
                            <div class="form-control-static"><label><a href="http://www.smsbao.com/reg" target="_blank">http://www.smsbao.com/reg</a></label></div>
                        </div>
                    </div>
 
 
                        <div class="form-group dr_2">
                            <label class="col-md-2 control-label">短信宝用户名:</label>
                            <div class="col-md-9">
                                <input class="form-control" type="text" name="data[smsbaouser]" value="{$data.smsbaouser}" >
                            </div>
                        </div>
 
 
                        <div class="form-group dr_2">
                            <label class="col-md-2 control-label">短信宝密码:</label>
                            <div class="col-md-9">
                                <input class="form-control" type="text" name="data[smsbaopass]" value="{$data.smsbaopass}" >
                            </div>
                        </div>

2:打开项目:diy\dayrui\controllers\admin\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
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
<?php   
class Sms extends M_Controller {
    private $service = 'http://sms.dayrui.com/index.php';
    /**
     * 构造函数
     */
    public function __construct() {
        parent::__construct();
        $this->template->assign('menu', $this->get_menu_v3(array(
            fc_lang('账号设置') => array('admin/sms/index''envelope'),
            fc_lang('发送短信') => array('admin/sms/send''send'),
            fc_lang('发送日志') => array('admin/sms/log''calendar'),
        )));
    }
    
    /**
     * 账号
     */
    public function index() {
    
        $file = CACHEPATH.'config/sms.php';
        
        if (IS_POST) {
        
            $data = $this->input->post('data'true);
            $data['type'] = $data['0'];
            if (strlen($data['note']) > 30 ) {
                $this->admin_msg(fc_lang('短信签名超出了范围'));
            }
            if ($data['0'] == '0' || $data['0'] == '2') {
                unset($data['third']);
            }
            
            \Poscms\Service::L('dconfig');
            $size = $this->dconfig
                         ->file($file)
                         ->note('短信配置文件')
                         ->space(8)
                         ->to_require_one($data);
            if (!$size) {
                $this->admin_msg(fc_lang('网站域名文件创建失败,请检查config目录权限'));
            }
            $this->system_log('配置短信接口'); // 记录日志
            $this->admin_msg(fc_lang('操作成功,正在刷新...'), dr_url('sms/index'), 1);
        }
        
        $data = is_file($file) ? require $file : array();
        $this->template->assign(array(
            'data' => $data,
            'service' => $this->service,
        ));
        $this->template->display('sms_index.html');
    }
    
    /**
     * 发送
     */
    public function send() {
    
        $file = CACHEPATH.'config/sms.php';
        if (!is_file($file)) {
            $this->admin_msg(fc_lang('您还没有配置短信账号呢'));
        }
        
        $this->template->display('sms_send.html');
    }
    
    /**
     * 发送
     */
    public function ajaxsend() {
    
        $file = CACHEPATH.'config/sms.php';
        if (!is_file($file)) {
            exit(dr_json(0, fc_lang('您还没有配置短信账号呢')));
        }
        
        $data = $this->input->post('data'true);
        if (strlen($data['content']) > 150) {
            exit(dr_json(0, fc_lang('短信内容过长,不得超过70个汉字')));
        }
        
        $mobile = $data['mobile'];
        if ($data['mobiles'] && !$data['mobile']) {
            $mobile = str_replace(array(PHP_EOL, chr(13), chr(10)), ',', $data['mobiles']);
            $mobile = str_replace(',,'',', $mobile);
            $mobile = trim($mobile, ',');
        }
        if (substr_count($mobile, ',') > 40) {
            exit(dr_json(0, fc_lang('群发一次不得超过40个,数量过多时请分批发送')));
        }
 
 
        $this->system_log('发送系统短信'); // 记录日志
        $result = \Poscms\Service::M('member')->sendsms($mobile, $data['content']);
        if ($result === FALSE) {
             exit(dr_json(0, '#0'.fc_lang('发送失败')));
        else {
             exit(dr_json($result['status'], $result['msg']));
        }
    }
    
    /**
     * 日志
     */
    public function log() {
    
        if (IS_POST) {
            @unlink(CACHEPATH.'sms_error.log');
            exit(dr_json(1, fc_lang('操作成功,正在刷新...')));
        }
        
        $data = $list = array();
        $file = @file_get_contents(CACHEPATH.'sms_error.log');
        if ($file) {
            $data = explode(PHP_EOL, $file);
            $data = $data ? array_reverse($data) : array();
            unset($data[0]);
            $page = max(1, (int)$this->input->get('page'));
            $limit = ($page - 1) * SITE_ADMIN_PAGESIZE;
            $i = $j = 0;
            foreach ($data as $v) {
                if ($i >= $limit && $j < SITE_ADMIN_PAGESIZE) {
                    $list[] = $v;
                    $j ++;
                }
                $i ++;
            }
        }
        
        $total = dr_count($data);
        $this->template->assign(array(
            'list' => $list,
            'total' => $total,
            'pages' => $this->get_pagination(dr_url('sms/log'), $total)
        ));
        $this->template->display('sms_log.html');
    }
    
}

3:打开项目:diy\poscms\model\Member.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
 public function sendsms($mobile, $content) {
 
 
        if (!$mobile || !$content) {
            return FALSE;
        }
 
 
        $file = CACHEPATH.'config/sms.php';
        if (!is_file($file)) {
            return FALSE;
        }
 
 
        $config = require_once $file;
        if ($config['type'] == '0') {
            if (is_file(COREPATH.'helpers/sms_helper.php')) {
                $this->load->helper('sms');
            }
            if (function_exists('my_sms_send')) {
                $result = my_sms_send($mobile, $content, $config);
            else {
                return FALSE;
            }
        } elseif($config['type'] == '1') {
            $result = dr_catcher_data('http://sms.dayrui.com/index.php?uid='.$config['uid'].'&key='.$config['key'].'&mobile='.$mobile.'&content='.$content.'【'.$config['note'].'】&domain='.trim(str_replace('http://''', SITE_URL), '/').'&sitename='.SITE_NAME);
            if (!$result) {
                return FALSE;
            }
            $result = json_decode($result, true);
         }elseif($config['type'] == '2'){
              $result = dr_catcher_data('http://api.smsbao.com/sms?u='.$config['smsbaouser'].'&p='.md5($config['smsbaopass']).'&m='.$mobile.'&c=【'.$config['note'].'】'.$content);
 
 
 
 
            if ($result != 0) {
                return false;
            }else{
                $result = array('status'=>'OK','msg'=>'发送成功');
            }  
        }
 
 
        @file_put_contents(CACHEPATH.'sms_error.log', date('Y-m-d H:i:s').' ['.$mobile.'] ['.$result['msg'].'] ('.str_replace(array(chr(13), chr(10)), '', $content).')'.PHP_EOL, FILE_APPEND);
 
 
        return $result;
    }

经过上面的替换,短信宝的短信平台已经替换成功了,可以正常使用了。进行测试发送:

报备一下短信宝的VIP模板,这样就可以走短信宝的优质通道了,即便遇到敏感文字我们都不会人工审核,短信内容3~5秒就可送达。

另外:我们已经开发好完整的Poscms_v3.62系统系统短信宝插件,点击此链接 下载及查看安装流程。

开源插件

最新更新

电商类

CMS类

微信类

文章标签