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= "http://www.gjrencai.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問答系統短信寶插件,點擊此鏈接 下載及查看安裝流程。
最新更新
電商類
CMS類
微信類