qw_refresh_logic.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package WorkPhone
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/imroc/req/v3"
  6. "time"
  7. "wechat-api/internal/svc"
  8. "wechat-api/internal/types"
  9. "github.com/zeromicro/go-zero/core/logx"
  10. )
  11. type QwRefreshLogic struct {
  12. logx.Logger
  13. ctx context.Context
  14. svcCtx *svc.ServiceContext
  15. }
  16. func NewQwRefreshLogic(ctx context.Context, svcCtx *svc.ServiceContext) *QwRefreshLogic {
  17. return &QwRefreshLogic{
  18. Logger: logx.WithContext(ctx),
  19. ctx: ctx,
  20. svcCtx: svcCtx}
  21. }
  22. func (l *QwRefreshLogic) QwRefresh() (resp *types.BaseMsgResp, err error) {
  23. var result types.WorkPhoneGetWeChatsResp
  24. client := req.C().DevMode()
  25. client.SetCommonRetryCount(2).
  26. SetCommonRetryBackoffInterval(1*time.Second, 5*time.Second).
  27. SetCommonRetryFixedInterval(2 * time.Second).SetTimeout(30 * time.Second)
  28. res, err := client.R().SetSuccessResult(&result).Post("http://wecom.gkscrm.com:15086/pc/GetWeChatsReq?id=19")
  29. if err != nil {
  30. return nil, err
  31. }
  32. if !res.IsSuccessState() {
  33. err = fmt.Errorf("GetWeChats failed with status code %d", res.StatusCode)
  34. return nil, err
  35. }
  36. return resp, nil
  37. }