待发短信

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

4001-021-502

工作时间

9:00-21:00

微擎V2.7.35新增短信宝短信接口

微擎是一款免费开源的公众平台管理系统,基于web2.0技术架构,他有很多的扩展模块,二次开发也非常方便,小编最近发现微擎升级到了2.7.35版本,今天小编就以微擎2.7.35版本的替换短信接口为例告诉大家如何进行二次开发,使用的短信接口是我们短信宝短信群发平台的接口,我们短信宝短信群发平台非常稳定,发送速度快,注册就送测试短信,推荐大家使用

1:打开项目:\web\themes\default\system\user-setting.html 新增短信宝接口页

?
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
{template 'common/header'}
{template 'system/user-setting-header'}
<form action="" method="post" class="we7-form">
    {if $do == 'login'}
    <div id="login">
        <div class="form-group">
            <label class="col-sm-2 control-label" style="text-align:left;">图形验证码</label>
            <div class="col-sm-8 form-control-static">
                <input type="radio" id="verifycode-1" name="verifycode" {if $settings['verifycode'] == 1} checked="checked" {/if} value="1" />
                <label class="radio-inline" for="verifycode-1">
                    开启
                </label>
                <input type="radio" id="verifycode-0" name="verifycode" {if $settings['verifycode'] == 0} checked="checked" {/if} value="0" />
                <label class="radio-inline" for="verifycode-0">
                    关闭
                </label>
                <span class="help-block"> 开启后,用户登录需要输入图形验证码</span>
            </div>
        </div>
 
        <div class="form-group">
            <label class="col-sm-2 control-label" style="text-align:left;">用户首页设置</label>
            <div class="col-sm-8">
                <select name="welcome_link" class="form-control">
                    <option value="{WELCOME_DISPLAY_TYPE}" {if $settings['welcome_link']==WELCOME_DISPLAY_TYPE}selected{/if}>用户欢迎页</option>
                    <option value="{PLATFORM_DISPLAY_TYPE}" {if $settings['welcome_link']==PLATFORM_DISPLAY_TYPE}selected{/if}>平台</option>
                </select>
                <div class="help-block">统一设置用户登录后跳转的页面,用户也可以自行设置,以用户设置的为准</div>
            </div>
        </div>
    </div>
    {/if}
 
    {if $do == 'binding'}
    <div id="binding">
        <div class="form-group">
            <label class="col-sm-2 control-label" style="text-align:left;">强制绑定信息</label>
            <div class="col-sm-8 form-control-static">
                <input type="radio" id="bind_status-0" name="bind" value="" {if empty($settings['bind'])}checked{/if}/>
                <label class="radio-inline" for="bind_status-0">
                    
                </label>
                <input type="radio" id="bind_status-1" name="bind" value="qq" {if $settings['bind'] == 'qq'}checked{/if}/>
                <label class="radio-inline" for="bind_status-1">
                    qq
                </label>
                <input type="radio" id="bind_status-2" name="bind" value="wechat" {if $settings['bind'] == 'wechat'}checked{/if}/>
                <label class="radio-inline" for="bind_status-2">
                    微信
                </label>
                <input type="radio" id="bind_status-3" name="bind" value="mobile" {if $settings['bind'] == 'mobile'}checked{/if}/>
                <label class="radio-inline" for="bind_status-3">
                    手机号
                </label>
                <span class="help-block"> 选择后,用户登录后,将强制绑定所选方式</span>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label" style="text-align:left;">第三方登录入口</label>
            <div class="col-sm-8 form-control-static">
                <input type="radio" name="oauth_bind" id="oauth_bind-1" value="1" {if $settings['oauth_bind'] == 1}checked{/if} />
                <label class="radio-inline" for="oauth_bind-1">
                    
                </label>
                <input type="radio" name="oauth_bind" id="oauth_bind-0" value="0"  {if $settings['oauth_bind'] == 0}checked{/if}/>
                <label class="radio-inline" for="oauth_bind-0">
                    
                </label>
                <div class="help-block">开启后,登录页面显示第三方登录入口,可以登录已关联账户或注册新帐号</div>
            </div>
        </div>
    </div>
    {/if}
 
    {if $do == 'sms'}
    <div id="sms">
 
        <div class="form-group">
            <label class="col-sm-2 control-label" style="text-align:left;">短信宝账号</label>
            <div class="col-sm-8">
                <input type="text" name="sms_name" class="form-control" value="{$settings['sms_name']}" />
                <span class="help-block">没有短信宝账号?点击<a class="btn btn-primary span3" target="_blank" href="http://www.smsbao.com">免费注册</a></span>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label" style="text-align:left;">短信宝密码</label>
            <div class="col-sm-8">
                <input type="password" name="sms_password" class="form-control" value="{$settings['sms_password']}" />
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-2 control-label" style="text-align:left;">短信签名</label>
            <div class="col-sm-8">
                <input type="text" name="sms_sign" class="form-control" value="{$settings['sms_sign']}" />
            </div>
        </div>
    </div>
    {/if}
 
    <input type="submit" name="submit" value="提交" class="btn btn-primary" style="padding: 6px 50px;">
    <input type="hidden" name="token" value="{$_W['token']}" />
</form>
{template 'common/footer'}

2:打开项目:\web\source\utility\verifycode.ctrl.php 修改下send_code 方法

?
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
if ('send_code' == $do) {
    $verifycode_table = table('uni_verifycode');
    $row = $verifycode_table->getByReceiverVerifycode($_W['uniacid'], $receiver, '');
 
    $record = array();
    $code = random(6, true);
 
    if (!empty($row)) {
        $imagecode = intval($_GPC['imagecode']);
        $failed_count = table('uni_verifycode')->getFailedCountByReceiver($receiver);
        if ($need_checkcaptcha && $failed_count >= 3) {
            if (empty($imagecode)) {
                iajax(-3, '请输入图形验证码!');
            }
 
            if (!checkcaptcha($imagecode)) {
                iajax(-1, '图形验证码错误!');
            }
        }
 
        if ($row['total'] >= 5) {
            iajax(-1, '您的操作过于频繁,请稍后再试');
        }
 
        $record['total'] = $row['total'] + 1;
    else {
        $record['uniacid'] = $_W['uniacid'];
        $record['receiver'] = $receiver;
        $record['total'] = 1;
    }
    $record['verifycode'] = $code;
    $record['createtime'] = TIMESTAMP;
 
    if (!empty($row)) {
        pdo_update('uni_verifycode', $record, array('id' => $row['id']));
    else {
        pdo_insert('uni_verifycode', $record);
    }
    if ('email' == $receiver_type) {
        load()->func('communication');
        $content = "您的邮箱验证码为: {$code} 您正在使用{$uniacid_arr['name']}相关功能, 需要你进行身份确认.";
        $result = ihttp_email($receiver, "{$uniacid_arr['name']}身份确认验证码", $content);
    else {
        load()->model('cloud');
        $r = cloud_prepare();
        if (is_error($r)) {
            iajax(-1, $r['message']);
        }
        $setting = uni_setting($_W['uniacid'], 'notify');
        $content = "您的短信验证码为: {$code} 您正在使用{$uniacid_arr['name']}相关功能, 需要你进行身份确认";
        $result = cloud_sms_send($receiver, $content, array(), $custom_sign);
        
    /*  $postdata = array('verify_code' => $code, 'module' => $uniacid_arr['name']);
        $result = cloud_sms_send($receiver, '800002', $postdata, $custom_sign);
        */
    }
    if (is_error($result)) {
        iajax(-1, $result['message']);
    }
    iajax(0, '短信发送成功!');
}

3:打开项目:\web\source\system\usersetting.ctrl.php 在16行左右新增短信配置

?
1
2
3
4
5
6
7
8
9
10
11
if ($do == 'sms') {
    $_W['page']['title'] = '短信配置';
    if (checksubmit('submit')) {
 
        $settings['sms_name'] = $_GPC['sms_name'];
        $settings['sms_password'] = $_GPC['sms_password'];
        $settings['sms_sign'] = $_GPC['sms_sign'];
        setting_save($settings, 'copyright');
        itoast('更新设置成功!''''success');
    }
}

4:打开项目:\web\source\system\ 新增user-setting-header.html

?
1
2
3
4
5
6
7
<ul class="we7-page-tab">
    <!--<li {if $type == 'system'}class="active"{/if}><a href="{php echo url('system/thirdlogin', array('type' => 'system'))}">系统登录</a></li>-->
    <li {if $action == 'registerset' && $do == 'display'}class="active"{/if}><a href="{php echo url('user/registerset/display');}">登录/注册设置</a></li>
    <li {if $action == 'thirdlogin'}class="active"{/if}><a href="{php echo url('system/thirdlogin')}">第三方配置</a></li>
    <li {if $do == 'clerk'}class="active"{/if}><a href="{php echo url('user/registerset/clerk')}">应用操作员登录/注册设置</a></li>
    <li {if $do == 'sms'}class="active"{/if}><a href="{php echo url('system/usersetting', array('do' => 'sms'))}">短信配置</a></li>
</ul>

5:打开项目:\framework\model\cloud.mod.php 修改cloud_sms_send方法

?
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
function cloud_sms_send($mobile, $content, $postdata = array(), $custom_sign = '', $use_system_balance = false) {
    global $_W;
    if(!preg_match('/^1\d{10}$/', $mobile) || empty($content)) {
        return error(1, '发送短信失败, 原因: 手机号错误或内容为空.');
    }
    $uniacid = empty($use_system_balance) ? $_W['uniacid'] : 0;
 
    if (empty($uniacid)) {
        $sms_info = cloud_sms_info();
        $balance = empty($sms_info['sms_count']) ? 0 : $sms_info['sms_count'];
        if (!empty($custom_sign)) {
            $sign = $custom_sign;
        }
    else {
        $row = pdo_get('uni_settings' , array('uniacid' => $uniacid), array('notify'));
        $row['notify'] = @iunserializer($row['notify']);
 
        $config = $row['notify']['sms'];
        $balance = intval($config['balance']);
 
        $sign = empty($custom_sign) ? $_W['setting']['copyright']['sms_sign'] : $custom_sign;
        $account_name = empty($_W['account']['type_name']) ? '' : $_W['account']['type_name'];
        $account_name .= empty($_W['account']['name']) ? '' " [{$_W['account']['name']}] ";
    }
    if(empty($sign) || $sign == 'null') {
                $sign = '短信宝';
        }
        //判断剩余条数
      if($balance<1){
                return error(-1, '短信发送失败, 原因:余额不足');
        
        //短信宝账号
       // $smsbao_info=pdo_get('uni_settings' , array('uniacid' => $_W['uniacid']), array('copyright'));
        //$smsbao_info=setting_load($key = 'copyright');
        $sms_param['u']=$_W['setting']['copyright']['sms_name'];
        $sms_param['p']=md5($_W['setting']['copyright']['sms_password']);
        $sms_param['m']=$mobile;
        $sms_param['c']='【'.$_W['setting']['copyright']['sms_sign'].'】'.$content;
        $response = file_get_contents("http://api.smsbao.com/sms?".http_build_query($sms_param));
        if (trim($response)!='0') {
        return error($response['errno'], '短信发送失败, 原因:'.$response['message']);
        }
 
        if (trim($response)=='0') {
        if (!empty($uniacid)) {
            $row['notify']['sms']['balance'] = $row['notify']['sms']['balance'] - 1;
            if ($row['notify']['sms']['balance'] < 0) {
                $row['notify']['sms']['balance'] = 0;
            }
            pdo_update('uni_settings', array('notify' => iserializer($row['notify'])), array('uniacid' => $uniacid));
            uni_setting_save('notify', $row['notify']);
        else {
            $sms_info['sms_count'] = $sms_info['sms_count'] - 1;
            if ($sms_info['sms_count'] < 0) {
                $sms_info['sms_count'] = 0;
            }
            setting_save($sms_info, 'sms.info');
        }
    }
    return true;
}

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

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

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

开源插件

最新更新

电商类

CMS类

微信类

文章标签