API接口名称

小结:

1)接口名称做为请求参数,不在请求路径中体现。

 2) 实践

type CommonResp struct {
    Code int32
}

type CommonReq struct {
    Action string
}
 

 

package server

import (
    "WebSvc/internal/conf"
    "WebSvc/internal/service"
    "encoding/json"
    "io"
    ghttp "net/http"

    "github.com/go-kratos/kratos/v2/log"
    "github.com/go-kratos/kratos/v2/middleware/recovery"
    "github.com/go-kratos/kratos/v2/transport/http"
)

// NewHTTPServer new a HTTP server.
func NewHTTPServer(c *conf.Server, goods *service.GoodsService, logger log.Logger) *http.Server {
    var opts = []http.ServerOption{
        http.Middleware(
            recovery.Recovery(),
        ),
    }
    if c.Http.Network != "" {
        opts = append(opts, http.Network(c.Http.Network))
    }
    if c.Http.Addr != "" {
        opts = append(opts, http.Address(c.Http.Addr))
    }
    if c.Http.Timeout != nil {
        opts = append(opts, http.Timeout(c.Http.Timeout.AsDuration()))
    }
    srv := http.NewServer(opts...)
    r := srv.Route("/")
    r.POST("/gateway", gateway(goods))
    return srv
}

func gateway(srv *service.GoodsService) func(ctx http.Context) error {
    return func(ctx http.Context) error {
        req := ctx.Request()
        w := ctx.Response()
        w.Header().Set("access-control-allow-methods", "OPTIONS,GET,POST")
        w.Header().Set("access-control-allow-origin", "*")
        w.Header().Set("access-control-allow-headers", "Content-Type,x-accesstoken")
        if req.Method == ghttp.MethodOptions {
            w.WriteHeader(ghttp.StatusOK)
            return ctx.Result(200, nil)
        }

        bs, err := io.ReadAll(ctx.Request().Body)
        if err != nil {
            return err
        }
        t := CommonReq{}
        err = json.Unmarshal(bs, &t)
        if err != nil {
            return err
        }
        Action := t.Action
        switch Action {
        case "DescribeGoodsCategory":
            return GoodsV1ObjCategory(srv, ctx, bs)
        }
        return ctx.Result(403, nil)
    }
}
 
 

1)
商品文件上传接口 - 支付宝文档中心 https://opendocs.alipay.com/mini/02ctgk
https://openapi.alipay.com/gateway.do?timestamp=2013-01-01 08:08:08&method=alipay.merchant.item.file.upload&app_id=20485&sign_type=RSA2&sign=ERITJKEIJKJHKKKKKKKHJEREEEEEEEEEEE&version=1.0&charset=GBK&scene=SYNC_ORDER


2)
CreateDefaultVpc - Amazon Elastic Compute Cloud https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_CreateDefaultVpc.html
https://ec2.amazonaws.com/?Action=CreateDefaultVpc
&AUTHPARAMS

CreateTags - Amazon Elastic Compute Cloud https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_CreateTags.html

https://ec2.amazonaws.com/?Action=CreateTags
&ResourceId.1=ami-1a2b3c4d
&ResourceId.2=i-1234567890abcdef0
&Tag.1.Key=webserver
&Tag.1.Value=
&Tag.2.Key=stack
&Tag.2.Value=Production
&AUTHPARAMS

3)
开放平台-文档中心 https://open.taobao.com/api.htm?docId=21348&docType=2

curl -X POST 'http://gw.api.taobao.com/router/rest' \
-H 'Content-Type:application/x-www-form-urlencoded;charset=utf-8' \
-d 'app_key=12129701' \
-d 'format=json' \
-d 'method=taobao.user.buyer.get' \
-d 'partner_id=apidoc' \
-d 'session=b778a4c2-4c89-499e-9d34-96721214bfba' \
-d 'sign=FA1A20635391859F92F85237EB409AF6' \
-d 'sign_method=hmac' \
-d 'timestamp=2022-02-15+09%3A40%3A28' \
-d 'v=2.0' \
-d 'fields=nick%2Csex'

3)
人脸融合 人脸融合 - 人脸融合相关接口 - API 中心 - 腾讯云 https://cloud.tencent.com/document/api/670/31061
https://facefusion.tencentcloudapi.com/?Action=FaceFusion
&ProjectId=100646
&ModelId=qc_100646_154021_9
&RspImgType=url
&Image=base64_string
&<公共请求参数>

 

 

 

 

开放平台-文档中心 https://open.taobao.com/api.htm?docId=21349&docType=2

公共参数

请求地址:
环境
HTTP地址
HTTPS地址
正式环境
http://gw.api.taobao.com/router/rest
https://eco.taobao.com/router/rest
公共请求参数:
名称
类型
必须
描述
method
String
API接口名称,例如:taobao.user.seller.get
method
String
API接口名称,例如:taobao.user.seller.get

 

开放平台-文档中心 https://open.taobao.com/doc.htm?docId=101618&docType=1

服务地址

注:服务地址主要用于请求API时填写的URL地址。

 API服务地址:

环境

HTTP请求地址

HTTPS请求地址

正式环境

http://gw.api.taobao.com/router/rest

https://eco.taobao.com/router/rest

海外正式环境

http://api.taobao.com/router/rest

https://api.taobao.com/router/rest

消息服务地址:

环境

服务地址

SSL服务地址

正式环境

ws://mc.api.taobao.com/

posted @ 2022-02-10 09:22  papering  阅读(610)  评论(0编辑  收藏  举报