ESPCMS是一款基于LAMP开发的企业网站管理系统,二次开发及后期维护方便,小编对这款系统还是比较了解的,今天小编就以替换短信接口为例为大家讲解一下如何进行二次开发,使用的短信接口是我们短信宝短信群发平台,我们短信宝短信群发平台非常稳定,发送速度快,注册就送测试短信,推荐大家使用。
首先我们打开项目\ESPCMS_V8\ESPCMS_V8\espcms_public\ESPCMS_Core.php文件,增加postsmsbao 方法
|
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
|
public static function postsmsbao($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;} |
接着打开项目\ESPCMS_V8\ESPCMS_V8\espcms_interface\ESPCMS_SendMessage.php文件替换smssend方法
|
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
|
public static function smssend($smsContent = null, $toMoblie = 0, $isSendtype = 0) { global $espcms_command; $smsContent = trim(strip_tags($smsContent)); if (empty($smsContent) || empty($toMoblie)) { return false; } if (!preg_match("/^1[0-9]{10}$/i", $toMoblie)) { return false; } $userid = $espcms_command['SMS_USER_ID']; $smssnid = $espcms_command['SMS_MESSAGE_ID']; $smskey = $espcms_command['SMS_KEY']; $moblienumber = $espcms_command['SMS_MOBLIE_NB']; $ipadd = real_remote_ip(true); $post['userid'] = $userid; $post['smssnid'] = md5($smssnid); $post['smskey'] = $smskey; $post['ip'] = $ipadd; $post['smsmoblie'] = $moblienumber; $post['sendmoblie'] = $toMoblie; $post['smscontent'] = $smsContent; $service_status = ESPCMS_Core::postsmsbao($post); if ($service_status == '0') { return true; } else { return false; } } |
在项目根目录下创建\ESPCMS_V8\ESPCMS_V8\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
38
39
40
41
|
<?phpheader("Content-type:text/html;charset=utf-8");require_once('./espcms_public/ESPCMS_Mysql.php' );require('./espcms_datacache/espcms_config.php');$conn = mysqli_connect(ESPCMS_DB_HOST,ESPCMS_DB_USER, ESPCMS_DB_PASSWORD);if(! $conn ){ die('连接失败: ' . mysqli_error($conn));}mysqli_query($conn , "set names".ESPCMS_DB_CHARSET);mysqli_select_db( $conn, ESPCMS_DB_NAME );$db_table = ESPCMS_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 = mysqli_query( $conn, $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;} |
最后在系统根目录中\ESPCMS_V8\ESPCMS_V8\smsbao.sql
|
1
2
3
|
UPDATE `$db_table` SET config_title='短信宝用户名',config_validation='',config_content='没有账号?请去http://www.smsbao.com/reg注册账号' WHERE config_name='SMS_USER_ID';UPDATE `$db_table` SET config_title='短信宝密码',config_validation='',config_content='请填写您的短信宝密码' WHERE config_name='SMS_MESSAGE_ID';UPDATE `$db_table` SET config_title='短信签名',config_validation='',config_content='请填写您的短信签名 ' WHERE config_name='SMS_KEY'; |
经过上面的替换,短信宝的短信平台已经替换成功了,可以正常使用了。进行测试发送:

报备一下短信宝的VIP模板,这样就可以走短信宝的优质通道了,即便遇到敏感文字我们都不会人工审核,短信内容3~5秒就可送达。
另外:我们已经开发好完整的ESPCMS企业网站管理系统短信宝插件,点击此链接 下载及查看安装流程。
- 上一篇:微擎框架系统新增短信宝短信接口 下一篇:DSShop商城新增短信宝短信接口

