hongze_sync_trial.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. TerminalCode string `json:"terminal_code"`
  30. } `json:"data"`
  31. }
  32. // GetHzWindUrl 获取wind的url
  33. func GetHzWindUrl(edbCode string, source int) (windUrl string, terminalCode string, err error, errMsg string) {
  34. requestSyncTrialUrl := syncTrialUrl + `common/edb_info/edb_code?edb_code=%s&source=%d`
  35. requestSyncTrialUrl = fmt.Sprintf(requestSyncTrialUrl, edbCode, source)
  36. payload := strings.NewReader("-----011000010111000001101001--\r\n\r\n")
  37. req, _ := http.NewRequest("GET", requestSyncTrialUrl, payload)
  38. req.Header.Add("authorization", syncToken)
  39. req.Header.Add("content-type", "multipart/form-data; boundary=---011000010111000001101001")
  40. res, err := http.DefaultClient.Do(req)
  41. if err != nil {
  42. return
  43. }
  44. defer res.Body.Close()
  45. body, err := io.ReadAll(res.Body)
  46. if err != nil {
  47. return
  48. }
  49. //fmt.Println("GetHzWindUrl body:")
  50. //fmt.Println(string(body))
  51. utils.FileLog.Info(fmt.Sprint("syncTrial result:", string(body)))
  52. item := new(SyncTrialEdbInfoResp)
  53. err = json.Unmarshal(body, &item)
  54. if err != nil {
  55. return
  56. }
  57. //异常的话,需要邮件通知
  58. if item.Code != 200 {
  59. errMsg = item.Msg
  60. err = errors.New(errMsg)
  61. return
  62. }
  63. windUrl = item.Data.ServerUrl
  64. terminalCode = item.Data.TerminalCode
  65. return
  66. }