PHPOK企业站新增短信接口
“PHPOK企业站”(简称PHPOK)建设系统是一套基于PHP和MySQL构建的高效企业网站建设方案之一,全面针对企业网(以展示为中心)进行合理的设计规划。这是一套开源的,免费的企业网站程序!二次开发比较简单,小编对这它还是比较了解的,今天小编就以新增短信接口为例,带大家进行二次开发。使用的短信接口是短信宝短信群发平台的短信接口,短信宝短信群发平台非常稳定,发送速度快,注册就送测试短信,推荐大家使用!
我们首先在项目:\gateway\sms 中创建smsbao文件夹,接着创建sendsms.php文件,代码:
<?php
/**
* 短信宝短信接口
**/
if(!defined("PHPOK_SET")){exit("<h1>Access Denied</h1>");}
$update = $this->get('update');
if($update){
$mobile = $this->get('mobile');
if(!$mobile){
$this->error('未指定手机号');
}
if(!$this->lib('common')->tel_check($mobile,'mobile')){
$this->error('手机号格式不正式');
}
$content = $this->get('content');
if(!$content){
$this->error('未指定要发送的内容');
}
if (empty($rs['ext']['smsbao_user']) || empty($rs['ext']['smsbao_pass']) || empty($rs['ext']['smsbao_sign'])) {
$this->error('请填写短信宝用户名、密码和签名');
}
$url = 'http://api.smsbao.com/sms?u='.$rs['ext']['smsbao_user'].'&p='.md5($rs['ext']['smsbao_pass']).'&m='.$mobile.'&c=【'.$rs['ext']['smsbao_sign'].'】'.$content;
$ret = file_get_contents($url);
if($ret == 0){
$this->success('短信发送成功');
return true;
}
$this->error($info['message']);
return false;
}
$this->view($this->dir_root.'gateway/'.$rs['type'].'/sendsms.html','abs-file');
然后接着创建exec.php文件,代码为:
<?php
if(!defined("PHPOK_SET")){exit("<h1>Access Denied</h1>");}
if (!$rs['ext'] || !$rs['ext']['smsbao_user'] || !$rs['ext']['smsbao_pass'] || !$rs['ext']['smsbao_sign']) {
if($this->config['debug']){
phpok_log(P_Lang('短信宝短信参数配置不全'));
}
return false;
}
if(!$extinfo['mobile'] || !$extinfo['content']){
if($this->config['debug']){
phpok_log(P_Lang('手机号或短信模版未配置'));
}
return false;
}
$url = 'http://api.smsbao.com/sms?u='.$rs['ext']['smsbao_user'].'&p='.md5($rs['ext']['smsbao_pass']).'&m='.$extinfo['mobile'].'&c=【'.$rs['ext']['smsbao_sign'].'】'.$extinfo['content'];
$ret = file_get_contents($url);
if ($ret == 0) {
return true;
} else {
if($this->config['debug']){
phpok_log($ret);
}
return false;
}
最后我们创建一个名为config.xml的文件,代码为:
<?xml version="1.0" encoding="utf-8"?>
<root>
<title>短信宝短信</title>
<note>官网(http://www.smsbao.com)</note>
<code>
<smsbao_user>
<title>短信宝用户名</title>
<note>请输入您在短信宝注册的帐号</note>
<type>text</type>
<required>true</required>
</smsbao_user>
<smsbao_pass>
<title>短信宝密码</title>
<note>请输入短信宝密码</note>
<type>text</type>
<required>true</required>
</smsbao_pass>
<smsbao_sign>
<title>短信签名</title>
<note>请输入短信签名</note>
<type>text</type>
<required>true</required>
</smsbao_sign>
<mobile>
<title>手机号</title>
<note>填写管理员接收短信要用到的手机号,仅支持一个手机号</note>
<type>text</type>
<required>true</required>
</mobile>
</code>
<manage>
<send>
<title>发短信</title>
<exec>sendsms</exec>
<type>page</type>
</send>
</manage>
</root>
好了,经过以上的替换,短信宝的短信平台已经替换成功了,可以正常使用了。我们可以进行测试发送。
报备一下短信宝的VIP模板,这样就可以走短信宝的优质通道了,短信内容3~5秒就可送达。