associate_outer.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. package vip
  2. import (
  3. "bytes"
  4. "context"
  5. "go-common/app/interface/main/account/model"
  6. v1 "go-common/app/service/main/vip/api"
  7. "go-common/library/log"
  8. )
  9. // ElemeOAuthURI get ele oauth uri.
  10. func (s *Service) ElemeOAuthURI(c context.Context, csrf string) string {
  11. var buf bytes.Buffer
  12. buf.WriteString(s.c.Vipproperty.EleOAuthURI)
  13. buf.WriteString("?consumer_key=")
  14. buf.WriteString(s.c.Vipproperty.EleConsumerKey)
  15. buf.WriteString("&scope=user_basic_info&redirect_uri=")
  16. buf.WriteString(s.c.Vipproperty.EleOAuthCallBackURI)
  17. buf.WriteString("&state=")
  18. buf.WriteString(csrf)
  19. return buf.String()
  20. }
  21. // OpenIDByAuthCode third get open_id by auth code.
  22. func (s *Service) OpenIDByAuthCode(c context.Context, a *model.ArgAuthCode) (res *model.OpenIDResp, err error) {
  23. var (
  24. data *model.OAuth2InfoResp
  25. r *v1.RegisterOpenIDReply
  26. )
  27. //oauth2 token.
  28. if data, err = s.vipDao.OAuth2ByCode(c, a); err != nil {
  29. return
  30. }
  31. res = new(model.OpenIDResp)
  32. if r, err = s.vipgRPC.RegisterOpenID(c, &v1.RegisterOpenIDReq{Mid: data.Mid, AppId: a.APPID}); err != nil {
  33. return
  34. }
  35. res.OpenID = r.OpenId
  36. return
  37. }
  38. // OpenAuthCallBack open auth callback[third->bilibili].
  39. func (s *Service) OpenAuthCallBack(c context.Context, a *model.ArgOpenAuthCallBack) (uri string) {
  40. var (
  41. ret = "0"
  42. err error
  43. )
  44. if _, err = s.vipgRPC.OpenAuthCallBack(c, &v1.OpenAuthCallBackReq{
  45. Mid: a.Mid,
  46. ThirdCode: a.ThirdCode,
  47. AppId: a.AppID,
  48. }); err != nil {
  49. log.Error("vipSvc.OpenAuthCallBack(%+v) err(%+v)", a, err)
  50. ret = "1"
  51. }
  52. uri = s.c.Vipproperty.ActivityURI + "?bind_ret=" + ret
  53. return
  54. }
  55. // BilibiliPrizeGrant vip prize grant.
  56. func (s *Service) BilibiliPrizeGrant(c context.Context, a *model.ArgBilibiliPrizeGrant) (res *v1.BilibiliPrizeGrantReply, err error) {
  57. return s.vipgRPC.BilibiliPrizeGrant(c, &v1.BilibiliPrizeGrantReq{
  58. PrizeKey: a.PrizeKey,
  59. UniqueNo: a.UniqueNo,
  60. OpenId: a.OpenID,
  61. AppId: a.AppID,
  62. })
  63. }
  64. // BilibiliVipGrant vip grant.
  65. func (s *Service) BilibiliVipGrant(c context.Context, a *model.ArgBilibiliVipGrant) (err error) {
  66. _, err = s.vipgRPC.BilibiliVipGrant(c, &v1.BilibiliVipGrantReq{
  67. OpenId: a.OpenID,
  68. AppId: a.AppID,
  69. OutOpenId: a.OutOpenID,
  70. OutOrderNo: a.OutOrderNO,
  71. Duration: a.Duration,
  72. })
  73. return
  74. }
  75. // OpenBindByOutOpenID associate user bind by out_open_id [third -> bilibili].
  76. func (s *Service) OpenBindByOutOpenID(c context.Context, a *model.ArgBind) (err error) {
  77. _, err = s.vipgRPC.OpenBindByOutOpenID(c, &v1.OpenBindByOutOpenIDReq{
  78. OpenId: a.OpenID,
  79. OutOpenId: a.OutOpenID,
  80. AppId: a.AppID,
  81. })
  82. return
  83. }
  84. // UserInfoByOpenID get userinfo by open_id.
  85. func (s *Service) UserInfoByOpenID(c context.Context, a *model.ArgUserInfoByOpenID) (res *v1.UserInfoByOpenIDReply, err error) {
  86. return s.vipgRPC.UserInfoByOpenID(c, &v1.UserInfoByOpenIDReq{
  87. OpenId: a.OpenID,
  88. Ip: a.IP,
  89. AppId: a.AppID,
  90. })
  91. }