hongze_sync_trial.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package services
  2. import (
  3. "encoding/json"
  4. "errors"
  5. "eta/eta_index_lib/utils"
  6. "fmt"
  7. "io"
  8. "net/http"
  9. "strings"
  10. )
  11. // var syncTrialUrl = `http://127.0.0.1:8810/api/` // 服务地址
  12. var syncTrialUrl = `http://172.19.173.232:8810/api/` // 服务地址
  13. var syncToken = `SF25sdsfwEW4fs53F4D.82SDdsooDg` // 校验token(目前是写死的,后续可以根据用户配置)
  14. //var syncTrialUrl = `http://127.0.0.1:8810/api/`
  15. // BaseSyncTrialResp 基础返回
  16. type BaseSyncTrialResp struct {
  17. Code int `json:"code"`
  18. Msg string `json:"msg"`
  19. Data interface{} `json:"data"`
  20. }
  21. // SyncTrialEdbInfoResp 指标详情返回
  22. type SyncTrialEdbInfoResp struct {
  23. Code int `json:"code"`
  24. Msg string `json:"msg"`
  25. Data struct {
  26. EdbCode string `json:"edb_code"`
  27. Source int `json:"source"`
  28. ServerUrl string `json:"server_url"`
  29. } `json:"data"`
  30. }
  31. // GetHzWindUrl 获取wind的url
  32. func GetHzWindUrl(edbCode string, source int) (windUrl string, err error, errMsg string) {
  33. requestSyncTrialUrl := syncTrialUrl + `common/edb_info/edb_code?edb_code=%s&source=%d`
  34. requestSyncTrialUrl = fmt.Sprintf(requestSyncTrialUrl, edbCode, source)
  35. payload := strings.NewReader("-----011000010111000001101001--\r\n\r\n")
  36. req, _ := http.NewRequest("GET", requestSyncTrialUrl, payload)
  37. req.Header.Add("authorization", syncToken)
  38. req.Header.Add("content-type", "multipart/form-data; boundary=---011000010111000001101001")
  39. res, err := http.DefaultClient.Do(req)
  40. if err != nil {
  41. return
  42. }
  43. defer res.Body.Close()
  44. body, err := io.ReadAll(res.Body)
  45. if err != nil {
  46. return
  47. }
  48. //fmt.Println("GetHzWindUrl body:")
  49. //fmt.Println(string(body))
  50. utils.FileLog.Info(fmt.Sprint("syncTrial result:", string(body)))
  51. item := new(SyncTrialEdbInfoResp)
  52. err = json.Unmarshal(body, &item)
  53. if err != nil {
  54. return
  55. }
  56. //异常的话,需要邮件通知
  57. if item.Code != 200 {
  58. errMsg = item.Msg
  59. err = errors.New(errMsg)
  60. return
  61. }
  62. windUrl = item.Data.ServerUrl
  63. return
  64. }