forRewindService.go 1022 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. package edge_service
  2. import (
  3. "fmt"
  4. "io/ioutil"
  5. "iot_manager_service/config"
  6. "net/http"
  7. "net/url"
  8. )
  9. // ForRewindService 回放记录
  10. type ForRewindService struct {
  11. }
  12. // getRewindApi 公用请求接口
  13. func (f *ForRewindService) getRewindApi(url string) (string, error) {
  14. //fmt.Printf("url = %v", url)
  15. method := "GET"
  16. client := &http.Client{}
  17. req, err := http.NewRequest(method, url, nil)
  18. if err != nil {
  19. fmt.Println(err)
  20. return "", nil
  21. }
  22. res, err := client.Do(req)
  23. if err != nil {
  24. fmt.Println(err)
  25. return "", nil
  26. }
  27. defer res.Body.Close()
  28. body, err := ioutil.ReadAll(res.Body)
  29. if err != nil {
  30. fmt.Println(err)
  31. return "", nil
  32. }
  33. fmt.Println(string(body))
  34. return string(body), err
  35. }
  36. // GetRewindText 请求回话加密数据
  37. func (f *ForRewindService) GetRewindText(streamId string, date string) (string, error) {
  38. cfg := config.Instance()
  39. api := cfg.Foreign.SecurityRewindUrl + "/list/%v/%v"
  40. url2 := fmt.Sprintf(api, (streamId), url.QueryEscape(date))
  41. return f.getRewindApi(url2)
  42. }