<?php
class duanxin extends pluginBase{
//插件中文名称
public static function name(){
return "发送短信";
}
//插件的功能简介
public static function description(){
return "发送短信测试,发个短信玩一玩";
}
//安装插件代码
public static function install(){
$onlineDB=new IModel('duanxin');
//检测表是否存在
if($onlineDB->exists()){
return true;
}
$data=array(
"comment" => self::name(),
"column" => array(
"id" => array("type"=>"int(11) unsigned",'auto_increment'=>1),
"mobile" => array("type"=>"varchar(255)",'comment'=>"发送手机号"),
"content" => array("type"=>"varchar(255)",'comment'=>"发送内容")
),
"index"=>array("primary"=>"id","key"=>"mobile"),
);
$onlineDB->setData($data);
return $onlineDB->createTable();
}
//卸载插件代码
public static function uninstall(){
$onlineDB=new IModel('duanxin');
return $onlineDB->dropTable();
}
//插件参数配置
public static function configName(){
return array(
"name_s"=>array("name"=>"配置账号","type"=>"text","value"=>"123"),
"pwd"=>array("name"=>"配置密码","type"=>"text","value"=>"123"),
);
}
//钩子插件
public function reg(){
//后台管理
plugin::reg("onSystemMenuCreate",function (){
$link="/plugins/duanxin_list";
$link="javascript:art.dialog.open('".IUrl::creatUrl($link)."')";
Menu::$menu["插件"]["插件管理"][$link]=$this->name();
});
//展示左侧
plugin::reg("onBeforeCreateAction@plugins@duanxin_list", function (){
self::controller()->duanxin_list=function (){$this->duanxin_list();};
});
//发送手机号
plugin::reg("onBeforeCreateAction@plugins@duanxin_edit", function (){
self::controller()->duanxin_edit=function (){$this->duanxin_edit();};
});
//提交手机号
plugin::reg("onBeforeCreateAction@plugins@duanxin_send", function (){
self::controller()->duanxin_send=function (){$this->duanxin_send();};
});
}
//展示左侧页面
function duanxin_list(){$this->view("duanxin_list");}
function duanxin_edit(){$this->view("duanxin_edit");}
//最终发送
function duanxin_send(){
$mobile=IReq::get('mobile');
$content=IReq::get('content');
$data=array(
'mobile'=>$mobile,
'content'=>$content
);
$plugin=new IModel('plugin');
$duanxin=$plugin->getObj("class_name='duanxin'");
$config=json_decode($duanxin['config_param'],true);
if(!$config||!$duanxin){
IError::show("数据错误");exit();
}
$target = "http://sms.106jiekou.com/utf8/sms.aspx";
$post_data = "account={$config['name_s']}&password={$config['pwd']}&mobile={$mobile}&content={$content}";
$res=$this->Post($post_data,$target);
if($res!=100){
IError::show($res."短信发送错误");exit();
}
$dxDB=new IModel('duanxin');
$dxDB->setData($data);
$dxDB->add();
$this->view("duanxin_list");
}
function Post($curlPost,$url){
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_NOBODY, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $curlPost);
$return_str = curl_exec($curl);
curl_close($curl);
return $return_str;
}
}
//修改短信
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
{js:jquery}
{js:validate}
{js:dialog}
{js:artTemplate}
{js:form}
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<link href="//cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container">
<form action="{url:/plugins/duanxin_send}" method="post" name='service_online'>
<table class='table'>
<tr>
<td>
<table class='table' id='service_box'>
<thead>
<tr>
<th>发送手机号</th>
<th>发送内容</th>
</tr>
</thead>
<tbody></tbody>
<script type='text/html' id='serviceTrTemplate'>
<tr>
<td><input type='text' name='mobile' class='form-control' value='<%=mobile%>' /></td>
<td><input type='text' name='content' class='form-control' value='<%=content%>' /></td>
</tr>
</script>
</table>
</td>
</tr>
<tr>
<td>
<input type="submit" class="btn btn-success" value="发送" />
<input type="button" class="btn btn-danger" value="取 消" οnclick="art.dialog.close();" />
</td>
</tr>
</table>
</form>
</div>
</body>
<script type="text/javascript">
//生成在线客服
{if:isset($qq) && $qq}
var serviceOnlineList = {echo:JSON::encode($qq)};
for(var index in serviceOnlineList)
{
add_service(serviceOnlineList[index]);
}
{else:}
add_service();
{/if}
//添加客服
function add_service(data)
{
var data = data ? data : {};
var serviceTrHtml = template.render('serviceTrTemplate',data);
$('#service_box tbody').append(serviceTrHtml);
var last_index = $('#service_box tbody tr').size()-1;
buttonInit(last_index,'#service_box');
}
//操作按钮绑定
function buttonInit(indexValue,ele)
{
ele = ele || "#guide_box";
if(indexValue == undefined || indexValue === '')
{
var button_times = $(ele+' tbody tr').length;
for(var item=0;item < button_times;item++)
{
buttonInit(item,ele);
}
}
else
{
var obj = $(ele+' tbody tr:eq('+indexValue+') .operator')
//功能操作按钮
obj.each(
function(i)
{
switch(i)
{
//向上排序
case 0:
{
$(this).click(
function()
{
var insertIndex = $(this).parent().parent().prev().index();
if(insertIndex >= 0)
{
$(ele+' tbody tr:eq('+insertIndex+')').before($(this).parent().parent());
}
}
)
}
break;
//向上排序
case 1:
{
$(this).click(
function()
{
var insertIndex = $(this).parent().parent().next().index();
$(ele+' tbody tr:eq('+insertIndex+')').after($(this).parent().parent());
}
)
}
break;
//删除排序
case 2:
{
$(this).click(
function()
{
var obj = $(this);
art.dialog.confirm('确定要删除么?',function(){obj.parent().parent().remove()});
}
)
}
break;
}
}
)
}
}
</script>
//短信列表
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
{js:jquery}
{js:validate}
{js:dialog}
{js:artTemplate}
{js:form}
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<link href="//cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container">
<ul class="nav nav-pills">
<li><input type="button" οnclick="window.location.href='{url:/plugins/duanxin_edit}';" class="btn btn-info" value="发送短信" /></li>
</ul>
<table class="table table-bordered">
<colgroup>
<col width="200px" />
<col width="180px" />
<col />
</colgroup>
<thead>
<tr>
<th>手机号</th>
<th>发送内容</th>
</tr>
</thead>
<tbody>
{query: name=duanxin order=id desc}
<tr>
<td>{$item['mobile']}</td>
<td>{$item['content']}</td>
</tr>
{/query}
</tbody>
</table>
</div>
</body>
</html>