2013-07-25 09:13:57 +00:00
|
|
|
<?php
|
|
|
|
namespace data;
|
2013-08-26 02:39:22 +00:00
|
|
|
|
|
|
|
use Helpers\View as view;
|
|
|
|
use Helpers\Curl;
|
|
|
|
|
2013-07-25 09:13:57 +00:00
|
|
|
class DataService
|
|
|
|
{
|
|
|
|
private $db; //传入PDO对象.
|
|
|
|
|
|
|
|
//使用到的公共变量
|
|
|
|
public $tbl_dataservice = "dataservice";
|
|
|
|
|
|
|
|
function __construct($db = NULL)
|
|
|
|
{
|
|
|
|
if(empty($db))
|
|
|
|
{
|
|
|
|
$this->db = \Zend_Registry::get('db');
|
|
|
|
}else{
|
|
|
|
$this->db = $db;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->config = \Zend_Registry::get('config');
|
|
|
|
}
|
|
|
|
|
|
|
|
function Fetch()
|
|
|
|
{
|
|
|
|
$sql = "SELECT * FROM ".$this->tbl_dataservice."";
|
|
|
|
$rs = $this->db->query($sql);
|
|
|
|
return $rs->fetchAll();
|
|
|
|
}
|
|
|
|
|
|
|
|
function get($uuid)
|
|
|
|
{
|
2013-07-26 10:44:59 +00:00
|
|
|
$sql = "SELECT * FROM ".$this->tbl_dataservice." WHERE uuid='$uuid' LIMIT 1";
|
2013-07-25 09:13:57 +00:00
|
|
|
$rs = $this->db->query($sql);
|
|
|
|
return $rs->fetch();
|
|
|
|
}
|
2013-07-26 10:44:59 +00:00
|
|
|
|
|
|
|
public function getWsnData($type,$uuid = "",$param = ""){
|
2013-08-26 02:39:22 +00:00
|
|
|
|
|
|
|
$info = $this->get($uuid);
|
2013-08-29 07:53:31 +00:00
|
|
|
|
2013-08-26 02:39:22 +00:00
|
|
|
$curl = new Curl();
|
2013-08-29 07:53:31 +00:00
|
|
|
|
|
|
|
$uid = view::User('id');
|
|
|
|
|
|
|
|
if(!is_numeric($uid) || $uid <1)
|
|
|
|
{
|
|
|
|
return "请先登录";
|
|
|
|
}
|
2013-07-26 10:44:59 +00:00
|
|
|
|
|
|
|
if($type == 'site')
|
|
|
|
{
|
|
|
|
$param = array(
|
2013-08-26 02:39:22 +00:00
|
|
|
'uuid'=>$uuid,
|
2013-08-29 07:53:31 +00:00
|
|
|
//'uuid'=> 'b7beb8bf-58d9-4e58-a945-7b6e1dc7705f', ///TEST TEST TEST
|
2013-08-26 02:39:22 +00:00
|
|
|
'uid'=> view::User('id')
|
2013-07-26 10:44:59 +00:00
|
|
|
);
|
|
|
|
$data = $curl->request($info['service_url']."site/",$param,"POST");
|
|
|
|
$data = json_decode($data['response'],TRUE);
|
|
|
|
}//site
|
2013-08-29 07:53:31 +00:00
|
|
|
|
2013-07-26 10:44:59 +00:00
|
|
|
if($type == 'var')
|
|
|
|
{
|
|
|
|
$param_temp = array(
|
2013-08-26 02:39:22 +00:00
|
|
|
'uuid'=>$uuid,
|
2013-08-29 07:53:31 +00:00
|
|
|
//'uuid'=> 'b7beb8bf-58d9-4e58-a945-7b6e1dc7705f', ///TEST TEST TEST
|
2013-08-26 02:39:22 +00:00
|
|
|
'uid'=> view::User('id'),
|
2013-07-26 10:44:59 +00:00
|
|
|
);
|
|
|
|
$param = array_merge($param,$param_temp);
|
|
|
|
$data = $curl->request($info['service_url']."var/",$param,"POST");
|
|
|
|
$data = json_decode($data['response'],TRUE);
|
|
|
|
}
|
|
|
|
|
2013-08-26 02:39:22 +00:00
|
|
|
if($type == 'submit')
|
|
|
|
{
|
|
|
|
$param_temp = array(
|
2013-09-05 01:50:29 +00:00
|
|
|
'uuid'=>$uuid,
|
|
|
|
//'uuid'=> 'b7beb8bf-58d9-4e58-a945-7b6e1dc7705f', ///TEST TEST TEST
|
2013-08-26 02:39:22 +00:00
|
|
|
'uid'=> view::User('id'),
|
|
|
|
);
|
|
|
|
$param = array_merge($param,$param_temp);
|
2013-08-29 07:53:31 +00:00
|
|
|
|
2013-08-26 02:39:22 +00:00
|
|
|
$data = $curl->request($info['service_url']."insert/",$param,"POST");
|
|
|
|
$data = json_decode($data['response'],TRUE);
|
|
|
|
}
|
|
|
|
|
2013-07-26 10:44:59 +00:00
|
|
|
if($data['status'] == 0)
|
|
|
|
{
|
|
|
|
return $data['error'];
|
|
|
|
}
|
|
|
|
|
|
|
|
else if($data['status'] == 1)
|
|
|
|
{
|
|
|
|
return $data['data'];
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}//获取Wsn数据
|
2013-09-05 04:00:07 +00:00
|
|
|
|
|
|
|
//访问wsn端生成数据的webservice
|
2013-09-12 08:06:05 +00:00
|
|
|
public function makeWsnData($param)
|
2013-09-05 04:00:07 +00:00
|
|
|
{
|
2013-09-12 08:06:05 +00:00
|
|
|
$param_temp = array(
|
|
|
|
//'uuid'=> 'b7beb8bf-58d9-4e58-a945-7b6e1dc7705f', ///TEST TEST TEST
|
|
|
|
);
|
|
|
|
$param = array_merge($param,$param_temp);
|
|
|
|
|
2013-09-26 04:11:27 +00:00
|
|
|
$url = "http://ftp2.westgis.ac.cn/wsndata.php";
|
2013-09-25 09:44:21 +00:00
|
|
|
$curl = new Curl();
|
2013-09-26 04:11:27 +00:00
|
|
|
$data = $curl->request($url,$param);
|
2013-09-12 08:06:05 +00:00
|
|
|
$data = json_decode($data['response'],TRUE);
|
2013-09-05 04:00:07 +00:00
|
|
|
}
|
2013-07-26 10:44:59 +00:00
|
|
|
}
|