待发短信

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

4001-021-502

工作时间

9:00-21:00

EyouCMS-V1.7.9新增短信宝短信接口

EyouCms是基于TP5.0框架为核心开发的稳定+开源的企业内容管理系统。营销功能采用插件化的方式方便扩展、二次开发系统大小任意控制。小编带着大家一起开发EyouCMS-V1.7.9的短信宝插件接口。我们使用的短信接口是我们短信宝短信群发平台的短信接口,我们短信宝短信群发平台非常稳定,发送速度快,注册就送测试短信,推荐大家使用。
1.首先执行以下SQL增加短信宝短信模板内容

1
2
3
4
5
6
7
8
9
10
INSERT INTO `ey_sms_template` VALUES '44','3''账号注册''''smsbao''验证码为 ${content} ,请在30分钟内输入验证。''0''0''cn''1591262356''1591262356');
INSERT INTO `ey_sms_template` VALUES ('45''3''手机绑定''''smsbao''验证码为 ${content} ,请在30分钟内输入验证。''1''0''cn''1591262356''1591262356');
INSERT INTO `ey_sms_template` VALUES ('46''3''找回密码''''smsbao''验证码为 ${content} ,请在30分钟内输入验证。''4''0''cn''1591262356''1591262356');
INSERT INTO `ey_sms_template` VALUES ('47''3''订单付款''''smsbao''您有新的消息:您有新的${content}订单,请注意查收!''5''1''cn''1591262356''1616460912');
INSERT INTO `ey_sms_template` VALUES ('48''3''订单发货''''smsbao''您有新的消息:您有新的${content}订单,请注意查收!''6''1''cn''1591262356''1616460912');
INSERT INTO `ey_sms_template` VALUES ('49''3''留言验证''''smsbao''验证码为 ${content} ,请在30分钟内输入验证。''7''1''cn''1591262356''1591262356');
INSERT INTO `ey_sms_template` VALUES ('50''3''账号登录''''smsbao''验证码为 ${content} ,请在30分钟内输入验证。''2''1''cn''1591262356''1591262356');
INSERT INTO `ey_sms_template` VALUES ('51''3''留言表单''''smsbao''您有新的留言消息,请查收!''11''1''cn''1591262356''1591262356');
INSERT INTO `ey_sms_template` VALUES ('52''3''投稿提醒''''smsbao''您有新的会员投稿,请查看!''20''1''cn''1591262356''1591262356');
INSERT INTO `ey_sms_template` VALUES ('53''3''后台登录''''smsbao''验证码为 ${content} ,请在30分钟内输入验证。''30''1''cn''1591262356''1591262356');

2.接着打开项目:application\admin\template\system\sms.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
37
38
39
            <dl class="row">
                <dt class="tit">
                    <label for="sms_type">短信平台</label>
                </dt>
                <dd class="opt">
                    <label class="curpoin"><input type="radio" name="sms_type" value="3" onclick="changeSmsType(this);" {if condition="empty($sms.sms_type) || $sms.sms_type eq 3"}checked="checked"{/if}>短信宝短信</label>
                    &nbsp;&nbsp;
                    <label class="curpoin"><input type="radio" name="sms_type" value="1" onclick="changeSmsType(this);" {if condition="empty($sms.sms_type) || $sms.sms_type eq 1"}checked="checked"{/if}>阿里云短信</label>
                    &nbsp;&nbsp;
                    <label class="curpoin"><input type="radio" name="sms_type" value="2" onclick="changeSmsType(this);" {if condition="isset($sms.sms_type) && $sms.sms_type eq 2"}checked="checked"{/if}>腾讯云短信</label>
                    <!-- ToSms短信通知插件内置代码 start -->
                    {if condition="file_exists(ROOT_PATH.'weapp/ToSms/template/admin/system/sms_type.htm')"}
                        {include file="/weapp/ToSms/template/admin/system/sms_type.htm" /}
                    {/if}
                    <!-- ToSms短信通知插件内置代码 end -->
                    <input type="hidden" id="old_sms_type" value="{if condition="empty($sms.sms_type) || $sms.sms_type eq 1"}1{else /}{$sms.sms_type}{/if}">
                    <p class="notic"></p>
                </dd>
            </dl>
                <dl class="row" id="sms_appkey_3" style="display: {if condition="!isset($sms.sms_type) || $sms.sms_type eq 3"} block{else /}none{/if};">
                <dt class="tit">
                    <em>*</em>
                    <label for="sms_smsbao_user">短信宝账号</label>
                </dt>
                <dd class="opt">
                    <input id="sms_smsbao_user" name="sms_smsbao_user" value="{$sms.sms_smsbao_user|default=''}" class="input-txt" type="text" autocomplete="off" />
                    <p class="notic">短信宝账号</p>
                </dd>
            </dl>
            <dl class="row" id="sms_secretkey_3" style="display: {if condition="!isset($sms.sms_type) || $sms.sms_type eq 3"} block{else /}none{/if};">
                <dt class="tit">
                    <em>*</em>
                    <label for="sms_smsbao_apikey">短信宝apikey</label>
                </dt>
                <dd class="opt">
                    <input id="sms_smsbao_apikey" name="sms_smsbao_apikey" value="{$sms.sms_smsbao_apikey|default=''}" class="input-txt" type="text" autocomplete="off" />
                    <p class="notic">短信宝apikey</p>
                </dd>
            </dl>

3.接着打开项目:application\admin\controller\System.php,替换sms,sms_tpl函数方法

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
    /**
     * 短信配置
     */
    public function sms()
    {
        $inc_type =  'sms';
        if (IS_POST) {
            $param = input('post.');
            empty($param['sms_shop_order_pay']) && $param['sms_shop_order_pay'] = 0;
            empty($param['sms_guestbook_send']) && $param['sms_guestbook_send'] = 0;
 
            if (!isset($param['sms_type'])) $param['sms_type'] = 1;
            if ($param['sms_type'] == 3) {
                unset($param['sms_smsbao_user']);
                unset($param['sms_smsbao_apikey']);
            }else if ($param['sms_type'] == 1) {
                unset($param['sms_appkey_tx']);
                unset($param['sms_appid_tx']);
            }else {
                unset($param['sms_appkey']);
                unset($param['sms_secretkey']);
            }
            if (!empty($param['sms_type'])){
                if (!empty($param['tpl_id'][$param['sms_type']])){
                    Db::name('sms_template')->where('sms_type',$param['sms_type'])->where('tpl_id','in',$param['tpl_id'][$param['sms_type']])->update(['is_open'=>1,'update_time'=>getTime()]);
                    Db::name('sms_template')->where('sms_type',$param['sms_type'])->where('tpl_id','not in',$param['tpl_id'][$param['sms_type']])->update(['is_open'=>0,'update_time'=>getTime()]);
                }else{
                    Db::name('sms_template')->where('sms_type',$param['sms_type'])->where('tpl_id','>',0)->update(['is_open'=>0,'update_time'=>getTime()]);
                }
            }
            if (isset($param['tpl_id'])) unset($param['tpl_id']);
 
            /*多语言*/
            if (is_language()) {
                $langRow = \think\Db::name('language')->order('id asc')
                    ->cache(true, EYOUCMS_CACHE_TIME, 'language')
                    ->select();
                foreach ($langRow as $key => $val) {
                    tpCache($inc_type$param$val['mark']);
                }
            else {
                tpCache($inc_type$param);
            }
            /*--end*/
 
            $this->success('操作成功', url('System/sms'));
        }
 
        $assign_data = [];
        $sms = tpCache('sms');
        if (!isset($sms['sms_type'])) {
            $sms['sms_type'] = 1;
            tpCache('sms'array('sms_type'=>1));
        }
        $assign_data['sms'] = $sms;
 
        $map = [
            'send_scene'=>['neq',30],
            'lang' => $this->admin_lang,
        ];
        $map['sms_type'] = 3;
        $assign_data['sms_list3'] = Db::name('sms_template')->where($map)->order('tpl_id asc')->select();
        $map['sms_type'] = 1;
        $assign_data['sms_list1'] = Db::name('sms_template')->where($map)->order('tpl_id asc')->select();
        $map['sms_type'] = 2;
        $assign_data['sms_list2'] = Db::name('sms_template')->where($map)->order('tpl_id asc')->select();
 
        // ToSms短信通知插件内置代码 start
        if (file_exists('./weapp/ToSms/model/ToSmsModel.php')) {
            $toSmsModel new \weapp\ToSms\model\ToSmsModel;
            $toSmsModel->admin_System_sms($assign_data);
        }
        // ToSms短信通知插件内置代码 end
 
        $this->assign($assign_data);
        return $this->fetch();
    }
 
    /**
     * 短信模板列表
     */
    public function sms_tpl()
    {
        $param = input('param.');
        $list array();
        $keywords = input('keywords/s');
        $sms_type = input('sms_type/d');
        if (empty($sms_type)) {
            $sms_type = tpCache('sms.sms_type');
            $sms_type = !empty($sms_type) ? $sms_type : 1;
        }
 
        $map = [
            'lang' => $this->admin_lang,
            'sms_type' => $sms_type,
        ];
        if (!empty($keywords)) $map['tpl_title'] = array('LIKE'"%{$keywords}%");
 
        $count = Db::name('sms_template')->where($map)->count('tpl_id');// 查询满足要求的总记录数
        $pageObj new Page($count, config('paginate.list_rows'));// 实例化分页类 传入总记录数和每页显示的记录数
        $list = Db::name('sms_template')->where($map)
            ->order('tpl_id asc')
            ->limit($pageObj->firstRow.','.$pageObj->listRows)
            ->select();
        $pageStr $pageObj->show(); // 分页显示输出
        $this->assign('list'$list); // 赋值数据集
        $this->assign('page'$pageStr); // 赋值分页输出
        $this->assign('pager'$pageObj); // 赋值分页对象
        $this->assign('sms_type'$sms_type); // 短信服务商
 
        // 是否填写手机短信配置
        $is_conf = 1;
        $sms_arr = [];
        $sms_config = tpCache('sms');
        foreach ($sms_config as $key => $val) {
            $sms_arr[$key] = $val;
        }
        if (3 == $sms_type) {
            foreach (['sms_smsbao_user','sms_smsbao_apikey'as $key => $val) {
                if (isset($sms_arr[$val]) && empty($sms_arr[$val])) {
                    $is_conf = 0;
                }
            }
        else if (2 == $sms_type) {
            foreach (['sms_appkey_tx','sms_appid_tx'as $key => $val) {
                if (isset($sms_arr[$val]) && empty($sms_arr[$val])) {
                    $is_conf = 0;
                }
            }
        else {
            foreach (['sms_appkey','sms_secretkey'as $key => $val) {
                if (isset($sms_arr[$val]) && empty($sms_arr[$val])) {
                    $is_conf = 0;
                }
            }
        }
        $this->assign('is_conf'$is_conf);
 
        $shop_open = getUsersConfigData('shop.shop_open');
        $this->assign('shop_open'$shop_open);
 
        // ToSms短信通知插件内置代码 start
        $show_sms_tpl_code = true;
        if (file_exists('./weapp/ToSms/model/ToSmsModel.php')) {
            $toSmsModel new \weapp\ToSms\model\ToSmsModel;
            $show_sms_tpl_code $toSmsModel->admin_system_sms_tpl($sms_type'show_sms_tpl_code');
        }
        if (3 == $sms_type) {
           $show_sms_tpl_code = false;
        }
        $this->assign('show_sms_tpl_code'$show_sms_tpl_code);
        // ToSms短信通知插件内置代码 end
 
        return $this->fetch();
    }

4.接着打开项目:application\common\logic\SmsLogic.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
    private function sendSmsBySmsbao($mobile$smsSign$smsParam$templateCode,$nationCode "86")
    {
        $statusStr array(
                    "0" => "短信发送成功",
                    "-1" => "参数不全",
                    "-2" => "服务器空间不支持,请确认支持curl或者fsocket,联系您的空间商解决或者更换空间!",
                    "30" => "密码错误",
                    "40" => "账号不存在",
                    "41" => "余额不足",
                    "42" => "帐户已过期",
                    "43" => "IP地址限制",
                    "50" => "内容含有敏感词"
                );
        $user     $this->config['sms_smsbao_user'];
        $apikey     $this->config['sms_smsbao_apikey'];
        $content     $smsParam['msg'];
 
        if (empty($user) || empty($apikey)) {
            return array('status' => -1, 'msg' => '请设置短信平台信息');
        }
        if (is_array($mobile)) {
            $mobile = implode(","$mobile);
        }
        $content=urlencode('【' $smsSign '】' $content);
        if (86 == $nationCode) {
            $url "http://api.smsbao.com/sms?u=" $user "&p=" $apikey "&m=" $mobile "&c=" $content;
        }else{
            $sender_arr explode(','$mobile);
            foreach ($sender_arr as $key => $val) {
                $val = trim($val);
                if (empty($val)) {
                    unset($sender_arr[$key]);
                    continue;
                }
                $sender_arr[$key] = '+'.$nationCode.$val;
            }
            $sender = implode(','$sender_arr);
            $mobile=urlencode($sender);
            $url "http://api.smsbao.com/wsms?u=" $user "&p=" $apikey "&m=" $mobile "&c=" $content;
        }
         
        if (function_exists('file_get_contents')) {
            $res file_get_contents($url);
        }else {
            $ch = curl_init();
            $timeout = 5;
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
            $res = curl_exec($ch);
            curl_close($ch);
        }
         
        $message $statusStr[$res];
        if($res == 0){
           return array('status' => 1, 'msg' => $message);
        }else{
            return array('status' => -1, 'msg' => $message);
        }
    }

好了经过以上的添加,短信宝的短信平台已经替换成功了,可以正常使用了

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

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

开源插件

最新更新

电商类

CMS类

微信类

文章标签