gosdk

package module
v0.0.0-...-905ac7b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 29, 2024 License: GPL-3.0 Imports: 6 Imported by: 0

README

一、环境说明

美团开放平台Go语言版本SDK,支持go 1.13.7及以上版本。

二、引入方式

下载sdk包,添加到项目依赖

三、调用示例

以接口门店本地验券历史 为例, SDK提供了CouponQueryListByDateRequest来封装请求,您调用此接口的代码可以参考:

import (
  "gitea.com/wan9bo7/meituan-sdk/model/tuangoung/coupon/couponquerylistbydate"
  "gitea.com/wan9bo7/meituan-sdk/mtclient"
)
// 使用developerId和signKey初始化client,建议使用单例
client := mtclient.NewDefaultClient(100567, "***signKey***")
appAuthToken := "xxxxxxxxxx"

var request couponquerylistbydate.CouponQueryListByDateRequest
request.Date = "2022-01-01"
request.Offset = 0
request.Limit = 10

response, err := request.DoInvoke(client, appAuthToken)

if err != nil {
	fmt.Printf("接口调用失败:%v\n", err)
} else {
	if response.IsSuccess() {
		data := response.Data
		fmt.Printf("接口调用成功,得到响应:%v\n", data)
	} else {
		fmt.Printf("接口调用响应异常, code: %s, msg: %s\n", response.Code, response.Msg)
	}
}

四、第三方业务授权获取和刷新Token

import (
"fmt"
"gitea.com/wan9bo7/meituan-sdk/mtclient"
"gitea.com/wan9bo7/meituan-sdk/oauth"
)

client := mtclient.NewDefaultClient(100567, "***signKey***")
getTokenRequest := oauth.NewGetTokenRequest(33, "***authCode***")
response, err := getTokenRequest.GetToken(client)
if err != nil {
	fmt.Printf("接口调用失败:%v\n", err)
} else {
	fmt.Printf("接口调用成功,得到响应:%v\n", response.Data)
}
import (
"fmt"
"gitea.com/wan9bo7/meituan-sdk/mtclient"
"gitea.com/wan9bo7/meituan-sdk/oauth"
)

client := mtclient.NewDefaultClient(100567, "***signKey***")
refreshTokenRequest := oauth.NewRefreshTokenRequest(33, "***refreshToken***")
response, err := getTokenRequest.TokenRefresh(client)
if err != nil {
	fmt.Printf("接口调用失败:%v\n", err)
} else {
	fmt.Printf("接口调用成功,得到响应:%v\n", response.Data)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ApiRequest

type ApiRequest struct {
	ApiPath    string            //api路径,不包含域名
	BusinessId int               //api对应的业务id,请参考API文档的说明赋值
	BizParams  map[string]string //业务参数,key放字段名,value放字段值
}

func NewApiRequest

func NewApiRequest(apiPath string, businessId int, bizParams map[string]string) ApiRequest

创建一个新的ApiRequest

func (ApiRequest) DoInvoke

func (req ApiRequest) DoInvoke(client mtclient.MeituanClient, appAuthToken string) (*ApiResponse, error)

DoInvoke 方法用于向美团服务端发起请求。对于无需业务授权的接口,appAuthToken可以传空

type ApiResponse

type ApiResponse struct {
	Code    string
	Msg     string
	Data    interface{}
	TraceId string
}

func (*ApiResponse) IsSuccess

func (response *ApiResponse) IsSuccess() bool

Directories

Path Synopsis
model

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL