微擎是一款免費(fèi)開(kāi)源的公眾平臺(tái)管理系統(tǒng),基于web2.0技術(shù)架構(gòu),他有很多的擴(kuò)展模塊,二次開(kāi)發(fā)也非常方便,智慧送水是微擎應(yīng)用市場(chǎng)針對(duì)考試管理的一套應(yīng)用模塊,小編對(duì)他還是了解, 今天小編就以替換短信接口為例告訴大家如何進(jìn)行二次開(kāi)發(fā),我們講解的是V2.19.5版本,使用的短信接口是我們短信寶短信群發(fā)平臺(tái)的接口,我們短信寶短信群發(fā)平臺(tái)非常穩(wěn)定,發(fā)送速度快,注冊(cè)就送測(cè)試短信,推薦大家使用。
1:打開(kāi)項(xiàng)目:online_testapp\template\config.html 新增短信寶頁(yè)面
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
|
<div class= "panel-heading" > <strong style= "font-size:16px;" >短信寶短信平臺(tái)接口設(shè)置</strong> <p style= "color:#666666;" >請(qǐng)正確填寫相關(guān)參數(shù),如果還沒(méi)有請(qǐng) <a href= " </div> <div class= "panel-body" > <div class= "form-group" > <label class= "col-xs-2 control-label" >短信驗(yàn)證碼登陸</label> <div class= "col-xs-9" > <p class= "form-control-static" > <input type= "radio" name= "sms_login" value= "1" { if $config[ 'sms_login' ] == 1}checked{/ if }/> 開(kāi)啟 <input type= "radio" name= "sms_login" value= "0" { if $config[ 'sms_login' ] != 1}checked{/ if }/> 關(guān)閉 </p> <p class= "form-control-static" > 短信接口開(kāi)啟時(shí)有效 </p> </div> </div> <div class= "form-group" > <label class= "col-xs-2 control-label" >短信接口</label> <div class= "col-xs-9" > <p class= "form-control-static" > <input type= "radio" name= "sms_open" value= "1" { if $config[ 'sms_open' ] == 1}checked{/ if }/> 開(kāi)啟 <input type= "radio" name= "sms_open" value= "0" { if $config[ 'sms_open' ] != 1}checked{/ if }/> 關(guān)閉 </p> </div> </div> <div class= "form-group" > <label class= "col-xs-2 control-label" >短信寶賬號(hào)</label> <div class= "col-xs-9" > <input class= "form-control" name= "sms_name" type= "text" value= "{$config['sms_name']}" style= "width:300px;" > </div> </div> <div class= "form-group" > <label class= "col-xs-2 control-label" >短信寶密碼</label> <div class= "col-xs-9" > <input class= "form-control" name= "sms_password" type= "password" value= "{$config['sms_password']}" style= "width:300px;" > </div> </div> <div class= "form-group" > <label class= "col-xs-2 control-label" >短信簽名</label> <div class= "col-xs-9" > <input class= "form-control" name= "sms_signsame" type= "text" value= "{$config['sms_signsame']}" style= "width:300px;" > </div> </div> <div class= "form-group" > <label class= "col-xs-2 control-label" >短信模板</label> <div class= "col-xs-9" > <input class= "form-control" name= "sms_templatecode" type= "text" value= "{$config['sms_templatecode']}" style= "width:300px;" > </div> </div> <div class= "form-group" > <label class= "col-xs-2 control-label" >驗(yàn)證碼模版內(nèi)容樣版</label> <div class= "col-xs-9" > <input class= "form-control" id= "reply-add-text" type= "text" value= "您的驗(yàn)證碼為:${code}" style= "width:300px; background-color:#E7E7E7;" > </div> </div> </div> |
2:打開(kāi)項(xiàng)目:addons\online_testapp\inc\mobile\sms.inc.php 修改大概30行代碼
1
2
3
4
5
6
7
8
9
10
11
|
$helper = new SignatureHelper(); //短信寶設(shè)置 $get = $helper->smsbao($accessKeyId, $accessKeySecret, $params); if ($get[ "code" ] == "0" ) { $_SESSION[ "mobile" ] = $mobile; $_SESSION[ "mobile_code" ] = $mobile_code; echo "請(qǐng)求成功" ; } else { echo $get[ "msg" ]; } exit; |
3:打開(kāi)項(xiàng)目:addons\online_testapp\class\signature_helper.class.php 修改發(fā)送短信函數(shù)
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
|
class SignatureHelper { public function request($accessKeyId, $accessKeySecret, $domain, $params, $security = false ) { $apiParams = array_merge(array( "SignatureMethod" => "HMAC-SHA1" , "SignatureNonce" => uniqid(mt_rand(0, 0xffff), true ), "SignatureVersion" => "1.0" , "AccessKeyId" => $accessKeyId, "Timestamp" => gmdate( "Y-m-d\\TH:i:s\\Z" ), "Format" => "JSON" ), $params); ksort($apiParams); $sortedQueryStringTmp = '' ; foreach ($apiParams as $key => $value) { $sortedQueryStringTmp .= "&" . $ this ->encode($key) . "=" . $ this ->encode($value); } $stringToSign = "GET&%2F&" . $ this ->encode(substr($sortedQueryStringTmp, 1)); $sign = base64_encode(hash_hmac( "sha1" , $stringToSign, $accessKeySecret . "&" , true )); $signature = $ this ->encode($sign); $url = ($security ? "https" : "http" ) . "://{$domain}/?Signature={$signature}{$sortedQueryStringTmp}" ; try { $content = $ this ->fetchContent($url); return json_decode($content); } catch (\Exception $e) { return false ; } } private function encode($str) { $res = urlencode($str); $res = preg_replace( "/\\+/" , "%20" , $res); $res = preg_replace( "/\\*/" , "%2A" , $res); $res = preg_replace( "/%7E/" , "~" , $res); return $res; } private function fetchContent($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_TIMEOUT, 5); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, array( "x-sdk-client" => "php/2.0.0" )); if (substr($url, 0, 5) == "https" ) { curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false ); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false ); } $rtn = curl_exec($ch); if ($rtn === false ) { trigger_error( "[CURL_" . curl_errno($ch) . "]: " . curl_error($ch), E_USER_ERROR); } curl_close($ch); return $rtn; } public function smsbao($smsuser,$smspwd,$params){ $statusStr = array( "0" => "短信發(fā)送成功" , "-1" => "參數(shù)不全" , "-2" => "服務(wù)器空間不支持,請(qǐng)確認(rèn)支持curl或者fsocket,聯(lián)系您的空間商解決或者更換空間!" , "30" => "密碼錯(cuò)誤" , "40" => "賬號(hào)不存在" , "41" => "余額不足" , "42" => "帳戶已過(guò)期" , "43" => "IP地址限制" , "50" => "內(nèi)容含有敏感詞" ); $user = $smsuser; //短信平臺(tái)帳號(hào) $pass = md5($smspwd); //短信平臺(tái)密碼 $content = '【' .$params[ "SignName" ]. '】' .str_replace( '${code}' ,$params[ "TemplateParam" ][ 'code' ],$params[ "TemplateCode" ]); //要發(fā)送的短信內(nèi)容 $phone = $params[ "PhoneNumbers" ]; //要發(fā)送短信的手機(jī)號(hào)碼 $sendurl = $smsapi. "sms?u=" .$user. "&p=" .$pass. "&m=" .$phone. "&c=" .urlencode($content); try { $result = $ this ->fetchContent($sendurl); return [ 'code' =>$result, 'msg' =>$statusStr[$result] ]; } catch (\Exception $e) { return false ; } } } |
經(jīng)過(guò)上面的替換,短信寶的短信平臺(tái)已經(jīng)替換成功了,可以正常使用了。進(jìn)行測(cè)試發(fā)送:
報(bào)備一下短信寶的VIP模板,這樣就可以走短信寶的優(yōu)質(zhì)通道了,即便遇到敏感文字我們都不會(huì)人工審核,短信內(nèi)容3~5秒就可送達(dá)。
另外:我們已經(jīng)開(kāi)發(fā)好完整的微擎模塊華旭在線考試注冊(cè)模塊系統(tǒng)短信寶插件,點(diǎn)擊此鏈接?下載及查看安裝流程。
最新更新
電商類
CMS類
微信類