Skip to content

Commit

Permalink
feat(servemarket): 新增获取App Access Token校验信息
Browse files Browse the repository at this point in the history
  • Loading branch information
bububa committed Dec 5, 2024
1 parent bb52c5a commit 944b4f3
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 0 deletions.
1 change: 1 addition & 0 deletions marketing-api/SERVE_MARKET.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@
- 应用市场(api/serve_market)
- 获取应用订单数据 [ OrderGet(ctx context.Context, clt *core.SDKClient, accessToken string, req *servemarket.OrderGetRequest) (*servemarket.OrderGetResponseData, error) ]
- 获取用户已购功能点列表 [ ActiveFuncGet(ctx context.Context, clt *core.SDKClient, accessToken string, req *servemarket.ActiveFuncGetRequest) ([]servemarket.OrderFunction, error) ]
- 获取App Access Token校验信息 [ CidVerifyToken(ctx context.Context, clt *core.SDKClient, token string) (*servemarket.CidVerifyTokenResult, error) ]
23 changes: 23 additions & 0 deletions marketing-api/api/servemarket/cid_verfiy_token.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package servemarket

import (
"context"
"net/http"

"github.com/bububa/oceanengine/marketing-api/core"
"github.com/bububa/oceanengine/marketing-api/model/servemarket"
)

// CidVerifyToken 获取App Access Token校验信息
func CidVerifyToken(ctx context.Context, clt *core.SDKClient, token string) (*servemarket.CidVerifyTokenResult, error) {
cltCopied := clt.Copy()
cltCopied.AddPreRequests(func(httpReq *http.Request) error {
httpReq.Header.Set("App-Access-Token", token)
return nil
})
var resp servemarket.CidVerifyTokenResponse
if err := cltCopied.GetAPI(ctx, "v1.0/serve_market/cid/verify_token/", nil, &resp, ""); err != nil {
return nil, err
}
return resp.Data, nil
}
19 changes: 19 additions & 0 deletions marketing-api/core/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type SDKClient struct {
limiter RateLimiter
Secret string
operatorIP string
preReqs []PreRequest
AppID uint64
debug bool
sandbox bool
Expand Down Expand Up @@ -93,6 +94,14 @@ func (c *SDKClient) WithTracer(namespace string) {
c.tracer = NewOtel(namespace, c.AppID)
}

func (c *SDKClient) WithPreRequests(reqs ...PreRequest) {
c.preReqs = reqs
}

func (c *SDKClient) AddPreRequests(reqs ...PreRequest) {
c.preReqs = append(c.preReqs, reqs...)
}

// Copy 复制SDKClient
func (c *SDKClient) Copy() *SDKClient {
return &SDKClient{
Expand All @@ -103,6 +112,7 @@ func (c *SDKClient) Copy() *SDKClient {
operatorIP: c.operatorIP,
client: c.client,
tracer: c.tracer,
preReqs: c.preReqs,
}
}

Expand Down Expand Up @@ -380,8 +390,17 @@ func (c *SDKClient) AnalyticsV1Post(ctx context.Context, gw string, req model.Po
return c.WithSpan(ctx, httpReq, resp, reqBytes, c.fetch)
}

type PreRequest func(httpReq *http.Request) error

// fetch execute http request
func (c *SDKClient) fetch(httpReq *http.Request, resp model.Response) (*http.Response, error) {
if len(c.preReqs) > 0 {
for _, req := range c.preReqs {
if err := req(httpReq); err != nil {
return nil, err
}
}
}
httpResp, err := c.client.Do(httpReq)
if err != nil {
return httpResp, err
Expand Down
47 changes: 47 additions & 0 deletions marketing-api/model/servemarket/cid_verify_token.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package servemarket

import "github.com/bububa/oceanengine/marketing-api/model"

// CidVerifyTokenResponse 获取App Access Token校验信息 API Response
type CidVerifyTokenResponse struct {
Data *CidVerifyTokenResult `json:"data,omitempty"`
model.BaseResponse
}

type CidVerifyTokenResult struct {
// AppAccessToken 传入的app_access_token
AppAccessToken string `json:"app_access_token,omitempty"`
// DevStatus 开放平台开发者状态:
// 1 开发者身份待申请
// 2 主体资质待认证
// 4 对公验证待认证
// 5 合同创建中
// 3 合同审核中
// 6 合同待签署
// 7 正常
// 8 其它
// 仅“7-正常”状态可校验通过
DevStatus int `json:"dev_status,omitempty"`
// DevQualificationName 开放平台开发者资质名称
DevQualificationName string `json:"dev_qualification_name,omitempty"`
// FacilitatorSubStatus 群峰服务商状态:
// 10 主体资质待认证
// 30 对公验证待认证
// 40 CA签章待申请
// 45 合同创建中
// 50 合同已签署
// 60 保证金已缴纳
// 100 其它
// 仅“60-保证金已缴纳”状态可校验通过
FacilitatorSubStatus int `json:"facilitator_sub_status,omitempty"`
// CidCapacityStatus 群峰服务商「电商技术服务」能力开通状态:
// 1 审核中
// 2 审核拒绝
// 3 审核通过
// 6 服务商退出
// 100 未知
// 仅“3-审核通过”状态可校验通过
CidCapacityStatus int `json:"cid_capacity_status,omitempty"`
// TokenIsValid app_access_token是否有效,如果为true,则表示,转化数据回传时,携带的app_access_token动态身份标识,可校验通过
TokenIsValid bool `json:"token_is_valid,omitempty"`
}

0 comments on commit 944b4f3

Please sign in to comment.