oauth2_api.go 816 B

123456789101112131415161718192021222324252627282930313233343536
  1. package vip
  2. import (
  3. "context"
  4. "net/url"
  5. "go-common/app/interface/main/account/model"
  6. "go-common/library/ecode"
  7. pkgerr "github.com/pkg/errors"
  8. )
  9. const (
  10. _oauth2UserInfoPath = "/oauth2/user_info"
  11. )
  12. //OAuth2ByCode get user info by oauth2 code.
  13. func (d *Dao) OAuth2ByCode(c context.Context, a *model.ArgAuthCode) (data *model.OAuth2InfoResp, err error) {
  14. params := url.Values{}
  15. params.Add("code", a.Code)
  16. params.Add("grant_type", "authorization_code")
  17. var res struct {
  18. Code int `json:"code"`
  19. Data *model.OAuth2InfoResp `json:"data"`
  20. }
  21. if err = d.cl.get(c, d.c.Host.PassportCom, _oauth2UserInfoPath, a.IP, params, &res); err != nil {
  22. return
  23. }
  24. if res.Code != 0 {
  25. err = ecode.Int(res.Code)
  26. err = pkgerr.Wrap(err, "dao oauth2 userinfo")
  27. return
  28. }
  29. data = res.Data
  30. return
  31. }