maycur.go 1.8 KB

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