maycur.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. package maycur
  2. import (
  3. "context"
  4. "encoding/json"
  5. "fmt"
  6. "hongze/hongze_task/models"
  7. "hongze/hongze_task/services/alarm_msg"
  8. "hongze/hongze_task/utils"
  9. "io/ioutil"
  10. "net/http"
  11. "strings"
  12. )
  13. const (
  14. SyncMaycurCompanyProfileUrl = "http://127.0.0.1:8602/adminapi/maycur/company_profile/daily_sync"
  15. )
  16. // DailyUpdateCompanyProfile 每日更新客户档案-请求hongze_admin同步接口
  17. func DailyUpdateCompanyProfile(cont context.Context) (err error) {
  18. defer func() {
  19. if err != nil {
  20. utils.FileLog.Info("DailyUpdateCompanyProfile ErrMsg: %s", err.Error())
  21. alarm_msg.SendAlarmMsg(fmt.Sprintf("每日更新客户档案失败, ErrMsg: %s", err.Error()), 3)
  22. }
  23. }()
  24. body := ioutil.NopCloser(strings.NewReader(""))
  25. client := &http.Client{}
  26. req, e := http.NewRequest("POST", SyncMaycurCompanyProfileUrl, body)
  27. if e != nil {
  28. err = fmt.Errorf("http create request err: %s", e.Error())
  29. return
  30. }
  31. contentType := "application/json;charset=utf-8"
  32. req.Header.Set("Content-Type", contentType)
  33. //req.Header.Set("Authorization", utils.SendTemplateMsgAuthorization)
  34. resp, e := client.Do(req)
  35. if e != nil {
  36. err = fmt.Errorf("http client do err: %s", e.Error())
  37. return err
  38. }
  39. defer func() {
  40. _ = resp.Body.Close()
  41. }()
  42. b, e := ioutil.ReadAll(resp.Body)
  43. if e != nil {
  44. err = fmt.Errorf("resp body read err: %s", e.Error())
  45. return
  46. }
  47. result := new(models.BaseResponse)
  48. if e = json.Unmarshal(b, &result); e != nil {
  49. err = fmt.Errorf("result unmarshal err: %s\nresult: %s", e.Error(), string(b))
  50. return
  51. }
  52. if result.Ret != 200 {
  53. err = fmt.Errorf("result: %s", string(b))
  54. return err
  55. }
  56. return
  57. }