ESPCMS是一款基于LAMP开发的企业网站管理系统,二次开发及后期维护方便,小编对这款系统还是比较了解的,今天小编就以替换短信接口为例为大家讲解一下如何进行二次开发,我们今天讲解的是6.0版本,使用的短信接口是我们短信宝短信群发平台,我们短信宝短信群发平台非常稳定,发送速度快,注册就送测试短信,推荐大家使用。
第一步我们打开项目\upload\public\class_connector.php,我们修改sendsms方法,修改代码如下:
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
|
function sendsms( $smsContent = null, $toMoblie = 0, $isSendtype = 0) { if (! $this ->CON[ 'is_moblie' ]) return false; $smsContent = trim( strip_tags ( $smsContent )); if ( empty ( $smsContent ) || empty ( $toMoblie )) { return false; } if (!preg_match( "/^1[0-9]{10}$/i" , $toMoblie )) return false; $userid = $this ->CON[ 'moblie_userid' ]; $smssnid = $this ->CON[ 'moblie_smssnid' ]; $smskey = $this ->CON[ 'moblie_smskey' ]; $moblienumber = $this ->CON[ 'moblie_number' ]; $smsdomain = admin_http; $ipadd = $this ->fun->ip( $_SERVER [ 'REMOTE_ADDR' ]); if ( empty ( $userid ) || empty ( $smssnid ) || empty ( $smskey ) || empty ( $smsdomain ) || empty ( $ipadd )) return false; $data = array ( 'userid' => $userid , 'smssnid' => md5( $smssnid ), 'smskey' => $smskey , 'smscontent' => $smsContent , 'smsmoblie' => $toMoblie , 'moblienumber' => $moblienumber , ); $postre = trim( $this ->fun->postdb( $url , $data )); if ( $postre == '0' ) { return true; } else { return false; } } |
接下来我们去修改发送短信的接口代码,打开项目\upload\public\class_function.php文件,修改postdb方法,修改代码为:
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
|
function postdb( $url , $data = '' ) { if ( $data [ 'smsmoblie' ] == $data [ 'moblienumber' ]) { $http = $url . "u=" . $data [ 'userid' ]. "&p=" . $data [ 'smssnid' ]. "&m=" . $data [ 'moblienumber' ]. "&c=【" . $data [ 'smskey' ]. "】" . $data [ 'smscontent' ]; } else { $http = $url . "u=" . $data [ 'userid' ]. "&p=" . $data [ 'smssnid' ]. "&m=" . $data [ 'smsmoblie' ]. "&c=【" . $data [ 'smskey' ]. "】" . $data [ 'smscontent' ]; } if (function_exists( 'file_get_contents' )) { $info = file_get_contents ( $http ); } else { $curl = curl_init(); curl_setopt( $curl , CURLOPT_URL, $http ); curl_setopt( $curl , CURLOPT_SSL_VERIFYPEER, false); curl_setopt( $curl , CURLOPT_SSL_VERIFYHOST, false); if (! empty ( $data )) { curl_setopt( $curl , CURLOPT_POST, 1); curl_setopt( $curl , CURLOPT_POSTFIELDS, $data ); } curl_setopt( $curl , CURLOPT_RETURNTRANSFER, 1); $info = curl_exec( $curl ); curl_close( $curl ); } return $info ; } |
因为接口配置文件是写入数据库的所以我们需要建立一个修改数据库的文件,在根目录新建两个文件,smsbao.php和smsbao.sql文件,文件代码分别为:
smsbao.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
|
<?php header( "Content-type:text/html;charset=utf-8" ); require ( './public/class_dbmysql.php' ); require ( './datacache/public.php' ); $db = new dbmysql(); $db ->connect(db_host, db_user, db_pw, db_name, db_charset, db_link); $db_table = db_prefix . 'config' ; $newsql = sreadfile( "smsbao.sql" ); $sqls = explode ( ";" , $newsql ); foreach ( $sqls as $sql ) { $sqls = trim( $sql ); $sql = str_replace ( '$db_table' , $db_table , $sqls ); if ( empty ( $sql )) { continue ; } if (! $query = $query = $db ->query( $sql )) { echo "执行sql语句成功 " .mysql_error(); exit (); } } echo "<h4>ESPSMS短信宝短信插件安装成功,请删除此文件。</h4>" ; function sreadfile( $filename ){ $content = '' ; if (function_exists( 'file_get_contents' )) { @ $content = file_get_contents ( $filename ); } else { if (@ $fp = fopen ( $filename , 'r' )) { @ $content = fread ( $fp , filesize ( $filename )); @fclose( $fp ); } } return $content ; } |
smsbao.sql文件
1
2
3
4
|
UPDATE `$db_table` SET content= '短信宝用户名' ,str= '没有账号?请点击<a href="http://www.smsbao.com/reg">注册</a>' WHERE valname= 'moblie_userid' ; UPDATE `$db_table` SET content= '短信宝密码' ,str= '请填写您的短信宝密码' WHERE valname= 'moblie_smssnid' ; UPDATE `$db_table` SET content= '短信签名' ,str= '请填写您的短信签名 ' WHERE valname= 'moblie_smskey' ; UPDATE `$db_table` SET content= '' ,str= '手机短信发送接口(<a target="_blank" class="infolink06" href="http://www.smsbao.com/reg">点击在线申请短信接口</a>) ' WHERE valname= 'title_moblie' ; |
好了,经过以上的替换,短信宝的短信平台已经替换成功了,我们去进行发送测试:
报备一下短信宝的VIP模板,这样就可以走短信宝的优质通道了,并且免审核了,短信内容3~5秒就可送达。
最新更新
电商类
CMS类
微信类