diff --git a/marketing-api/SERVE_MARKET.md b/marketing-api/SERVE_MARKET.md index c4851efb..5af52634 100644 --- a/marketing-api/SERVE_MARKET.md +++ b/marketing-api/SERVE_MARKET.md @@ -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) ] diff --git a/marketing-api/api/servemarket/cid_verfiy_token.go b/marketing-api/api/servemarket/cid_verfiy_token.go new file mode 100644 index 00000000..585f3b42 --- /dev/null +++ b/marketing-api/api/servemarket/cid_verfiy_token.go @@ -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 +} diff --git a/marketing-api/core/client.go b/marketing-api/core/client.go index f8b020ec..e2612818 100644 --- a/marketing-api/core/client.go +++ b/marketing-api/core/client.go @@ -45,6 +45,7 @@ type SDKClient struct { limiter RateLimiter Secret string operatorIP string + preReqs []PreRequest AppID uint64 debug bool sandbox bool @@ -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{ @@ -103,6 +112,7 @@ func (c *SDKClient) Copy() *SDKClient { operatorIP: c.operatorIP, client: c.client, tracer: c.tracer, + preReqs: c.preReqs, } } @@ -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 diff --git a/marketing-api/model/servemarket/cid_verify_token.go b/marketing-api/model/servemarket/cid_verify_token.go new file mode 100644 index 00000000..95a766e3 --- /dev/null +++ b/marketing-api/model/servemarket/cid_verify_token.go @@ -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"` +}