DBShop基于PHP官方ZendFramework 2框架開發(fā)的新一代電子商務(wù)系統(tǒng)(完美支持 PHP7)。方便的操作管理、詳細(xì)的使用教程、自動(dòng)化的在線處理,便于進(jìn)行二次開發(fā),小編對(duì)這款軟件還比較熟悉,今天小編就以增加短信接口為例,一步步教大家如何進(jìn)行二次開發(fā),短信接口是我們短信寶短信群發(fā)平臺(tái)的短信接口,我們短信寶非常穩(wěn)定,發(fā)送速度快,注冊(cè)就送測(cè)試條數(shù),推薦大家使用。
首先我們修改后臺(tái)模版文件,打開項(xiàng)目\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('短信提醒設(shè)置'); ?></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('短信提醒設(shè)置'); ?></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> <button type="submit" class="btn btn-small btn-primary"><i class="icon-ok icon-white"></i> <?php echo $this->translate('保存提醒設(shè)置'); ?></button> <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('查看幫助說(shuō)明'); ?></a> </div> </div> <div id="system_a" class="tab-pane active"> <div class="well admin_add_header_well"><?php echo $this->translate('手機(jī)短信'); ?></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('設(shè)置類型'); ?>:</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('無(wú)類型'); ?></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('短信寶旗下的通訊平臺(tái)。'); ?>"></i> </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('應(yīng)用'); ?>):</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('應(yīng)用'); ?>):</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">短信寶帳號(hào)(<?php echo $this->translate('應(yīng)用'); ?>):</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('應(yīng)用'); ?>):</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('管理員手機(jī)號(hào)'); ?>:</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('目前僅支持中國(guó)內(nèi)地手機(jī)號(hào)碼。'); ?></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('發(fā)貨完成'); ?></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('確認(rèn)收貨'); ?></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是空,為關(guān)閉此信息提醒;如果模板ID非空,為開啟此信息提醒。'); ?></font><br> <b>目前官方提供的可設(shè)置標(biāo)簽有 ${buyname} 購(gòu)買人、${ordersn} 訂單編號(hào)、${ordertotal} 訂單金額、${expressname} 快遞名稱、${expressnumber} 快遞單號(hào)</b> </div> <div class="smsbao" style="display: none;"> <font color="red"><?php echo $this->translate('模板內(nèi)容是空,為關(guān)閉此信息提醒;如果模板內(nèi)容非空,為開啟此信息提醒。'); ?></font><br> <b>目前官方提供的可設(shè)置標(biāo)簽有 ${buyname} 購(gòu)買人、${ordersn} 訂單編號(hào)、${ordertotal} 訂單金額、${expressname} 快遞名稱、${expressnumber} 快遞單號(hào)</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('發(fā)貨完成模板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('確認(rèn)收貨模板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('訂單提交模板內(nèi)容'); ?>:</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('付款完成模板內(nèi)容'); ?>:</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('發(fā)貨完成模板內(nèi)容'); ?>:</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('確認(rèn)收貨模板內(nèi)容'); ?>:</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('訂單取消模板內(nèi)容'); ?>:</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>目前官方提供的可設(shè)置標(biāo)簽有 ${code} 驗(yàn)證碼 、 ${product} 站點(diǎn)名稱</b> </div> <div class="smsbao" style="display: none;"> <b>目前官方提供的可設(shè)置標(biāo)簽有 {code} 驗(yàn)證碼 、 {product} 站點(diǎn)名稱</b> </div> <br> <div class="control-group alidayu" style="display: none;"> <label for="input01" class="control-label"><?php echo $this->translate('手機(jī)驗(yàn)證碼模板內(nèi)容'); ?>:</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('使用手機(jī)驗(yàn)證碼,要在 系統(tǒng)管理-》系統(tǒng)設(shè)置-》驗(yàn)證碼設(shè)置 里開啟手機(jī)短信驗(yàn)證碼。'); ?></font> </div> </div> <div class="control-group smsbao" style="display: none;"> <label for="input01" class="control-label"><?php echo $this->translate('手機(jī)驗(yàn)證碼模板內(nèi)容'); ?>:</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('使用手機(jī)驗(yàn)證碼,要在 系統(tǒng)管理-》系統(tǒng)設(shè)置-》驗(yàn)證碼設(shè)置 里開啟手機(jī)短信驗(yàn)證碼。'); ?></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> |
接下來(lái)修改后臺(tái)配置短信方法,打開項(xiàng)目\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)); } |
最后我們?nèi)バ薷陌l(fā)送代碼,打開項(xiàng)目\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 = '') { //判斷是否存在,手機(jī)是否開啟了短信服務(wù)功能,如果不存在未開啟則不進(jìn)行操作 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"=>"密碼錯(cuò)誤", "40"=>"賬號(hào)不存在", "41"=>"余額不足", "42"=>"帳號(hào)過(guò)期", "43"=>"IP地址限制", "50"=>"內(nèi)容含有敏感詞", "51"=>"手機(jī)號(hào)碼不正確" ); $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); } } |
到這一步短信寶接口就替換完成了,但是有個(gè)問(wèn)題是發(fā)送出來(lái)的短信變量沒(méi)辦法匹配成功,這是因?yàn)槎绦艃?nèi)容沒(méi)有匹配成功,因?yàn)榘l(fā)送很多這里就不寫出了,可以根據(jù)我給的代碼包進(jìn)行對(duì)比替換, dbshop替換變量文件下載地址。
替換完成后,短信寶短信接口可以正常使用了,我們進(jìn)行發(fā)送測(cè)試:

報(bào)備一下短信寶的VIP模板,這樣就可以走短信寶的優(yōu)質(zhì)通道了,并且免審核了,短信內(nèi)容3~5秒就可送達(dá)。
最新更新
電商類
CMS類
微信類