Esempio n. 1
0
    /**
     * 发送控制指令
     * 
     * @param params    params
     */
    protected static function control($params, $cmd)
    {
        if (!isset($params["mid"])) {
            return Error::getRetString(10007);
        }
        $mid = $params["mid"];
        $uuid = $_GET["uuid"];
        $udid = $_GET["udid"];
        $db = Db::init();
        //验证用户
        $user = $db->get_var("select user from user where uuid=\"{$uuid}\"");
        if (!isset($user)) {
            return Error::getRetString(10009);
        }
        //uuid无效
        if ($db->query(<<<EOD
select mid from device_modules where mid="{$mid}" and udid="{$udid}"
and exists(select udid from user_device where user="******" and udid="{$udid}")
EOD
)) {
            //本地验证成功,开始与设备进行通信
            $string = file_get_contents("php://input");
            return self::sendToDevice($string, $uuid, $udid, $uuid);
            return Error::getRetString(0);
        } else {
            return Error::getRetString(10016);
        }
        return Error::getRetString(0, array("uuid" => $uuid, "udid" => $udid, "cmd" => $cmd));
    }
Esempio n. 2
0
 /**
  * 
  * @param params    params
  */
 public static function _List($params)
 {
     $email = $_GET["u"];
     $db = Db::init();
     $notifies = array();
     $recs = $db->get_results("select mid,time from user_notify where email='{$email}'order by id DESC LIMIT 20 ");
     if (isset($recs[0])) {
         foreach ($recs as $mid) {
             $notifies[] = self::getInfo($mid->mid, $mid->time);
         }
     }
     return Error::getRetString(0, array("notifies" => $notifies));
 }
Esempio n. 3
0
 /**
  * 
  * @param params    params
  */
 public static function _Login($params)
 {
     if (is_array($params) && isset($params["account"])) {
         $account = $params["account"];
         $db = Db::init();
         $uuid = self::createUUID();
         if ($db->query("select email from user where email=\"{$account}\"")) {
             $db->query("update user set uuid=\"{$uuid}\" where email=\"{$account}\"");
             return Error::getRetString(0, array("uuid" => $uuid));
         }
     } else {
         return Error::getRetString(10007);
     }
 }
Esempio n. 4
0
 /**
  * 处理请求事件
  * 
  * @param data
  * @param class_dir    class_dir
  */
 public static function onMessage($data, $class_dir)
 {
     // 判断数据是否正确
     if (empty($data['class']) || empty($data['method'])) {
         return json_encode(array('code' => 1, 'msg' => 'bad request', 'data' => null));
     }
     // 获得要调用的类、方法、及参数
     $class = $data['class'];
     $method = $data['method'];
     if (isset($data['params'])) {
         $param_array = $data['params'];
     } else {
         $param_array = array();
     }
     $class = "_" . $class;
     $method = "_" . $method;
     $success = false;
     // 判断类对应文件是否载入
     if (!class_exists($class)) {
         $include_file = $class_dir . "/{$class}.php";
         if (is_file($include_file)) {
             require_once $include_file;
         }
         if (!class_exists($class)) {
             $code = 33404;
             $msg = "class {$class} not found";
             // 发送数据给客户端 类不存在
             //var_dump($connection);
             //return json_encode(array('code'=>$code, 'msg'=>$msg));
             return Error::getRetString($code);
         }
     }
     // 调用类的方法
     try {
         $ret = call_user_func_array(array($class, $method), array($param_array));
         // 发送数据给客户端,调用成功,data下标对应的元素即为调用结果
         if (isset($ret)) {
             //var_dump($ret);
             return $ret;
         } else {
             //return json_encode(array('code'=>33405, 'msg'=>"Method $class.$method invoke error"));
             return Error::getRetString(33405);
         }
     } catch (Exception $e) {
         // 发送数据给客户端,发生异常,调用失败
         $code = $e->getCode() ? $e->getCode() : 500;
         return json_encode(array('code' => $code, 'msg' => $e->getMessage(), 'result' => $e));
     }
 }
Esempio n. 5
0
 /**
  * 
  * @param params    params
  */
 public static function _List($params)
 {
     if (isset($params["pageNO"]) && isset($params["pageRecs"])) {
         $email = $_GET["u"];
         $db = Db::init();
         $notifies = array();
         $pageTotal = 0;
         $total = 0;
         $page = (int) $params["pageNO"];
         $limit = (int) $params["pageRecs"];
         //限制每页条数
         $offset = $page * $limit;
         $resmid = $db->get_results("select mid from udevice where email='{$email}'");
         if (isset($resmid[0])) {
             $tmp = $resmid[0]->mid;
             $cmd = " mid='{$tmp}' ";
             for ($i = 1; $i < count($resmid); $i++) {
                 $tmp = $resmid[$i]->mid;
                 $cmd = $cmd . "or mid='{$tmp}' ";
             }
             $recs = $db->get_results("select mid, did, email, time, msg from user_notify where {$cmd} order by id DESC LIMIT {$offset},{$limit} ");
             $total = (int) $db->get_var("select count(*) from user_notify where {$cmd} order by id");
             $pageTotal = ceil($total / $limit);
             if (isset($recs[0])) {
                 foreach ($recs as $rec) {
                     $_info = self::getInfo($rec);
                     if (isset($_info)) {
                         $notifies[] = $_info;
                     }
                 }
             }
         }
         return Error::getRetString(0, array("notifies" => $notifies, "pageTotal" => $pageTotal, "pageRecs" => $limit, "recsTotal" => $total));
     } else {
         return Error::getRetString(10007);
     }
 }
Esempio n. 6
0
 public static function onMessage($data, $class_dir)
 {
     if (empty($data['class']) || empty($data['method'])) {
         return json_encode(array('code' => 1, 'msg' => 'bad_request'));
     }
     $class = $data['class'];
     $method = $data['method'];
     if (isset($data['params'])) {
         $params_array = $data['params'];
     } else {
         $params_array = array();
     }
     $class = '_' . $class;
     $method = '_' . $method;
     $success = false;
     if (!class_exists($class)) {
         $include_file = $class_dir . "/{$class}.php";
         if (is_file($include_file)) {
             require_once $include_file;
         } else {
             $code = 33404;
             $msg = "class {$class} not found";
             return Error::getRetString($code);
         }
     }
     try {
         $ret = call_user_func_array(array($class, $method), array($params_array));
         if (isset($ret)) {
             return $ret;
         } else {
             return Error::getRetString(33405);
         }
     } catch (Exception $e) {
         $code = $e->getCode() ? $e->getCode() : 500;
         return json_encode(array('code' => $code, 'msg' => $e->getMessage(), 'result' => $e));
     }
 }
Esempio n. 7
0
 /**
  * 
  * @param params    params
  */
 public static function _List($params)
 {
     $db = Db::init();
     $email = $_GET["u"];
     $re = array("houses" => array());
     $results = $db->get_results("select houseid,name,mid,vercode from house where email=\"{$email}\"");
     if (isset($results[0])) {
         foreach ($results as $rec) {
             $re["houses"][] = array("houseid" => intval($rec->houseid), "name" => (string) $rec->name, "mid" => (string) $rec->mid, "vercode" => (string) $rec->vercode);
         }
     }
     return Error::getRetString(0, $re);
 }
Esempio n. 8
0
    /**
     * 
     * @param params    params
     */
    public static function _List($params)
    {
        if (is_array($params) && isset($params["houseid"])) {
            $db = Db::init();
            $email = $_GET["u"];
            $houseid = $params["houseid"];
            $re = array("rooms" => array());
            $results = $db->get_results(<<<EOD
select roomid,name from room where houseid={$houseid} and exists(select houseid from house where houseid={$houseid} and email="{$email}") 
EOD
);
            if (isset($results[0])) {
                foreach ($results as $rec) {
                    $re["rooms"][] = array("roomid" => $rec->roomid * 1, "name" => $rec->name);
                }
            }
            return Error::getRetString(0, $re);
        } else {
            return Error::getRetString(10007);
        }
    }
Esempio n. 9
0
 /**
  * 
  * @param params    params
  */
 public static function _ListAll($params)
 {
     $uuid = $_GET["uuid"];
     $db = Db::init();
     $user = $db->get_var("select user from user where uuid=\"{$uuid}\"");
     if (!isset($user)) {
         return Error::getRetString(10009);
     }
     //uuid无效
     $re = array("rooms" => array());
     $results = $db->get_results("select roomid,name from user_room where user=\"{$user}\"");
     if (isset($results[0])) {
         foreach ($results as $rec) {
             $roomid = $rec->roomid * 1;
             $list = array();
             $modules = $db->get_results("select * from device_modules where roomid={$roomid}");
             //有模块
             if (isset($modules[0])) {
                 foreach ($modules as $mod) {
                     $ch_info = array();
                     $m = $mod->mid;
                     $children = $db->get_results("select * from device_modules_child where mid=\"{$m}\" order by no");
                     foreach ($children as $child) {
                         $ch_name = $child->name;
                         $ch_no = $child->no * 1;
                         $ch_info[] = array("no" => $ch_no, "name" => $ch_name);
                     }
                     $list[] = array("udid" => $mod->udid, "mid" => $mod->mid, "devclass" => $mod->type, "name" => $ch_info);
                 }
             }
             $re["rooms"][] = array("roomid" => $roomid, "name" => $rec->name, "devices" => $list);
         }
     }
     return Error::getRetString(0, $re);
 }
Esempio n. 10
0
 /**
  * 执行情景模式
  * 
  * @param params    params
  */
 public static function _Excute($params)
 {
     return Error::getRetString(0);
 }
Esempio n. 11
0
    /**
     * 
     * @param params    参数列表
     */
    public static function _Rename($params)
    {
        if (is_array($params) && isset($params["user"]) && isset($params["udid"]) && isset($params["name"])) {
            $user = $params["user"];
            $name = $params["name"];
            $uuid = $_GET["uuid"];
            $udid = $params["udid"];
            $db = Db::init();
            //执行主机改名
            if ($db->query(<<<EOD
update user_device set name="{$name}" WHERE EXISTS(SELECT user FROM user WHERE uuid="{$uuid}" and user="******" and priv=3) and user="******" and udid="{$udid}";
EOD
)) {
                return Error::getRetString(0);
            } else {
                return Error::getRetString(10016);
            }
        } else {
            return Error::getRetString(10007);
        }
    }
Esempio n. 12
0
    /**
     * 
     * @param params    params
     */
    public static function _List($params)
    {
        if (is_array($params) && isset($params["mid"]) && isset($params["vercode"])) {
            $db = Db::init();
            $email = $_GET["u"];
            $mid = $params["mid"];
            $vercode = $params["vercode"];
            $re = array("rooms" => array());
            $results = $db->get_results(<<<EOD
select roomid,name from room where mid='{$mid}' and exists(select mid from mdevice where mid='{$mid}' and vercode='{$vercode}') 
EOD
);
            if (isset($results[0])) {
                foreach ($results as $rec) {
                    $re["rooms"][] = array("roomid" => $rec->roomid * 1, "name" => $rec->name);
                }
            }
            return Error::getRetString(0, $re);
        } else {
            return Error::getRetString(10007);
        }
    }
Esempio n. 13
0
<?php

require_once __DIR__ . "/../libs/Event.php";
require_once __DIR__ . "/../libs/Error.php";
require_once __DIR__ . "/../db/Db.php";
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . 'GMT');
header('Cache-Control: no-cache, must-revalidate');
header('Pragma: no-cache');
if (!isset($_GET["u"])) {
    exit(Error::getRetString(1));
}
$json_string = file_get_contents("php://input");
// $json_string = $GLOBALS['HTTP_RAW_POST_DATA'];
$array = json_decode($json_string, true);
echo Event::onMessage($array, __DIR__ . "/../base/");
// file_put_contents("./test.txt", $_GET["u"]."\n".$json_string, FILE_APPEND);
Esempio n. 14
0
    /**
     * 
     * @param params    params
     */
    public static function _GetInfo($params)
    {
        if (isset($params["email"])) {
            $db = Db::init();
            $email = $params["email"];
            //是否已存在
            if (!$db->query(<<<EOD
select email from user where email="{$email}"
EOD
)) {
                return Error::getRetString(10020);
            }
            $info = $db->get_row("select * from user where email='{$email}'");
            return Error::getRetString(0, array("name" => $info->name, "email" => $info->email, "sex" => $info->sex, "phone" => $info->phone, "QQ" => $info->QQ, "address" => $info->address));
        } else {
            return Error::getRetString(10007);
        }
    }
Esempio n. 15
0
 public static function _VerifyUUID($params)
 {
     if (is_array($params) && isset($params['uuid']) && isset($params['email'])) {
         $uuid = $params['uuid'];
         $email = $params['email'];
         $db = Db::init();
         if ($db->query("select email from user where email=\"{$email}\"")) {
             $results = $db->get_result("select uuid from user where email=\"{$email}\"");
             if (isset($results[0])) {
                 foreach ($results as $re) {
                     if ($re['uuid'] === $uuid) {
                         $results = $db->get_result("select mid,vercode,name from udevice where email=\"{$email}\"");
                         return Error::getRetString(0, results);
                     }
                 }
             }
         } else {
             return Error::getRetString(10007);
         }
     }
 }
Esempio n. 16
0
 /**
  * 
  * @param params    params
  */
 public static function _List($params)
 {
     $db = Db::init();
     $uuid = $_GET["uuid"];
     $user = $db->get_var("select user from user where uuid=\"{$uuid}\"");
     if (!isset($user)) {
         return Error::getRetString(10009);
     }
     //uuid无效
     $re = array("rooms" => array());
     $results = $db->get_results("select roomid,name,icon from user_room where user=\"{$user}\"");
     if (isset($results[0])) {
         foreach ($results as $rec) {
             $re["rooms"][] = array("roomid" => $rec->roomid * 1, "icon" => $rec->icon * 1, "name" => $rec->name);
         }
     }
     return Error::getRetString(0, $re);
 }
Esempio n. 17
0
 /**
  * 执行情景模式
  * 
  * @param params    params
  */
 public static function _Excute($params)
 {
     if (isset($params["sceneid"])) {
         $sceneid = $params["sceneid"];
         $db = Db::init();
         $invokes = $db->get_results("select * from scene_info where sceneid={$sceneid}");
         if (isset($invokes[0])) {
             foreach ($invokes as $invoke) {
                 //var_dump($invoke);
                 Action::run($invoke->cmdline, $invoke->mid, $_GET["u"]);
             }
         }
         return Error::getRetString(0);
     } else {
         return Error::getRetString(10007);
     }
 }
Esempio n. 18
0
    /**
     * 
     * @param params    params
     */
    public static function _AssisEnable($params)
    {
        if (is_array($params) && isset($params["roomid"]) && isset($params["did"]) && isset($params["assisEn"])) {
            $email = $_GET["u"];
            $roomid = $params["roomid"];
            $did = $params["did"];
            $assisEn = $params["assisEn"];
            $db = Db::init();
            if ($db->query(<<<EOD
UPDATE device set assisEn='{$assisEn}' 
WHERE EXISTS(SELECT roomid FROM room WHERE roomid="{$roomid}")
and did='{$did}' and roomid='{$roomid}';
EOD
)) {
                //成功
                return Error::getRetString(0);
            } else {
                //区域不存在
                return Error::getRetString(10021);
            }
        } else {
            return Error::getRetString(10007);
        }
    }
Esempio n. 19
0
 public static function _GetEnable($params)
 {
     if (isset($params["mid"])) {
         $mid = $params["mid"];
         $db = Db::init();
         $assid = $db->get_var("select assid from mdevice where mid=\"{$mid}\"");
         if ($assid == 1) {
             $ad = true;
         } else {
             $ad = false;
         }
         return Error::getRetString(0, array("Enable" => $ad));
     } else {
         return Error::getRetString(10007);
     }
 }
Esempio n. 20
0
    public static function _Verify($params)
    {
        if (is_array($params) && isset($params['mid'])) {
            $db = Db::init();
            $mid = $params['mid'];
            if ($db->query(<<<EOD
select mid from alldevice where mid={$mid}
EOD
)) {
                return Error::getRetString(0);
            }
            return Error::getRetString(10007);
        }
    }