大米CMS(又名3gcms)是一個免費開源、快速、簡單的PC建站和手機建站集成一體化系統, 致力于為用戶提供簡單、快捷的PC建站和智能手機建站解決方案。小編對他還是比較了解的,今天小編就以新增短信接口為例,給大家講解一下如何進行二次開發,我們今天講解的是V7版本,使用的短信接口是我們短信寶短信群發平臺的短信接口,我們短信寶短信群發平臺的接口非常穩定,發送速度快,注冊就送測試短信,推薦大家使用。
1:打開項目:app\admin\view\config\index.html 在38行增加下代碼
|
1
2
3
4
5
6
7
8
9
|
<ul class="nav nav-tabs"> <li style="width:100px;"><a data-toggle="tab"></a></li> <li class="active"><a href="#total_config" data-toggle="tab">網站整體配置</a></li> <li><a href="#home_config" data-toggle="tab">首頁配置</a></li> <li><a href="#list_config" data-toggle="tab">列表頁配置</a></li> <li><a href="#content_config" data-toggle="tab">內容頁配置</a></li> <li><a href="#mail_config" data-toggle="tab">郵件發送配置</a></li> <li><a href="#sms_config" data-toggle="tab">短信發送配置</a></li></ul> |
2:當前項目下同時增加下短信配置
|
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
|
<div class="tab-pane" id="sms_config"> <div id="myTab1_Content3" style="clear:both;"> <table width="100%" border="0" align=center cellpadding="3" cellspacing="1" style="margin:5px 0;background:#FFF"> <tr onMouseOver="this.style.backgroundColor='#EEFCDD';this.style.color='red'" onMouseOut="this.style.backgroundColor='';this.style.color=''"> <td width="40%" align="right">短信寶賬號: </td> <td align="center"> </td> <td width="60%" align="left"> <input name="SMS_FROM" type="text" id="MAIL_FROM" onFocus="hSiteTitle.style.color='blue';" onBlur="hSiteTitle.style.color='#ccc';" value="" style="width:300px;"> 還沒有注冊短信寶賬號?<a href="HTTP://www.gjrencai.com/register.jhtml" target="_blank" style="color: red;">立即注冊</a> </td> </tr> <tr onMouseOver="this.style.backgroundColor='#EEFCDD';this.style.color='red'" onMouseOut="this.style.backgroundColor='';this.style.color=''"> <td width="40%" align="right">短信寶密碼: </td> <td align="center"> </td> <td width="60%" align="left"><input name="SMS_PASSSWORD" type="password" id="MAIL_PASSSWORD" onFocus="hSiteTitle.style.color='blue';" onBlur="hSiteTitle.style.color='#ccc';" value="" style="width:300px;"></td> </tr> <tr onMouseOver="this.style.backgroundColor='#EEFCDD';this.style.color='red'" onMouseOut="this.style.backgroundColor='';this.style.color=''"> <td width="40%" align="right">短信寶簽名: </td> <td align="center"> </td> <td width="60%" align="left"><input name="SMS_SING" type="text" id="MAIL_PASSSWORD" onFocus="hSiteTitle.style.color='blue';" onBlur="hSiteTitle.style.color='#ccc';" value="" style="width:300px;"></td> </tr> <tr class="css_page_list"> <td height="30" colspan=3 align="center"> <input type="hidden" name="id" value="{$list.id}"/> <input name='Submit' type='submit' class="btn btn-success" value=' 保存設置 '></td> </tr> </table> </div> </div> |
3:打開項目:app\admin\controller\Config.php 大概143行 修改保存方法
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
//保存全局配置 $config_file = "../config/app.php";$fp = fopen($config_file, "r");$configStr = fread($fp, filesize($config_file));fclose($fp);$configStr = preg_replace("/'LOCAL_REMOTE_PIC'(\s)*=>(\s)*[0-9]/", "'LOCAL_REMOTE_PIC'=>" . $data['islocalpic'], $configStr);$configStr = preg_replace("/'MAIL_TRADE'(\s)*=>(\s)*[0-9]/", "'MAIL_TRADE'=>" . htmlspecialchars($_POST['MAIL_TRADE'], ENT_QUOTES) , $configStr);$configStr = preg_replace("/'MAIL_REG'(\s)*=>(\s)*[0-9]/", "'MAIL_REG'=>" . htmlspecialchars($_POST['MAIL_REG'], ENT_QUOTES) , $configStr);$configStr = preg_replace("/'MAIL_SMTP_SERVER'(\s)*=>(\s)*'.*'/", "'MAIL_SMTP_SERVER'=>'" . htmlspecialchars($_POST['MAIL_SMTP_SERVER'], ENT_QUOTES) . "'", $configStr);$configStr = preg_replace("/'MAIL_FROM'(\s)*=>(\s)*'.*'/", "'MAIL_FROM'=>'" . htmlspecialchars($_POST['MAIL_FROM'], ENT_QUOTES) . "'", $configStr);$configStr = preg_replace("/'SMS_FROM'=>'.*'/","'SMS_FROM'=>'".htmlspecialchars($_POST['SMS_FROM'],ENT_QUOTES)."'",$configStr);$configStr = preg_replace("/'SMS_SING'=>'.*'/","'SMS_SING'=>'".htmlspecialchars($_POST['SMS_SING'],ENT_QUOTES)."'",$configStr);if(config('app.SMS_PASSSWORD') != $_POST['SMS_PASSSWORD']){ $configStr = preg_replace("/'SMS_PASSSWORD'=>'.*'/","'SMS_PASSSWORD'=>'".$_POST['SMS_PASSSWORD']."'",$configStr);}if (config('app.MAIL_PASSSWORD') != $_POST['MAIL_PASSSWORD'] ) { $configStr = preg_replace("/'MAIL_PASSSWORD'(\s)*=>(\s)*'.*'/", "'MAIL_PASSSWORD'=>'" . dami_encrypt($_POST['MAIL_PASSSWORD']) . "'", $configStr);}$configStr = preg_replace("/'MAIL_TOADMIN'(\s)*=>(\s)*'.*'/", "'MAIL_TOADMIN'=>'" . htmlspecialchars($_POST['MAIL_TOADMIN'], ENT_QUOTES) . "'", $configStr);$configStr = preg_replace("/'MAIL_PORT'(\s)*=>(\s)*[0-9]+/", "'MAIL_PORT'=>" . intval($_POST['MAIL_PORT']) , $configStr);$fp = fopen($config_file, "w") or die("<script>alert('寫入配置失敗,請檢查'.$config_file.'是否可寫入!');history.go(-1);</script>");fwrite($fp, $configStr);fclose($fp); |
4:打開項目:app\home\common.php 修改發送短信類
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
function send_smsmess($to_mobile,$content,$isvail=0){ if($isvail==1){ $config = F('basic', '', './Web/Conf/'); $mobile_code = mt_rand(1000,9999); $content = "您的驗證碼是:".$mobile_code."。請不要把驗證碼泄露給其他人。"; } $user = C('SMS_FROM'); //短信平臺帳號 $pass = md5(C('SMS_PASSSWORD')); //短信平臺密碼 $content='【'.C('SMS_SING').'】'.$content;//要發送的短信內容 $phone = $to_mobile;//要發送短信的手機號碼 $sendurl = $smsapi."sms?u=".$user."&p=".$pass."&m=".$phone."&c=".urlencode($content); $result =file_get_contents($sendurl) ; //$data = ("account=".C('SMS_FROM')."&password=".C('SMS_PWD')."&mobile=".$to_mobile."&content=".rawurlencode($content));//短信用戶名與密碼請在這里改 //密碼可以使用明文密碼或使用32位MD5加密 //$gets = xml_to_array(SPost($data, $target)); //var_dump($gets); if($result==0 && $isvail==1){ $_SESSION['mobile_verify'] = md5($mobile_code); } return $result;} |
5:打開項目:config\app.php 新增以下配置
|
1
2
3
4
|
'SMS_FROM'=>'',//短信寶賬號'SMS_PASSSWORD'=>'',//短信寶密碼'SMS_SING'=>'',//短信寶簽名 |
經過上面的替換,短信寶的短信平臺已經替換成功了,可以正常使用了。
報備一下短信寶的VIP模板,這樣就可以走短信寶的優質通道了,即便遇到敏感文字我們都不會人工審核,短信內容3~5秒就可送達。
另外:我們已經開發好完整的大米cms_v7系統短信寶插件,點擊此鏈接 下載及查看安裝流程。
最新更新
電商類
CMS類
微信類