Explorar o código

:add 增加控制球阀的api 接口

fly hai 1 mes
pai
achega
ed35a82052
Modificáronse 1 ficheiros con 20 adicións e 0 borrados
  1. 20 0
      api/xph/xph_api.go

+ 20 - 0
api/xph/xph_api.go

@@ -165,6 +165,26 @@ func (x *Xph) PostControlRelay(id, index, state int, token string) (bool, error)
 	return string(body) == "true", nil
 }
 
+func (x *Xph) PostControlBallValve(id, index, percent int, token string) (bool, error) {
+	client := &http.Client{Timeout: 30 * time.Second}
+	relayParam := map[string]int{"deviceId": id, "relayNum": index, "percent": percent}
+	jsonStr, _ := json.Marshal(relayParam)
+	req, err := http.NewRequest("POST", x.baseUrl+"/relay", bytes.NewBuffer(jsonStr))
+	if err != nil {
+		return false, err
+	}
+	req.Header.Set("token", token)
+	req.Header.Set("Content-Type", "application/json")
+	resp, err := client.Do(req)
+	if err != nil {
+		return false, err
+	}
+	defer resp.Body.Close()
+	body, _ := ioutil.ReadAll(resp.Body)
+
+	return string(body) == "true", nil
+}
+
 func (x *Xph) GetDeviceData(id, token string) (data DeviceData, err error) {
 	client := &http.Client{Timeout: 5 * time.Second}
 	req, err := http.NewRequest("GET", x.baseUrl+"/screen/datas?deviceId="+id, nil)