DSKMS具備圖文、音頻、視頻等多種內容形式,支持專欄聚合優質內容。通過內置的營銷體系(會員、搶購、分銷、廣告)讓您的品牌深入人心,輕松將知識變現。小編帶著大家一起開發DSKMS-V3.1.2的短信寶插件接口。我們使用的短信接口是我們短信寶短信群發平臺的短信接口,我們短信寶短信群發平臺非常穩定,發送速度快,注冊就送測試短信,推薦大家使用。
一:首先執行以下sql增加短信寶參數配置
|
1
2
3
|
INSERT INTO `ds_config` (`code`, `value`, `remark`) VALUES('smscf_smsbao_username', '', '短信寶賬號'),('smscf_smsbao_key', '', '短信寶ApiKey'); |
二:接著打開項目app\admin\controller\Message.php,替換mobile、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
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
|
/** * 短信平臺設置 */ public function mobile() { $config_model = model('config'); if (!(request()->isPost())) { $list_config = rkcache('config', true); $smscf_num = ''; if($list_config['smscf_type']=='wj' && !empty($list_config['smscf_wj_username'])&&!empty($list_config['smscf_wj_key'])){ //如果配置了信息,可以查看具體可用短信條數 $smscf_num = http_request(' } View::assign('smscf_num', $smscf_num); View::assign('list_config', $list_config); $this->setAdminCurItem('mobile'); return View::fetch('mobile'); } else { $update_array = array(); $update_array['smscf_type'] = input('post.smscf_type'); $update_array['smscf_ali_id'] = input('post.smscf_ali_id'); $update_array['smscf_ali_secret'] = input('post.smscf_ali_secret'); $update_array['smscf_ten_id'] = input('post.smscf_ten_id'); $update_array['smscf_ten_secret'] = input('post.smscf_ten_secret'); $update_array['smscf_sign'] = input('post.smscf_sign'); $update_array['smscf_wj_username'] = input('post.smscf_wj_username'); $update_array['smscf_wj_key'] = input('post.smscf_wj_key'); $update_array['sms_register'] = input('post.sms_register'); $update_array['sms_login'] = input('post.sms_login'); $update_array['sms_password'] = input('post.sms_password'); $update_array['smscf_smsbao_username'] = input('post.smscf_smsbao_username'); $update_array['smscf_smsbao_key'] = input('post.smscf_smsbao_key'); $result = $config_model->editConfig($update_array); if ($result === true) { $this->log(lang('ds_edit') . lang('message_mobile'), 1); $this->success(lang('ds_common_save_succ')); } else { $this->log(lang('ds_edit') . lang('message_mobile'), 0); $this->error(lang('ds_common_save_fail')); } } } /** * 測試手機短信發送 * * @param * @return */ 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'); $smsbao_test_content = input('param.smsbao_test_content'); $smsbao_user = input('param.smscf_smsbao_username'); // 這里填寫用戶名 $smsbao_apikey = input('param.smscf_smsbao_key'); // 這里填接口安全密鑰 $user_id = urlencode(input('param.smscf_wj_username')); // 這里填寫用戶名 $key = urlencode(input('param.smscf_wj_key')); // 這里填接口安全密鑰 $smscf_sign = input('param.smscf_sign'); config('ds_config.smscf_smsbao_username', $smsbao_user); config('ds_config.smscf_smsbao_key', $smsbao_apikey); 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); $smslog_param=array( 'ali_template_code'=>$ali_template_code, 'ali_template_param'=>array(), 'ten_template_code' => $ten_template_code, 'ten_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; } |
三:接著打開項目app\admin\lang\zh-cn\message.lang.php,在94行左右增加以下代碼
|
1
2
3
|
$lang['smscf_type_smsbao'] = '短信寶';$lang['smscf_smsbao_username'] = '短信寶賬號';$lang['smscf_smsbao_key'] = '短信寶ApiKey'; |
四:接著打開項目app\admin\view\message\mobile.html,替換24~65行代碼
|
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
|
<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_wj" {if $list_config.smscf_type!='wj'}style="display:none"{/if}> <td class="required w120">{$Think.lang.smscf_wj_username}</td> <td class="vatop rowform"> <input type="text" name="smscf_wj_username" id="smscf_wj_username" value="{$list_config.smscf_wj_username}" class="w200"/> </td> <td class="vatop tips"></td> </tr> <tr class="noborder smscf_type_wj" {if $list_config.smscf_type!='wj'}style="display:none"{/if}> <td class="required w120">{$Think.lang.smscf_wj_key}</td> <td class="vatop rowform"> <input type="text" name="smscf_wj_key" id="smscf_wj_key" value="{$list_config.smscf_wj_key}" 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_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"/> </td> <td class="vatop tips"></td> </tr> |
五:接著替換app\admin\view\message\mobile.html中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
|
$(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(), 'smsbao_test_content':$('#smsbao_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(), '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() } }) }); |
六:接著打開項目extend\sendmsg\Sms.php,替換send,增加smsbao_send方法
|
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
|
/* * 發送手機短信 * @param unknown $mobile 手機號 * @param unknown $smslog_param 短信參數 */ public function send($mobile, $smslog_param) { if(config('ds_config.smscf_type')=='wj'){ $content=$smslog_param['message']; return $this->mysend_sms($mobile, $content); }elseif(config('ds_config.smscf_type')=='smsbao'){ $content=$smslog_param['message']; return $this->smsbao_send($mobile, $content); }elseif(config('ds_config.smscf_type')=='ali'){ return $this->ali_send($mobile, $smslog_param); }elseif(config('ds_config.smscf_type')=='ten'){ return $this->ten_send($mobile, $smslog_param); }else{ return ds_callback(false,lang('param_error')); } } /* 您驗證碼是:{$verify_code} http://api.smsbao.com/sms?u=本站用戶名&p=接口安全秘鑰&m=手機號碼E&c=短信內容 */ public function smsbao_send($mobile, $content) { $statusStr = array( "0" => "短信發送成功", "-1" => "參數不全", "-2" => "服務器空間不支持,請確認支持curl或者fsocket,聯系您的空間商解決或者更換空間!", "30" => "密碼錯誤", "40" => "賬號不存在", "41" => "余額不足", "42" => "帳戶已過期", "43" => "IP地址限制", "50" => "內容含有敏感詞" ); $user_name = config('ds_config.smscf_smsbao_username'); // 這里填寫用戶名 $key = config('ds_config.smscf_smsbao_key'); // 這里填接口安全密鑰 if (!$mobile || !$content || !$user_name || !$key) return false; if (is_array($mobile)) { $mobile = implode(",", $mobile); } $mobile=urlencode($mobile); $content=urlencode($content); if (function_exists('file_get_contents')) { $res = file_get_contents($url); } else { $ch = curl_init(); $timeout = 5; curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout); $res = curl_exec($ch); curl_close($ch); } //短信發送后返回值 說明 $message = $statusStr[$res]; if($res == '0'){ return ds_callback(true); }else{ return ds_callback(false,$message); } } |
好了經過以上的添加,短信寶的短信平臺已經替換成功了,可以正常使用了

報備一下短信寶的VIP模板,這樣就可以走短信寶的優質通道了,即便遇到敏感文字我們都不會人工審核,短信內容3~5秒就可送達。
另外:我們已經開發好完整的DSKMS-內容視頻付費系統短信寶插件,點擊此鏈接 下載及查看安裝流程。
最新更新
電商類
CMS類
微信類