正在显示
2 个修改的文件
包含
148 行增加
和
5 行删除
@@ -32,7 +32,6 @@ class Index extends Api | @@ -32,7 +32,6 @@ class Index extends Api | ||
32 | public function getCamera(){ | 32 | public function getCamera(){ |
33 | $url="https://camera.ynzhsk.cn/api/reservoir/hkws/Hardware/getListByReservoir"; | 33 | $url="https://camera.ynzhsk.cn/api/reservoir/hkws/Hardware/getListByReservoir"; |
34 | $info =HttpHelper::get($url); | 34 | $info =HttpHelper::get($url); |
35 | - | ||
36 | $info = json_decode($info, true); | 35 | $info = json_decode($info, true); |
37 | if($info['data']){ | 36 | if($info['data']){ |
38 | return $this->success("返回成功",$info); | 37 | return $this->success("返回成功",$info); |
@@ -42,8 +41,10 @@ class Index extends Api | @@ -42,8 +41,10 @@ class Index extends Api | ||
42 | } | 41 | } |
43 | //获取token | 42 | //获取token |
44 | public function tokenLogin(){ | 43 | public function tokenLogin(){ |
45 | - $appKey="waterPro_54989312"; | ||
46 | - $appSecret="bef381707451606b34c1f9b4b18bd5d7"; | 44 | + $appKey= $this->request->param('appKey',""); |
45 | + $appSecret= $this->request->param('appSecret',""); | ||
46 | +// $appKey="waterPro_54989312"; | ||
47 | +// $appSecret="bef381707451606b34c1f9b4b18bd5d7"; | ||
47 | $url="https://tyuims.tenyes.cn/api/access_token"; | 48 | $url="https://tyuims.tenyes.cn/api/access_token"; |
48 | $postdata=[ | 49 | $postdata=[ |
49 | "appKey"=>$appKey, | 50 | "appKey"=>$appKey, |
@@ -68,4 +69,73 @@ class Index extends Api | @@ -68,4 +69,73 @@ class Index extends Api | ||
68 | return $this->error("请求失败"); | 69 | return $this->error("请求失败"); |
69 | } | 70 | } |
70 | } | 71 | } |
72 | + | ||
73 | + //获取水厂列表 | ||
74 | + public function getwaterworks(){ | ||
75 | + $token= $this->request->param('token',""); | ||
76 | + $url="http://124.71.107.128:9040/data_api/v1/getWaterworksListData"; | ||
77 | + //$token="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6IjE5OTY5MTA2NzEwIiwicGFzc3dvcmQiOiJhMGUxNWM0NDRmOGNiY2NiNTAwM2U1MDk5OGI2OGZhNyIsImV4cCI6MTczMTY2ODA5MSwiaXNzIjoidWltcyJ9.W3RBwrFdidL9ERykKC_gHtjp911xrkNvUKglSes1w7c"; | ||
78 | + $res =HttpHelper::postheader($url,"","",$token); | ||
79 | + $res=json_decode($res,true); | ||
80 | + return $this->success($res['message'],$res['data']); | ||
81 | + } | ||
82 | + | ||
83 | + //获取水厂列表 | ||
84 | + public function getWaterworksDetailData(){ | ||
85 | + $id= $this->request->param('id',""); | ||
86 | + $token= $this->request->param('token',""); | ||
87 | + $url="http://124.71.107.128:9040/data_api/v1/getWaterworksDetailData"; | ||
88 | + $token="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6IjE5OTY5MTA2NzEwIiwicGFzc3dvcmQiOiJhMGUxNWM0NDRmOGNiY2NiNTAwM2U1MDk5OGI2OGZhNyIsImV4cCI6MTczMTY2ODA5MSwiaXNzIjoidWltcyJ9.W3RBwrFdidL9ERykKC_gHtjp911xrkNvUKglSes1w7c"; | ||
89 | + $data=['id'=>$id]; | ||
90 | + $res =HttpHelper::postheader($url,$data,"",$token); | ||
91 | + $res=json_decode($res,true); | ||
92 | + return $this->success($res['message'],$res['data']); | ||
93 | + } | ||
94 | + | ||
95 | + | ||
96 | + //获得净水设备列表 | ||
97 | + public function getWaterworksEquipmentListData(){ | ||
98 | + $token= $this->request->param('token',""); | ||
99 | + $url="http://124.71.107.128:9040/data_api/v1/getWaterworksEquipmentListData"; | ||
100 | + $token="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6IjE5OTY5MTA2NzEwIiwicGFzc3dvcmQiOiJhMGUxNWM0NDRmOGNiY2NiNTAwM2U1MDk5OGI2OGZhNyIsImV4cCI6MTczMTY2ODA5MSwiaXNzIjoidWltcyJ9.W3RBwrFdidL9ERykKC_gHtjp911xrkNvUKglSes1w7c"; | ||
101 | + $res =HttpHelper::postheader($url,"","",$token); | ||
102 | + $res=json_decode($res,true); | ||
103 | + return $this->success($res['message'],$res['data']); | ||
104 | + } | ||
105 | + | ||
106 | + //获得净水设备列表 | ||
107 | + public function getWaterworksEquipmentDetailData(){ | ||
108 | + $id= $this->request->param('id',""); | ||
109 | + $token= $this->request->param('token',""); | ||
110 | + $url="http://124.71.107.128:9040/data_api/v1/getWaterworksEquipmentDetailData"; | ||
111 | + $token="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6IjE5OTY5MTA2NzEwIiwicGFzc3dvcmQiOiJhMGUxNWM0NDRmOGNiY2NiNTAwM2U1MDk5OGI2OGZhNyIsImV4cCI6MTczMTY2ODA5MSwiaXNzIjoidWltcyJ9.W3RBwrFdidL9ERykKC_gHtjp911xrkNvUKglSes1w7c"; | ||
112 | + $data=['id'=>$id]; | ||
113 | + $res =HttpHelper::postheader($url,$data,"",$token); | ||
114 | + $res=json_decode($res,true); | ||
115 | + return $this->success($res['message'],$res['data']); | ||
116 | + } | ||
117 | + | ||
118 | + //-获得净水设备数据列表 | ||
119 | + public function getWaterworksEquipmentDataListData(){ | ||
120 | + $token= $this->request->param('token',""); | ||
121 | + $url="http://124.71.107.128:9040/data_api/v1/getWaterworksEquipmentDataListData"; | ||
122 | + $token="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6IjE5OTY5MTA2NzEwIiwicGFzc3dvcmQiOiJhMGUxNWM0NDRmOGNiY2NiNTAwM2U1MDk5OGI2OGZhNyIsImV4cCI6MTczMTY2ODA5MSwiaXNzIjoidWltcyJ9.W3RBwrFdidL9ERykKC_gHtjp911xrkNvUKglSes1w7c"; | ||
123 | + $res =HttpHelper::postheader($url,"","",$token); | ||
124 | + $res=json_decode($res,true); | ||
125 | + return $this->success($res['message'],$res['data']); | ||
126 | + } | ||
127 | + | ||
128 | + | ||
129 | + //-获得设备数据详情 | ||
130 | + public function getWaterworksEquipmentDataDetailData(){ | ||
131 | + $id= $this->request->param('id',""); | ||
132 | + $token= $this->request->param('token',""); | ||
133 | + $url="http://124.71.107.128:9040/data_api/v1/getWaterworksEquipmentDataDetailData"; | ||
134 | + $token="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6IjE5OTY5MTA2NzEwIiwicGFzc3dvcmQiOiJhMGUxNWM0NDRmOGNiY2NiNTAwM2U1MDk5OGI2OGZhNyIsImV4cCI6MTczMTY2ODA5MSwiaXNzIjoidWltcyJ9.W3RBwrFdidL9ERykKC_gHtjp911xrkNvUKglSes1w7c"; | ||
135 | + $data=['id'=>$id]; | ||
136 | + $res =HttpHelper::postheader($url,$data,"",$token); | ||
137 | + $res=json_decode($res,true); | ||
138 | + return $this->success($res['message'],$res['data']); | ||
139 | + } | ||
140 | + | ||
71 | } | 141 | } |
@@ -35,6 +35,19 @@ class HttpHelper | @@ -35,6 +35,19 @@ class HttpHelper | ||
35 | * @param array $options 扩展参数 | 35 | * @param array $options 扩展参数 |
36 | * @return mixed|string | 36 | * @return mixed|string |
37 | */ | 37 | */ |
38 | + public static function postheader($url, $params = [], $options = [],$header) | ||
39 | + { | ||
40 | + $req = self::sendRequestheader($url, $params, 'POST', $options,$header); | ||
41 | + return $req['ret'] ? $req['msg'] : ''; | ||
42 | + } | ||
43 | + | ||
44 | + /** | ||
45 | + * 发送一个POST请求 | ||
46 | + * @param string $url 请求URL | ||
47 | + * @param array $params 请求参数 | ||
48 | + * @param array $options 扩展参数 | ||
49 | + * @return mixed|string | ||
50 | + */ | ||
38 | public static function get($url, $params = [], $options = []) | 51 | public static function get($url, $params = [], $options = []) |
39 | { | 52 | { |
40 | $req = self::sendRequest($url, $params, 'GET', $options); | 53 | $req = self::sendRequest($url, $params, 'GET', $options); |
@@ -75,7 +88,7 @@ class HttpHelper | @@ -75,7 +88,7 @@ class HttpHelper | ||
75 | * @param mixed $options CURL的参数 | 88 | * @param mixed $options CURL的参数 |
76 | * @return array | 89 | * @return array |
77 | */ | 90 | */ |
78 | - public static function sendRequest($url, $params = [], $method = 'POST', $options = []) | 91 | + public static function sendRequestheader($url, $params = [], $method = 'POST', $options = [],$header) |
79 | { | 92 | { |
80 | $method = strtoupper($method); | 93 | $method = strtoupper($method); |
81 | $protocol = substr($url, 0, 5); | 94 | $protocol = substr($url, 0, 5); |
@@ -104,7 +117,7 @@ class HttpHelper | @@ -104,7 +117,7 @@ class HttpHelper | ||
104 | $defaults[CURLOPT_TIMEOUT] =7; | 117 | $defaults[CURLOPT_TIMEOUT] =7; |
105 | 118 | ||
106 | // disable 100-continue | 119 | // disable 100-continue |
107 | - curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:')); | 120 | + curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization:'.$header)); |
108 | 121 | ||
109 | if ('https' == $protocol) { | 122 | if ('https' == $protocol) { |
110 | $defaults[CURLOPT_SSL_VERIFYPEER] = false; | 123 | $defaults[CURLOPT_SSL_VERIFYPEER] = false; |
@@ -134,6 +147,7 @@ class HttpHelper | @@ -134,6 +147,7 @@ class HttpHelper | ||
134 | ]; | 147 | ]; |
135 | } | 148 | } |
136 | 149 | ||
150 | + | ||
137 | /** | 151 | /** |
138 | * 异步发送一个请求 | 152 | * 异步发送一个请求 |
139 | * @param string $url 请求的链接 | 153 | * @param string $url 请求的链接 |
@@ -278,4 +292,63 @@ class HttpHelper | @@ -278,4 +292,63 @@ class HttpHelper | ||
278 | return $data; | 292 | return $data; |
279 | } | 293 | } |
280 | 294 | ||
295 | + public function curlheader($url,$method,$params=[],$auth=[],$headers){ | ||
296 | + //初始化CURL句柄 | ||
297 | + $curl = curl_init(); | ||
298 | + curl_setopt($curl, CURLOPT_URL, $url);//设置请求的URL | ||
299 | + curl_setopt($curl, CURLOPT_HEADER, false);// 不要http header 加快效率 | ||
300 | + curl_setopt($curl, CURLOPT_RETURNTRANSFER,1); //设为TRUE把curl_exec()结果转化为字串,而不是直接输出 | ||
301 | + | ||
302 | + //SSL验证 | ||
303 | + curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); // https请求时要设置为false 不验证证书和hosts FALSE 禁止 cURL 验证对等证书(peer's certificate), 自cURL 7.10开始默认为 TRUE。从 cURL 7.10开始默认绑定安装。 | ||
304 | + curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);//检查服务器SSL证书中是否存在一个公用名(common name)。 | ||
305 | + | ||
306 | + $header[] = "Content-Type:application/json;charset=utf-8;Authorization=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6IjE5OTY5MTA2NzEwIiwicGFzc3dvcmQiOiJhMGUxNWM0NDRmOGNiY2NiNTAwM2U1MDk5OGI2OGZhNyIsImV4cCI6MTczMTY2ODA5MSwiaXNzIjoidWltcyJ9.W3RBwrFdidL9ERykKC_gHtjp911xrkNvUKglSes1w7c"; | ||
307 | + if(!empty($header)){ | ||
308 | + curl_setopt ( $curl, CURLOPT_HTTPHEADER, $header );//设置 HTTP 头字段的数组。格式: array('Content-type: text/plain', 'Content-length: 100') | ||
309 | + } | ||
310 | + | ||
311 | + //请求时间 | ||
312 | + $timeout = 30; | ||
313 | + curl_setopt ($curl, CURLOPT_CONNECTTIMEOUT, $timeout);//设置连接等待时间 | ||
314 | + | ||
315 | + //不同请求方法的数据提交 | ||
316 | + switch ($method){ | ||
317 | + case "GET" : | ||
318 | + curl_setopt($curl, CURLOPT_HTTPGET, true);//TRUE 时会设置 HTTP 的 method 为 GET,由于默认是 GET,所以只有 method 被修改时才需要这个选项。 | ||
319 | + break; | ||
320 | + case "POST": | ||
321 | + if(is_array($params)){ | ||
322 | + $params = json_encode($params,320); | ||
323 | + } | ||
324 | + #curl_setopt($curl, CURLOPT_POST,true);//TRUE 时会发送 POST 请求,类型为:application/x-www-form-urlencoded,是 HTML 表单提交时最常见的一种。 | ||
325 | + #curl_setopt($curl, CURLOPT_NOBODY, true);//TRUE 时将不输出 BODY 部分。同时 Mehtod 变成了 HEAD。修改为 FALSE 时不会变成 GET。 | ||
326 | + curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");//HTTP 请求时,使用自定义的 Method 来代替"GET"或"HEAD"。对 "DELETE" 或者其他更隐蔽的 HTTP 请求有用。 有效值如 "GET","POST","CONNECT"等等; | ||
327 | + //设置提交的信息 | ||
328 | + curl_setopt($curl, CURLOPT_POSTFIELDS,$params);//全部数据使用HTTP协议中的 "POST" 操作来发送。 | ||
329 | + break; | ||
330 | + case "PUT" : | ||
331 | + curl_setopt ($curl, CURLOPT_CUSTOMREQUEST, "PUT"); | ||
332 | + curl_setopt($curl, CURLOPT_POSTFIELDS,json_encode($params,320)); | ||
333 | + break; | ||
334 | + case "DELETE": | ||
335 | + curl_setopt ($curl, CURLOPT_CUSTOMREQUEST, "DELETE"); | ||
336 | + curl_setopt($curl, CURLOPT_POSTFIELDS,$params); | ||
337 | + break; | ||
338 | + } | ||
339 | + | ||
340 | + //传递一个连接中需要的用户名和密码,格式为:"[username]:[password]"。 | ||
341 | + if (!empty($auth) && isset($auth['username']) && isset($auth['password'])) { | ||
342 | + curl_setopt($curl, CURLOPT_USERPWD, "{$auth['username']}:{$auth['password']}"); | ||
343 | + } | ||
344 | + | ||
345 | + | ||
346 | + $data = curl_exec($curl);//执行预定义的CURL | ||
347 | + $status = curl_getinfo($curl, CURLINFO_HTTP_CODE);//获取http返回值,最后一个收到的HTTP代码 | ||
348 | + curl_close($curl);//关闭cURL会话 | ||
349 | +// $res = json_decode($data,true); | ||
350 | + | ||
351 | + return $data; | ||
352 | + } | ||
353 | + | ||
281 | } | 354 | } |
-
请 注册 或 登录 后发表评论