WhatsnsV4问答系统是一款可以根据自身业务需求快速搭建垂直化领域的php开源问答系统,内置上百个功能帮助站长一分钟完成PC、Wap、微信端、小程序、APP问答应用建设。小编对他还是比较了解的,今天小编就以新增短信接口为例,给大家讲解一下如何进行二次开发,我们今天讲解的是V4版本,使用的短信接口是我们短信宝短信群发平台的短信接口,我们短信宝短信群发平台的接口非常稳定,发送速度快,注册就送测试短信,推荐大家使用。
首先打开项目:\system\helpers\public_helper.php 增加下短信发送方法
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
function smsbao($user,$phone,$key,$sing,$code){ $message [] = array (); $user = $user; //短信平台帐号 $pass = md5($key); //短信平台密码 $content = '您的注册验证码是'.$code.'请不要把验证码泄露给其他人。若非本人操作,可不用理会。'; $content='【'.$sing.'】'.$content;//要发送的短信内容 $phone = $phone;//要发送短信的手机号码 $sendurl = $smsapi."sms?u=".$user."&p=".$pass."&m=".$phone."&c=".urlencode($content); $result =file_get_contents($sendurl) ; if ($result == 0){ $message ['errorcode'] = 0; // 状态为0,说明短信发送成功 $message ['msg'] = '短信发送成功'; }else{ $message ['errorcode'] = 1; $message ['msg'] = '短信发送失败'; } return $message;} |
打开项目:\application\views\default\register.php 修改下代码
|
1
2
3
4
5
|
<div class="input-prepend no-radius security-up-code js-security-number "> <input type="text" id="seccode_verify" name="seccode_verify" placeholder="手机验证码" onblur="check_phone();"> <i class="fa fa-get-pocket"></i> <a id="testbtn" onclick="gosms()" class="btn-up-resend js-send-code-button" href="javascript:;">发送验证码</a> <div> |
打开项目:\application\views\admin\setting_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
|
<!--{template header}--><div style="width:100%; height:15px;color:#000;margin:0px 0px 10px;"> <div style="float:left;"><a href="index.php?admin_main/stat{$setting['seo_suffix']}" target="main"><b>控制面板首页</b></a> » 短信设置</div></div><!--{if isset($message)}--><!--{eval $type=isset($type)?$type:'correctmsg'; }--><div class="alert alert-warning">{$message}</div><!--{/if}--> <form action="index.php?admin_setting/sms{$setting['seo_suffix']}" method="post"> <table class="table"> <tr class="header"> <td colspan="2">短信参数设置</td> </tr> <tr> <td class="altbg1" width="45%"><b>短信宝账号:</b><br><span class="smalltxt"></span></td> <td class="altbg2"><input class="form-control shortinput" type="text" value="{if isset($setting['smsid'])}$setting['smsid']{/if}" name="smsid" /></td> <td class="altbg3">还没有注册账号?<a target="_blank" style="color: red;" href="https://www.smsbao.com/register.jhtml">立即注册</a></td> </tr> <tr> <td class="altbg1" width="45%"><b>短信宝密码:</b><br><span class="smalltxt"></span></td> <td class="altbg2"><input class="form-control shortinput" type="text" value="{if isset($setting['smskey'])}$setting['smskey']{/if}" name="smskey" /></td> </tr> <tr> <td class="altbg1" width="45%"><b>短信宝签名:</b><br><span class="smalltxt"></span></td> <td class="altbg2"><input class="form-control shortinput" type="text" value="{if isset($setting['smssing'])}$setting['smssing']{/if}" name="smssing" /></td> </tr> <tbody > <tr> <td class="altbg1" width="45%"><b>是否启用短信验证码注册:</b><br><span class="smalltxt">开启后没有手机注册的用户登录后会提示验证手机号,同时注册入口取消图形验证码启用短信验证码</span></td> <td class="altbg2"><input type="checkbox" class=" " {if isset($setting['smscanuse'])&&$setting['smscanuse']==1} checked {/if} name="smscanuse">启用手机验证码</td> </tr </tbody> </table> <br /> <center><input type="submit" class="btn btn-success" name="submit" value="提 交"></center><br> </form><br /><style>html,body{ overflow:scroll;}</style><!--{template footer}--> |
打开项目:\application\views\admin\public_menu.php 增加行下代码
|
1
|
<li><a href="{SITE_URL}index.php?admin_setting/sms{$setting['seo_suffix']}" target="main"><i class="fa fa-genderless text-success"></i>短信设置</a> </li> |
打开项目:\application\controllers\Admin\Admin_setting.php 增加行短信设置
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
/* 短信设置 */ function sms() { if (null!== $this->input->post ('submit')) { checkattack($_POST, 'post'); foreach ( $_POST as $key => $value ) { if ('sms' == substr ( $key, 0, 3 )) { $this->setting [$key] = $value; } } if ($this->input->post ('smscanuse') == 'on') { $this->setting ['smscanuse'] = 1; } else { $this->setting ['smscanuse'] = 0; } $this->setting_model->update ( $this->setting ); $message = '短信设置更新成功!'; } |
打开项目:\application\controllers\User.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
|
function getsmscode() { // $startime=tcookie('smstime'); // $timespan=time()-$startime; // echo $timespan;exit(); if ($this->setting ['smscanuse'] == 0) { echo '0'; exit (); } $phone = $this->input->post ( 'phone' ); if (! preg_match ( "/^1[34578]{1}\d{9}$/", $phone )) { exit ( "3" ); } if ($_POST ['type'] && $_POST ['type'] == 'reg') { $userone = $this->user_model->get_by_phone ( $phone ); if ($userone != null) { exit ( '2' ); } } // $userone=$_ENV['user']->get_by_phone($phone); // if($userone!=null){ // exit("2"); // } session_start (); if ($_SESSION ["time"] != null) { $startime = $_SESSION ['time']; $timespan = time () - $startime; if ($timespan < 60) { echo '0'; exit (); } else { $phone = $this->input->post ( 'phone' ); $_SESSION ["time"] = null; $_SESSION ["time"] = time (); $code = random ( 4, 1 ); $this->user_model->save_code ( strtolower ( $code ) );// $codenum = $this->setting ['smstmpvalue'];// $codenum = str_replace ( '{code}', $code, $codenum ); $msg = smsbao ( $this->setting ['smsid'], $phone, $this->setting ['smskey'],$this->setting ['smssing'], $code ); exit ( '1' ); } } else { // $phone=$this->post['phone']; // $userone=$_ENV['user']->get_by_phone($phone); // if($userone!=null){ // exit("2"); // } $code = random ( 4, 1 ); $this->user_model->save_code ( strtolower ( $code ) );// $codenum = $this->setting ['smstmpvalue'];// $codenum = str_replace ( '{code}', $code, $codenum ); $msg = smsbao ( $this->setting ['smsid'], $phone, $this->setting ['smskey'],$this->setting ['smssing'], $code ); $_SESSION ["time"] = time (); exit ( '1' ); } echo $timespan; exit (); } |
经过上面的替换,短信宝的短信平台已经替换成功了,可以正常使用了。

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

