third-platform-sdk/README.md
2024-05-04 16:57:40 +08:00

71 lines
2.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 第三方平台SDK
本sdk主要对接各个第三方平台的api如美团、饿了么。。。, 内部的其他项目服务可以直接通过本sdk调用相应的第三方平台的api而不用关心第三方平台的api调用细节。
本sdk只是对第三方api调用的封装不涉及业务逻辑具体的业务逻辑需要在调用方实现。
注意: 相同的业务接口如获取订单信息不同第三方平台的api返回的数据结构会有所不同需要在业务服务中做不同平台数据的映射本sdk不做数据映射。
## 1. 项目结构
```
third-party-sdk
├── README.md
├── client
│ └── http_client.go // http请求的client
├── platform // 第三方平台
│ ├── eleme-union // 饿了么联盟
│ ├── meituan-csr // 美团分销联盟
│ ├── meituan-union // 美团联盟
│ ├── api.go // 美团联盟api
│ ├── client.go // 美团联盟client
│ ├── consts.go // 常量
│ └── types.go // 结构体定义
├── sdk // 第三方平台的sdk包
├── util // 工具包
```
## 2. 使用
对接的不同第三方平台在platform目录下不同的文件目录对应不同的平台使用时只需要调用index.go文件中不同平台api的New...()方法传入不同的AuthConf参数即可调用相应的api。
示例如下:
```go
package main
import (
"context"
"github.com/zeromicro/go-zero/core/logx"
sdk "gitee.com/chengdu-lenntc/third-platform-sdk"
meituanapi "gitee.com/chengdu-lenntc/third-platform-sdk/platform/meituan-union"
)
type PromotionConf struct {
AppKey string
AppSecret string
Ext1 string
Ext2 string
Ext3 string
Ext4 string
}
// 美团联盟
func meituanUnion(ctx context.Context, c *PromotionConf) error {
// meituan union 的api client
client := sdk.NewMeituanUnionApi(logx.WithContext(ctx), meituanapi.AuthConfig{
SignKey: c.Ext1,
NotifyKey: c.Ext2,
})
params := meituanapi.GenerateLinkRequest{
// ...
}
url, err := client.GetLink(params)
if err != nil {
logx.Errorf("get meituan union link failed: %v", err)
return nil
}
logx.Infof("get meituan union link success: %v", url)
return nil
}
```