tribally task verify
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
|||||||
"nova_task/internal/model"
|
"nova_task/internal/model"
|
||||||
"nova_task/internal/pkg/aptos"
|
"nova_task/internal/pkg/aptos"
|
||||||
"nova_task/internal/pkg/errs"
|
"nova_task/internal/pkg/errs"
|
||||||
|
"nova_task/internal/pkg/tribally"
|
||||||
"nova_task/internal/svc"
|
"nova_task/internal/svc"
|
||||||
"nova_task/internal/types"
|
"nova_task/internal/types"
|
||||||
"time"
|
"time"
|
||||||
@@ -88,6 +89,15 @@ func (l *VerifyTaskResultLogic) VerifyTaskResult(req *types.VerifyTaskResultReq)
|
|||||||
if !l.svcCtx.IsAmbassador(l.ctx, uint(uid), 0) {
|
if !l.svcCtx.IsAmbassador(l.ctx, uint(uid), 0) {
|
||||||
return &types.VerifyTaskResultResp{Finish: false}, nil
|
return &types.VerifyTaskResultResp{Finish: false}, nil
|
||||||
}
|
}
|
||||||
|
case model.TASKTYPE_BIND_TRIBALLY:
|
||||||
|
if req.Params == "" {
|
||||||
|
return &types.VerifyTaskResultResp{Finish: false}, nil
|
||||||
|
} else {
|
||||||
|
if err := tribally.VerifyTribally(req.Params); err != nil {
|
||||||
|
l.Errorw("verify tribally error", logx.Field("err", err), logx.Field("params", req.Params), logx.Field("uid", uid))
|
||||||
|
return &types.VerifyTaskResultResp{Finish: false}, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ const (
|
|||||||
TASKTYPE_INVITE_USER = 10 // 邀请任务
|
TASKTYPE_INVITE_USER = 10 // 邀请任务
|
||||||
TASKTYPE_AMBASSADOR_TASK = 11 // 大使任务
|
TASKTYPE_AMBASSADOR_TASK = 11 // 大使任务
|
||||||
TASKTYPE_TRUMP_HEAD = 12 // trump_head
|
TASKTYPE_TRUMP_HEAD = 12 // trump_head
|
||||||
|
TASKTYPE_BIND_TRIBALLY = 13 // 绑定TRIBALLY任务
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
|
|||||||
@@ -46,3 +46,44 @@ func BindTribally(apiKey, userId string) (string, error) {
|
|||||||
}
|
}
|
||||||
return result.Data.AuthURL, nil
|
return result.Data.AuthURL, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func VerifyTribally(token string) error {
|
||||||
|
url := "https://api.tribally.games/member/me"
|
||||||
|
req, err := http.NewRequest(http.MethodGet, url, nil)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
req.Header.Add("Content-Type", "application/json")
|
||||||
|
req.Header.Add("Accept", "application/json")
|
||||||
|
req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", token))
|
||||||
|
res, err := http.DefaultClient.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer res.Body.Close()
|
||||||
|
|
||||||
|
body, err := io.ReadAll(res.Body)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
result := struct {
|
||||||
|
Error string `json:"error"`
|
||||||
|
Code string `json:"code"`
|
||||||
|
Data struct {
|
||||||
|
UserID string `json:"userId"`
|
||||||
|
ScreenName string `json:"screenName"`
|
||||||
|
Slug string `json:"slug"`
|
||||||
|
HasBattlePass bool `json:"hasBattlePass"`
|
||||||
|
ProfileImage string `json:"profileImage"`
|
||||||
|
} `json:"data"`
|
||||||
|
}{}
|
||||||
|
err = json.Unmarshal(body, &result)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if result.Error != "" {
|
||||||
|
return fmt.Errorf("error: %s, code: %s", result.Error, result.Code)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user