Laysns采用Think+Layui做为技术基础进行开发,采用OOP方式进行基础运行框架搭建,模块化开发方式做为功能开发形式,五年开发经验的团队,勇于创新追求完美的设计理念,被更多的政府机构、教育机构、事业单位、商业企业、个人站长所认可。小编对他还是比较了解的,今天小编就以新增短信接口为例,给大家讲解一下如何进行二次开发,我们今天讲解的是2.54版本,使用的短信接口是我们短信宝短信群发平台的短信接口,我们短信宝短信群发平台的接口非常稳定,发送速度快,注册就送测试短信,推荐大家使用。
打开项目:\application\index\controller\Api.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
|
function send_sms() { $arr = array ( 0=> '发送成功' , 30=> '短信平台密码错误' , 40=> '短信平台账号不存在' , 41=> '短信平台余额不足' , 42=> '短信平台帐户已过期' , 43=> 'IP地址受短信平台限制' , 50=> '内容含有敏感词' , 51=> '手机号码不正确' , -2=> '服务器空间不支持' , -1=> '发送短信参数不全,请联系站长' ); $data = $this ->request->param(); if (!captcha_check(input( 'vercode' ))) { return json( array ( 'code' => -1, 'msg' => '验证码错误' )); } $code =rand(1000,9999); $mobile = $data [ 'mobile' ]; $find = Db::name( 'system' )->field( 'value' )->where( 'name' , 'sms' )->find(); $smsConfig = unserialize( $find [ 'value' ]); $params = explode ( "\n" , $smsConfig [ 'params' ]); $paramArr =[]; foreach ( $params as $v ){ $_arr = explode ( "=" , $v ); $paramArr [ $_arr [0]]= $_arr [1]; } $ip = $this ->request->ip(); $model = new SmsModel(); $where1 [ 'created_at' ]= $where2 [ 'created_at' ]=[ 'gt' , date ( 'Y-m-d' )]; $where1 [ 'mobile' ]= $mobile ; $mobileCount = $model ->where( $where1 )-> count (); if (!isset( $smsConfig [ 'mobile_max' ])){ return json( array ( 'code' => -1, 'msg' => '短信服务配置有误,请联系管理员' )); } $mobileMax = $smsConfig [ 'mobile_max' ]; if ( $mobileCount >= $mobileMax ){ return json( array ( 'code' => -1, 'msg' => '每个手机号每天限制发送' . $mobileMax . '条短信' )); } $where2 [ 'ip' ]=[ 'eq' , $ip ]; $ipCount = $model ->where( $where2 )-> count (); $ipMax = $smsConfig [ 'ip_max' ]; if ( $ipCount >= $ipMax ){ return json( array ( 'code' => -1, 'msg' => '每个IP每天限制发送' . $ipMax . '条短信' )); } //获取结果 $url = $smsConfig [ 'apiurl' ]. "?u=" . $paramArr [ 'u' ]. "&p=" .md5( $paramArr [ 'p' ]). "&m=" . $mobile . "&c=" .urlencode( "【" . $this ->site_config[ 'site_title' ]. "】验证码:" . $code . ",您正在绑定" . $this ->site_config[ 'site_title' ]. "手机号,请5分钟内完成验证。如非本人操作,请忽略本短信。" ); $htd = new Http(); $data = $htd ->get_curl( $url ); if ( is_numeric ( $data )) { if ( $data ==0){ $model ->type= 'REG' ; $model ->content= $code ; $model ->mobile= $mobile ; $model ->ip= $ip ; $model ->expiry_time= date ( 'Y-m-d H:i:s' ,time()+ $smsConfig [ 'expiry_time' ]); $model ->save(); } return json( array ( 'code' => $data , 'msg' => $arr [ $data ])); } else { return json( array ( 'code' => -1, 'msg' => $data )); } } function send_sms() { $arr = array ( 0=> '发送成功' , 30=> '短信平台密码错误' , 40=> '短信平台账号不存在' , 41=> '短信平台余额不足' , 42=> '短信平台帐户已过期' , 43=> 'IP地址受短信平台限制' , 50=> '内容含有敏感词' , 51=> '手机号码不正确' , -2=> '服务器空间不支持' , -1=> '发送短信参数不全,请联系站长' ); $data = $this ->request->param(); if (!captcha_check(input( 'vercode' ))) { return json( array ( 'code' => -1, 'msg' => '验证码错误' )); } $code =rand(1000,9999); $mobile = $data [ 'mobile' ]; $find = Db::name( 'system' )->field( 'value' )->where( 'name' , 'sms' )->find(); $smsConfig = unserialize( $find [ 'value' ]); $params = explode ( "\n" , $smsConfig [ 'params' ]); $paramArr =[]; foreach ( $params as $v ){ $_arr = explode ( "=" , $v ); $paramArr [ $_arr [0]]= $_arr [1]; } $ip = $this ->request->ip(); $model = new SmsModel(); $where1 [ 'created_at' ]= $where2 [ 'created_at' ]=[ 'gt' , date ( 'Y-m-d' )]; $where1 [ 'mobile' ]= $mobile ; $mobileCount = $model ->where( $where1 )-> count (); if (!isset( $smsConfig [ 'mobile_max' ])){ return json( array ( 'code' => -1, 'msg' => '短信服务配置有误,请联系管理员' )); } $mobileMax = $smsConfig [ 'mobile_max' ]; if ( $mobileCount >= $mobileMax ){ return json( array ( 'code' => -1, 'msg' => '每个手机号每天限制发送' . $mobileMax . '条短信' )); } $where2 [ 'ip' ]=[ 'eq' , $ip ]; $ipCount = $model ->where( $where2 )-> count (); $ipMax = $smsConfig [ 'ip_max' ]; if ( $ipCount >= $ipMax ){ return json( array ( 'code' => -1, 'msg' => '每个IP每天限制发送' . $ipMax . '条短信' )); } //获取结果 $url = $smsConfig [ 'apiurl' ]. "?u=" . $paramArr [ 'u' ]. "&p=" .md5( $paramArr [ 'p' ]). "&m=" . $mobile . "&c=" .urlencode( "【" . $this ->site_config[ 'site_title' ]. "】验证码:" . $code . ",您正在绑定" . $this ->site_config[ 'site_title' ]. "手机号,请5分钟内完成验证。如非本人操作,请忽略本短信。" ); $htd = new Http(); $data = $htd ->get_curl( $url ); if ( is_numeric ( $data )) { if ( $data ==0){ $model ->type= 'REG' ; $model ->content= $code ; $model ->mobile= $mobile ; $model ->ip= $ip ; $model ->expiry_time= date ( 'Y-m-d H:i:s' ,time()+ $smsConfig [ 'expiry_time' ]); $model ->save(); } return json( array ( 'code' => $data , 'msg' => $arr [ $data ])); } else { return json( array ( 'code' => -1, 'msg' => $data )); } } |
打开项目:\application\admin\view\site_config.html 新增下代码
1
2
3
4
5
6
7
8
9
10
|
<div class = "layui-form-item" > <label class = "layui-form-label" >短信功能</label> <div class = "layui-input-inline" > <input type= "radio" name= "site_config[open_sms]" value= "1" title= "开启" { if condition= "@$site_config.open_sms eq 1" }checked{/ if }> <input type= "radio" name= "site_config[open_sms]" value= "0" title= "关闭" { if condition= "@$site_config.open_sms eq 0" }checked{/ if }> </div> <a href= "{:url('admin/system/sms')}" class = "layui-btn layui-btn" style= "float:left" > 短信宝配置 </a> </div> |
打开项目:\application\admin\view\ 新增system_sms.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
|
{extend name= "base" /} {block name= "body" } <form class = "layui-form form-container" data-url= "{:url('admin/system/updatesms')}" localtion-url= "{:url('system/siteConfig')}" > <div class = "layui-tab-content" > <div class = "layui-tab-item layui-show" > <div class = "layui-form-item" > <label class = "layui-form-label" >短信接口地址</label> <div class = "layui-input-block" > <input type= "text" name= "sms[apiurl]" value= "{$sms.apiurl|default='http://api.smsbao.com/sms'}" placeholder= "填写短信接口API地址" autocomplete= "off" class = "layui-input" > </div> </div> <div class = "layui-form-item" > <label class = "layui-form-label" >单个手机发送条数</label> <div class = "layui-input-block" > <input type= "text" name= "sms[mobile_max]" value= "{$sms.mobile_max|default='5'}" placeholder= "每个手机每天可发送条数" autocomplete= "off" class = "layui-input" > </div> </div> <div class = "layui-form-item" > <label class = "layui-form-label" >发送间隔</label> <div class = "layui-input-block" > <input type= "number" name= "sms[interval_time]" value= "{$sms.interval_time|default='60'}" placeholder= "每条短信发送间隔" autocomplete= "off" class = "layui-input" > </div> </div> <div class = "layui-form-item" > <label class = "layui-form-label" >同一IP一天限制</label> <div class = "layui-input-block" > <input type= "number" name= "sms[ip_max]" value= "{$sms.ip_max|default='10'}" placeholder= "每条短信发送间隔" autocomplete= "off" class = "layui-input" > </div> </div> <div class = "layui-form-item" > <label class = "layui-form-label" >过期时间</label> <div class = "layui-input-block" > <input type= "number" name= "sms[expiry_time]" value= "{$sms.expiry_time|default='60'}" placeholder= "过期时间(秒)" autocomplete= "off" class = "layui-input" > </div> </div> <div class = "layui-form-item" > <label class = "layui-form-label" >请求参数配置</label> <div class = "layui-input-block" > <textarea name= "sms[params]" class = "layui-textarea" style= "height: 60px;" >{ $sms .params| default = "u=你的用户名/np=你的密码" }</textarea> </div> </div> </div> </div> <div class = "formbtngroup" > <button id= "creatlink" class = "layui-btn layui-btn-sm" lay-submit= "" type= "submit" lay-filter= "formadd" >保存</button> <button onclick= "history.go(-1);return false;" class = "layui-btn layui-btn-primary layui-btn-sm" >返回</button> </div> </form> {/block} {block name= "js" } <script type= "text/javascript" src= "__ADMIN__/js/formadd.js" ></script> {/block} |
经过上面的替换,短信宝的短信平台已经替换成功了,可以正常使用了。
报备一下短信宝的VIP模板,这样就可以走短信宝的优质通道了,即便遇到敏感文字我们都不会人工审核,短信内容3~5秒就可送达。
另外:我们已经开发好完整的Laysns2.5短信宝插件,点击此链接 下载及查看安装流程。
最新更新
电商类
CMS类
微信类