大米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.smsbao.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类
微信类