待发短信

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

4001-021-502

工作时间

9:00-21:00

人人店短信接口插件开发

人人店是一款基于微信展示、营销推广和互动成交的产品体系软件,通过“人人店”,传统企业可将线下分销渠道一键上线,自动生成分店二维码,实现线上线下互通。

今天来分享一下,如何进行二次开发。我以替换短信接口为例,一步一步的手把手教大家开发过程,我们做演示的短信平台是短信宝(http://www.smsbao.com)短信平台,小伙伴一定会问为什么使用短信宝作为案例呢?原因很简单,因为短信宝的平台极其稳定,而且短信发送速度相当快捷,验证码和订单通知在3~5秒就能收到,用户体验非常好。To B类的产品,往往是专注于一点核心团队公司做出的要什么业务都做的公司要靠谱好多,他们专做短信业务,所以我们公司一直和短信宝保持着合作关系,小伙伴们也可以去短信宝注册一个账号,还有免费的短信条数送呢。

接下来我就说一下开发步骤:

1.先打开项目/core/com/sms.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
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
<?php
    if (!defined('IN_IA')) 
    {
        exit('Access Denied');
    }
class Sms_EweiShopV2ComModel extends ComModel 
{
    public function send($mobile$tplid$data$replace = true) 
    {
        global $_W;
        $smsset $this->sms_set();
        $template $this->sms_verify($tplid$smsset);
        if (empty($template['status'])) 
        {
            return $template;
        }
        $params $this->sms_data($template['type'], $data$replace$template);
        if ($template['type'] == 'juhe'
        {
            $data array('mobile' => $mobile'tpl_id' => $template['smstplid'], 'tpl_value' => $params'key' => $smsset['juhe_key']);
            $result $this->http_post('http://v.juhe.cn/sms/send'$data);
            if (empty($result) || (0 < $result['error_code'])) 
            {
                    return array('status' => 0, 'message' => '短信发送失败(' $result['error_code'] . '):' $result['reason']);
                    
                    
            }
        }
            
        if ($template['type'] == 'smsbao') {
 
            $results array(
                    '30' => '密码错误',
                    '40' => '账号不存在',
                    '41' => '余额不足',
                    '42' => '帐号过期',
                    '43' => 'IP地址限制',
                    '50' => '内容含有敏感词',
                    '51' => '手机号码不正确'
            );
 
            $url 'http://api.smsbao.com/sms?u='.$smsset['smsbao_key'].'&p='.md5($smsset['smsbao_secret']).'&m='.$mobile.'&c='.'【'.$smsset['smsbao_sign'].'】'.$params;
 
            $res file_get_contents($url);
 
            if ($res != 0) {
                return array('status' => $res'message' => $results[$res]);
            }
 
        }
            
            if ($template['type'] == 'dayu'
            {
                include_once EWEI_SHOPV2_VENDOR . 'dayu/TopSdk.php';
                $dayuClient new TopClient();
                $dayuClient->appkey = $smsset['dayu_key'];
                $dayuClient->secretKey = $smsset['dayu_secret'];
                $dayuRequest new AlibabaAliqinFcSmsNumSendRequest();
                $dayuRequest->setSmsType('normal');
                $dayuRequest->setSmsFreeSignName($template['smssign']);
                $dayuRequest->setSmsParam($params);
                $dayuRequest->setRecNum('' $mobile);
                $dayuRequest->setSmsTemplateCode($template['smstplid']);
                $dayuResult $dayuClient->execute($dayuRequest);
                $dayuResult = (array$dayuResult;
                if (empty($dayuResult) || !empty($dayuResult['code'])) 
                {
                    return array('status' => 0, 'message' => '短信发送失败(' $dayuResult['sub_msg'] . '/code: ' $dayuResult['code'] . '/sub_code: ' $dayuResult['sub_code'] . ')');
                        
                }
            }
            
            
            
            if ($template['type'] == 'emay'
            {
                include_once EWEI_SHOPV2_VENDOR . 'emay/SMSUtil.php';
                $balance $this->sms_num('emay'$smsset);
                if ($balance <= 0) 
                {
                    return array('status' => 0, 'message' => '短信发送失败(亿美软通余额不足, 当前余额' $balance ')');
                }
                $emayClient new SMSUtil($smsset['emay_url'], $smsset['emay_sn'], $smsset['emay_pw'], $smsset['emay_sk'], array('proxyhost' => $smsset['emay_phost'], 'proxyport' => $smsset['pport'], 'proxyusername' => $smsset['puser'], 'proxypassword' => $smsset['ppw']), $smsset['emay_out'], $smsset['emay_outresp']);
                $emayResult $emayClient->send($mobile'【' $template['smssign'] . '】' $params);
                if (!empty($emayResult)) 
                {
                    return array('status' => 0, 'message' => '短信发送失败(错误信息: ' $emayResult ')');
                }
            }
                                            
            return array('status' => 1);
    }
    public function sms_set() 
    {
        global $_W;
        return pdo_fetch('SELECT * FROM ' . tablename('ewei_shop_sms_set') . ' WHERE uniacid=:uniacid 'array(':uniacid' => $_W['uniacid']));
    }
    public function sms_temp() 
    {
        global $_W;
        $list = pdo_fetchall('SELECT id, `type`, `name` FROM ' . tablename('ewei_shop_sms') . ' WHERE status=1 and uniacid=:uniacid 'array(':uniacid' => $_W['uniacid']));
        foreach ($list as $i => &$item 
        {
            if ($item['type'] == 'juhe'
            {
                $item['name'] = '[聚合]' $item['name'];
            }
            else if ($item['type'] == 'dayu'
            {
                $item['name'] = '[大于]' $item['name'];
            }
            else if ($item['type'] == 'emay'
            {
                $item['name'] = '[亿美]' $item['name'];
            }
        }
        unset($item);
        return $list;
    }
    public function sms_num($type$smsset = NULL) 
    {
        if (empty($type)) 
        {
            return NULL;
        }
        if (empty($smsset) || !is_array($smsset)) 
        {
            $smsset $this->sms_set();
        }
        if ($type == 'emay'
        {
            include_once EWEI_SHOPV2_VENDOR . 'emay/SMSUtil.php';
            $emayClient new SMSUtil($smsset['emay_url'], $smsset['emay_sn'], $smsset['emay_pw'], $smsset['emay_sk'], array('proxyhost' => $smsset['emay_phost'], 'proxyport' => $smsset['pport'], 'proxyusername' => $smsset['puser'], 'proxypassword' => $smsset['ppw']), $smsset['emay_out'], $smsset['emay_outresp']);
            $num $emayClient->getBalance();
            if (!empty($smsset['emay_warn']) && !empty($smsset['emay_mobile']) && ($num $smsset['emay_warn']) && (($smsset['emay_warn_time'] + (60 * 60 * 24)) < time())) 
            {
                $emayClient new SMSUtil($smsset['emay_url'], $smsset['emay_sn'], $smsset['emay_pw'], $smsset['emay_sk'], array('proxyhost' => $smsset['emay_phost'], 'proxyport' => $smsset['pport'], 'proxyusername' => $smsset['puser'], 'proxypassword' => $smsset['ppw']), $smsset['emay_out'], $smsset['emay_outresp']);
                $emayResult $emayClient->send($smsset['emay_mobile'], '【系统预警】' '您的亿美软通SMS余额为:' $num ',低于预警值:' $smsset['emay_warn'] . ' (24小时内仅通知一次)');
                if (empty($emayResult)) 
                {
                        pdo_update('ewei_shop_sms_set'array('emay_warn_time' => time()), array('id' => $smsset['id']));
                }
            }
            return $num;
        }
    }
    protected function sms_verify($tplid$smsset
    {
        global $_W;
        $template = pdo_fetch('SELECT * FROM ' . tablename('ewei_shop_sms') . ' WHERE id=:id and uniacid=:uniacid 'array(':id' => $tplid':uniacid' => $_W['uniacid']));
        $template['data'] = iunserializer($template['data']);
        if (empty($template)) 
        {
                return array('status' => 0, 'message' => '模板不存在!');
        }
        if (empty($template['status'])) 
        {
                return array('status' => 0, 'message' => '模板未启用!');
        }
        if (empty($template['type'])) 
        {
                return array('status' => 0, 'message' => '模板类型错误!');
        }
        if ($template['type'] == 'juhe'
        {
            if (empty($smsset['juhe'])) 
            {
                return array('status' => 0, 'message' => '未开启聚合数据!');
            }
            if (empty($smsset['juhe_key'])) 
            {
                return array('status' => 0, 'message' => '未填写聚合数据Key!');
            }
            if (empty($template['data']) || !is_array($template['data'])) 
            {
                return array('status' => 0, 'message' => '模板类型错误!');
            }
        }
        else if ($template['type'] == 'dayu'
        {
            if (empty($smsset['dayu'])) 
            {
                return array('status' => 0, 'message' => '未开启阿里大于!');
            }
            if (empty($smsset['dayu_key'])) 
            {
                return array('status' => 0, 'message' => '未填写阿里大于Key!');
            }
            if (empty($smsset['dayu_secret'])) 
            {
                return array('status' => 0, 'message' => '未填写阿里大于Secret!');
            }
            if (empty($template['data']) || !is_array($template['data'])) 
            {
                return array('status' => 0, 'message' => '模板类型错误!');
            }
            if (empty($template['smssign'])) 
            {
                return array('status' => 0, 'message' => '未填写阿里大于短信签名!');
            }
        }
        else if ($template['type'] == 'emay'
        {
            if (empty($smsset['emay'])) 
            {
                return array('status' => 0, 'message' => '未开启亿美软通!');
            }
            if (empty($smsset['emay_url'])) 
            {
                return array('status' => 0, 'message' => '未填写亿美软通网关!');
            }
            if (empty($smsset['emay_sn'])) 
            {
                return array('status' => 0, 'message' => '未填写亿美软通序列号!');
            }
            if (empty($smsset['emay_pw'])) 
            {
                return array('status' => 0, 'message' => '未填写亿美软通密码!');
            }
            if (empty($smsset['emay_sk'])) 
            {
                return array('status' => 0, 'message' => '未填写亿美软通SessionKey!');
            }
            if (empty($template['smssign'])) 
            {
                return array('status' => 0, 'message' => '未填写亿美软通短信签名!');
            }
        }else if($template['type'] == 'smsbao'){
            if (empty($smsset['smsbao'])) {
                return array('status' => 0, 'message' => '未开启短信宝!');
            }
            if (empty($smsset['smsbao_key'])) {
                return array('status' => 0, 'message' => '未填写短信宝帐号!');
            }
            if (empty($smsset['smsbao_secret'])) {
                return array('status' => 0, 'message' => '未填写短信宝密码!');
            }
            if (empty($smsset['smsbao_sign'])) {
                return array('status' => 0, 'message' => '未填写短信宝签名!');
            }
        }
            return $template;
    }
    protected function sms_data($type$data$replace$template
    {
        if ($type == 'smsbao') {
            $tempdata $template['content'];
            foreach ($data as $key => $value 
            {        
                $tempdata str_replace("{".$key."}", trim($value), $tempdata);
            }
            $result $tempdata;
 
        }
 
        if ($replace
        {
            if ($type == 'emay'
            {
                $tempdata $template['content'];
                foreach ($data as $key => $value 
                {
                    $tempdata str_replace('[' $key ']'$value$tempdata);
                }
                $data $tempdata;
            }
            else
            {
                $tempdata = iunserializer($template['data']);
                foreach ($tempdata as &$td 
                {
                    foreach ($data as $key => $value 
                    {
                        $td['data_shop'] = str_replace('[' $key ']'$value$td['data_shop']);
                    }
                }
                unset($td);
                $newdata array();
                foreach ($tempdata as $td 
                {
                    $newdata[$td['data_temp']] = $td['data_shop'];
                }
                $data $newdata;
            }
        }
        if ($type == 'juhe'
        {
            $result '';
            $count count($data);
            $i = 0;
            foreach ($data as $key => $value 
            {
                if ((0 < $i) && ($i $count)) 
                {
                        $result .= '&';
                }
                $result .= '#' $key '#=' $value;
                ++$i;
            }
        }
        else if ($type == 'dayu'
        {
            $result = json_encode($data);
        }
        else if ($type == 'emay'
        {
            $result $data;
        }
            return $result;
    }
    protected function http_post($url$postData
    {
        $postData = http_build_query($postData);
        $options array'http' => array('method' => 'POST''header' => 'Content-type:application/x-www-form-urlencoded''content' => $postData'timeout' => 15 * 60) );
        $context = stream_context_create($options);
        $result file_get_contents($url, false, $context);
        if (!is_array($result)) 
        {
            $result = json_decode($result, true);
        }
        return $result;
    }
    public function callsms(array $params
    {
        global $_W;
        $tag = ((isset($params['tag']) ? $params['tag'] : ''));
        $datas = ((isset($params['datas']) ? $params['datas'] : array()));
        $tm $_W['shopset']['notice'];
        if (empty($tm)) 
        {
            $tm = m('common')->getSysset('notice');
        }
        $smsid $tm[$tag '_sms'];
        $smsclose $tm[$tag '_close_sms'];
        if (!empty($smsid) && empty($smsclose) && !empty($params['mobile'])) 
        {
            $sms_data array();
            foreach ($datas as $i => $value 
            {
                $sms_data[$value['name']] = $value['value'];
            }
            $this->send($params['mobile'], $smsid$sms_data);
        }
    }
}
?>

2。打开项目/core/mobile/account/index.php文件,修改发送内容参数:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
public function set()
{
    global $_W;
    global $_GPC;
    $item = pdo_fetch('SELECT * FROM ' . tablename('ewei_shop_sms_set') . ' WHERE uniacid=:uniacid 'array(':uniacid' => $_W['uniacid']));
    if ($_W['ispost']) {
           $arr array('juhe' => intval($_GPC['juhe']), 'juhe_key' => trim($_GPC['juhe_key']), 'dayu' => intval($_GPC['dayu']), 'dayu_key' => trim($_GPC['dayu_key']), 'dayu_secret' => trim($_GPC['dayu_secret']), 'emay' => intval($_GPC['emay']), 'emay_url' => trim($_GPC['emay_url']), 'emay_sn' => trim($_GPC['emay_sn']), 'emay_pw' => trim($_GPC['emay_pw']), 'emay_sk' => trim($_GPC['emay_sk']), 'emay_phost' => trim($_GPC['emay_phost']), 'emay_pport' => intval($_GPC['emay_pport']), 'emay_puser' => trim($_GPC['emay_puser']), 'emay_ppw' => trim($_GPC['emay_ppw']), 'emay_out' => intval($_GPC['emay_out']), 'emay_outresp' => (empty($_GPC['emay_outresp']) ? 30 : intval($_GPC['emay_outresp'])), 'emay_warn' => intval($_GPC['emay_warn']), 'emay_mobile' => intval($_GPC['emay_mobile']), 'smsbao' => intval($_GPC['smsbao']), 'smsbao_key' => trim($_GPC['smsbao_key']), 'smsbao_secret' => trim($_GPC['smsbao_secret']), 'smsbao_sign' => trim($_GPC['smsbao_sign']));
 
            if (empty($item)) {
                $arr['uniacid'] = $_W['uniacid'];
                pdo_insert('ewei_shop_sms_set'$arr);
                $id = pdo_insertid();
            }else {
                pdo_update('ewei_shop_sms_set'$arrarray('id' => $item['id'], 'uniacid' => $_W['uniacid']));
            }
 
            show_json(1);
    }
 
 
    include $this->template();
}

4。 修改后台的模版文件,打开项目/template/web/sysset/sms/set.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
<div class="form-group-title">短信宝<kbd>推荐</kbd>
    <small style="padding-left:10px;"><a target="_blank" href="http://www.smsbao.com">立即申请</a></small>
    <span class="pull-right">
        <input type="hidden" value="<?php echo $item['smsbao'];?>" name="smsbao" />
        <input class="js-switch small" type="checkbox" <?php if(!empty($item['smsbao'])) {?>checked<?php  }?>/>
    </span>
</div>
<div class=" sms-smsbao" style="<?php  if(empty($item['smsbao'])) { ?>display: none;<?php  } ?>">
    <div class="form-group">
        <label class="col-sm-2 control-label must">短信宝帐号</label>
        <div class="col-sm-9 col-xs-12">
            <input type="text" name="smsbao_key" class="form-control valid" value="<?php  echo $item['smsbao_key'];?>" data-rule-required="true">
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label must">短信宝密码</label>
        <div class="col-sm-9 col-xs-12">
            <input type="text" name="smsbao_secret" class="form-control valid" value="<?php  echo $item['smsbao_secret'];?>" data-rule-required="true">
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label must">短信宝签名</label>
        <div class="col-sm-9 col-xs-12">
            <input type="text" name="smsbao_sign" class="form-control valid" value="<?php  echo $item['smsbao_sign'];?>" data-rule-required="true">
        </div>
    </div>
</div>

打开项目/template/web/sysset/sms/temp/post.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
104
105
<form {ife 'sysset.sms.temp' $item}action="" method="post"{/if} class="form-horizontal form-validate" enctype="multipart/form-data">
    <input type="hidden" name="template" value="{if !empty($item)}{$item['template']}{else}1{/if}" />
    <div class="form-group">
        <label class="col-sm-2 control-label {ifp 'sysset.sms.temp.edit'}must{/if}" >模板名称</label>
        <div class="col-sm-9 col-xs-12">
            {ife 'sysset.sms.temp' $item}
            <input type="text" name="name" class="form-control" value="{$item['name']}" placeholder="模版名称,例:订单创建成功通知(自定义)" data-rule-required='true' />
            {else}
            <div class='form-control-static'>{$item['name']}</div>
            {/if}
        </div>
    </div>
    <div class="form-group">
        <label class="col-sm-2 control-label {ifp 'sysset.sms.temp.edit'}must{/if}">服务商</label>
        <div class="col-sm-9 col-xs-12">
            {ife 'sysset.sms.temp' $item}
            {if !empty($smsset['juhe']) || (!empty($item) && $item['type']=='juhe')}<label class="radio-inline"><input type="radio" class="sms-type" data-template="1" name="type" value="juhe" {if $item['type']=='juhe' || empty($item)}checked{/if} {if !empty($item['type'])}disabled{/if}> 聚合数据</label>{/if}
            {if !empty($smsset['dayu']) || (!empty($item) && $item['type']=='dayu')}<label class="radio-inline"><input type="radio" class="sms-type" data-template="1" name="type" value="dayu" {if $item['type']=='dayu'} checked{/if} {if !empty($item['type'])}disabled{/if}> 阿里大于</label>{/if}
            {if !empty($smsset['emay']) || (!empty($item) && $item['type']=='emay')}<label class="radio-inline"><input type="radio" class="sms-type" data-template="0" name="type" value="emay" {if $item['type']=='emay'} checked{/if} {if !empty($item['type'])}disabled{/if}> 亿美软通</label>{/if}
            {if !empty($smsset['smsbao']) || (!empty($item) && $item['type']=='smsbao')}<label class="radio-inline"><input type="radio" class="sms-type" data-template="0" name="type" value="smsbao" {if $item['type']=='smsbao'} checked{/if} {if !empty($item['type'])}disabled{/if}> 短信宝(请参考已有的短信宝模板)</label>{/if}
            <div class="help-block">注意:选择短信服务商请先至 <a href="{php echo webUrl('sysset/sms/set')}" target="_blank">短信接口设置</a> 页面设置好短信服务商的接口信息。(<span class="text-danger">保存后不可修改</span> )</div>
            {else}
            <div class='form-control-static'>{if $item['type']=='juhe'}聚合数据{elseif $item['type']=='dayu'}阿里大于{elseif $item['type']=='smsbao'}短信宝{elseif $item['type']=='emay'}亿美软通{/if}</div>
            {/if}
        </div>
    </div>
    <div class="form-group sms-template-1" style="{if !empty($item['template']) || empty($item)}display:block;{else}display:none;{/if}">
        <label class="col-sm-2 control-label {ifp 'sysset.sms.temp.edit'}must{/if}" >模板ID</label>
        <div class="col-sm-9 col-xs-12">
            {ife 'sysset.sms.temp' $item}
            <input type="text" name="smstplid" class="form-control" value="{$item['smstplid']}" placeholder="短信模板ID,例:1234(短信服务商提供的模板ID)" data-rule-required='true' />
            <div class="help-block">服务商提供的模板ID</div>
            {else}
            <div class='form-control-static'>{$item['smstplid']}</div>
            {/if}
        </div
    </div>
 
    <div class="form-group sms-template-sign" style="{if $item['type']=='dayu' || $item['type']=='emay'}display:block;{else}display:none;{/if}">
        <label class="col-sm-2 control-label {ifp 'sysset.sms.temp.edit'}must{/if}" >短信签名</label>
        <div class="col-sm-9 col-xs-12">
        {ife 'sysset.sms.temp' $item}
        <input type="text" name="smssign" class="form-control" value="{$item['smssign']}" placeholder="" data-rule-required='true' />
        <div class="help-block">请填写短信签名(如果服务商是大于请填写审核成功的签名)</div>
        {else}
        <div class='form-control-static'>{$item['smssign']}</div>
        {/if}
        </div>
    </div>
 
    <div class="form-group sms-template-0" style="{if empty($item['template']) && !empty($item)}display:block;{else}display:none;{/if}">
        <label class="col-sm-2 control-label {ifp 'sysset.sms.temp.edit'}must{/if}" >短信内容</label>
        <div class="col-sm-9 col-xs-12">
        {ife 'sysset.sms.temp' $item}
        <textarea class="form-control" name="content" placeholder="请填写短信内容" rows="4" style="resize: none" data-rule-required="true">{$item['content']}</textarea>
        {else}
        <div class='form-control-static'>{$item['content']}</div>
        {/if}
        </div>
    </div>
 
    <div class="form-group splitter sms-template-1"></div>
    <div id="datas" class="sms-template-1" style="{if !empty($item['template']) || empty($item)}display:block;{else}display:none;{/if}">
        {if empty($item['data'])}
        {template 'sysset/sms/temp/tpl'}
        {else}
        {loop $item['data'] $data}
        {template 'sysset/sms/temp/tpl'}
        {/loop}
        {/if}
    </div>
    {ife 'sysset.sms.temp' $item}
    <div class="form-group sms-template-1" style="{if !empty($item['template']) || empty($item)}display:block;{else}display:none;{/if}">
        <label class="col-sm-2 control-label"></label>
        <div class="col-sm-9 col-xs-12">
            <a class="btn btn-default btn-add-type" href="javascript:;" onclick="addType();"><i class="fa fa-plus" title=""></i> 增加一条数据值</a>
        </div>
    </div>
    {/if}
 
    <div class="form-group">
        <label class="col-sm-2 control-label {ifp 'sysset.sms.temp.edit'}must{/if}">状态</label>
        <div class="col-sm-9 col-xs-12">
            {ife 'sysset.sms.temp' $item}
                <label class="radio-inline"><input type="radio" name="status" value="0" {if empty($item['status'])}checked{/if}> 禁用</label>
                <label class="radio-inline"><input type="radio" name="status" value="1" {if !empty($item['status'])}checked{/if}> 启用</label>
                <div class="help-block">关闭后将不能调用</div>
            {else}
                <div class='form-control-static'>{if empty($item['status'])}禁用{else}启用{/if}</div>
            {/if}
        </div>
    </div>
    <div class="form-group"></div>
    <div class="form-group">
        <label class="col-sm-2 control-label" ></label>
        <div class="col-sm-9 col-xs-12">
            {ife 'sysset.sms.temp' $item}
                <input type="submit"  value="提交" class="btn btn-primary"  />
            {/if}
            {ifp 'sysset.sms.temp.main'}
                <input type="button" name="back" onclick='history.back()' {ifp 'sysset.sms.temp.add|sysset.sms.temp.edit'}style='margin-left:10px;'{/if} value="返回列表" class="btn btn-default" />
            {/if}
        </div>
    </div>
</form>

打开项目/template/web/sysset/sms/temp/index.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
{template '_header'}
    <div class="page-heading"
        <span class='pull-right'>
            {ifp 'sysset.sms.temp.add'}
                <a class='btn btn-primary btn-sm' href="{php echo webUrl('sysset/sms/temp/add')}"><i class="fa fa-plus"></i> 添加新模板</a>
            {/if}
        </span>
        <h2>短信消息库管理</h2>
    </div>
 
    <form action="./index.php" method="get" class="form-horizontal form-search" role="form">
        <input type="hidden" name="c" value="site"/>
        <input type="hidden" name="a" value="entry"/>
        <input type="hidden" name="m" value="ewei_shopv2"/>
        <input type="hidden" name="do" value="web"/>
        <input type="hidden" name="r" value="sysset.sms.temp"/>
        <div class="page-toolbar row m-b-sm m-t-sm">
            <div class="col-sm-4">
                <div class="input-group-btn">
                    <button class="btn btn-default btn-sm" type="button" data-toggle='refresh'><i class='fa fa-refresh'></i></button>
                    {ifp 'sysset.sms.temp.edit'}
                    <button class="btn btn-default btn-sm dropdown-toggle" type="button" data-toggle='batch' data-confirm="确认要启用?" data-href="{php echo webUrl('sysset/sms/temp/status', array('status'=>1))}"><i class='fa fa fa-circle'></i> 启用
                    </button>
                    <button class="btn btn-default btn-sm dropdown-toggle" type="button" data-toggle='batch' data-confirm="确认要禁用?" data-href="{php echo webUrl('sysset/sms/temp/status', array('status'=>0))}"><i class='fa fa fa-circle-o'></i> 禁用
                    </button>
                    {/if}
                    {ifp 'sysset.sms.temp.delete'}
                    <button class="btn btn-default btn-sm dropdown-toggle" type="button" data-toggle='batch-remove' data-confirm="确认要删除?" data-href="{php echo webUrl('sysset/sms/temp/delete')}"><i class='fa fa-trash'></i> 删除
                    </button>
                    {/if}
                </div>
            </div>
            <div class="col-sm-7 pull-right">
                <select name="type" class="form-control input-sm select-sm" style="width:120px;">
                    <option value="" {if $_GPC['type']==''}selected{/if}>服务商</option>
                    <option value="juhe" {if $_GPC['type']=='juhe'}selected{/if}>聚合数据</option>
                    <option value="dayu" {if $_GPC['type']=='dayu'}selected{/if}>阿里大于</option>
                    <option value="emay" {if $_GPC['type']=='emay'}selected{/if}>亿美软通</option>
                    <option value="smsbao" {if $_GPC['type']=='smsbao'}selected{/if}>短信宝</option>
                </select>
                <select name="status" class="form-control input-sm select-sm" style="width:80px;">
                    <option value="" {if $_GPC['status']==''}selected{/if}>状态</option>
                    <option value="0" {if $_GPC['status']=='0'}selected{/if}>关闭</option>
                    <option value="1" {if $_GPC['status']=='1'}selected{/if}>开启</option>
                </select>
                <div class="input-group">
                    <input type="text" class="input-sm form-control" name='keyword' value="{$_GPC['keyword']}" placeholder="请输入关键词"> <span class="input-group-btn">
                    <button class="btn btn-sm btn-primary" type="submit"> 搜索</button> </span>
                </div>
            </div>
        </div>
    </form>
 
    {if count($list)>0}
        <table class="table table-responsive table-hover">
            <thead>
                <tr>
                    <th style="width:25px;"><input type='checkbox'/></th>
                    <th>模板名称</th>
                    <th style="width: 100px; text-align: center;">服务商</th>
                    <th style="width: 80px; text-align: center;">状态</th>
                    {ifp 'sysset.sms.temp.testsend'}
                    <th style="width: 100px; text-align: center;">测试发送</th>
                    {/if}
                    <th style="width: 150px;">操作</th>
                </tr>
            </thead>
            <tbody>
                {loop $list $item}
                <tr>
                    <td>
                        <input type='checkbox' value="{$item['id']}"/>
                    </td>
                    <td>{$item['name']}</td>
                    <td style="text-align: center;">
                        {if $item['type']=='juhe'}
                        <span class="label label-primary">聚合数据</span>
                        {elseif $item['type']=='dayu'}
                        <span class="label label-success">阿里大于</span>
                        {elseif $item['type']=='smsbao'}
                        <span class="label label-success">短信宝</span>
                        {elseif $item['type']=='emay'}
                        <span class="label label-warning">亿美软通</span>
                        {/if}
                    </td>
                    <td style="text-align: center;">
                        <span class="label
                            {if !empty($item['status'])}label-success{else}label-default{/if}"
                            {ifp 'sysset.sms.temp.edit'}
                            data-toggle="ajaxSwitch"
                            data-confirm = "确认{if !empty($item['status'])}关闭{else}开启{/if}吗?"
                            data-switch-value="{$item['status']}"
                            data-switch-value0="0|关闭|label label-default|{php echo webUrl('sysset/sms/temp/status',array('status'=>1,'id'=>$item['id']))}"
                            data-switch-value1="1|开启|label label-success|{php echo webUrl('sysset/sms/temp/status',array('status'=>0,'id'=>$item['id']))}"
                            {/if}>
                            {if !empty($item['status'])}开启{else}关闭{/if}
                        </span>
                    </td>
                    {ifp 'sysset.sms.temp.testsend'}
                    <td style="text-align: center;">
                    <a class="btn btn-primary btn-sm" data-toggle="ajaxModal" href="{php echo webUrl('sysset/sms/temp/testsend', array('id'=>$item['id']))}"><i class="fa fa-paper-plane-o"></i> 发送</a>
                    </td>
                    {/if}
                    <td>
                    {ifp 'sysset.sms.temp.edit|sysset.sms.temp.view'}
                    <a class='btn btn-default  btn-sm' href="{php echo webUrl('sysset/sms/temp/edit', array('id' => $item['id']))}"><i class='fa fa-edit'></i> {ifp 'sysset.sms.temp.edit'}编辑{else}查看{/if}</a>
                    {/if}
                    {ifp 'sysset.sms.temp.delete'}
                    <a class='btn btn-default  btn-sm' data-toggle='ajaxRemove' href="{php echo webUrl('sysset/sms/temp/delete', array('id' => $item['id']))}" data-confirm="确认删除此模板吗?"><i class='fa fa-trash'></i> 删除</a>
                    {/if}
                    </td>
                </tr>
                {/loop}
            </tbody>
        </table>
        {$pager}
        {else}
        <div class='panel panel-default'>
            <div class='panel-body' style='text-align: center;padding:30px;'>
            暂时没有任何短信模板!
            </div>
        </div>
        {/if}
    </div>
{template '_footer'}

以上修改完成之后我们需要在数据库中添加几条数据,我们需要在根目录建立两个文件,smsbao_install.sql,代码如下:

?
1
2
3
4
alter table `ims_ewei_shop_sms_set` add `smsbao` tinyint(3) NOT NULL DEFAULT '0' 
alter table `ims_ewei_shop_sms_set` add `smsbao_key` varchar(255) NOT NULL DEFAULT ''
alter table `ims_ewei_shop_sms_set` add `smsbao_secret` varchar(255) NOT NULL DEFAULT ''
alter table `ims_ewei_shop_sms_set` add `smsbao_sign` varchar(255) NOT NULL DEFAULT ''

第二个文件smsbao_install.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
<?php
 
 
define('IN_SYS', true);
require './framework/bootstrap.inc.php';
require './data/config.php';
 
$mysql_server_name $config['db']['host'];
$mysql_username $config['db']['username'];
$mysql_password $config['db']['password'];
$mysql_database $config['db']['database'];
$mysql_tablepre $config['db']['tablepre'];
 
$conn=mysql_connect($mysql_server_name,$mysql_username,$mysql_passwordor die("error connecting") ;
mysql_query("set names 'utf8'");
mysql_select_db($mysql_database);
 
$newsql = sreadfile("smsbao_install.sql");
 
if ($mysql_tablepre != 'ims_') {
    $newsql str_replace('ims_'$mysql_tablepre$newsql);
}
 
 
$sqls explode(";"$newsql);
 
foreach ($sqls as $sql) {
    $sql = trim($sql);
    if (empty($sql)) {
        continue;
    }
    if(!$query =mysql_query($sql)) {
        echo "执行sql语句成功 ".mysql_error();
        exit();
    }
}
 
echo "<h4>人人店短信宝短信插件安装成功,请删除此文件。</h4>";
 
function sreadfile($filename) {
    $content '';
    if(function_exists('file_get_contents')) {
            @$content file_get_contents($filename);
    else {
            if(@$fp fopen($filename'r')) {
                    @$content fread($fpfilesize($filename));
                    @fclose($fp);
            }
    }
    return $content;
}
 
?>

注:如果你的人人店版本为3.5.0的话,或者有PC端的,那么还需要修改一个文件,在项目/plugin/pc/core/mobile/account/index.php,修改verifycode方法,代码如下:

?
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
 public function verifycode() 
        {
                global $_W;
                global $_GPC;
                $mobile = trim($_GPC['mobile']);
                $temp = trim($_GPC['temp']);
                if (empty($mobile) || empty($temp)) 
                {
                        show_json(0, '参数错误');
                }
                $data = m('common')->getSysset('wap');
                $sms_id $data[$temp];
                if (empty($sms_id)) 
                {
                        show_json(0, '短信发送失败(NOSMSID)');
                }
                $key '__ewei_shop_member_verifycodesession_' $_W['uniacid'] . '_' $mobile;
                @session_start();
                $code = random(5, true);
                $shopname $_W['shopset']['shop']['name'];
                $ret = com('sms')->send($mobile$sms_idarray('$code' => $code,'$mobile' => $mobile'$shopname' => (!(empty($shopname)) ? $shopname '商城名称')));
                if ($ret['status']) 
                {
                        $_SESSION[$key] = $code;
                        $_SESSION['verifycodesendtime'] = time();
                        show_json(1, "短信发送成功");
                }
                show_json(0, $ret['message']);
        }

至此短信宝短信接口已经开发完成了,在短信宝官网中也提供了插件下载地址:http://www.smsbao.com/plugin/153.html 小伙伴们可以对着短信宝短信插件,来看我这篇文章,这样会更直观一些。

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

最新更新

电商类

CMS类

微信类

文章标签