Bozhidar Slaveykov 1 年之前
父節點
當前提交
742dddb16a
共有 1 個文件被更改,包括 45 次插入0 次删除
  1. 45 0
      web/app/ApiSDK/PhyreApiSDK.php

+ 45 - 0
web/app/ApiSDK/PhyreApiSDK.php

@@ -0,0 +1,45 @@
+<?php
+
+namespace app\ApiSDK;
+
+class PhyreApiSDK
+{
+    public $ip;
+    public $port;
+    public $password;
+    public $username;
+
+    public function __construct($ip, $port, $password, $username)
+    {
+        $this->ip = $ip;
+        $this->port = $port;
+        $this->password = $password;
+        $this->username = $username;
+    }
+
+    public function healthCheck()
+    {
+        $response = $this->sendRequest('health', [], 'GET');
+
+        return $response;
+    }
+
+    public function sendRequest($resource, $params, $requestType)
+    {
+        $url = 'http://' . $this->ip . ':' . $this->port . '/api/' . $resource;
+
+        $ch = curl_init($url);
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $requestType);
+        curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($params));
+//        curl_setopt($ch, CURLOPT_HTTPHEADER, array(
+//            'Content-Type: application/x-www-form-urlencoded',
+//            'Authorization: Basic '.base64_encode($this->username.':'.$this->password)
+//        ));
+        $response = curl_exec($ch);
+        curl_close($ch);
+        
+        return $response;
+    }
+
+}