forRewindService.go 907 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. method := "GET"
  15. client := &http.Client{}
  16. req, err := http.NewRequest(method, url, nil)
  17. if err != nil {
  18. return "", nil
  19. }
  20. res, err := client.Do(req)
  21. if err != nil {
  22. return "", nil
  23. }
  24. defer res.Body.Close()
  25. body, err := ioutil.ReadAll(res.Body)
  26. if err != nil {
  27. return "", nil
  28. }
  29. return string(body), err
  30. }
  31. // GetRewindText 请求回话加密数据
  32. func (f *ForRewindService) GetRewindText(streamId string, date string) (string, error) {
  33. cfg := config.Instance()
  34. api := cfg.Foreign.SecurityRewindUrl + "/list/%v/%v"
  35. url2 := fmt.Sprintf(api, (streamId), url.QueryEscape(date))
  36. return f.getRewindApi(url2)
  37. }