待发短信

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

4001-021-502

工作时间

9:00-21:00

WellCMS_V2.3.0新增短信宝短信接口

WellCMS 是一款具备亿级负载、开源、倾向移动端、轻量级、具有超快反应能力的高负载CMS,是大数据量、高并发访问网站最佳选择的轻CMS。wellcms具有安全、高效、稳定、速度超快、负载超强的特点。是大数据时代下诞生的CMS,低成本解决网站负载和性能问题,专为大数据量站点设计的高性能、高负载的CMS。小编对他还是比较了解的,今天小编就以新增短信接口为例,给大家讲解一下如何进行二次开发,我们今天讲解的是v2.3.0版本,使用的短信接口是我们短信宝短信群发平台的短信接口,我们短信宝短信群发平台的接口非常稳定,发送速度快,注册就送测试短信,推荐大家使用
1:打开项目:admin\view\htm\setting_base.htm 在48行增加短信宝配置页面

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
<div class="form-group row">
    <label class="col-sm-2 form-control-label">开启注册手机验证:</label>
    <div class="col-sm-10">
        <?php echo $input['user_create_mobile_on'];?>
    </div>
</div>
 
<div class="form-group row">
    <label class="col-sm-2 form-control-label">短信宝账号:</label>
    <div class="col-sm-10">
        <?php echo $input['smsbao_user'];?>
    </div>
</div>
<div class="form-group row">
    <label class="col-sm-2 form-control-label">短信宝密码:</label>
    <div class="col-sm-10">
        <?php echo $input['smsbao_pwd'];?>
    </div>
</div>
<div class="form-group row">
    <label class="col-sm-2 form-control-label">短信宝签名:</label>
    <div class="col-sm-10">
        <?php echo $input['smsbao_sign'];?>
    </div>
</div>
<div class="form-group row">
    <label class="col-sm-2 form-control-label">短信模板:</label>
    <div class="col-sm-10">
        <?php echo $input['smsbao_template'];?>
    </div>
</div>

2:打开项目:\admin\route\setting.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
    case 'base':
        // hook admin_setting_base_get_post.php
 
        if ('GET' == $method) {
 
            // hook admin_setting_base_get_start.php
 
            $input = array();
            $input['sitename'] = form_text('sitename', $conf['sitename']);
            $input['sitebrief'] = form_textarea('sitebrief', $conf['sitebrief'], '''100%', 100);
            $input['runlevel'] = form_radio('runlevel', array(0 => lang('runlevel_0'), 1 => lang('runlevel_1'), 2 => lang('runlevel_2'), 3 => lang('runlevel_3'), 4 => lang('runlevel_4'), 5 => lang('runlevel_5')), $conf['runlevel']);
            $input['user_create_on'] = form_radio_yes_no('user_create_on', $conf['user_create_on']);
            $input['user_create_email_on'] = form_radio_yes_no('user_create_email_on', $conf['user_create_email_on']);
 
            $input['user_create_mobile_on'] = form_radio_yes_no('user_create_mobile_on', $conf['user_create_mobile_on']);
            $input['smsbao_user'] = form_text('smsbao_user', $conf['smsbao_user']);
            $input['smsbao_pwd'] = form_password('smsbao_pwd', $conf['smsbao_pwd']);
            $input['smsbao_sign'] = form_text('smsbao_sign', $conf['smsbao_sign']);
            $input['smsbao_template'] = form_text('smsbao_template', $conf['smsbao_template']);
 
            $input['user_resetpw_on'] = form_radio_yes_no('user_resetpw_on', $conf['user_resetpw_on']);
            $input['lang'] = form_select('lang', array('zh-cn' => lang('lang_zh_cn'), 'zh-tw' => lang('lang_zh_tw'), 'en-us' => lang('lang_en_us')), $conf['lang']);
            $safe_token = well_token_set($uid, 'admin_setting_base');
            $input['safe_token'] = form_hidden('safe_token', $safe_token);
 
            $header['title'] = lang('admin_setting_base');
            $header['mobile_title'] = lang('admin_setting_base');
 
            // hook admin_setting_base_get_end.php
 
            include _include(ADMIN_PATH . 'view/htm/setting_base.htm');
 
        } elseif ('POST' == $method) {
 
            $safe_token = param('safe_token');
            FALSE === well_token_verify($uid, $safe_token, 'admin_setting_base') AND message(1, lang('illegal_operation'));
 
            FALSE === group_access($gid, 'managesetting') AND message(1, lang('user_group_insufficient_privilege'));
 
            $sitebrief = param('sitebrief''', FALSE);
            $sitename = param('sitename''', FALSE);
            $sitename = trim($sitename);
            $runlevel = param('runlevel', 0);
            $user_create_on = param('user_create_on', 0);
            $user_create_email_on = param('user_create_email_on', 0);
 
            $user_create_mobile_on = param('user_create_mobile_on', 0);
            $smsbao_user = param('smsbao_user''');
            $smsbao_pwd = param('smsbao_pwd''');
            $smsbao_sign = param('smsbao_sign''');
            $smsbao_template = param('smsbao_template''');
 
            $user_resetpw_on = param('user_resetpw_on', 0);
 
            $_lang = param('lang');
 
            // hook admin_setting_base_post_start.php
 
            $replace = array();
            $replace['sitename'] = xn_html_safe(filter_all_html($sitename));
            $replace['sitebrief'] = xn_html_safe($sitebrief);
            $replace['runlevel'] = $runlevel;
            $replace['user_create_on'] = $user_create_on;
            $replace['user_create_email_on'] = $user_create_email_on;
 
            $replace['user_create_mobile_on'] = $user_create_mobile_on;
            $replace['smsbao_user'] = $smsbao_user;
            $replace['smsbao_pwd'] = $smsbao_pwd;
            $replace['smsbao_sign'] = $smsbao_sign;
            $replace['smsbao_template'] = $smsbao_template;
 
 
            $replace['user_resetpw_on'] = $user_resetpw_on;
            $replace['lang'] = $_lang;
 
            file_replace_var(APP_PATH . 'conf/conf.php', $replace);
 
            // hook admin_setting_base_post_end.php
 
            message(0, lang('modify_successfully'));
        }
        break;

3:打开项目:view\htm\user_create.htm 31行左右 增加手机号注册页面

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
<?php if($conf['user_create_mobile_on']) { ?>
<div class="form-group input-group">
    <div class="input-group-prepend">
        <span class="input-group-text"><i class="icon-mobile-phone icon-fw"></i></span>
    </div>
    <input type="mobile" class="form-control" placeholder="手机号" name="mobile" id="mobile" required>
</div>
<div class="media">
    <div class="media-body">
        <div class="form-group input-group">
            <div class="input-group-prepend">
                <span class="input-group-text"><i class="icon-barcode icon-fw"></i></span>
            </div>
            <input type="text" class="form-control" placeholder="手机验证码" name="mobile_code" id="mobile_code" required>
        </div>
    </div>
    <div class="align-self-center ml-1">
        <button type="submit" class="btn btn-primary btn-sm ml-3 form-group" id="sendmobilecode" data-loading-text="<?php echo lang('sending');?>...">
            <?php echo lang('send_verify_code');?>
        </button>
    </div>
</div>
<?php } else { ?>
<div class="form-group input-group">
    <div class="input-group-prepend">
        <span class="input-group-text"><i class="icon-envelope icon-fw"></i></span>
    </div>
    <input type="email" class="form-control" placeholder="<?php echo lang('email');?>" name="email" id="email" required>
</div>
<?php } ?>

4:打开项目:\view\htm\user_resetpw.htm 修改密码重置页面

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
<?php if($conf['user_create_mobile_on']) { ?>
<div class="form-group input-group">
    <div class="input-group-prepend">
        <span class="input-group-text"><i class="icon icon-mobile-phone icon-fw"></i></span>
    </div>
    <input type="text" class="form-control" placeholder="手机号" name="mobile" id="mobile" required>
    <div class="invalid-feedback"></div>
</div>
 
<!--{hook user_resetpw_verify_code_before.htm}-->
<div class="media">
 
    <div class="media-body">
        <div class="form-group input-group">
            <div class="input-group-prepend">
                <span class="input-group-text"><i class="icon icon-key icon-fw"></i></span>
            </div>
            <input type="text" class="form-control" placeholder="<?php echo lang('verify_code');?>" name="mobile_code" id="mobile_code" required>
        </div>
    </div>
    <div class="ml-1 mt-1">
        <button type="submit" class="btn btn-primary btn-sm ml-3" id="mobile_send" data-loading-text="<?php echo lang('sending');?>...">
            <?php echo lang('send_verify_code');?>
        </button>
    </div>
</div>
<!--{hook user_resetpw_verify_code_after.htm}-->
<?php } else{ ?>
<div class="form-group input-group">
    <div class="input-group-prepend">
        <span class="input-group-text"><i class="icon icon-envelope icon-fw"></i></span>
    </div>
    <input type="text" class="form-control" placeholder="<?php echo lang('email');?>" name="email" id="email" required>
    <div class="invalid-feedback"></div>
</div>
<?php } ?>

5:打开项目:route\user.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
    case 'create':
 
        $uid and http_location($conf['path']);
 
        // hook user_create_get_post.php
 
        empty($conf['user_create_on']) and message(-1, lang('user_create_not_on'));
 
        if ('GET' == $method) {
 
            // hook user_create_get_start.php
 
            $header['title'] = lang('create_user');
            $referer = user_http_referer();
            empty($safe_token) and $safe_token = well_token_set(0);
            $extra = array('safe_token' => $safe_token);
 
            $form_action = url('user-create', $extra);
 
            // hook user_create_get_end.php
 
            if ('1' == _GET('ajax')) {
                $apilist['header'] = $header;
                $apilist['safe_token'] = $safe_token;
                $apilist['referer'] = $referer;
                $apilist['action'] = $form_action;
                $conf['api_on'] ? message(0, $apilist) : message(0, lang('closed'));
            else {
                include _include(theme_load('user_create'));
            }
 
        else if ('POST' == $method) {
            // hook user_create_post_start.php
 
            $email = param('email');
            $username = param('username');
            $password = param('password');
            if ($conf['user_create_mobile_on']){
                $mobile = param('mobile');
                $code = param('mobile_code');
            }else{
                $code = param('code');
                $email = filter_all_html($email);
                empty($email) and message('email', lang('please_input_email'));
            }
            $username = filter_all_html($username);
            empty($username) and message('username', lang('please_input_username'));
            empty($password) and message('password', lang('please_input_password'));
 
            if ($conf['user_create_email_on']) {
                $sess_email = _SESSION('user_create_email');
                $sess_code = _SESSION('user_create_code');
                empty($sess_code) and message('code', lang('click_to_get_verify_code'));
                empty($sess_email) and message('code', lang('click_to_get_verify_code'));
                $email != $sess_email and message('code', lang('verify_code_incorrect'));
                $code != $sess_code and message('code', lang('verify_code_incorrect'));
            }
 
            if ($conf['user_create_mobile_on']) {
                $sess_mobile = _SESSION('user_create_mobile');
                $sess_code = _SESSION('user_create_code');
                empty($sess_code) and message('code', lang('click_to_get_verify_code'));
                empty($sess_mobile) and message('code', lang('click_to_get_verify_code'));
                $mobile != $sess_mobile and message('code', lang('verify_code_incorrect'));
                $code != $sess_code and message('code', lang('verify_code_incorrect'));
                if (!preg_match('/^1[3-9]\d{9}$/', $mobile)) {
                    message('mobile''手机号错误');
                }
                $_user = user_read_by_mobile($mobile);
                $_user and message('mobile''手机号已经使用');
            }else{
                is_email($email, $err) || message('email', $err);
                $_user = user_read_by_email($email);
                $_user and message('email', lang('email_is_in_use'));
            }
 
 
            is_username($username, $err) || message('username', $err);
            $_user = user_read_by_username($username);
            $_user and message('username', lang('username_is_in_use'));
 
            is_password($password, $err) || message('password', $err);
            // hook user_create_post_before.php
            $salt = xn_rand(16);
            $_user = array(
                'username' => $username,
                'email' => $email,
                'mobile' => $mobile,
                'password' => md5($password . $salt),
                'salt' => $salt,
                'gid' => 101,
                'create_ip' => $longip,
                'create_date' => $time,
                'logins' => 1,
                'login_date' => $time,
                'login_ip' => $longip,
            );
 
            // hook user_create_post_center.php
 
            $uid = user_create($_user);
            FALSE === $uid and message(-1, lang('user_create_failed'));
            $user = user_read($uid);
 
            // hook user_create_post_after.php
 
            // 更新 session
 
            unset($_SESSION['user_create_email'],$_SESSION['user_create_mobile'], $_SESSION['user_create_code']);
            $_SESSION['uid'] = $uid;
            $token = user_token_set($uid);
            unset($user['password'], $user['salt'], $user['password_sms'], $user['create_ip'], $user['create_ip_fmt'], $user['create_date'], $user['login_ip'], $user['login_date'], $user['login_ip_fmt'], $user['avatar_path']);
            $extra = array('user' => $user, 'token_key' => $conf['cookie_pre'] . 'token''token' => $token);
 
            // hook user_create_post_end.php
 
            message(0, lang('user_create_successfully'), $extra);
        }
        break;

6:打开当前项目:修改重置密码方法

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
case 'resetpw':
        // 重设密码第 1 步 | reset password first step
        // hook user_resetpw_get_post.php
 
        empty($conf['user_resetpw_on']) and message(-1, lang('closed'));
 
        if ('GET' == $method) {
 
            // hook user_resetpw_get_start.php
 
            $header['title'] = lang('resetpw');
            $form_action = url('user-resetpw');
 
            // hook user_resetpw_get_end.php
 
            if ('1' == _GET('ajax')) {
                $apilist['header'] = $header;
                $apilist['form_action'] = $form_action;
                $conf['api_on'] ? message(0, $apilist) : message(0, lang('closed'));
            else {
                include _include(theme_load('user_resetpw'));
            }
 
        else if ('POST' == $method) {
 
            // hook user_resetpw_post_start.php
 
            if ($conf['user_create_mobile_on']){
                $mobile = param('mobile');
                empty($mobile) and message('mobile''请填写手机号');
                if (!preg_match('/^1[3-9]\d{9}$/', $mobile)) {
                    message('mobile''手机号错误');
                }
                $_user = user_read_by_mobile($mobile);
                empty($_user) and message('mobile''手机号未被注册');
                $code = param('mobile_code');
            }else{
                $email = param('email');
                empty($email) and message('email', lang('please_input_email'));
                is_email($email, $err) || message('email', $err);
                $_user = user_read_by_email($email);
                empty($_user) and message('email', lang('email_is_not_in_use'));
                $code = param('code');
            }
            empty($code) and message('code', lang('please_input_verify_code'));
            $sess_code = _SESSION('user_resetpw_code');
            empty($sess_code) and message('code', lang('click_to_get_verify_code'));
            $code != $sess_code and message('code', lang('verify_code_incorrect'));
            if ($conf['user_create_mobile_on']){
                $sess_mobile = _SESSION('user_resetpw_mobile');
                (empty($sess_mobile) || $mobile != $sess_mobile) and message('mobile''数据有问题');
                $_SESSION['resetpw_verify_mobile'] = $sess_mobile;
            }else{
                $sess_email = _SESSION('user_resetpw_email');
                (empty($sess_email) || $email != $sess_email) and message('email', lang('data_malformation'));
                $_SESSION['resetpw_verify_email'] = $sess_email;
            }
            // hook user_resetpw_post_end.php
            message(0, lang('check_ok_to_next_step'));
        }
        break;
    case 'resetpw_complete':
        // 重设密码第 3 步 | reset password step 3
 
        // hook user_resetpw_get_post.php
 
        // 校验数据
        if ($conf['user_create_mobile_on']){
            $mobile = _SESSION('user_resetpw_mobile');
            $resetpw_verify_mobile = _SESSION('resetpw_verify_mobile');
            (empty($mobile) || empty($resetpw_verify_mobile) || $resetpw_verify_mobile != $mobile) and message(-1, lang('data_empty_to_last_step'));
 
            $_user = user_read_by_mobile($mobile);
        }else{
            $email = _SESSION('user_resetpw_email');
            $resetpw_verify_email = _SESSION('resetpw_verify_email');
            (empty($email) || empty($resetpw_verify_email) || $resetpw_verify_email != $email) and message(-1, lang('data_empty_to_last_step'));
 
            $_user = user_read_by_email($email);
        }
 
 
 
        empty($_user) and message(-1, lang('email_not_exists'));
        $_uid = $_user['uid'];
 
        if ('GET' == $method) {
 
            // hook user_resetpw_get_start.php
 
            $header['title'] = lang('resetpw');
            $form_action = url('user-resetpw_complete');
 
            // hook user_resetpw_get_end.php
 
            if ('1' == _GET('ajax')) {
                $apilist['header'] = $header;
                $apilist['form_action'] = $form_action;
                $conf['api_on'] ? message(0, $apilist) : message(0, lang('closed'));
            else {
                include _include(theme_load('user_resetpw_complete'));
            }
 
        else if ('POST' == $method) {
 
            // hook user_resetpw_post_start.php
 
            $password = param('password');
            empty($password) and message('password', lang('please_input_password'));
 
            $salt = $_user['salt'];
            $password = md5($password . $salt);
 
            is_password($password, $err) || message('password', $err);
 
            user_update($_uid, array('password' => $password));
 
            unset($_SESSION['user_resetpw_email'],$_SESSION['user_resetpw_mobile'],$_SESSION['user_resetpw_code']);
 
            // hook user_resetpw_post_end.php
 
            message(0, lang('modify_successfully'));
        }
        break;

7:打开当前项目:新增短信发送方法

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
case 'send_mobile_code':
        // 发送验证码
        'POST' != $method and message(-1, lang('method_error'));
 
        // hook user_send_code_start.php
 
        $action2 = param(2);
 
        if ('user_create' == $action2) {
            // 创建用户
            $mobile = param('mobile');
 
            empty($mobile) and message('mobile''手机号为空');
            if (!preg_match('/^1[3-9]\d{9}$/', $mobile)) {
                message('mobile''手机号错误');
            }
            empty($conf['user_create_mobile_on']) and message(-1,'未开启手机验证');
 
            $_user = user_read_by_mobile($mobile);
            empty($_user) || message('mobile''手机号已注册');
 
            $code = rand(100000, 999999);
            $_SESSION['user_create_mobile'] = $mobile;
            $_SESSION['user_create_code'] = $code;
 
        }
        elseif ('user_resetpw' == $action2) {
            // 重置密码,往老地址发送
            $mobile = param('mobile');
            empty($mobile) and message('mobile''手机号为空');
 
            if (!preg_match('/^1[3-9]\d{9}$/', $mobile)) {
                message('mobile''手机号错误');
            }
            $_user = user_read_by_mobile($mobile);
            empty($_user) and message('mobile''手机号未被注册');
 
            empty($conf['user_resetpw_on']) and message(-1, lang('resetpw_not_on'));
 
            $code = rand(100000, 999999);
            $_SESSION['user_resetpw_mobile'] = $mobile;
            $_SESSION['user_resetpw_code'] = $code;
 
        else {
            message(-1, 'action2 error');
        }
        $statusStr = array(
            "0" => "短信发送成功",
            "-1" => "参数不全",
            "-2" => "服务器空间不支持,请确认支持curl或者fsocket,联系您的空间商解决或者更换空间!",
            "30" => "密码错误",
            "40" => "账号不存在",
            "41" => "余额不足",
            "42" => "帐户已过期",
            "43" => "IP地址限制",
            "50" => "内容含有敏感词"
        );
        $smsapi = "http://api.smsbao.com/";
        $user = $conf['smsbao_user']; //短信平台帐号
        $pass = md5($conf['smsbao_pwd']); //短信平台密码
        $content= '【'.$conf['smsbao_sign'].'】'.str_replace('{$code}',$code,$conf['smsbao_template']);//要发送的短信内容
        $phone = $mobile;//要发送短信的手机号码
        $sendurl = $smsapi."sms?u=".$user."&p=".$pass."&m=".$phone."&c=".urlencode($content);
        $result =file_get_contents($sendurl) ;
        if ('0' === $result) {
            message(0, lang('send_successfully'));
        else {
            xn_log($statusStr[$result], 'send_mail_error');
            message(-1, $statusStr[$result]);
        }
        break;

8:打开项目:model\user.func.php 增加获取手机号方法

1
2
3
4
5
6
7
8
9
10
11
12
function user_read_by_mobile($mobile)
{
    global $g_static_users;
    // hook model_user_read_by_email_start.php
    $user = user__read(array('mobile' => $mobile));
    if ($user) {
        user_format($user);
        $g_static_users[$user['uid']] = $user;
    }
    // hook model_user_read_by_email_end.php
    return $user;
}

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

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

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

开源插件

最新更新

电商类

CMS类

微信类

文章标签