待发短信

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

4001-021-502

工作时间

9:00-21:00

DBShop短信接口替换

DBShop基于PHP官方ZendFramework 2框架开发的新一代电子商务系统(完美支持 PHP7)。方便的操作管理、详细的使用教程、自动化的在线处理,便于进行二次开发,小编对这款软件还比较熟悉,今天小编就以增加短信接口为例,一步步教大家如何进行二次开发,短信接口是我们短信宝短信群发平台的短信接口,我们短信宝非常稳定,发送速度快,注册就送测试条数,推荐大家使用。

首先我们修改后台模版文件,打开项目\module\system\view\system\system\phpone-message-set.phtml文件,修改代码如下:

?
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
<div class="tabbable tabs-left">
    <ul class="nav nav-tabs">
        <li><h5><?php echo $this->translate('短信提醒设置'); ?></h5></li>
        <li class="active"><a data-toggle="tab" href="#system_a"><?php echo $this->translate('基本信息'); ?></a></li>
    </ul>
    <form class="form-horizontal" name="phone_message_form" id="phone_message_form" method="post">
        <div class="tab-content">
            <div id="sticky_navigation" style="height:30px;border-bottom:4px solid #DFDFDF;">
                <div class="pull-left" style="font-size:16px;line-height:30px;"><strong><?php echo $this->translate('短信提醒设置'); ?></strong></div>
                <div class="pull-right">
                    <a href="<?php echo $this->serverUrl(true); ?>" class="btn btn-small btn-warning"><i class="icon-repeat icon-white"></i> <?php echo $this->translate('刷新'); ?></a>
                    &nbsp;<button type="submit" class="btn btn-small btn-primary"><i class="icon-ok icon-white"></i> <?php echo $this->translate('保存提醒设置'); ?></button>
                    &nbsp;<a href="<?php echo $this->myviewalias()->dbshopHelpUrl('phone_message_set'); ?>" target="_blank" class="btn btn-small btn-info"><i class="icon-info-sign icon-white"></i> <?php echo $this->translate('查看帮助说明'); ?></a>
                </div>
            </div>
            <div id="system_a" class="tab-pane active">
                <div class="well admin_add_header_well"><?php echo $this->translate('手机短信'); ?></div>
                <div class="well admin_add_well">
                    <div class="message_one">
                    </div>
                    <div class="control-group">
                        <label for="input01" class="control-label"><?php echo $this->translate('设置类型'); ?>:</label>
                        <div class="controls">
                            <select name="phone_sms_type" id="phone_sms_type" onchange="select_phone_sms_type();" class="span2">
                                <option value="" <?php if(!isset($this->phonesms_config['shop_phone_sms']['phone_sms_type']) or empty($this->phonesms_config['shop_phone_sms']['phone_sms_type'])) echo 'selected="selected"'; ?>><?php echo $this->translate('无类型'); ?></option>
                                <option value="alidayu" <?php if(isset($this->phonesms_config['shop_phone_sms']['phone_sms_type']) and $this->phonesms_config['shop_phone_sms']['phone_sms_type'] == 'alidayu') echo 'selected="selected"'; ?>><?php echo $this->translate('阿里大于'); ?></option>
                                <option value="smsbao" <?php if(isset($this->phonesms_config['shop_phone_sms']['phone_sms_type']) and $this->phonesms_config['shop_phone_sms']['phone_sms_type'] == 'smsbao') echo 'selected="selected"'; ?>><?php echo $this->translate('短信宝'); ?></option>
                            </select>
                            <i class="cus-help shop_admin_help_note" data-content="<?php echo $this->translate('短信宝旗下的通讯平台。'); ?>"></i>
                            &nbsp;&nbsp;<a href="http://www.smsbao.com/" target="_blank">查看官方网站</a>
                        </div>
                    </div>
                    <div class="control-group alidayu" style="display: none;">
                        <label for="input01" class="control-label"><?php echo $this->translate('签名名称'); ?>:</label>
                        <div class="controls">
                            <input type="text" name="alidayu_sign_name" id="alidayu_sign_name" value="<?php if(isset($this->phonesms_config['shop_phone_sms']['alidayu_sign_name'])) echo $this->escapeHtml($this->phonesms_config['shop_phone_sms']['alidayu_sign_name']); ?>" class="span3">
                        </div>
                    </div>
                    <div class="control-group alidayu" style="display: none;">
                        <label for="input01" class="control-label">App Key(<?php echo $this->translate('应用'); ?>):</label>
                        <div class="controls">
                            <input type="text" name="alidayu_app_key" id="alidayu_app_key" value="<?php if(isset($this->phonesms_config['shop_phone_sms']['alidayu_app_key'])) echo $this->escapeHtml($this->phonesms_config['shop_phone_sms']['alidayu_app_key']); ?>" class="span3">
                        </div>
                    </div>
                    <div class="control-group alidayu" style="display: none;">
                        <label for="input01" class="control-label">App Secret(<?php echo $this->translate('应用'); ?>):</label>
                        <div class="controls">
                            <input type="text" name="alidayu_app_secret" id="alidayu_app_secret" value="<?php if(isset($this->phonesms_config['shop_phone_sms']['alidayu_app_secret'])) echo $this->escapeHtml($this->phonesms_config['shop_phone_sms']['alidayu_app_secret']); ?>" class="span3">
                        </div>
                    </div>
 
                     <div class="control-group smsbao" style="display: none;">
                        <label for="input01" class="control-label"><?php echo $this->translate('短信宝签名'); ?>:</label>
                        <div class="controls">
                            <input type="text" name="smsbao_sign_name" id="smsbao_sign_name" value="<?php if(isset($this->phonesms_config['shop_phone_sms']['smsbao_sign_name'])) echo $this->escapeHtml($this->phonesms_config['shop_phone_sms']['smsbao_sign_name']); ?>" class="span3">
                        </div>
                    </div>
                    <div class="control-group smsbao" style="display: none;">
                        <label for="input01" class="control-label">短信宝帐号(<?php echo $this->translate('应用'); ?>):</label>
                        <div class="controls">
                            <input type="text" name="smsbao_app_key" id="smsbao_app_key" value="<?php if(isset($this->phonesms_config['shop_phone_sms']['smsbao_app_key'])) echo $this->escapeHtml($this->phonesms_config['shop_phone_sms']['smsbao_app_key']); ?>" class="span3">
                        </div>
                    </div>
                    <div class="control-group smsbao" style="display: none;">
                        <label for="input01" class="control-label">短信宝密码(<?php echo $this->translate('应用'); ?>):</label>
                        <div class="controls">
                            <input type="text" name="smsbao_app_secret" id="smsbao_app_secret" value="<?php if(isset($this->phonesms_config['shop_phone_sms']['smsbao_app_secret'])) echo $this->escapeHtml($this->phonesms_config['shop_phone_sms']['smsbao_app_secret']); ?>" class="span3">
                        </div>
                    </div>
 
                    <hr>
                    <div class="control-group sms_opinion" style="display: none;">
                        <label for="input01" class="control-label"><?php echo $this->translate('管理员手机号'); ?>:</label>
                        <div class="controls">
                            <input type="text" name="admin_phone" id="admin_phone" value="<?php if(isset($this->phonesms_config['shop_phone_sms']['admin_phone'])) echo $this->escapeHtml($this->phonesms_config['shop_phone_sms']['admin_phone']); ?>" class="span3">
                            <font color="red"><?php echo $this->translate('目前仅支持中国内地手机号码。'); ?></font>
                        </div>
                    </div>
                    <div class="control-group sms_opinion" style="display: none;">
                        <label for="input01" class="control-label"><?php echo $this->translate('接收短信'); ?>:</label>
                        <div class="controls">
                            <label class="checkbox inline"><input <?php if(isset($this->phonesms_config['shop_phone_sms']['admin_submit_order_phone_message']) and $this->phonesms_config['shop_phone_sms']['admin_submit_order_phone_message'] == 1) echo 'checked'; ?> type="checkbox" name="admin_submit_order_phone_message" value="1"><?php echo $this->translate('订单提交'); ?></label>
                            <label class="checkbox inline"><input <?php if(isset($this->phonesms_config['shop_phone_sms']['admin_payment_order_phone_message']) and $this->phonesms_config['shop_phone_sms']['admin_payment_order_phone_message'] == 1) echo 'checked'; ?> type="checkbox" name="admin_payment_order_phone_message" value="1"><?php echo $this->translate('付款完成'); ?></label>
                            <label class="checkbox inline"><input <?php if(isset($this->phonesms_config['shop_phone_sms']['admin_ship_order_phone_message']) and $this->phonesms_config['shop_phone_sms']['admin_ship_order_phone_message'] == 1) echo 'checked'; ?> type="checkbox" name="admin_ship_order_phone_message" value="1"><?php echo $this->translate('发货完成'); ?></label>
                            <label class="checkbox inline"><input <?php if(isset($this->phonesms_config['shop_phone_sms']['admin_finish_order_phone_message']) and $this->phonesms_config['shop_phone_sms']['admin_finish_order_phone_message'] == 1) echo 'checked'; ?> type="checkbox" name="admin_finish_order_phone_message" value="1"><?php echo $this->translate('确认收货'); ?></label>
                            <label class="checkbox inline"><input <?php if(isset($this->phonesms_config['shop_phone_sms']['admin_cancel_order_phone_message']) and $this->phonesms_config['shop_phone_sms']['admin_cancel_order_phone_message'] == 1) echo 'checked'; ?> type="checkbox" name="admin_cancel_order_phone_message" value="1"><?php echo $this->translate('取消订单'); ?></label>
                        </div>
                    </div>
 
 
                    <hr>
                    <div class="alidayu" style="display: none;">
                        <font color="red"><?php echo $this->translate('模板ID是空,为关闭此信息提醒;如果模板ID非空,为开启此信息提醒。'); ?></font><br>
                        <b>目前官方提供的可设置标签有 ${buyname} 购买人、${ordersn} 订单编号、${ordertotal} 订单金额、${expressname} 快递名称、${expressnumber} 快递单号</b>
                    </div>
 
                     <div class="smsbao" style="display: none;">
                        <font color="red"><?php echo $this->translate('模板内容是空,为关闭此信息提醒;如果模板内容非空,为开启此信息提醒。'); ?></font><br>
                        <b>目前官方提供的可设置标签有 ${buyname} 购买人、${ordersn} 订单编号、${ordertotal} 订单金额、${expressname} 快递名称、${expressnumber} 快递单号</b>
                    </div>
 
                    <br>
                    <div class="control-group alidayu" style="display: none;">
                        <label for="input01" class="control-label"><?php echo $this->translate('订单提交模板ID'); ?>:</label>
                        <div class="controls">
                            <input type="text" name="alidayu_submit_order_template_id" id="alidayu_submit_order_template_id" value="<?php if(isset($this->phonesms_config['shop_phone_sms']['alidayu_submit_order_template_id'])) echo $this->escapeHtml($this->phonesms_config['shop_phone_sms']['alidayu_submit_order_template_id']); ?>" class="span3">
                        </div>
                    </div>
                    <div class="control-group alidayu" style="display: none;">
                        <label for="input01" class="control-label"><?php echo $this->translate('付款完成模板ID'); ?>:</label>
                        <div class="controls">
                            <input type="text" name="alidayu_payment_order_template_id" id="alidayu_payment_order_template_id" value="<?php if(isset($this->phonesms_config['shop_phone_sms']['alidayu_payment_order_template_id'])) echo $this->escapeHtml($this->phonesms_config['shop_phone_sms']['alidayu_payment_order_template_id']); ?>" class="span3">
                        </div>
                    </div>
                    <div class="control-group alidayu" style="display: none;">
                        <label for="input01" class="control-label"><?php echo $this->translate('发货完成模板ID'); ?>:</label>
                        <div class="controls">
                            <input type="text" name="alidayu_ship_order_template_id" id="alidayu_ship_order_template_id" value="<?php if(isset($this->phonesms_config['shop_phone_sms']['alidayu_ship_order_template_id'])) echo $this->escapeHtml($this->phonesms_config['shop_phone_sms']['alidayu_ship_order_template_id']); ?>" class="span3">
                        </div>
                    </div>
                    <div class="control-group alidayu" style="display: none;">
                        <label for="input01" class="control-label"><?php echo $this->translate('确认收货模板ID'); ?>:</label>
                        <div class="controls">
                            <input type="text" name="alidayu_finish_order_template_id" id="alidayu_finish_order_template_id" value="<?php if(isset($this->phonesms_config['shop_phone_sms']['alidayu_finish_order_template_id'])) echo $this->escapeHtml($this->phonesms_config['shop_phone_sms']['alidayu_finish_order_template_id']); ?>" class="span3">
                        </div>
                    </div>
                    <div class="control-group alidayu" style="display: none;">
                        <label for="input01" class="control-label"><?php echo $this->translate('订单取消模板ID'); ?>:</label>
                        <div class="controls">
                            <input type="text" name="alidayu_cancel_order_template_id" id="alidayu_cancel_order_template_id" value="<?php if(isset($this->phonesms_config['shop_phone_sms']['alidayu_cancel_order_template_id'])) echo $this->escapeHtml($this->phonesms_config['shop_phone_sms']['alidayu_cancel_order_template_id']); ?>" class="span3">
                        </div>
                    </div>
 
                      <div class="control-group smsbao" style="display: none;">
                        <label for="input01" class="control-label"><?php echo $this->translate('订单提交模板内容'); ?>:</label>
                        <div class="controls">
                            <input type="text" name="smsbao_submit_order_template_id" id="smsbao_submit_order_template_id" value="<?php if(isset($this->phonesms_config['shop_phone_sms']['smsbao_submit_order_template_id'])) echo $this->escapeHtml($this->phonesms_config['shop_phone_sms']['smsbao_submit_order_template_id']); ?>" class="span3">
                        </div>
                    </div>
                    <div class="control-group smsbao" style="display: none;">
                        <label for="input01" class="control-label"><?php echo $this->translate('付款完成模板内容'); ?>:</label>
                        <div class="controls">
                            <input type="text" name="smsbao_payment_order_template_id" id="smsbao_payment_order_template_id" value="<?php if(isset($this->phonesms_config['shop_phone_sms']['smsbao_payment_order_template_id'])) echo $this->escapeHtml($this->phonesms_config['shop_phone_sms']['smsbao_payment_order_template_id']); ?>" class="span3">
                        </div>
                    </div>
                    <div class="control-group smsbao" style="display: none;">
                        <label for="input01" class="control-label"><?php echo $this->translate('发货完成模板内容'); ?>:</label>
                        <div class="controls">
                            <input type="text" name="smsbao_ship_order_template_id" id="smsbao_ship_order_template_id" value="<?php if(isset($this->phonesms_config['shop_phone_sms']['smsbao_ship_order_template_id'])) echo $this->escapeHtml($this->phonesms_config['shop_phone_sms']['smsbao_ship_order_template_id']); ?>" class="span3">
                        </div>
                    </div>
                    <div class="control-group smsbao" style="display: none;">
                        <label for="input01" class="control-label"><?php echo $this->translate('确认收货模板内容'); ?>:</label>
                        <div class="controls">
                            <input type="text" name="smsbao_finish_order_template_id" id="smsbao_finish_order_template_id" value="<?php if(isset($this->phonesms_config['shop_phone_sms']['smsbao_finish_order_template_id'])) echo $this->escapeHtml($this->phonesms_config['shop_phone_sms']['smsbao_finish_order_template_id']); ?>" class="span3">
                        </div>
                    </div>
                    <div class="control-group smsbao" style="display: none;">
                        <label for="input01" class="control-label"><?php echo $this->translate('订单取消模板内容'); ?>:</label>
                        <div class="controls">
                            <input type="text" name="smsbao_cancel_order_template_id" id="smsbao_cancel_order_template_id" value="<?php if(isset($this->phonesms_config['shop_phone_sms']['smsbao_cancel_order_template_id'])) echo $this->escapeHtml($this->phonesms_config['shop_phone_sms']['smsbao_cancel_order_template_id']); ?>" class="span3">
                        </div>
                    </div>
 
 
                    <hr>
                    <div class="alidayu" style="display: none;">
                        <b>目前官方提供的可设置标签有 ${code} 验证码 、 ${product} 站点名称</b>
                    </div>
                    <div class="smsbao" style="display: none;">
                        <b>目前官方提供的可设置标签有 {code} 验证码 、 {product} 站点名称</b>
                    </div>
                    <br>
                    <div class="control-group alidayu" style="display: none;">
                        <label for="input01" class="control-label"><?php echo $this->translate('手机验证码模板内容'); ?>:</label>
                        <div class="controls">
                            <input type="text" name="alidayu_phone_captcha_template_id" id="alidayu_phone_captcha_template_id" value="<?php if(isset($this->phonesms_config['shop_phone_sms']['alidayu_phone_captcha_template_id'])) echo $this->escapeHtml($this->phonesms_config['shop_phone_sms']['alidayu_phone_captcha_template_id']); ?>" class="span3">
                            <font color="red"><?php echo $this->translate('使用手机验证码,要在 系统管理-》系统设置-》验证码设置 里开启手机短信验证码。'); ?></font>
                        </div>
                    </div>
 
                    <div class="control-group smsbao" style="display: none;">
                        <label for="input01" class="control-label"><?php echo $this->translate('手机验证码模板内容'); ?>:</label>
                        <div class="controls">
                            <input type="text" name="smsbao_phone_captcha_template_id" id="smsbao_phone_captcha_template_id" value="<?php if(isset($this->phonesms_config['shop_phone_sms']['smsbao_phone_captcha_template_id'])) echo $this->escapeHtml($this->phonesms_config['shop_phone_sms']['smsbao_phone_captcha_template_id']); ?>" class="span3">
                            <font color="red"><?php echo $this->translate('使用手机验证码,要在 系统管理-》系统设置-》验证码设置 里开启手机短信验证码。'); ?></font>
                        </div>
                    </div>
                </div>
            </div>
 
        </div>
    </form>
</div>
<script>
    <?php if ($this->success_msg != '') { ?>
    show_message('.message_one','<?php echo date("Y-m-d H:i:s"); ?>','<?php echo $this->success_msg; ?>','alert-success');
    <?php } ?>
 
 
    function select_phone_sms_type() {
        var phone_sms_type = $("#phone_sms_type").val();
        if(phone_sms_type == '') {
            $(".alidayu").css('display', 'none');
            $('.sms_opinion').css('display', 'none');
        }
        if(phone_sms_type == 'alidayu') {
            $(".alidayu,.sms_opinion").css('display', '');
            $(".smsbao").css('display','none');
        }
        if (phone_sms_type == 'smsbao') {
            $(".smsbao,.sms_opinion").css('display','');
            $(".alidayu").css('display','none');
        }
    }
    <?php if(isset($this->phonesms_config['shop_phone_sms']['phone_sms_type']) and $this->phonesms_config['shop_phone_sms']['phone_sms_type'] != '') { ?>
    select_phone_sms_type();
    <?php } ?>
</script>

接下来修改后台配置短信方法,打开项目\module\system\src\system\controller\systemcontroller.php文件,修改savePhoneSmsConfig方法,修改代码如下:

?
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
   private function savePhoneSmsConfig(array $data$e) {
 
        $phonesmsConfig array();
        $phonesmsConfig['phone_sms_type']       = isset($data['phone_sms_type'])     ? $data['phone_sms_type']           : '';
        $phonesmsConfig['alidayu_sign_name']    = isset($data['alidayu_sign_name'])  ? trim($data['alidayu_sign_name'])    : '';
        $phonesmsConfig['alidayu_app_key']      = isset($data['alidayu_app_key'])    ? trim($data['alidayu_app_key'])    : '';
        $phonesmsConfig['alidayu_app_secret']   = isset($data['alidayu_app_secret']) ? trim($data['alidayu_app_secret']) : '';
 
        $phonesmsConfig['smsbao_sign_name']    = isset($data['smsbao_sign_name'])  ? trim($data['smsbao_sign_name'])    : '';
        $phonesmsConfig['smsbao_app_key']      = isset($data['smsbao_app_key'])    ? trim($data['smsbao_app_key'])    : '';
        $phonesmsConfig['smsbao_app_secret']   = isset($data['smsbao_app_secret']) ? trim($data['smsbao_app_secret']) : '';
 
        $phonesmsConfig['admin_phone']   = isset($data['admin_phone'])  ? trim($data['admin_phone']) : '';
        $phonesmsConfig['admin_submit_order_phone_message']   = isset($data['admin_submit_order_phone_message'])  ? intval($data['admin_submit_order_phone_message']) : '';
        $phonesmsConfig['admin_payment_order_phone_message']  = isset($data['admin_payment_order_phone_message']) ? intval($data['admin_payment_order_phone_message']) : '';
        $phonesmsConfig['admin_finish_order_phone_message']   = isset($data['admin_finish_order_phone_message'])  ? intval($data['admin_finish_order_phone_message']) : '';
        $phonesmsConfig['admin_cancel_order_phone_message']   = isset($data['admin_cancel_order_phone_message'])  ? intval($data['admin_cancel_order_phone_message']) : '';
         $phonesmsConfig['admin_ship_order_phone_message']   = isset($data['admin_ship_order_phone_message'])  ? intval($data['admin_ship_order_phone_message']) : '';
 
        $phonesmsConfig['alidayu_submit_order_template_id']   = isset($data['alidayu_submit_order_template_id'])  ? trim($data['alidayu_submit_order_template_id']) : '';
        $phonesmsConfig['alidayu_payment_order_template_id']  = isset($data['alidayu_payment_order_template_id']) ? trim($data['alidayu_payment_order_template_id']) : '';
        $phonesmsConfig['alidayu_ship_order_template_id']     = isset($data['alidayu_ship_order_template_id'])    ? trim($data['alidayu_ship_order_template_id']) : '';
        $phonesmsConfig['alidayu_finish_order_template_id']   = isset($data['alidayu_finish_order_template_id'])  ? trim($data['alidayu_finish_order_template_id']) : '';
        $phonesmsConfig['alidayu_cancel_order_template_id']   = isset($data['alidayu_cancel_order_template_id'])  ? trim($data['alidayu_cancel_order_template_id']) : '';
 
        $phonesmsConfig['alidayu_phone_captcha_template_id']   = isset($data['alidayu_phone_captcha_template_id'])  ? trim($data['alidayu_phone_captcha_template_id']) : '';
 
 
         $phonesmsConfig['smsbao_submit_order_template_id']   = isset($data['smsbao_submit_order_template_id'])  ? trim($data['smsbao_submit_order_template_id']) : '';
        $phonesmsConfig['smsbao_payment_order_template_id']  = isset($data['smsbao_payment_order_template_id']) ? trim($data['smsbao_payment_order_template_id']) : '';
        $phonesmsConfig['smsbao_ship_order_template_id']     = isset($data['smsbao_ship_order_template_id'])    ? trim($data['smsbao_ship_order_template_id']) : '';
        $phonesmsConfig['smsbao_finish_order_template_id']   = isset($data['smsbao_finish_order_template_id'])  ? trim($data['smsbao_finish_order_template_id']) : '';
        $phonesmsConfig['smsbao_cancel_order_template_id']   = isset($data['smsbao_cancel_order_template_id'])  ? trim($data['smsbao_cancel_order_template_id']) : '';
 
        $phonesmsConfig['smsbao_phone_captcha_template_id']   = isset($data['smsbao_phone_captcha_template_id'])  ? trim($data['smsbao_phone_captcha_template_id']) : '';
 
 
        $e->toFile(DBSHOP_PATH . '/data/moduledata/System/phonesms.ini'array('shop_phone_sms'=>$phonesmsConfig));
    }

最后我们去修改发送代码,打开项目\module\email\src\email\service\SendPhoneSms.php文件,修改toSendSms方法,修改代码如下:

?
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
    public function toSendSms($data$user_phone$phone_template=''$user_id '') {
       
        //判断是否存在,手机是否开启了短信服务功能,如果不存在未开启则不进行操作
 
        if (!isset($this->smsConfig['shop_phone_sms']['phone_sms_type']) or $this->smsConfig['shop_phone_sms']['phone_sms_type'] == ''return false;
       
 
 
        $user_phone = !empty($user_phone) ? (is_array($user_phone) ? implode(','$user_phone) : $user_phone) : '';
 
 
 
 
 
        if ($this->smsConfig['shop_phone_sms']['phone_sms_type'] == 'smsbao') {
 
             if(!isset($this->smsConfig['shop_phone_sms'][$phone_template['smsbao']]) or $this->smsConfig['shop_phone_sms'][$phone_template['smsbao']] == ''return false;
 
            if(!empty($this->smsConfig['shop_phone_sms']['admin_phone'])) {
            if($phone_template['smsbao'] == 'smsbao_submit_order_template_id' && $this->smsConfig['shop_phone_sms']['admin_submit_order_phone_message'] == 1)    $user_phone = !empty($user_phone) ? $user_phone.','.$this->smsConfig['shop_phone_sms']['admin_phone'] : $this->smsConfig['shop_phone_sms']['admin_phone'];
            if($phone_template['smsbao'] == 'smsbao_payment_order_template_id' && $this->smsConfig['shop_phone_sms']['admin_payment_order_phone_message'] == 1)  $user_phone = !empty($user_phone) ? $user_phone.','.$this->smsConfig['shop_phone_sms']['admin_phone'] : $this->smsConfig['shop_phone_sms']['admin_phone'];
 
            if($phone_template['smsbao'] == 'smsbao_ship_order_template_id' && $this->smsConfig['shop_phone_sms']['admin_ship_order_phone_message'] == 1)  $user_phone = !empty($user_phone) ? $user_phone.','.$this->smsConfig['shop_phone_sms']['admin_phone'] : $this->smsConfig['shop_phone_sms']['admin_phone'];
            if($phone_template['smsbao'] == 'smsbao_finish_order_template_id' && $this->smsConfig['shop_phone_sms']['admin_finish_order_phone_message'] == 1)    $user_phone = !empty($user_phone) ? $user_phone.','.$this->smsConfig['shop_phone_sms']['admin_phone'] : $this->smsConfig['shop_phone_sms']['admin_phone'];
            if($phone_template['smsbao'] == 'smsbao_cancel_order_template_id' && $this->smsConfig['shop_phone_sms']['admin_cancel_order_phone_message'] == 1)    $user_phone = !empty($user_phone) ? $user_phone.','.$this->smsConfig['shop_phone_sms']['admin_phone'] : $this->smsConfig['shop_phone_sms']['admin_phone'];
        }
 
             if(empty($user_phone)) return false;
              $user_phone is_array($user_phone) ? implode(','$user_phone) : $user_phone;
 
             $smsJson    $this->createSmsbaoArray($data);
 
             $tempdata $this->smsConfig['shop_phone_sms'][$phone_template['smsbao']];
            foreach ($smsJson as $key => $value 
                {   
                    $tempdata str_replace(trim($key), trim($value), $tempdata);
                };
 
                $content $tempdata;
 
                $content "【".$this->smsConfig['shop_phone_sms']['smsbao_sign_name']."】".$tempdata;
 
            $result array(
                "30"=>"密码错误",
                "40"=>"账号不存在",
                "41"=>"余额不足",
                "42"=>"帐号过期",
                "43"=>"IP地址限制",
                "50"=>"内容含有敏感词",
                "51"=>"手机号码不正确"
                );
 
 
             $url 'http://api.smsbao.com/sms?u='.$this->smsConfig['shop_phone_sms']['smsbao_app_key'].'&p='.md5($this->smsConfig['shop_phone_sms']['smsbao_app_secret']).'&m='.$user_phone.'&c='.$content;
 
             $ret file_get_contents($url);
 
             if ($ret == 0) {
                 return true;
             }else{
                return $result[$ret];
             }
        }else{
 
            if(!isset($this->smsConfig['shop_phone_sms'][$phone_template['alidayu']]) or $this->smsConfig['shop_phone_sms'][$phone_template['alidayu']] == ''return false;
 
            if(!empty($this->smsConfig['shop_phone_sms']['admin_phone'])) {
                if($phone_template['alidayu'] == 'alidayu_submit_order_template_id' && $this->smsConfig['shop_phone_sms']['admin_submit_order_phone_message'] == 1)    $user_phone = !empty($user_phone) ? $user_phone.','.$this->smsConfig['shop_phone_sms']['admin_phone'] : $this->smsConfig['shop_phone_sms']['admin_phone'];
                if($phone_template['alidayu'] == 'alidayu_payment_order_template_id' && $this->smsConfig['shop_phone_sms']['admin_payment_order_phone_message'] == 1)  $user_phone = !empty($user_phone) ? $user_phone.','.$this->smsConfig['shop_phone_sms']['admin_phone'] : $this->smsConfig['shop_phone_sms']['admin_phone'];
 
                if($phone_template['alidayu'] == 'alidayu_ship_order_template_id' && $this->smsConfig['shop_phone_sms']['admin_ship_order_phone_message'] == 1)  $user_phone = !empty($user_phone) ? $user_phone.','.$this->smsConfig['shop_phone_sms']['admin_phone'] : $this->smsConfig['shop_phone_sms']['admin_phone'];
                if($phone_template['alidayu'] == 'alidayu_finish_order_template_id' && $this->smsConfig['shop_phone_sms']['admin_finish_order_phone_message'] == 1)    $user_phone = !empty($user_phone) ? $user_phone.','.$this->smsConfig['shop_phone_sms']['admin_phone'] : $this->smsConfig['shop_phone_sms']['admin_phone'];
                if($phone_template['alidayu'] == 'alidayu_cancel_order_template_id' && $this->smsConfig['shop_phone_sms']['admin_cancel_order_phone_message'] == 1)    $user_phone = !empty($user_phone) ? $user_phone.','.$this->smsConfig['shop_phone_sms']['admin_phone'] : $this->smsConfig['shop_phone_sms']['admin_phone'];
            }
            if(empty($user_phone)) return false;
 
            $smsJson    $this->createSmsArray($data);
 
            include(DBSHOP_PATH . '/vendor/alibaba/dayu/TopSdk.php');
            $c new \TopClient();
            $c->appkey    = $this->smsConfig['shop_phone_sms']['alidayu_app_key'];
            $c->secretKey = $this->smsConfig['shop_phone_sms']['alidayu_app_secret'];
 
            $req new \AlibabaAliqinFcSmsNumSendRequest();
            $req->setExtend($user_id);
            $req->setSmsType('normal');
            $req->setSmsFreeSignName($this->smsConfig['shop_phone_sms']['alidayu_sign_name']);
            $req->setSmsParam($smsJson);
            $req->setRecNum($user_phone);
            $req->setSmsTemplateCode($this->smsConfig['shop_phone_sms'][$phone_template]);
            $resp $c->execute($req);
 
        }
 
 
 
    }

到这一步短信宝接口就替换完成了,但是有个问题是发送出来的短信变量没办法匹配成功,这是因为短信内容没有匹配成功,因为发送很多这里就不写出了,可以根据我给的代码包进行对比替换, dbshop替换变量文件下载地址。

替换完成后,短信宝短信接口可以正常使用了,我们进行发送测试:

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

最新更新

电商类

CMS类

微信类

文章标签