hadsky是一个原创开源轻系统, 致力于为用户提供简单的解决方案。小编对他还是比较了解的,最近看到很多客户在找HadSky8.4.11版本的短信接口,今天小编就以新增短信接口为例,给大家讲解一下如何进行二次开发,我们今天讲解的是使用的短信接口是我们短信宝短信群发平台的短信接口,我们短信宝短信群发平台的接口非常稳定,发送速度快,注册就送测试短信,推荐大家使用:
1:打开项目:\app\hadskycloudserver\setting.hst 在129行左右 新增短信宝页面代码
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
|
<div class= "pk-row pk-padding-bottom-5" > <label class= "pk-w-sm-3 pk-padding-top-5 pk-text-bold pk-text-right pk-text-nowrap" >短信宝账号</label> <div class= "pk-w-sm-8" > <input class= "pk-textbox" type= "text" name= "app_puyuetian_sms_smsbao_user" value= "{$_G['SET']['APP_PUYUETIAN_SMS_SMSBAO_USER']}" placeholder= "请填写短信宝用户名" > </div> </div> <div class= "pk-row pk-padding-bottom-5" > <label class= "pk-w-sm-3 pk-padding-top-5 pk-text-bold pk-text-right pk-text-nowrap" >短信宝密码</label> <div class= "pk-w-sm-8" > <input class= "pk-textbox" type= "text" name= "app_puyuetian_sms_smsbao_pass" value= "{$_G['SET']['APP_PUYUETIAN_SMS_SMSBAO_PASS']}" placeholder= "请填写短信宝密码" > </div> </div> <div class= "pk-row pk-padding-bottom-5" > <label class= "pk-w-sm-3 pk-padding-top-5 pk-text-bold pk-text-right pk-text-nowrap" >自定义短信签名</label> <div class= "pk-w-sm-8" > <input class= "pk-textbox" type= "text" name= "app_puyuetian_sms_smsbao_sign" value= "{$_G['SET']['APP_PUYUETIAN_SMS_SMSBAO_SIGN']}" placeholder= "请填写短信宝签名" > </div> </div> <div class= "pk-row pk-padding-bottom-15" > <label class= "pk-w-sm-3" > </label> <div class= "pk-w-sm-8" > <p class= "pk-text-sm" > <span>需要提前在官网申请,申请地址</span> <a class= "pk-text-primary pk-hover-underline" target= "_blank" href= "https://www.smsbao.com/reg" >https://www.smsbao.com/reg</a> </p> </div> </div> |
2:打开项目:app\hadskycloudserver\embed.php 新增短信宝发送函数smsbaoSms
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
|
function smsbaoSms($phonenumber, $code) { global $_G; if (!preg_match( '/^1[3456789]\d{9}$/' , $phonenumber)) { return '手机号错误' ; } $content = '【' .$_G[ 'SET' ][ 'APP_PUYUETIAN_SMS_SMSBAO_SIGN' ]. '】 您的验证码为:' .$code. ',请妥善保存。' ; $url = 'http://api.smsbao.com/sms?u=' .$_G[ 'SET' ][ 'APP_PUYUETIAN_SMS_SMSBAO_USER' ]. '&p=' .md5($_G[ 'SET' ][ 'APP_PUYUETIAN_SMS_SMSBAO_PASS' ]). '&m=' .$phonenumber. '&c=' .$content; $ret = file_get_contents($url); if ($ret == 0) { $r[ 'state' ] = 'ok' ; } else { $r[ 'state' ] = $ret; } //记录发送记录 $_G[ 'TABLE' ][ 'APP_PUYUETIAN_SMS_RECORD' ]->newData(array( 'pn' => $phonenumber, 'ip' => getClientInfos( 'ip' ), 'state' => $r[ 'state' ], 'msg' => $r[ 'msg' ], 'code' => $code, 'date' => date( 'Ymd' ), 'datetime' => date( 'Y-m-d H:i:s' ))); if ( 'ok' == $r[ 'state' ]) { return true ; } $r = $r[ 'msg' ] ? $r[ 'msg' ] : '请求失败' ; return $r; } |
3:打开项目:app\hadskycloudserver\phpscript\sms_send.php 替换原有的短信发送函数大概65行
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
//创建短信验证码 if (!Cnum($_SESSION[ 'APP_PUYUETIAN_SMS_CODE' ]) || !Cstr($_SESSION[ 'APP_PUYUETIAN_SMS_PHONE' ], false , $_G[ 'STRING' ][ 'NUMERICAL' ], 11, 11) || $phonenumber != $_SESSION[ 'APP_PUYUETIAN_SMS_PHONE' ]) { $_SESSION[ 'APP_PUYUETIAN_SMS_CODE' ] = $code = rand(1000, 9999); $_SESSION[ 'APP_PUYUETIAN_SMS_PHONE' ] = $phonenumber; } else { $code = $_SESSION[ 'APP_PUYUETIAN_SMS_CODE' ]; } //请求发送短信 $r = smsbaoSms($phonenumber, $code); if ( true === $r) { setcookie( 'APP_PUYUETIAN_SMS_TIME' , true , time() + 60); ExitJson( '发送成功' , true ); } ExitJson($r); |
经过上面的替换,短信宝的短信平台已经替换成功了,可以正常使用了。进行测试发送:
报备一下短信宝的VIP模板,这样就可以走短信宝的优质通道了,即便遇到敏感文字我们都不会人工审核,短信内容3~5秒就可送达。
另外:我们已经开发好完整的HadSky8.4.11系统短信宝插件,点击此链接 下载及查看安装流程。
最新更新
电商类
CMS类
微信类