Browse Source

im聊天记录自动拉取

lizhen_gitee 8 months ago
parent
commit
8b57eb67da

+ 122 - 0
application/admin/controller/Imlogc2c.php

@@ -0,0 +1,122 @@
+<?php
+
+namespace app\admin\controller;
+
+use app\common\controller\Backend;
+use think\Db;
+/**
+ * 
+ *
+ * @icon fa fa-circle-o
+ */
+class Imlogc2c extends Backend
+{
+    
+    /**
+     * Imlogc2c模型对象
+     * @var \app\admin\model\Imlogc2c
+     */
+    protected $model = null;
+
+    public function _initialize()
+    {
+        parent::_initialize();
+        $this->model = new \app\admin\model\Imlogc2c;
+
+    }
+
+    public function import()
+    {
+        parent::import();
+    }
+
+    /**
+     * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
+     * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
+     * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
+     */
+    
+
+    /**
+     * 查看
+     */
+    public function index()
+    {
+        //当前是否为关联查询
+        $this->relationSearch = true;
+        //设置过滤方法
+        $this->request->filter(['strip_tags', 'trim']);
+        if ($this->request->isAjax()) {
+            //如果发送的来源是Selectpage,则转发到Selectpage
+            if ($this->request->request('keyField')) {
+                return $this->selectpage();
+            }
+            list($where, $sort, $order, $offset, $limit) = $this->buildparams();
+
+            $list = $this->model
+                    ->with(['fromuser','touser'])
+                    ->where($where)
+                    ->order($sort, $order)
+                    ->paginate($limit);
+
+            foreach ($list as $row) {
+                
+                $row->getRelation('fromuser')->visible(['nickname']);
+				$row->getRelation('touser')->visible(['nickname']);
+            }
+
+            $list2 = collection($list->items())->toArray();
+
+            $type_arr = $this->type_arr();
+            foreach($list2 as $key => &$val){
+                $val['MsgType'] = isset($type_arr[$val['MsgType']]) ? $type_arr[$val['MsgType']] : '其他';
+            }
+
+            $result = array("total" => $list->total(), "rows" => $list2);
+
+            return json($result);
+        }
+        return $this->view->fetch();
+    }
+
+    private function type_arr(){
+        $type_arr = [
+            'TIMTextElem' => '文本',
+            'TIMImageElem' => '图片',
+            'TIMSoundElem' => '声音',
+            'TIMVideoFileElem' => '视频',
+        ];
+        return $type_arr;
+    }
+
+    /**
+     * 消息体
+     */
+    public function showbody(){
+        $id = input('id',0);
+        $info = Db::name('imlog_c2c')->where('id',$id)->find();
+
+
+        $type_arr = $this->type_arr();
+
+        $info['typetext'] = isset($type_arr[$info['MsgType']]) ? $type_arr[$info['MsgType']] : '其他';
+
+        if($info['MsgType'] == 'TIMTextElem'){
+            $info['MsgInfo'] = $info['MsgInfo'];
+        }
+        if($info['MsgType'] == 'TIMImageElem'){
+            $info['MsgInfo'] = '<img width="800" height="800" src="'.$info['MsgInfo'].'">';
+        }
+        if($info['MsgType'] == 'TIMSoundElem'){
+            $info['MsgInfo'] = '<audio controls><source src="'.$info['MsgInfo'].'"></audio>';
+        }
+        if($info['MsgType'] == 'TIMVideoFileElem'){
+            $info['MsgInfo'] = '<video width="800" height="800" controls preload src="'.$info['MsgInfo'].'"></video>';
+        }
+
+        $this->assign('info',$info);
+
+        return $this->view->fetch();
+    }
+
+}

+ 110 - 0
application/admin/controller/Imloggroup.php

@@ -0,0 +1,110 @@
+<?php
+
+namespace app\admin\controller;
+
+use app\common\controller\Backend;
+use think\Db;
+/**
+ * 群组聊天记录
+ *
+ * @icon fa fa-circle-o
+ */
+class Imloggroup extends Backend
+{
+    
+    /**
+     * Imloggroup模型对象
+     * @var \app\admin\model\Imloggroup
+     */
+    protected $model = null;
+
+    public function _initialize()
+    {
+        parent::_initialize();
+        $this->model = new \app\admin\model\Imloggroup;
+
+    }
+
+    public function import()
+    {
+        parent::import();
+    }
+
+    /**
+     * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
+     * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
+     * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
+     */
+    
+
+    /**
+     * 查看
+     */
+    public function index()
+    {
+        //当前是否为关联查询
+        $this->relationSearch = true;
+        //设置过滤方法
+        $this->request->filter(['strip_tags', 'trim']);
+        if ($this->request->isAjax()) {
+            //如果发送的来源是Selectpage,则转发到Selectpage
+            if ($this->request->request('keyField')) {
+                return $this->selectpage();
+            }
+            list($where, $sort, $order, $offset, $limit) = $this->buildparams();
+
+            $list = $this->model
+                    ->with(['user','party'])
+                    ->where($where)
+                    ->order($sort, $order)
+                    ->paginate($limit);
+
+            foreach ($list as $row) {
+                
+                $row->getRelation('user')->visible(['nickname']);
+				$row->getRelation('party')->visible(['room_type','party_name']);
+            }
+
+            $list2 = collection($list->items())->toArray();
+
+            $type_arr = $this->type_arr();
+            foreach($list2 as $key => &$val){
+                $val['MsgType'] = isset($type_arr[$val['MsgType']]) ? $type_arr[$val['MsgType']] : '其他';
+            }
+
+            $result = array("total" => $list->total(), "rows" => $list2);
+
+            return json($result);
+        }
+        return $this->view->fetch();
+    }
+
+    private function type_arr(){
+        $type_arr = [
+            'TIMTextElem' => '文本',
+            'TIMImageElem' => '图片',
+            'TIMSoundElem' => '声音',
+            'TIMVideoFileElem' => '视频',
+        ];
+        return $type_arr;
+    }
+
+    /**
+     * 消息体
+     */
+    public function showbody(){
+        $id = input('id',0);
+        $info = Db::name('imlog_group')->where('id',$id)->find();
+
+
+        $type_arr = $this->type_arr();
+
+        $info['typetext'] = isset($type_arr[$info['MsgType']]) ? $type_arr[$info['MsgType']] : '其他';
+
+
+        $this->assign('info',$info);
+
+        return $this->view->fetch();
+    }
+
+}

+ 13 - 0
application/admin/lang/zh-cn/imlogc2c.php

@@ -0,0 +1,13 @@
+<?php
+
+return [
+    'Id'              => 'ID',
+    'Clientip'        => 'ip',
+    'From_account'    => '发送人id',
+    'Msgbody'         => '消息体',
+    'Msgfromplatform' => '平台',
+    'Msgtimestamp'    => '发送时间',
+    'To_account'      => '接收人id',
+    'fromuser.nickname' => '发送人昵称',
+    'touser.nickname'   => '接收人昵称'
+];

+ 18 - 0
application/admin/lang/zh-cn/imloggroup.php

@@ -0,0 +1,18 @@
+<?php
+
+return [
+    'Id'                => 'ID',
+    'Clientip'          => 'ip',
+    'From_account'      => '发送人id',
+    'Groupid'           => '房间ID',
+    'Msgbody'           => '消息体',
+    'Msgfromplatform'   => '平台',
+    'Msgtimestamp'      => '发送时间',
+    'Msgtype'           => '内容类型',
+    'Msginfo'           => '内容',
+    'User.nickname'     => '发送人昵称',
+    'Party.room_type'   => '房间类型',
+    'Party.room_type 1' => '派对',
+    'Party.room_type 2' => '直播',
+    'Party.party_name'  => '派对名称'
+];

+ 50 - 0
application/admin/model/Imlogc2c.php

@@ -0,0 +1,50 @@
+<?php
+
+namespace app\admin\model;
+
+use think\Model;
+
+
+class Imlogc2c extends Model
+{
+
+    
+
+    
+
+    // 表名
+    protected $name = 'imlog_c2c';
+    
+    // 自动写入时间戳字段
+    protected $autoWriteTimestamp = false;
+
+    // 定义时间戳字段名
+    protected $createTime = false;
+    protected $updateTime = false;
+    protected $deleteTime = false;
+
+    // 追加属性
+    protected $append = [
+
+    ];
+    
+
+    
+
+
+
+
+
+
+
+    public function fromuser()
+    {
+        return $this->belongsTo('User', 'From_Account', 'id', [], 'LEFT')->setEagerlyType(0);
+    }
+
+
+    public function touser()
+    {
+        return $this->belongsTo('User', 'To_Account', 'id', [], 'LEFT')->setEagerlyType(0);
+    }
+}

+ 50 - 0
application/admin/model/Imloggroup.php

@@ -0,0 +1,50 @@
+<?php
+
+namespace app\admin\model;
+
+use think\Model;
+
+
+class Imloggroup extends Model
+{
+
+    
+
+    
+
+    // 表名
+    protected $name = 'imlog_group';
+    
+    // 自动写入时间戳字段
+    protected $autoWriteTimestamp = false;
+
+    // 定义时间戳字段名
+    protected $createTime = false;
+    protected $updateTime = false;
+    protected $deleteTime = false;
+
+    // 追加属性
+    protected $append = [
+
+    ];
+    
+
+    
+
+
+
+
+
+
+
+    public function user()
+    {
+        return $this->belongsTo('User', 'From_Account', 'id', [], 'LEFT')->setEagerlyType(0);
+    }
+
+
+    public function party()
+    {
+        return $this->belongsTo('app\admin\model\party\Party', 'GroupId', 'id', [], 'LEFT')->setEagerlyType(0);
+    }
+}

+ 27 - 0
application/admin/validate/Imlogc2c.php

@@ -0,0 +1,27 @@
+<?php
+
+namespace app\admin\validate;
+
+use think\Validate;
+
+class Imlogc2c extends Validate
+{
+    /**
+     * 验证规则
+     */
+    protected $rule = [
+    ];
+    /**
+     * 提示消息
+     */
+    protected $message = [
+    ];
+    /**
+     * 验证场景
+     */
+    protected $scene = [
+        'add'  => [],
+        'edit' => [],
+    ];
+    
+}

+ 27 - 0
application/admin/validate/Imloggroup.php

@@ -0,0 +1,27 @@
+<?php
+
+namespace app\admin\validate;
+
+use think\Validate;
+
+class Imloggroup extends Validate
+{
+    /**
+     * 验证规则
+     */
+    protected $rule = [
+    ];
+    /**
+     * 提示消息
+     */
+    protected $message = [
+    ];
+    /**
+     * 验证场景
+     */
+    protected $scene = [
+        'add'  => [],
+        'edit' => [],
+    ];
+    
+}

+ 64 - 0
application/admin/view/imlogc2c/add.html

@@ -0,0 +1,64 @@
+<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
+
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Clientip')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-ClientIP" class="form-control" name="row[ClientIP]" type="text">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Cloudcustomdata')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <textarea id="c-CloudCustomData" class="form-control " rows="5" name="row[CloudCustomData]" cols="50"></textarea>
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('From_account')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-From_Account" class="form-control" name="row[From_Account]" type="number">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Msgbody')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <textarea id="c-MsgBody" class="form-control " rows="5" name="row[MsgBody]" cols="50"></textarea>
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Msgfromplatform')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-MsgFromPlatform" class="form-control" name="row[MsgFromPlatform]" type="text">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Msgrandom')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-MsgRandom" class="form-control" name="row[MsgRandom]" type="text">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Msgseq')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-MsgSeq" class="form-control" name="row[MsgSeq]" type="text">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Msgtimestamp')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-MsgTimestamp" class="form-control" name="row[MsgTimestamp]" type="text">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('To_account')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-To_Account" class="form-control" name="row[To_Account]" type="number">
+        </div>
+    </div>
+    <div class="form-group layer-footer">
+        <label class="control-label col-xs-12 col-sm-2"></label>
+        <div class="col-xs-12 col-sm-8">
+            <button type="submit" class="btn btn-success btn-embossed disabled">{:__('OK')}</button>
+            <button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
+        </div>
+    </div>
+</form>

+ 64 - 0
application/admin/view/imlogc2c/edit.html

@@ -0,0 +1,64 @@
+<form id="edit-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
+
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Clientip')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-ClientIP" class="form-control" name="row[ClientIP]" type="text" value="{$row.ClientIP|htmlentities}">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Cloudcustomdata')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <textarea id="c-CloudCustomData" class="form-control " rows="5" name="row[CloudCustomData]" cols="50">{$row.CloudCustomData|htmlentities}</textarea>
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('From_account')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-From_Account" class="form-control" name="row[From_Account]" type="number" value="{$row.From_Account|htmlentities}">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Msgbody')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <textarea id="c-MsgBody" class="form-control " rows="5" name="row[MsgBody]" cols="50">{$row.MsgBody|htmlentities}</textarea>
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Msgfromplatform')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-MsgFromPlatform" class="form-control" name="row[MsgFromPlatform]" type="text" value="{$row.MsgFromPlatform|htmlentities}">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Msgrandom')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-MsgRandom" class="form-control" name="row[MsgRandom]" type="text" value="{$row.MsgRandom|htmlentities}">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Msgseq')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-MsgSeq" class="form-control" name="row[MsgSeq]" type="text" value="{$row.MsgSeq|htmlentities}">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Msgtimestamp')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-MsgTimestamp" class="form-control" name="row[MsgTimestamp]" type="text" value="{$row.MsgTimestamp|htmlentities}">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('To_account')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-To_Account" class="form-control" name="row[To_Account]" type="number" value="{$row.To_Account|htmlentities}">
+        </div>
+    </div>
+    <div class="form-group layer-footer">
+        <label class="control-label col-xs-12 col-sm-2"></label>
+        <div class="col-xs-12 col-sm-8">
+            <button type="submit" class="btn btn-success btn-embossed disabled">{:__('OK')}</button>
+            <button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
+        </div>
+    </div>
+</form>

+ 35 - 0
application/admin/view/imlogc2c/index.html

@@ -0,0 +1,35 @@
+<div class="panel panel-default panel-intro">
+    {:build_heading()}
+
+    <div class="panel-body">
+        <div id="myTabContent" class="tab-content">
+            <div class="tab-pane fade active in" id="one">
+                <div class="widget-body no-padding">
+                    <div id="toolbar" class="toolbar">
+                        <a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a>
+                        <!--<a href="javascript:;" class="btn btn-success btn-add {:$auth->check('imlogc2c/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a>
+                        <a href="javascript:;" class="btn btn-success btn-edit btn-disabled disabled {:$auth->check('imlogc2c/edit')?'':'hide'}" title="{:__('Edit')}" ><i class="fa fa-pencil"></i> {:__('Edit')}</a>
+                        <a href="javascript:;" class="btn btn-danger btn-del btn-disabled disabled {:$auth->check('imlogc2c/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a>
+                        <a href="javascript:;" class="btn btn-danger btn-import {:$auth->check('imlogc2c/import')?'':'hide'}" title="{:__('Import')}" id="btn-import-file" data-url="ajax/upload" data-mimetype="csv,xls,xlsx" data-multiple="false"><i class="fa fa-upload"></i> {:__('Import')}</a>
+
+                        <div class="dropdown btn-group {:$auth->check('imlogc2c/multi')?'':'hide'}">
+                            <a class="btn btn-primary btn-more dropdown-toggle btn-disabled disabled" data-toggle="dropdown"><i class="fa fa-cog"></i> {:__('More')}</a>
+                            <ul class="dropdown-menu text-left" role="menu">
+                                <li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status=normal"><i class="fa fa-eye"></i> {:__('Set to normal')}</a></li>
+                                <li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status=hidden"><i class="fa fa-eye-slash"></i> {:__('Set to hidden')}</a></li>
+                            </ul>
+                        </div>-->
+
+                        
+                    </div>
+                    <table id="table" class="table table-striped table-bordered table-hover table-nowrap"
+                           data-operate-edit="{:$auth->check('imlogc2c/edit')}" 
+                           data-operate-del="{:$auth->check('imlogc2c/del')}" 
+                           width="100%">
+                    </table>
+                </div>
+            </div>
+
+        </div>
+    </div>
+</div>

+ 17 - 0
application/admin/view/imlogc2c/showbody.html

@@ -0,0 +1,17 @@
+<table class="table table-bordered">
+    <!--<tr>
+        <td><?php
+            $body = json_decode($info['MsgBody'],true);
+            dump($body);
+
+        ?></td>
+    </tr>-->
+    <tr>
+        <td><?php echo $info['typetext']?><td>
+    </tr>
+    <tr>
+        <td><?php echo $info['MsgInfo']?><td>
+    </tr>
+
+</table>
+

+ 64 - 0
application/admin/view/imloggroup/add.html

@@ -0,0 +1,64 @@
+<form id="add-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
+
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Clientip')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-ClientIP" class="form-control" name="row[ClientIP]" type="text">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('From_account')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-From_Account" class="form-control" name="row[From_Account]" type="number">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Groupid')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-GroupId" class="form-control" name="row[GroupId]" type="number">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Msgbody')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <textarea id="c-MsgBody" class="form-control " rows="5" name="row[MsgBody]" cols="50"></textarea>
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Msgfromplatform')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-MsgFromPlatform" class="form-control" name="row[MsgFromPlatform]" type="text">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Msgseq')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-MsgSeq" class="form-control" name="row[MsgSeq]" type="text">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Msgtimestamp')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-MsgTimestamp" class="form-control" name="row[MsgTimestamp]" type="text">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Msgtype')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-MsgType" class="form-control" name="row[MsgType]" type="text">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Msginfo')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <textarea id="c-MsgInfo" class="form-control " rows="5" name="row[MsgInfo]" cols="50"></textarea>
+        </div>
+    </div>
+    <div class="form-group layer-footer">
+        <label class="control-label col-xs-12 col-sm-2"></label>
+        <div class="col-xs-12 col-sm-8">
+            <button type="submit" class="btn btn-success btn-embossed disabled">{:__('OK')}</button>
+            <button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
+        </div>
+    </div>
+</form>

+ 64 - 0
application/admin/view/imloggroup/edit.html

@@ -0,0 +1,64 @@
+<form id="edit-form" class="form-horizontal" role="form" data-toggle="validator" method="POST" action="">
+
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Clientip')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-ClientIP" class="form-control" name="row[ClientIP]" type="text" value="{$row.ClientIP|htmlentities}">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('From_account')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-From_Account" class="form-control" name="row[From_Account]" type="number" value="{$row.From_Account|htmlentities}">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Groupid')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-GroupId" class="form-control" name="row[GroupId]" type="number" value="{$row.GroupId|htmlentities}">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Msgbody')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <textarea id="c-MsgBody" class="form-control " rows="5" name="row[MsgBody]" cols="50">{$row.MsgBody|htmlentities}</textarea>
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Msgfromplatform')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-MsgFromPlatform" class="form-control" name="row[MsgFromPlatform]" type="text" value="{$row.MsgFromPlatform|htmlentities}">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Msgseq')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-MsgSeq" class="form-control" name="row[MsgSeq]" type="text" value="{$row.MsgSeq|htmlentities}">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Msgtimestamp')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-MsgTimestamp" class="form-control" name="row[MsgTimestamp]" type="text" value="{$row.MsgTimestamp|htmlentities}">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Msgtype')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <input id="c-MsgType" class="form-control" name="row[MsgType]" type="text" value="{$row.MsgType|htmlentities}">
+        </div>
+    </div>
+    <div class="form-group">
+        <label class="control-label col-xs-12 col-sm-2">{:__('Msginfo')}:</label>
+        <div class="col-xs-12 col-sm-8">
+            <textarea id="c-MsgInfo" class="form-control " rows="5" name="row[MsgInfo]" cols="50">{$row.MsgInfo|htmlentities}</textarea>
+        </div>
+    </div>
+    <div class="form-group layer-footer">
+        <label class="control-label col-xs-12 col-sm-2"></label>
+        <div class="col-xs-12 col-sm-8">
+            <button type="submit" class="btn btn-success btn-embossed disabled">{:__('OK')}</button>
+            <button type="reset" class="btn btn-default btn-embossed">{:__('Reset')}</button>
+        </div>
+    </div>
+</form>

+ 35 - 0
application/admin/view/imloggroup/index.html

@@ -0,0 +1,35 @@
+<div class="panel panel-default panel-intro">
+    {:build_heading()}
+
+    <div class="panel-body">
+        <div id="myTabContent" class="tab-content">
+            <div class="tab-pane fade active in" id="one">
+                <div class="widget-body no-padding">
+                    <div id="toolbar" class="toolbar">
+                        <a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a>
+                        <!--<a href="javascript:;" class="btn btn-success btn-add {:$auth->check('imloggroup/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a>
+                        <a href="javascript:;" class="btn btn-success btn-edit btn-disabled disabled {:$auth->check('imloggroup/edit')?'':'hide'}" title="{:__('Edit')}" ><i class="fa fa-pencil"></i> {:__('Edit')}</a>
+                        <a href="javascript:;" class="btn btn-danger btn-del btn-disabled disabled {:$auth->check('imloggroup/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a>
+                        <a href="javascript:;" class="btn btn-danger btn-import {:$auth->check('imloggroup/import')?'':'hide'}" title="{:__('Import')}" id="btn-import-file" data-url="ajax/upload" data-mimetype="csv,xls,xlsx" data-multiple="false"><i class="fa fa-upload"></i> {:__('Import')}</a>
+
+                        <div class="dropdown btn-group {:$auth->check('imloggroup/multi')?'':'hide'}">
+                            <a class="btn btn-primary btn-more dropdown-toggle btn-disabled disabled" data-toggle="dropdown"><i class="fa fa-cog"></i> {:__('More')}</a>
+                            <ul class="dropdown-menu text-left" role="menu">
+                                <li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status=normal"><i class="fa fa-eye"></i> {:__('Set to normal')}</a></li>
+                                <li><a class="btn btn-link btn-multi btn-disabled disabled" href="javascript:;" data-params="status=hidden"><i class="fa fa-eye-slash"></i> {:__('Set to hidden')}</a></li>
+                            </ul>
+                        </div>
+-->
+                        
+                    </div>
+                    <table id="table" class="table table-striped table-bordered table-hover table-nowrap"
+                           data-operate-edit="{:$auth->check('imloggroup/edit')}" 
+                           data-operate-del="{:$auth->check('imloggroup/del')}" 
+                           width="100%">
+                    </table>
+                </div>
+            </div>
+
+        </div>
+    </div>
+</div>

+ 17 - 0
application/admin/view/imloggroup/showbody.html

@@ -0,0 +1,17 @@
+<table class="table table-bordered">
+    <!--<tr>
+        <td><?php
+            $body = json_decode($info['MsgBody'],true);
+            dump($body);
+
+        ?></td>
+    </tr>-->
+    <tr>
+        <td><?php echo $info['typetext']?><td>
+    </tr>
+    <tr>
+        <td><?php echo $info['MsgInfo']?><td>
+    </tr>
+
+</table>
+

+ 470 - 0
application/common/library/Tlssigapiv2.php

@@ -0,0 +1,470 @@
+<?php
+
+namespace app\common\library;
+
+class Tlssigapiv2 {
+
+    private $key = false;
+    private $sdkappid = 0;
+
+    /**
+    *【功能说明】用于签发 TRTC 和 IM 服务中必须要使用的 UserSig 鉴权票据
+    *
+    *【参数说明】
+    * @param string userid - 用户id,限制长度为32字节,只允许包含大小写英文字母(a-zA-Z)、数字(0-9)及下划线和连词符。
+    * @param string expire - UserSig 票据的过期时间,单位是秒,比如 86400 代表生成的 UserSig 票据在一天后就无法再使用了。
+    * @return string 签名字符串
+    * @throws \Exception
+    */
+
+    /**
+     * Function: Used to issue UserSig that is required by the TRTC and IM services.
+     *
+     * Parameter description:
+     * @param userid - User ID. The value can be up to 32 bytes in length and contain letters (a-z and A-Z), digits (0-9), underscores (_), and hyphens (-).
+     * @param expire - UserSig expiration time, in seconds. For example, 86400 indicates that the generated UserSig will expire one day after being generated.
+     * @return string signature string
+     * @throws \Exception
+    */
+
+    public function genUserSig( $userid, $expire = 86400*180 ) {
+        return $this->__genSig( $userid, $expire, '', false );
+    }
+
+    /**
+    *【功能说明】
+    * 用于签发 TRTC 进房参数中可选的 PrivateMapKey 权限票据。
+    * PrivateMapKey 需要跟 UserSig 一起使用,但 PrivateMapKey 比 UserSig 有更强的权限控制能力:
+    *  - UserSig 只能控制某个 UserID 有无使用 TRTC 服务的权限,只要 UserSig 正确,其对应的 UserID 可以进出任意房间。
+    *  - PrivateMapKey 则是将 UserID 的权限控制的更加严格,包括能不能进入某个房间,能不能在该房间里上行音视频等等。
+    * 如果要开启 PrivateMapKey 严格权限位校验,需要在【实时音视频控制台】=>【应用管理】=>【应用信息】中打开“启动权限密钥”开关。
+    *
+    *【参数说明】
+    * @param userid - 用户id,限制长度为32字节,只允许包含大小写英文字母(a-zA-Z)、数字(0-9)及下划线和连词符。
+    * @param expire - PrivateMapKey 票据的过期时间,单位是秒,比如 86400 生成的 PrivateMapKey 票据在一天后就无法再使用了。
+    * @param roomid - 房间号,用于指定该 userid 可以进入的房间号
+    * @param privilegeMap - 权限位,使用了一个字节中的 8 个比特位,分别代表八个具体的功能权限开关:
+    *  - 第 1 位:0000 0001 = 1,创建房间的权限
+    *  - 第 2 位:0000 0010 = 2,加入房间的权限
+    *  - 第 3 位:0000 0100 = 4,发送语音的权限
+    *  - 第 4 位:0000 1000 = 8,接收语音的权限
+    *  - 第 5 位:0001 0000 = 16,发送视频的权限
+    *  - 第 6 位:0010 0000 = 32,接收视频的权限
+    *  - 第 7 位:0100 0000 = 64,发送辅路(也就是屏幕分享)视频的权限
+    *  - 第 8 位:1000 0000 = 200,接收辅路(也就是屏幕分享)视频的权限
+    *  - privilegeMap == 1111 1111 == 255 代表该 userid 在该 roomid 房间内的所有功能权限。
+    *  - privilegeMap == 0010 1010 == 42  代表该 userid 拥有加入房间和接收音视频数据的权限,但不具备其他权限。
+    */
+
+    /**
+     * Function:
+     * Used to issue PrivateMapKey that is optional for room entry.
+     * PrivateMapKey must be used together with UserSig but with more powerful permission control capabilities.
+     *  - UserSig can only control whether a UserID has permission to use the TRTC service. As long as the UserSig is correct, the user with the corresponding UserID can enter or leave any room.
+     *  - PrivateMapKey specifies more stringent permissions for a UserID, including whether the UserID can be used to enter a specific room and perform audio/video upstreaming in the room.
+     * To enable stringent PrivateMapKey permission bit verification, you need to enable permission key in TRTC console > Application Management > Application Info.
+     *
+     * Parameter description:
+     * userid - User ID. The value can be up to 32 bytes in length and contain letters (a-z and A-Z), digits (0-9), underscores (_), and hyphens (-).
+     * roomid - ID of the room to which the specified UserID can enter.
+     * expire - PrivateMapKey expiration time, in seconds. For example, 86400 indicates that the generated PrivateMapKey will expire one day after being generated.
+     * privilegeMap - Permission bits. Eight bits in the same byte are used as the permission switches of eight specific features:
+     *  - Bit 1: 0000 0001 = 1, permission for room creation
+     *  - Bit 2: 0000 0010 = 2, permission for room entry
+     *  - Bit 3: 0000 0100 = 4, permission for audio sending
+     *  - Bit 4: 0000 1000 = 8, permission for audio receiving
+     *  - Bit 5: 0001 0000 = 16, permission for video sending
+     *  - Bit 6: 0010 0000 = 32, permission for video receiving
+     *  - Bit 7: 0100 0000 = 64, permission for substream video sending (screen sharing)
+     *  - Bit 8: 1000 0000 = 200, permission for substream video receiving (screen sharing)
+     *  - privilegeMap == 1111 1111 == 255: Indicates that the UserID has all feature permissions of the room specified by roomid.
+     *  - privilegeMap == 0010 1010 == 42: Indicates that the UserID has only the permissions to enter the room and receive audio/video data.
+     */
+
+    public function genPrivateMapKey( $userid, $expire, $roomid, $privilegeMap ) {
+        $userbuf = $this->__genUserBuf( $userid, $roomid, $expire, $privilegeMap, 0, '' );
+        return $this->__genSig( $userid, $expire, $userbuf, true );
+    }
+    /**
+    *【功能说明】
+    * 用于签发 TRTC 进房参数中可选的 PrivateMapKey 权限票据。
+    * PrivateMapKey 需要跟 UserSig 一起使用,但 PrivateMapKey 比 UserSig 有更强的权限控制能力:
+    *  - UserSig 只能控制某个 UserID 有无使用 TRTC 服务的权限,只要 UserSig 正确,其对应的 UserID 可以进出任意房间。
+    *  - PrivateMapKey 则是将 UserID 的权限控制的更加严格,包括能不能进入某个房间,能不能在该房间里上行音视频等等。
+    * 如果要开启 PrivateMapKey 严格权限位校验,需要在【实时音视频控制台】=>【应用管理】=>【应用信息】中打开“启动权限密钥”开关。
+    *
+    *【参数说明】
+    * @param userid - 用户id,限制长度为32字节,只允许包含大小写英文字母(a-zA-Z)、数字(0-9)及下划线和连词符。
+    * @param expire - PrivateMapKey 票据的过期时间,单位是秒,比如 86400 生成的 PrivateMapKey 票据在一天后就无法再使用了。
+    * @param roomstr - 房间号,用于指定该 userid 可以进入的房间号
+    * @param privilegeMap - 权限位,使用了一个字节中的 8 个比特位,分别代表八个具体的功能权限开关:
+    *  - 第 1 位:0000 0001 = 1,创建房间的权限
+    *  - 第 2 位:0000 0010 = 2,加入房间的权限
+    *  - 第 3 位:0000 0100 = 4,发送语音的权限
+    *  - 第 4 位:0000 1000 = 8,接收语音的权限
+    *  - 第 5 位:0001 0000 = 16,发送视频的权限
+    *  - 第 6 位:0010 0000 = 32,接收视频的权限
+    *  - 第 7 位:0100 0000 = 64,发送辅路(也就是屏幕分享)视频的权限
+    *  - 第 8 位:1000 0000 = 200,接收辅路(也就是屏幕分享)视频的权限
+    *  - privilegeMap == 1111 1111 == 255 代表该 userid 在该 roomid 房间内的所有功能权限。
+    *  - privilegeMap == 0010 1010 == 42  代表该 userid 拥有加入房间和接收音视频数据的权限,但不具备其他权限。
+    */
+
+    /**
+     * Function:
+     * Used to issue PrivateMapKey that is optional for room entry.
+     * PrivateMapKey must be used together with UserSig but with more powerful permission control capabilities.
+     *  - UserSig can only control whether a UserID has permission to use the TRTC service. As long as the UserSig is correct, the user with the corresponding UserID can enter or leave any room.
+     *  - PrivateMapKey specifies more stringent permissions for a UserID, including whether the UserID can be used to enter a specific room and perform audio/video upstreaming in the room.
+     * To enable stringent PrivateMapKey permission bit verification, you need to enable permission key in TRTC console > Application Management > Application Info.
+     *
+     * Parameter description:
+     * @param userid - User ID. The value can be up to 32 bytes in length and contain letters (a-z and A-Z), digits (0-9), underscores (_), and hyphens (-).
+     * @param roomstr - ID of the room to which the specified UserID can enter.
+     * @param expire - PrivateMapKey expiration time, in seconds. For example, 86400 indicates that the generated PrivateMapKey will expire one day after being generated.
+     * @param privilegeMap - Permission bits. Eight bits in the same byte are used as the permission switches of eight specific features:
+     *  - Bit 1: 0000 0001 = 1, permission for room creation
+     *  - Bit 2: 0000 0010 = 2, permission for room entry
+     *  - Bit 3: 0000 0100 = 4, permission for audio sending
+     *  - Bit 4: 0000 1000 = 8, permission for audio receiving
+     *  - Bit 5: 0001 0000 = 16, permission for video sending
+     *  - Bit 6: 0010 0000 = 32, permission for video receiving
+     *  - Bit 7: 0100 0000 = 64, permission for substream video sending (screen sharing)
+     *  - Bit 8: 1000 0000 = 200, permission for substream video receiving (screen sharing)
+     *  - privilegeMap == 1111 1111 == 255: Indicates that the UserID has all feature permissions of the room specified by roomid.
+     *  - privilegeMap == 0010 1010 == 42: Indicates that the UserID has only the permissions to enter the room and receive audio/video data.
+     */
+
+    public function genPrivateMapKeyWithStringRoomID( $userid, $expire, $roomstr, $privilegeMap ) {
+        $userbuf = $this->__genUserBuf( $userid, 0, $expire, $privilegeMap, 0, $roomstr );
+        return $this->__genSig( $userid, $expire, $userbuf, true );
+    }
+
+    public function __construct( $sdkappid, $key ) {
+        $this->sdkappid = $sdkappid;
+        $this->key = $key;
+    }
+
+    /**
+    * 用于 url 的 base64 encode
+    * '+' => '*', '/' => '-', '=' => '_'
+    * @param string $string 需要编码的数据
+    * @return string 编码后的base64串,失败返回false
+    * @throws \Exception
+    */
+
+    /**
+    * base64 encode for url
+    * '+' => '*', '/' => '-', '=' => '_'
+    * @param string $string data to be encoded
+    * @return string The encoded base64 string, returns false on failure
+    * @throws \Exception
+    */
+    private function base64_url_encode( $string ) {
+        static $replace = Array( '+' => '*', '/' => '-', '=' => '_' );
+        $base64 = base64_encode( $string );
+        if ( $base64 === false ) {
+            throw new \Exception( 'base64_encode error' );
+        }
+        return str_replace( array_keys( $replace ), array_values( $replace ), $base64 );
+    }
+
+    /**
+    * 用于 url 的 base64 decode
+    * '+' => '*', '/' => '-', '=' => '_'
+    * @param string $base64 需要解码的base64串
+    * @return string 解码后的数据,失败返回false
+    * @throws \Exception
+    */
+
+    /**
+    * base64 decode for url
+    * '+' => '*', '/' => '-', '=' => '_'
+    * @param string $base64 base64 string to be decoded
+    * @return string Decoded data, return false on failure
+    * @throws \Exception
+    */
+    private function base64_url_decode( $base64 ) {
+        static $replace = Array( '+' => '*', '/' => '-', '=' => '_' );
+        $string = str_replace( array_values( $replace ), array_keys( $replace ), $base64 );
+        $result = base64_decode( $string );
+        if ( $result == false ) {
+            throw new \Exception( 'base64_url_decode error' );
+        }
+        return $result;
+    }
+    /**
+    * TRTC业务进房权限加密串使用用户定义的userbuf
+    * @brief 生成 userbuf
+    * @param account 用户名
+    * @param dwSdkappid sdkappid
+    * @param dwAuthID  数字房间号
+    * @param dwExpTime 过期时间:该权限加密串的过期时间. 过期时间 = now+dwExpTime
+    * @param dwPrivilegeMap 用户权限,255表示所有权限
+    * @param dwAccountType 用户类型, 默认为0
+    * @param roomStr 字符串房间号
+    * @return userbuf string  返回的userbuf
+    */
+
+    /**
+    * User-defined userbuf is used for the encrypted string of TRTC service entry permission
+    * @brief generate userbuf
+    * @param account username
+    * @param dwSdkappid sdkappid
+    * @param dwAuthID  digital room number
+    * @param dwExpTime Expiration time: The expiration time of the encrypted string of this permission. Expiration time = now+dwExpTime
+    * @param dwPrivilegeMap User permissions, 255 means all permissions
+    * @param dwAccountType User type, default is 0
+    * @param roomStr String room number
+    * @return userbuf string  returned userbuf
+    */
+
+    private function __genUserBuf( $account, $dwAuthID, $dwExpTime, $dwPrivilegeMap, $dwAccountType,$roomStr ) {
+     
+        //cVer  unsigned char/1 版本号,填0
+        if($roomStr == '')
+            $userbuf = pack( 'C1', '0' );
+        else
+            $userbuf = pack( 'C1', '1' );
+        
+        $userbuf .= pack( 'n', strlen( $account ) );
+        //wAccountLen   unsigned short /2   第三方自己的帐号长度
+        $userbuf .= pack( 'a'.strlen( $account ), $account );
+        //buffAccount   wAccountLen 第三方自己的帐号字符
+        $userbuf .= pack( 'N', $this->sdkappid );
+        //dwSdkAppid    unsigned int/4  sdkappid
+        $userbuf .= pack( 'N', $dwAuthID );
+        //dwAuthId  unsigned int/4  群组号码/音视频房间号
+        $expire = $dwExpTime + time();
+        $userbuf .= pack( 'N', $expire );
+        //dwExpTime unsigned int/4  过期时间 (当前时间 + 有效期(单位:秒,建议300秒))
+        $userbuf .= pack( 'N', $dwPrivilegeMap );
+        //dwPrivilegeMap unsigned int/4  权限位
+        $userbuf .= pack( 'N', $dwAccountType );
+        //dwAccountType  unsigned int/4
+        if($roomStr != '')
+        {
+            $userbuf .= pack( 'n', strlen( $roomStr ) );
+            //roomStrLen   unsigned short /2   字符串房间号长度
+            $userbuf .= pack( 'a'.strlen( $roomStr ), $roomStr );
+            //roomStr   roomStrLen 字符串房间号
+        }
+        return $userbuf;
+    }
+    /**
+    * 使用 hmac sha256 生成 sig 字段内容,经过 base64 编码
+    * @param $identifier 用户名,utf-8 编码
+    * @param $curr_time 当前生成 sig 的 unix 时间戳
+    * @param $expire 有效期,单位秒
+    * @param $base64_userbuf base64 编码后的 userbuf
+    * @param $userbuf_enabled 是否开启 userbuf
+    * @return string base64 后的 sig
+    */
+
+    /**
+    * Use hmac sha256 to generate sig field content, base64 encoded
+    * @param $identifier Username, utf-8 encoded
+    * @param $curr_time The unix timestamp of the current generated sig
+    * @param $expire Validity period, in seconds
+    * @param $base64_userbuf base64 encoded userbuf
+    * @param $userbuf_enabled 是No enable userbuf
+    * @return string sig after base64
+    */
+    private function hmacsha256( $identifier, $curr_time, $expire, $base64_userbuf, $userbuf_enabled ) {
+        $content_to_be_signed = 'TLS.identifier:' . $identifier . "\n"
+        . 'TLS.sdkappid:' . $this->sdkappid . "\n"
+        . 'TLS.time:' . $curr_time . "\n"
+        . 'TLS.expire:' . $expire . "\n";
+        if ( true == $userbuf_enabled ) {
+            $content_to_be_signed .= 'TLS.userbuf:' . $base64_userbuf . "\n";
+        }
+        return base64_encode( hash_hmac( 'sha256', $content_to_be_signed, $this->key, true ) );
+    }
+
+    /**
+    * 生成签名。
+    *
+    * @param $identifier 用户账号
+    * @param int $expire 过期时间,单位秒,默认 180 天
+    * @param $userbuf base64 编码后的 userbuf
+    * @param $userbuf_enabled 是否开启 userbuf
+    * @return string 签名字符串
+    * @throws \Exception
+    */
+    
+    /**
+    * Generate signature.
+    *
+    * @param $identifier user account
+    * @param int $expire Expiration time, in seconds, default 180 days
+    * @param $userbuf base64 encoded userbuf
+    * @param $userbuf_enabled Whether to enable userbuf
+    * @return string signature string
+    * @throws \Exception
+    */
+    private function __genSig( $identifier, $expire, $userbuf, $userbuf_enabled ) {
+        $curr_time = time();
+        $sig_array = Array(
+            'TLS.ver' => '2.0',
+            'TLS.identifier' => strval( $identifier ),
+            'TLS.sdkappid' => intval( $this->sdkappid ),
+            'TLS.expire' => intval( $expire ),
+            'TLS.time' => intval( $curr_time )
+        );
+
+        $base64_userbuf = '';
+        if ( true == $userbuf_enabled ) {
+            $base64_userbuf = base64_encode( $userbuf );
+            $sig_array['TLS.userbuf'] = strval( $base64_userbuf );
+        }
+
+        $sig_array['TLS.sig'] = $this->hmacsha256( $identifier, $curr_time, $expire, $base64_userbuf, $userbuf_enabled );
+        if ( $sig_array['TLS.sig'] === false ) {
+            throw new \Exception( 'base64_encode error' );
+        }
+        $json_str_sig = json_encode( $sig_array );
+        if ( $json_str_sig === false ) {
+            throw new \Exception( 'json_encode error' );
+        }
+        $compressed = gzcompress( $json_str_sig );
+        if ( $compressed === false ) {
+            throw new \Exception( 'gzcompress error' );
+        }
+        return $this->base64_url_encode( $compressed );
+    }
+
+    /**
+    * 验证签名。
+    *
+    * @param string $sig 签名内容
+    * @param string $identifier 需要验证用户名,utf-8 编码
+    * @param int $init_time 返回的生成时间,unix 时间戳
+    * @param int $expire_time 返回的有效期,单位秒
+    * @param string $userbuf 返回的用户数据
+    * @param string $error_msg 失败时的错误信息
+    * @return boolean 验证是否成功
+    * @throws \Exception
+    */
+
+     /**
+    * Verify signature.
+    *
+    * @param string $sig Signature content
+    * @param string $identifier Need to authenticate user name, utf-8 encoding
+    * @param int $init_time Returned generation time, unix timestamp
+    * @param int $expire_time Return the validity period, in seconds
+    * @param string $userbuf returned user data
+    * @param string $error_msg error message on failure
+    * @return boolean Verify success
+    * @throws \Exception
+    */
+
+    private function __verifySig( $sig, $identifier, &$init_time, &$expire_time, &$userbuf, &$error_msg ) {
+        try {
+            $error_msg = '';
+            $compressed_sig = $this->base64_url_decode( $sig );
+            $pre_level = error_reporting( E_ERROR );
+            $uncompressed_sig = gzuncompress( $compressed_sig );
+            error_reporting( $pre_level );
+            if ( $uncompressed_sig === false ) {
+                throw new \Exception( 'gzuncompress error' );
+            }
+            $sig_doc = json_decode( $uncompressed_sig );
+            if ( $sig_doc == false ) {
+                throw new \Exception( 'json_decode error' );
+            }
+            $sig_doc = ( array )$sig_doc;
+            if ( $sig_doc['TLS.identifier'] !== $identifier ) {
+                throw new \Exception( "identifier dosen't match" );
+            }
+            if ( $sig_doc['TLS.sdkappid'] != $this->sdkappid ) {
+                throw new \Exception( "sdkappid dosen't match" );
+            }
+            $sig = $sig_doc['TLS.sig'];
+            if ( $sig == false ) {
+                throw new \Exception( 'sig field is missing' );
+            }
+
+            $init_time = $sig_doc['TLS.time'];
+            $expire_time = $sig_doc['TLS.expire'];
+
+            $curr_time = time();
+            if ( $curr_time > $init_time+$expire_time ) {
+                throw new \Exception( 'sig expired' );
+            }
+
+            $userbuf_enabled = false;
+            $base64_userbuf = '';
+            if ( isset( $sig_doc['TLS.userbuf'] ) ) {
+                $base64_userbuf = $sig_doc['TLS.userbuf'];
+                $userbuf = base64_decode( $base64_userbuf );
+                $userbuf_enabled = true;
+            }
+            $sigCalculated = $this->hmacsha256( $identifier, $init_time, $expire_time, $base64_userbuf, $userbuf_enabled );
+
+            if ( $sig != $sigCalculated ) {
+                throw new \Exception( 'verify failed' );
+            }
+
+            return true;
+        } catch ( \Exception $ex ) {
+            $error_msg = $ex->getMessage();
+            return false;
+        }
+    }
+
+    /**
+    * 带 userbuf 验证签名。
+    *
+    * @param string $sig 签名内容
+    * @param string $identifier 需要验证用户名,utf-8 编码
+    * @param int $init_time 返回的生成时间,unix 时间戳
+    * @param int $expire_time 返回的有效期,单位秒
+    * @param string $error_msg 失败时的错误信息
+    * @return boolean 验证是否成功
+    * @throws \Exception
+    */
+
+    /**
+    * Verify signature with userbuf.
+    *
+    * @param string $sig Signature content
+    * @param string $identifier Need to authenticate user name, utf-8 encoding
+    * @param int $init_time Returned generation time, unix timestamp
+    * @param int $expire_time Return the validity period, in seconds
+    * @param string $error_msg error message on failure
+    * @return boolean Verify success
+    * @throws \Exception
+    */
+    public function verifySig( $sig, $identifier, &$init_time, &$expire_time, &$error_msg ) {
+        $userbuf = '';
+        return $this->__verifySig( $sig, $identifier, $init_time, $expire_time, $userbuf, $error_msg );
+    }
+
+    /**
+    * 验证签名
+    * @param string $sig 签名内容
+    * @param string $identifier 需要验证用户名,utf-8 编码
+    * @param int $init_time 返回的生成时间,unix 时间戳
+    * @param int $expire_time 返回的有效期,单位秒
+    * @param string $userbuf 返回的用户数据
+    * @param string $error_msg 失败时的错误信息
+    * @return boolean 验证是否成功
+    * @throws \Exception
+    */
+
+    /**
+    * Verify signature
+    * @param string $sig Signature content
+    * @param string $identifier Need to authenticate user name, utf-8 encoding
+    * @param int $init_time Returned generation time, unix timestamp
+    * @param int $expire_time Return the validity period, in seconds
+    * @param string $userbuf returned user data
+    * @param string $error_msg error message on failure
+    * @return boolean Verify success
+    * @throws \Exception
+    */
+    public function verifySigWithUserBuf( $sig, $identifier, &$init_time, &$expire_time, &$userbuf, &$error_msg ) {
+        return $this->__verifySig( $sig, $identifier, $init_time, $expire_time, $userbuf, $error_msg );
+    }
+}

+ 310 - 11
application/index/controller/Plantask.php

@@ -2,14 +2,320 @@
 
 namespace app\index\controller;
 
-use app\utils\JingXiu\JingXiuPayUtil;
+//use app\utils\JingXiu\JingXiuPayUtil;
 use think\Controller;
 use think\Db;
-use think\Cache;
+use app\common\library\Tlssigapiv2;
 
 class Plantask extends Controller
 {
-    //精秀支付订单支付状态查询。 一分钟一次
+    //主动拉取im群组内 聊天记录。没用到
+    public function auto_imgroup(){
+        $im_config = config('tencent_im');
+        $sdkappid  = $im_config['sdkappid'];
+        $sdkappkey = $im_config['key'];
+        $identifier= $im_config['identifier'];
+        $usersig   = $this->usersig($sdkappid,$sdkappkey,$identifier);
+
+
+        $random = rand(10000000,99999999);
+        $url = 'https://console.tim.qq.com/v4/open_msg_svc/get_history?sdkappid='.$sdkappid.'&identifier=administrator&usersig='.$usersig.'&random='.$random.'&contenttype=json';
+
+        $data = [
+            'ChatType' => 'Group',
+            'MsgTime'  => date('YmdH',strtotime('-3 Hours')),
+        ];
+        $tasklog = [
+            'type' => $data['ChatType'] == 'C2C' ? 1 : 2,
+            'datehour' => $data['MsgTime'],
+            'createtime' => time(),
+            'status' => 0,
+        ];
+        dump($data);
+        $jsonStr = json_encode($data);
+
+        $header = array(
+            'Content-Type: application/json; charset=utf-8',
+            'Content-Length: ' . strlen($jsonStr)
+        );
+        $rs = curl_post($url,$jsonStr,$header);
+        $rs = json_decode($rs,true);
+        dump($rs);
+        if(is_array($rs) && isset($rs['ErrorCode']) && $rs['ErrorCode'] == 0){
+            $tasklog['status'] = 1;
+            //正常的,可以下载了
+            if(isset($rs['File']) && !empty($rs['File'])){
+                foreach($rs['File'] as $key => $val){
+                    echo $val['URL'];
+                    //下载
+                    $gz_path = $this->downloadfile($val['URL'],$data['ChatType'],$data['MsgTime'].'_'.$data['ChatType'].'.json.gz');
+                    dump($gz_path);
+                    //解压
+                    $json_path = $this->jieyagz($gz_path);
+                    dump($json_path);
+                    //分析
+                    $content = $this->readjson_group($json_path);
+                    dump(count($content));
+                    //入库
+                    if(!empty($content)){
+                        Db::name('imlog_group')->insertAll($content);
+                    }
+                }
+            }
+        }
+        Db::name('imlog_tasklog')->insertGetId($tasklog);
+
+        echo '结束';
+        exit;
+    }
+
+    //主动拉取im用户私聊 聊天记录
+    public function auto_imc2c(){
+        $im_config = config('tencent_im');
+        $sdkappid  = $im_config['sdkappid'];
+        $sdkappkey = $im_config['key'];
+        $identifier= $im_config['identifier'];
+        $usersig   = $this->usersig($sdkappid,$sdkappkey,$identifier);
+
+
+        $random = rand(10000000,99999999);
+        $url = 'https://console.tim.qq.com/v4/open_msg_svc/get_history?sdkappid='.$sdkappid.'&identifier=administrator&usersig='.$usersig.'&random='.$random.'&contenttype=json';
+
+        $data = [
+            'ChatType' => 'C2C',
+            'MsgTime'  => date('YmdH',strtotime('-3 Hours')),
+        ];
+        $tasklog = [
+            'type' => $data['ChatType'] == 'C2C' ? 1 : 2,
+            'datehour' => $data['MsgTime'],
+            'createtime' => time(),
+            'status' => 0,
+        ];
+        dump($data);
+        $jsonStr = json_encode($data);
+
+        $header = array(
+            'Content-Type: application/json; charset=utf-8',
+            'Content-Length: ' . strlen($jsonStr)
+        );
+        $rs = curl_post($url,$jsonStr,$header);
+        $rs = json_decode($rs,true);
+        dump($rs);
+        if(is_array($rs) && isset($rs['ErrorCode']) && $rs['ErrorCode'] == 0){
+            $tasklog['status'] = 1;
+            //正常的,可以下载了
+            if(isset($rs['File']) && !empty($rs['File'])){
+                foreach($rs['File'] as $key => $val){
+                    //下载
+                    $gz_path = $this->downloadfile($val['URL'],$data['ChatType'],$data['MsgTime'].'_'.$data['ChatType'].'.json.gz');
+                    dump($gz_path);
+                    //解压
+                    $json_path = $this->jieyagz($gz_path);
+                    dump($json_path);
+                    //分析
+                    $content = $this->readjson($json_path);
+                    dump(count($content));
+                    //入库
+                    if(!empty($content)){
+                        Db::name('imlog_c2c')->insertAll($content);
+                    }
+                }
+            }
+        }
+        Db::name('imlog_tasklog')->insertGetId($tasklog);
+
+        echo '结束';
+        exit;
+    }
+
+    //定时跑用户活跃,改成离线。 一分钟一次
+    public function auto_user_active()
+    {
+        $start_time = time() - (3600 * 24);
+        $end_time   = time() - (3600 * 2);
+        $sql        = "update `mt_user` set is_active = 0 where is_active = 1 and id in (select user_id from mt_user_active where requesttime between {$start_time} and {$end_time})";
+        db()->query($sql);
+    }
+
+    ////////////////////////////////////////////////////////
+    /////////////////////////////////////////下面都是工具方法////////////////////////////////////////////////
+    //下载远程文件 到指定目录
+    private function downloadfile($file_url, $path = '', $save_file_name = '')
+    {
+        $basepath = '/uploaded/';
+        if ($path) {
+            $basepath = $basepath . $path . '/';
+        }
+        $basepath = $basepath . date('Ymd');
+        $dir_path = ROOT_PATH . '/public' . $basepath;
+        if (!is_dir($dir_path)) {
+            mkdir($dir_path, 0777, true);
+        }
+
+
+        $file = file_get_contents($file_url);
+
+
+        //传入保存文件的名称
+        $filename = $save_file_name ?: pathinfo($file_url, PATHINFO_BASENAME);
+
+        $resource = fopen($dir_path. '/'. $filename, 'w');
+
+        fwrite($resource, $file);
+
+        fclose($resource);
+
+        return $dir_path . '/' . $filename;
+    }
+
+    //解压
+    private function jieyagz($gz_path = ''){
+        $json_path = substr($gz_path,0,-3);
+
+
+        if ($zp = gzopen($gz_path, 'r')) { // 打开压缩文件
+            if ($fp = fopen($json_path, 'w')) { // 打开目标文件
+                while (!gzeof($zp)) {
+                    fwrite($fp, gzread($zp, 1024 * 512)); // 逐块读取和解压缩后写入
+                }
+                fclose($fp);
+            }
+            gzclose($zp);
+        }
+        return $json_path;
+    }
+
+    //读取json并分析,c2c
+    private function readjson($json_path = ''){
+        $newMsgList = [];
+        $json_content = file_get_contents($json_path);
+        $json_content = json_decode($json_content,true);
+
+        if(!empty($json_content) && is_array($json_content) && isset($json_content['MsgList'])){
+            $MsgList = $json_content['MsgList'];
+
+            if(!empty($MsgList)){
+                foreach($MsgList as $key => $val)
+                {
+                    $newone = [
+                        'ClientIP'        => isset($val['ClientIP'])        ? $val['ClientIP']             : '',
+                        'CloudCustomData' => isset($val['CloudCustomData']) ? $val['CloudCustomData']      : '',
+                        'From_Account'    => isset($val['From_Account'])    ? intval($val['From_Account']) : 0,
+                        //'MsgBody'         => isset($val['MsgBody'])         ? json_encode($val['MsgBody']) : '',
+                        'MsgFromPlatform' => isset($val['MsgFromPlatform']) ? $val['MsgFromPlatform']      : '',
+                        'MsgRandom'       => isset($val['MsgRandom'])       ? $val['MsgRandom']            : '',
+                        'MsgSeq'          => isset($val['MsgSeq'])          ? $val['MsgSeq']               : '',
+                        'MsgTimestamp'    => isset($val['MsgTimestamp'])    ? $val['MsgTimestamp']         : '',
+                        'To_Account'      => isset($val['To_Account'])      ? intval($val['To_Account'])   : 0,
+                    ];
+                    //解析数据类型
+                    if(isset($val['MsgBody'][0]['MsgType'])){
+                        $newone['MsgType'] = $val['MsgBody'][0]['MsgType'];
+                        //文本
+                        if($val['MsgBody'][0]['MsgType'] == 'TIMTextElem'){
+                            $newone['MsgInfo'] = '';
+                            if(isset($val['MsgBody'][0]['MsgContent']['Text'])){
+                                $newone['MsgInfo'] = $val['MsgBody'][0]['MsgContent']['Text'];
+                            }
+                        }
+                        //图片
+                        if($val['MsgBody'][0]['MsgType'] == 'TIMImageElem'){
+                            $newone['MsgInfo'] = '';
+                            if(isset($val['MsgBody'][0]['MsgContent']['ImageInfoArray'][0]['URL'])){
+                                $newone['MsgInfo'] = $val['MsgBody'][0]['MsgContent']['ImageInfoArray'][0]['URL'];
+                            }
+                        }
+                        //声音
+                        if($val['MsgBody'][0]['MsgType'] == 'TIMSoundElem'){
+                            $newone['MsgInfo'] = '';
+                            if(isset($val['MsgBody'][0]['MsgContent']['Url'])){
+                                $newone['MsgInfo'] = $val['MsgBody'][0]['MsgContent']['Url'];
+                            }
+                        }
+                        //视频
+                        if($val['MsgBody'][0]['MsgType'] == 'TIMVideoFileElem'){
+                            $newone['MsgInfo'] = '';
+                            if(isset($val['MsgBody'][0]['MsgContent']['VideoUrl'])){
+                                $newone['MsgInfo'] = $val['MsgBody'][0]['MsgContent']['VideoUrl'];
+                            }
+                        }
+                        //其他
+                        continue;
+                    }else{
+                        continue;
+                    }
+
+                    $newMsgList[] = $newone;
+                }
+            }
+        }
+
+        return $newMsgList;
+    }
+
+    //读取json并分析,group
+    private function readjson_group($json_path = ''){
+        $newMsgList = [];
+        $json_content = file_get_contents($json_path);
+        $json_content = json_decode($json_content,true);
+
+        if(!empty($json_content) && is_array($json_content) && isset($json_content['MsgList'])){
+            $MsgList = $json_content['MsgList'];
+
+            if(!empty($MsgList)){
+                foreach($MsgList as $key => $val)
+                {
+                    $newone = [
+                        //'key' => $key,辅助查找
+                        'ClientIP'        => isset($val['ClientIP'])        ? $val['ClientIP']             : '',
+                        'From_Account'    => isset($val['From_Account'])    ? intval($val['From_Account']) : 0,
+                        'GroupId'         => isset($val['GroupId'])         ? intval($val['GroupId'])      : 0,
+                        //'MsgBody'         => isset($val['MsgBody'])         ? json_encode($val['MsgBody']) : '',
+                        'MsgFromPlatform' => isset($val['MsgFromPlatform']) ? $val['MsgFromPlatform']      : '',
+                        'MsgSeq'          => isset($val['MsgSeq'])          ? $val['MsgSeq']               : '',
+                        'MsgTimestamp'    => isset($val['MsgTimestamp'])    ? $val['MsgTimestamp']         : '',
+                    ];
+                    //解析数据类型
+                    if(isset($val['MsgBody'][0]['MsgType'])){
+                        $newone['MsgType'] = $val['MsgBody'][0]['MsgType'];
+                        //文本
+                        if($val['MsgBody'][0]['MsgType'] == 'TIMTextElem'){
+                            $newone['MsgInfo'] = '';
+                            if(isset($val['MsgBody'][0]['MsgContent']['Text'])){
+                                //继续解析
+                                $text = json_decode($val['MsgBody'][0]['MsgContent']['Text'],true);
+                                if(isset($text['type']) && $text['type'] == 1){
+                                    //TYPE_NORMAL =1;//普通消息
+                                    $newone['MsgInfo'] = isset($text['content']) ? $text['content'] : '';
+                                    $newMsgList[] = $newone;
+                                }
+                                //其他$text['type']的值都是房间内的,礼物的,表情等,不需要记录
+                            }
+                        }
+                        //房间内的不需要显示的内容
+                        if($val['MsgBody'][0]['MsgType'] == 'TIMCustomElem'){
+
+                        }
+
+                    }
+
+                    //大循环结束
+                }
+            }
+        }
+
+        return $newMsgList;
+    }
+
+    //请求im的签名
+    private function usersig($sdkappid,$key,$identifier){
+        $api = new TLSSigAPIv2($sdkappid,$key );
+        $sig = $api->genUserSig($identifier);
+        return $sig;
+    }
+    ////////////////////////////////////////////////////////
+
+    //精秀支付订单支付状态查询。 一分钟一次,没用到
     public function auto_pay_queue()
     {
         // 处理次数
@@ -92,14 +398,7 @@ class Plantask extends Controller
     }
 
 
-    //定时跑用户活跃,改成离线。 一分钟一次
-    public function auto_user_active()
-    {
-        $start_time = time() - (3600 * 24);
-        $end_time   = time() - (3600 * 2);
-        $sql        = "update `mt_user` set is_active = 0 where is_active = 1 and id in (select user_id from mt_user_active where requesttime between {$start_time} and {$end_time})";
-        db()->query($sql);
-    }
+
 
     //发放代理奖励。没用到
     public function issuingreward() {

+ 76 - 0
public/assets/js/backend/imlogc2c.js

@@ -0,0 +1,76 @@
+define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
+
+    var Controller = {
+        index: function () {
+            // 初始化表格参数配置
+            Table.api.init({
+                extend: {
+                    index_url: 'imlogc2c/index' + location.search,
+                    add_url: 'imlogc2c/add',
+//                    edit_url: 'imlogc2c/edit',
+//                    del_url: 'imlogc2c/del',
+                    multi_url: 'imlogc2c/multi',
+                    import_url: 'imlogc2c/import',
+                    table: 'imlog_c2c',
+                }
+            });
+
+            var table = $("#table");
+
+            // 初始化表格
+            table.bootstrapTable({
+                url: $.fn.bootstrapTable.defaults.extend.index_url,
+                pk: 'id',
+                sortName: 'id',
+                columns: [
+                    [
+                        {checkbox: true},
+                        {field: 'id', title: __('Id')},
+                        {field: 'ClientIP', title: __('Clientip'), operate: 'LIKE'},
+                        {field: 'From_Account', title: __('From_account')},
+                        {field: 'fromuser.nickname', title: __('fromuser.nickname'), operate: 'LIKE'},
+                        {field: 'MsgFromPlatform', title: __('Msgfromplatform'), operate: 'LIKE'},
+//                        {field: 'MsgRandom', title: __('Msgrandom'), operate: 'LIKE'},
+//                        {field: 'MsgSeq', title: __('Msgseq'), operate: 'LIKE'},
+                        {field: 'MsgTimestamp', title: __('Msgtimestamp'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
+                        {field: 'To_Account', title: __('To_account')},
+                        {field: 'touser.nickname', title: __('touser.nickname'), operate: 'LIKE'},
+                        {field: 'MsgType', title: '类型'},
+                        {field: 'operate', title: __('Operate'),
+                            buttons:[
+                                {
+                                    name:'showbody',
+                                    text:'消息体',
+                                    title:'消息体',
+                                    icon:'fa fa-exclamation-circle',
+                                    classname:'btn btn-xs btn-info btn-dialog',
+                                    url:'imlogc2c/showbody/id/{ids}?dialog=1',
+                                    target:'_self',
+                                    extend: 'data-area=["90%","90%"]'
+                                },
+                            ],
+                            table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
+                    ]
+                ]
+            });
+
+            // 为表格绑定事件
+            Table.api.bindevent(table);
+        },
+        add: function () {
+            Controller.api.bindevent();
+        },
+        edit: function () {
+            Controller.api.bindevent();
+        },
+        showbody: function () {
+            Controller.api.bindevent();
+        },
+        api: {
+            bindevent: function () {
+                Form.api.bindevent($("form[role=form]"));
+            }
+        }
+    };
+    return Controller;
+});

+ 80 - 0
public/assets/js/backend/imloggroup.js

@@ -0,0 +1,80 @@
+define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {
+
+    var Controller = {
+        index: function () {
+            // 初始化表格参数配置
+            Table.api.init({
+                extend: {
+                    index_url: 'imloggroup/index' + location.search,
+                    add_url: 'imloggroup/add',
+//                    edit_url: 'imloggroup/edit',
+//                    del_url: 'imloggroup/del',
+                    multi_url: 'imloggroup/multi',
+                    import_url: 'imloggroup/import',
+                    table: 'imlog_group',
+                }
+            });
+
+            var table = $("#table");
+
+            // 初始化表格
+            table.bootstrapTable({
+                url: $.fn.bootstrapTable.defaults.extend.index_url,
+                pk: 'id',
+                sortName: 'id',
+                columns: [
+                    [
+                        {checkbox: true},
+                        {field: 'id', title: __('Id')},
+                        {field: 'ClientIP', title: __('Clientip'), operate: 'LIKE'},
+                        {field: 'From_Account', title: __('From_account')},
+                        {field: 'user.nickname', title: __('User.nickname'), operate: 'LIKE'},
+                        {field: 'GroupId', title: __('Groupid')},
+                        {field: 'party.party_name', title: __('Party.party_name'), operate: 'LIKE'},
+//                        {field: 'MsgBody', title: __('Msgbody')},
+                        {field: 'MsgFromPlatform', title: __('Msgfromplatform'), operate: 'LIKE'},
+//                        {field: 'MsgSeq', title: __('Msgseq'), operate: 'LIKE'},
+                        {field: 'MsgTimestamp', title: __('Msgtimestamp'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
+                        {field: 'MsgType', title: __('Msgtype'), operate: 'LIKE'},
+                        {field: 'MsgInfo', title: __('Msginfo'), operate: 'LIKE'},
+
+//                        {field: 'party.room_type', title: __('Party.room_type')},
+
+                        {field: 'operate', title: __('Operate'),
+                            buttons:[
+                                {
+                                    name:'showbody',
+                                    text:'消息体',
+                                    title:'消息体',
+                                    icon:'fa fa-exclamation-circle',
+                                    classname:'btn btn-xs btn-info btn-dialog',
+                                    url:'imloggroup/showbody/id/{ids}?dialog=1',
+                                    target:'_self',
+                                    extend: 'data-area=["90%","90%"]'
+                                },
+                            ],
+                            table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
+                    ]
+                ]
+            });
+
+            // 为表格绑定事件
+            Table.api.bindevent(table);
+        },
+        add: function () {
+            Controller.api.bindevent();
+        },
+        edit: function () {
+            Controller.api.bindevent();
+        },
+        showbody: function () {
+            Controller.api.bindevent();
+        },
+        api: {
+            bindevent: function () {
+                Form.api.bindevent($("form[role=form]"));
+            }
+        }
+    };
+    return Controller;
+});