DSSHOP是基于DSMall(B2B2C商城)分离出来的单店铺B2C商城系统,基于国内优秀开源框架THinkPHP、打造出的一套开源的B2C电子商务系统。今天小编就以DSShop单店铺3.1版本的替换短信接口为例告诉大家如何进行二次开发,使用的短信接口是我们短信宝短信群发平台的接口,我们短信宝短信群发平台非常稳定,发送速度快,注册就送测试短信,推荐大家使用。
覆盖之后执行以下sql,表名`ds_config` 根据自定义前缀进行修改:
|
1
|
INSERT INTO `ds_config` ( `code`, `value`, `remark`) VALUES('smscf_smsbao_id', '', '短信宝账号'),('smscf_smsbao_secret', '', '短信宝APIKEY'); |
1.首先我们打开项目app\admin\view\message\mobile.html文件,替换24~50行代码:
|
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
|
<tr> <td class="required w120">{$Think.lang.smscf_type}</td> <td class="vatop rowform"> <select id="smscf_type" name="smscf_type"> <option value="wj" {if $list_config.smscf_type=='wj'}selected{/if}>{$Think.lang.smscf_type_wj}</option> <option value="smsbao" {if $list_config.smscf_type=='smsbao'}selected{/if}>{$Think.lang.smscf_type_smsbao}</option> <option value="ali" {if $list_config.smscf_type=='ali'}selected{/if}>{$Think.lang.smscf_type_ali}</option> <option value="ten" {if $list_config.smscf_type=='ten'}selected{/if}>{$Think.lang.smscf_type_ten}</option> </select> </td> <td class="vatop tips"></td> </tr> <tr class="noborder smscf_type_smsbao" {if $list_config.smscf_type!='smsbao'}style="display:none"{/if}> <td class="required w120">{$Think.lang.smscf_smsbao_username}</td> <td class="vatop rowform"> <input type="text" name="smscf_smsbao_username" id="smscf_smsbao_username" value="{$list_config.smscf_smsbao_username}" class="w200"/> </td> <td class="vatop tips"></td> </tr> <tr class="noborder smscf_type_smsbao" {if $list_config.smscf_type!='smsbao'}style="display:none"{/if}> <td class="required w120">{$Think.lang.smscf_smsbao_key}</td> <td class="vatop rowform"> <input type="text" name="smscf_smsbao_key" id="smscf_smsbao_key" value="{$list_config.smscf_smsbao_key}" class="w200"/> <a href="https://console.smsbao.com/#/register" target="_blank" class="btn btn-blue btn-mini">{$Think.lang.ds_apply}</a> </td> <td class="vatop tips"></td> </tr> |
接着替换script标签代码
|
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
|
<script> $(document).ready(function(){ $('#send_test_mobile').click(function(){ $.ajax({ type:'POST', url:"{:url('Message/mobile_testing')}", data:{ 'smscf_sign':$('#smscf_sign').val(), 'smscf_type':$('#smscf_type').val(), 'smscf_ali_secret':$('#smscf_ali_secret').val(), 'smscf_ali_id':$('#smscf_ali_id').val(), 'ali_template_content':$('#ali_template_content').val(), 'ali_template_param':$('#ali_template_param').val(), 'ali_template_code':$('#ali_template_code').val(), 'smscf_ten_secret':$('#smscf_ten_secret').val(), 'smscf_ten_id':$('#smscf_ten_id').val(), 'ten_template_content':$('#ten_template_content').val(), 'ten_template_param':$('#ten_template_param').val(), 'ten_template_code':$('#ten_template_code').val(), 'mobile_test_content':$('#mobile_test_content').val(), 'smscf_wj_username':$('#smscf_wj_username').val(), 'smscf_wj_key':$('#smscf_wj_key').val(), 'smscf_smsbao_username':$('#smscf_smsbao_username').val(), 'smscf_smsbao_key':$('#smscf_smsbao_key').val(), 'smsbao_test_content':$('#smsbao_test_content').val(), 'mobile_test':$('#mobile_test').val() }, error:function(html){ layer.alert('{$Think.lang.ds_common_op_fail}'); }, success:function(html){ if(html.msg){ layer.alert(html.msg); } }, dataType:'json' }); }); $('#smscf_type').change(function(){ if($(this).val()=='smsbao'){ $('.smscf_type_smsbao').show() $('.smscf_type_ali').hide() $('.smscf_type_wj').hide() $('.smscf_type_ten').hide() } if($(this).val()=='wj'){ $('.smscf_type_ali').hide() $('.smscf_type_wj').show() $('.smscf_type_ten').hide() $('.smscf_type_smsbao').hide() } if($(this).val()=='ali'){ $('.smscf_type_ali').show() $('.smscf_type_wj').hide() $('.smscf_type_ten').hide() $('.smscf_type_smsbao').hide() } if($(this).val()=='ten'){ $('.smscf_type_ali').hide() $('.smscf_type_wj').hide() $('.smscf_type_ten').show() $('.smscf_type_smsbao').hide() } }) });</script> |
2.接着打开项目app\admin\lang\zh-cn\message.lang.php 文件,在67~70行增加以下代码:
|
1
2
3
|
$lang['smscf_type_smsbao'] = '短信宝';$lang['smscf_smsbao_id'] = '短信宝账号';$lang['smscf_smsbao_secret'] = '短信宝APIKEY'; |
3.接着打开项目app\admin\controller\Message.php 文件,替换mobile_testing 方法
|
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
|
public function mobile_testing() { $mobile = input('param.mobile_test'); $content = input('param.mobile_test_content'); $smscf_type = input('param.smscf_type'); $smscf_ali_id = input('param.smscf_ali_id'); $smscf_ali_secret = input('param.smscf_ali_secret'); $ali_template_param=input('param.ali_template_param'); $ali_template_code=input('param.ali_template_code'); $ali_template_content=input('param.ali_template_content'); $smscf_ten_id = input('param.smscf_ten_id'); $smscf_ten_secret = input('param.smscf_ten_secret'); $ten_template_param = input('param.ten_template_param'); $ten_template_code = input('param.ten_template_code'); $ten_template_content = input('param.ten_template_content'); $user_id = urlencode(input('param.smscf_wj_username')); // 这里填写用户名 $key = urlencode(input('param.smscf_wj_key')); // 这里填接口安全密钥 $smsbao_user = input('param.smscf_smsbao_username'); // 这里填写用户名 $smsbao_apikey = input('param.smscf_smsbao_key'); // 这里填接口安全密钥 $smsbao_test_content = input('param.smsbao_test_content'); $smscf_sign = input('param.smscf_sign'); config('ds_config.smscf_type',$smscf_type); config('ds_config.smscf_wj_username',$user_id); config('ds_config.smscf_wj_key',$key); config('ds_config.smscf_ali_id',$smscf_ali_id); config('ds_config.smscf_ali_secret',$smscf_ali_secret); config('ds_config.smscf_ten_id', $smscf_ten_id); config('ds_config.smscf_ten_secret', $smscf_ten_secret); config('ds_config.smscf_sign', $smscf_sign); config('ds_config.smscf_smsbao_username', $smsbao_user); config('ds_config.smscf_smsbao_key', $smsbao_apikey); $smslog_param = array( 'ali_template_code' => $ali_template_code, 'ali_template_param' => array(), 'ten_template_code' => $ten_template_code, 'ten_template_param' => array(), ); $smslog_param=array( 'ali_template_code'=>$ali_template_code, 'ali_template_param'=>array(), ); if($smscf_type=='wj'){ $smslog_param['message']=$content; }else if ($smscf_type == 'smsbao') { $smslog_param['message'] = $smsbao_test_content; }elseif($smscf_type=='ali'){ $param=json_decode(htmlspecialchars_decode($ali_template_param),true); if(!$param){ echo json_encode(array('msg'=>lang('ali_template_param_error')));exit; } $smslog_param['message'] = ds_replace_text(htmlspecialchars_decode($ali_template_content), $param); $smslog_param['ali_template_param']= $param; }elseif ($smscf_type == 'ten') { $param = json_decode(htmlspecialchars_decode($ten_template_param), true); if (!$param) { echo json_encode(array('msg' => lang('ten_template_param_error'))); exit; } $smslog_param['message'] = ds_replace_text(htmlspecialchars_decode($ten_template_content), $param); $smslog_param['ten_template_param'] = $param; }else{ echo json_encode(array('msg' => lang('param_error'))); exit; } $result=model('smslog')->sendSms($mobile, $smslog_param); if ($result['code'] == 10000){ $data['msg'] = '测试手机短信发送成功'; }else{ $data['msg'] = $result['message']; } echo json_encode($data); exit; } |
4.接着打开项目extend\sendmsg\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
|
public function smsbao_send($mobile, $content) { $user_id = config('ds_config.smscf_smsbao_id'); $key = config('ds_config.smscf_smsbao_secret'); if (!$mobile || !$content || !$user_id || !$key) return false; if (is_array($mobile)) { $mobile = implode(",", $mobile); } $mobile=urlencode($mobile); $content=urlencode($content); $url = "http://api.smsbao.com/sms?u=" . $user_id . "&p=" . $key . "&m=" . $mobile . "&c=" . $content; if (function_exists('file_get_contents')) { $res = file_get_contents($url); } else { $ch = curl_init(); $timeout = 5; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); $res = curl_exec($ch); curl_close($ch); } //短信发送后返回值 说明 $statusStr = array( "0" => "短信发送成功", "-1" => "参数不全", "-2" => "服务器空间不支持,请确认支持curl或者fsocket,联系您的空间商解决或者更换空间!", "30" => "密码错误", "40" => "账号不存在", "41" => "余额不足", "42" => "帐户已过期", "43" => "IP地址限制", "50" => "内容含有敏感词" ); $message = $statusStr[$res]; if($res == 0){ return ds_callback(true); }else{ return ds_callback(false,$message); } } |

报备一下短信宝的VIP模板,这样就可以走短信宝的优质通道了,即便遇到敏感文字我们都不会人工审核,短信内容3~5秒就可送达。
另外:我们已经开发好完整的Dsshop商城系统短信宝插件,点击此链接 下载及查看安装流程。
最新更新
电商类
CMS类
微信类