Compare commits
14 Commits
Author | SHA1 | Date |
---|---|---|
dtapps | 7daa9533f0 | 3 months ago |
dtapps | 95899b0216 | 5 months ago |
李光春 | 0ecd4ac383 | 1 year ago |
李光春 | 286592ca79 | 1 year ago |
李光春 | ab8caafa05 | 1 year ago |
李光春 | ff8c77434f | 2 years ago |
李光春 | 3c70879ec4 | 2 years ago |
李光春 | 86ae22b8e9 | 2 years ago |
李光春 | 8ac09de612 | 2 years ago |
李光春 | 5958ed27af | 2 years ago |
李光春 | b1491a2fe0 | 2 years ago |
李光春 | e4968213fa | 2 years ago |
李光春 | 0161d06cd2 | 2 years ago |
李光春 | a7dbfb8585 | 2 years ago |
@ -0,0 +1,25 @@
|
||||
package dingdanxia
|
||||
|
||||
import (
|
||||
"context"
|
||||
"go.dtapp.net/gorequest"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func (c *Client) Get(ctx context.Context, _method string, notMustParams ...gorequest.Params) ([]byte, error) {
|
||||
// 参数
|
||||
params := gorequest.NewParamsWith(notMustParams...)
|
||||
// 请求
|
||||
request, err := c.request(ctx, apiUrl+_method, params, http.MethodGet)
|
||||
// 定义
|
||||
return request.ResponseBody, err
|
||||
}
|
||||
|
||||
func (c *Client) Post(ctx context.Context, _method string, notMustParams ...gorequest.Params) ([]byte, error) {
|
||||
// 参数
|
||||
params := gorequest.NewParamsWith(notMustParams...)
|
||||
// 请求
|
||||
request, err := c.request(ctx, apiUrl+_method, params, http.MethodPost)
|
||||
// 定义
|
||||
return request.ResponseBody, err
|
||||
}
|
@ -1,75 +1,35 @@
|
||||
package dingdanxia
|
||||
|
||||
import (
|
||||
"go.dtapp.net/dorm"
|
||||
"go.dtapp.net/golog"
|
||||
"go.dtapp.net/gorequest"
|
||||
)
|
||||
|
||||
// client *dorm.GormClient
|
||||
type gormClientFun func() *dorm.GormClient
|
||||
|
||||
// client *dorm.MongoClient
|
||||
// databaseName string
|
||||
type mongoClientFun func() (*dorm.MongoClient, string)
|
||||
|
||||
// ClientConfig 实例配置
|
||||
type ClientConfig struct {
|
||||
ApiKey string // 密钥
|
||||
GormClientFun gormClientFun // 日志配置
|
||||
MongoClientFun mongoClientFun // 日志配置
|
||||
Debug bool // 日志开关
|
||||
ApiKey string // 密钥
|
||||
}
|
||||
|
||||
// Client 实例
|
||||
type Client struct {
|
||||
requestClient *gorequest.App // 请求服务
|
||||
config struct {
|
||||
config struct {
|
||||
apiKey string // 密钥
|
||||
}
|
||||
log struct {
|
||||
gorm bool // 日志开关
|
||||
gormClient *dorm.GormClient // 日志数据库
|
||||
logGormClient *golog.ApiClient // 日志服务
|
||||
mongo bool // 日志开关
|
||||
mongoClient *dorm.MongoClient // 日志数据库
|
||||
logMongoClient *golog.ApiClient // 日志服务
|
||||
gormLog struct {
|
||||
status bool // 状态
|
||||
client *golog.ApiGorm // 日志服务
|
||||
}
|
||||
mongoLog struct {
|
||||
status bool // 状态
|
||||
client *golog.ApiMongo // 日志服务
|
||||
}
|
||||
}
|
||||
|
||||
// NewClient 创建实例化
|
||||
func NewClient(config *ClientConfig) (*Client, error) {
|
||||
|
||||
var err error
|
||||
c := &Client{}
|
||||
|
||||
c.config.apiKey = config.ApiKey
|
||||
|
||||
c.requestClient = gorequest.NewHttp()
|
||||
|
||||
gormClient := config.GormClientFun()
|
||||
if gormClient != nil && gormClient.Db != nil {
|
||||
c.log.logGormClient, err = golog.NewApiGormClient(func() (*dorm.GormClient, string) {
|
||||
return gormClient, logTable
|
||||
}, config.Debug)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
c.log.gorm = true
|
||||
c.log.gormClient = gormClient
|
||||
}
|
||||
|
||||
mongoClient, databaseName := config.MongoClientFun()
|
||||
if mongoClient != nil && mongoClient.Db != nil {
|
||||
c.log.logMongoClient, err = golog.NewApiMongoClient(func() (*dorm.MongoClient, string, string) {
|
||||
return mongoClient, databaseName, logTable
|
||||
}, config.Debug)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
c.log.mongo = true
|
||||
c.log.mongoClient = mongoClient
|
||||
}
|
||||
|
||||
return c, nil
|
||||
}
|
||||
|
@ -0,0 +1,23 @@
|
||||
package dingdanxia
|
||||
|
||||
import (
|
||||
"go.dtapp.net/golog"
|
||||
)
|
||||
|
||||
// ConfigApiGormFun 接口日志配置
|
||||
func (c *Client) ConfigApiGormFun(apiClientFun golog.ApiGormFun) {
|
||||
client := apiClientFun()
|
||||
if client != nil {
|
||||
c.gormLog.client = client
|
||||
c.gormLog.status = true
|
||||
}
|
||||
}
|
||||
|
||||
// ConfigApiMongoFun 接口日志配置
|
||||
func (c *Client) ConfigApiMongoFun(apiClientFun golog.ApiMongoFun) {
|
||||
client := apiClientFun()
|
||||
if client != nil {
|
||||
c.mongoLog.client = client
|
||||
c.mongoLog.status = true
|
||||
}
|
||||
}
|
@ -1,96 +1,65 @@
|
||||
module go.dtapp.net/dingdanxia
|
||||
|
||||
go 1.19
|
||||
go 1.21.5
|
||||
|
||||
require (
|
||||
go.dtapp.net/dorm v1.0.30
|
||||
go.dtapp.net/golog v1.0.44
|
||||
go.dtapp.net/gorequest v1.0.27
|
||||
go.dtapp.net/gotime v1.0.5
|
||||
go.dtapp.net/gojson v1.0.4
|
||||
go.dtapp.net/golog v1.0.121
|
||||
go.dtapp.net/gorequest v1.0.47
|
||||
go.dtapp.net/gotime v1.0.6
|
||||
)
|
||||
|
||||
require (
|
||||
github.com/MercuryEngineering/CookieMonster v0.0.0-20180304172713-1584578b3403 // indirect
|
||||
github.com/basgys/goxml2json v1.1.0 // indirect
|
||||
github.com/beego/beego/v2 v2.0.5 // indirect
|
||||
github.com/cespare/xxhash/v2 v2.1.2 // indirect
|
||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
|
||||
github.com/bytedance/sonic v1.10.2 // indirect
|
||||
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
|
||||
github.com/chenzhuoyu/iasm v0.9.1 // indirect
|
||||
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
|
||||
github.com/gin-contrib/sse v0.1.0 // indirect
|
||||
github.com/gin-gonic/gin v1.8.1 // indirect
|
||||
github.com/go-playground/locales v0.14.0 // indirect
|
||||
github.com/go-playground/universal-translator v0.18.0 // indirect
|
||||
github.com/go-playground/validator/v10 v10.11.0 // indirect
|
||||
github.com/go-redis/redis/v9 v9.0.0-beta.2 // indirect
|
||||
github.com/go-sql-driver/mysql v1.6.0 // indirect
|
||||
github.com/goccy/go-json v0.9.11 // indirect
|
||||
github.com/golang-sql/sqlexp v0.1.0 // indirect
|
||||
github.com/gin-gonic/gin v1.9.1 // indirect
|
||||
github.com/go-ole/go-ole v1.3.0 // indirect
|
||||
github.com/go-playground/locales v0.14.1 // indirect
|
||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||
github.com/go-playground/validator/v10 v10.17.0 // indirect
|
||||
github.com/goccy/go-json v0.10.2 // indirect
|
||||
github.com/golang/snappy v0.0.4 // indirect
|
||||
github.com/hashicorp/golang-lru v0.5.4 // indirect
|
||||
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
|
||||
github.com/jackc/pgconn v1.13.0 // indirect
|
||||
github.com/jackc/pgio v1.0.0 // indirect
|
||||
github.com/jackc/pgpassfile v1.0.0 // indirect
|
||||
github.com/jackc/pgproto3/v2 v2.3.1 // indirect
|
||||
github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b // indirect
|
||||
github.com/jackc/pgtype v1.12.0 // indirect
|
||||
github.com/jackc/pgx/v4 v4.17.1 // indirect
|
||||
github.com/jinzhu/inflection v1.0.0 // indirect
|
||||
github.com/jinzhu/now v1.1.5 // indirect
|
||||
github.com/json-iterator/go v1.1.12 // indirect
|
||||
github.com/klauspost/compress v1.15.9 // indirect
|
||||
github.com/leodido/go-urn v1.2.1 // indirect
|
||||
github.com/lib/pq v1.10.6 // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
github.com/mattn/go-isatty v0.0.16 // indirect
|
||||
github.com/klauspost/compress v1.17.5 // indirect
|
||||
github.com/klauspost/cpuid/v2 v2.2.6 // indirect
|
||||
github.com/kr/pretty v0.3.0 // indirect
|
||||
github.com/leodido/go-urn v1.3.0 // indirect
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||
github.com/montanaflynn/stats v0.6.6 // indirect
|
||||
github.com/montanaflynn/stats v0.7.1 // indirect
|
||||
github.com/natefinch/lumberjack v2.0.0+incompatible // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.0.5 // indirect
|
||||
github.com/pkg/errors v0.9.1 // indirect
|
||||
github.com/rs/zerolog v1.28.0 // indirect
|
||||
github.com/saracen/go7z v0.0.0-20191010121135-9c09b6bd7fda // indirect
|
||||
github.com/saracen/solidblock v0.0.0-20190426153529-45df20abab6f // indirect
|
||||
github.com/shiena/ansicolor v0.0.0-20200904210342-c7312218db18 // indirect
|
||||
github.com/sirupsen/logrus v1.9.0 // indirect
|
||||
github.com/syndtr/goleveldb v1.0.0 // indirect
|
||||
github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc // indirect
|
||||
github.com/ugorji/go/codec v1.2.7 // indirect
|
||||
github.com/ulikunitz/xz v0.5.10 // indirect
|
||||
github.com/upper/db/v4 v4.5.4 // indirect
|
||||
github.com/uptrace/bun v1.1.8 // indirect
|
||||
github.com/uptrace/bun/dialect/mysqldialect v1.1.8 // indirect
|
||||
github.com/uptrace/bun/dialect/pgdialect v1.1.8 // indirect
|
||||
github.com/uptrace/bun/driver/pgdriver v1.1.8 // indirect
|
||||
github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect
|
||||
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
|
||||
github.com/pelletier/go-toml/v2 v2.1.1 // indirect
|
||||
github.com/shirou/gopsutil v3.21.11+incompatible // indirect
|
||||
github.com/tklauser/go-sysconf v0.3.13 // indirect
|
||||
github.com/tklauser/numcpus v0.7.0 // indirect
|
||||
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
|
||||
github.com/ugorji/go/codec v1.2.12 // indirect
|
||||
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
|
||||
github.com/xdg-go/scram v1.1.1 // indirect
|
||||
github.com/xdg-go/stringprep v1.0.3 // indirect
|
||||
github.com/xdg-go/scram v1.1.2 // indirect
|
||||
github.com/xdg-go/stringprep v1.0.4 // indirect
|
||||
github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a // indirect
|
||||
go.dtapp.net/goip v1.0.28 // indirect
|
||||
go.dtapp.net/gorandom v1.0.1 // indirect
|
||||
go.dtapp.net/gostring v1.0.10 // indirect
|
||||
go.dtapp.net/gotrace_id v1.0.6 // indirect
|
||||
github.com/yusufpapurcu/wmi v1.2.4 // indirect
|
||||
go.dtapp.net/gorandom v1.0.2 // indirect
|
||||
go.dtapp.net/gostring v1.0.13 // indirect
|
||||
go.dtapp.net/gotrace_id v1.0.8 // indirect
|
||||
go.dtapp.net/gourl v1.0.0 // indirect
|
||||
go.dtapp.net/goxml v1.0.1 // indirect
|
||||
go.mongodb.org/mongo-driver v1.10.1 // indirect
|
||||
go.uber.org/atomic v1.10.0 // indirect
|
||||
go.uber.org/multierr v1.8.0 // indirect
|
||||
go.uber.org/zap v1.23.0 // indirect
|
||||
golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90 // indirect
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
|
||||
golang.org/x/net v0.0.0-20220826154423-83b083e8dc8b // indirect
|
||||
golang.org/x/sync v0.0.0-20220819030929-7fc1605a5dde // indirect
|
||||
golang.org/x/sys v0.0.0-20220829200755-d48e67d00261 // indirect
|
||||
golang.org/x/text v0.3.7 // indirect
|
||||
google.golang.org/protobuf v1.28.1 // indirect
|
||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||
gorm.io/datatypes v1.0.7 // indirect
|
||||
gorm.io/driver/mysql v1.3.6 // indirect
|
||||
gorm.io/driver/postgres v1.3.9 // indirect
|
||||
gorm.io/gorm v1.23.8 // indirect
|
||||
mellium.im/sasl v0.3.0 // indirect
|
||||
modernc.org/sqlite v1.18.1 // indirect
|
||||
xorm.io/builder v0.3.12 // indirect
|
||||
xorm.io/xorm v1.3.1 // indirect
|
||||
go.mongodb.org/mongo-driver v1.13.1 // indirect
|
||||
golang.org/x/arch v0.7.0 // indirect
|
||||
golang.org/x/crypto v0.18.0 // indirect
|
||||
golang.org/x/net v0.20.0 // indirect
|
||||
golang.org/x/sync v0.6.0 // indirect
|
||||
golang.org/x/sys v0.16.0 // indirect
|
||||
golang.org/x/text v0.14.0 // indirect
|
||||
google.golang.org/protobuf v1.32.0 // indirect
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
gorm.io/gorm v1.25.6 // indirect
|
||||
)
|
||||
|
@ -0,0 +1,52 @@
|
||||
package dingdanxia
|
||||
|
||||
import (
|
||||
"context"
|
||||
"go.dtapp.net/gojson"
|
||||
"go.dtapp.net/gorequest"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type TbkActivityinfoResponse struct {
|
||||
Code int `json:"code"`
|
||||
Msg string `json:"msg"`
|
||||
Data struct {
|
||||
ClickUrl string `json:"click_url"`
|
||||
WxQrcodeUrl string `json:"wx_qrcode_url"`
|
||||
ShortClickUrl string `json:"short_click_url"`
|
||||
TerminalType string `json:"terminal_type"`
|
||||
MaterialOssUrl string `json:"material_oss_url"`
|
||||
PageName string `json:"page_name"`
|
||||
PageStartTime string `json:"page_start_time"`
|
||||
PageEndTime string `json:"page_end_time"`
|
||||
WxMiniprogramPath string `json:"wx_miniprogram_path"`
|
||||
Tpwd string `json:"tpwd"`
|
||||
LongTpwd string `json:"long_tpwd"`
|
||||
} `json:"data"`
|
||||
}
|
||||
|
||||
type TbkActivityinfoResult struct {
|
||||
Result TbkActivityinfoResponse // 结果
|
||||
Body []byte // 内容
|
||||
Http gorequest.Response // 请求
|
||||
}
|
||||
|
||||
func newTbkActivityinfoResult(result TbkActivityinfoResponse, body []byte, http gorequest.Response) *TbkActivityinfoResult {
|
||||
return &TbkActivityinfoResult{Result: result, Body: body, Http: http}
|
||||
}
|
||||
|
||||
// TbkActivityinfo 官方活动转链,饿了么/口碑活动转链
|
||||
// https://www.dingdanxia.com/doc/122/173
|
||||
func (c *Client) TbkActivityinfo(ctx context.Context, notMustParams ...gorequest.Params) (*TbkActivityinfoResult, error) {
|
||||
// 参数
|
||||
params := gorequest.NewParamsWith(notMustParams...)
|
||||
// 请求
|
||||
request, err := c.request(ctx, apiUrl+"/tbk/activityinfo", params, http.MethodPost)
|
||||
if err != nil {
|
||||
return newTbkActivityinfoResult(TbkActivityinfoResponse{}, request.ResponseBody, request), err
|
||||
}
|
||||
// 定义
|
||||
var response TbkActivityinfoResponse
|
||||
err = gojson.Unmarshal(request.ResponseBody, &response)
|
||||
return newTbkActivityinfoResult(response, request.ResponseBody, request), err
|
||||
}
|
@ -0,0 +1,5 @@
|
||||
package dingdanxia
|
||||
|
||||
const (
|
||||
Version = "1.0.17"
|
||||
)
|
@ -0,0 +1,41 @@
|
||||
package dingdanxia
|
||||
|
||||
import (
|
||||
"context"
|
||||
"go.dtapp.net/gojson"
|
||||
"go.dtapp.net/gorequest"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type WaiMaiMeituanGenerateLinkResponse struct {
|
||||
Code int `json:"code"`
|
||||
Msg string `json:"msg"`
|
||||
Data struct{} `json:"data"`
|
||||
MiniCode string `json:"miniCode"` // 小程序码地址
|
||||
}
|
||||
|
||||
type WaiMaiMeituanGenerateLinkResult struct {
|
||||
Result WaiMaiMeituanGenerateLinkResponse // 结果
|
||||
Body []byte // 内容
|
||||
Http gorequest.Response // 请求
|
||||
}
|
||||
|
||||
func newWaiMaiMeituanGenerateLinkResult(result WaiMaiMeituanGenerateLinkResponse, body []byte, http gorequest.Response) *WaiMaiMeituanGenerateLinkResult {
|
||||
return &WaiMaiMeituanGenerateLinkResult{Result: result, Body: body, Http: http}
|
||||
}
|
||||
|
||||
// WaiMaiMeituanGenerateLink 美团外卖/闪购/酒店/优选CPS转链接口【推荐使用】
|
||||
// https://www.dingdanxia.com/doc/221/173
|
||||
func (c *Client) WaiMaiMeituanGenerateLink(ctx context.Context, notMustParams ...gorequest.Params) (*WaiMaiMeituanGenerateLinkResult, error) {
|
||||
// 参数
|
||||
params := gorequest.NewParamsWith(notMustParams...)
|
||||
// 请求
|
||||
request, err := c.request(ctx, apiUrl+"/waimai/meituan_generateLink", params, http.MethodPost)
|
||||
if err != nil {
|
||||
return newWaiMaiMeituanGenerateLinkResult(WaiMaiMeituanGenerateLinkResponse{}, request.ResponseBody, request), err
|
||||
}
|
||||
// 定义
|
||||
var response WaiMaiMeituanGenerateLinkResponse
|
||||
err = gojson.Unmarshal(request.ResponseBody, &response)
|
||||
return newWaiMaiMeituanGenerateLinkResult(response, request.ResponseBody, request), err
|
||||
}
|
@ -0,0 +1,54 @@
|
||||
package dingdanxia
|
||||
|
||||
import (
|
||||
"context"
|
||||
"go.dtapp.net/gojson"
|
||||
"go.dtapp.net/gorequest"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type WaiMaiMeituanYouxuanGoodsResponse struct {
|
||||
Code int `json:"code"`
|
||||
Msg string `json:"msg"`
|
||||
Data struct {
|
||||
Total int64 `json:"total"` // 数据总量
|
||||
skuList []struct {
|
||||
ItemId string `json:"itemId"` // 商品信息-宝贝 id skuid
|
||||
Title string `json:"title"` // 商品信息-商品标题
|
||||
PictUrl string `json:"pictUrl"` // 商品信息-商品主图
|
||||
SmallImages []string `json:"smallImages"` // 商品信息-商品小图列表
|
||||
OriginPrice string `json:"originPrice"` // 原价(单位为元)
|
||||
PromotionPrice string `json:"promotionPrice"` // 促销价(活动价格)秒杀价格 (单位为元)
|
||||
ItemDeepLinkUrl string `json:"itemDeepLinkUrl"` // 宝贝的 deeplink 地址
|
||||
ItemMiddlePageLinkUrl string `json:"itemMiddlePageLinkUrl"` // 宝贝的中间页地址
|
||||
ItemWXLinkUrl string `json:"itemWXLinkUrl"` // 宝贝的微信小程序链接地址
|
||||
HotFlag bool `json:"hotFlag"` // 是否是热门商品
|
||||
}
|
||||
} `json:"data"`
|
||||
}
|
||||
|
||||
type WaiMaiMeituanYouxuanGoodsResult struct {
|
||||
Result WaiMaiMeituanYouxuanGoodsResponse // 结果
|
||||
Body []byte // 内容
|
||||
Http gorequest.Response // 请求
|
||||
}
|
||||
|
||||
func newWaiMaiMeituanYouxuanGoodsResult(result WaiMaiMeituanYouxuanGoodsResponse, body []byte, http gorequest.Response) *WaiMaiMeituanYouxuanGoodsResult {
|
||||
return &WaiMaiMeituanYouxuanGoodsResult{Result: result, Body: body, Http: http}
|
||||
}
|
||||
|
||||
// WaiMaiMeituanYouxuanGoods 优选商品查询API【2022年1月17日暂停数据访问】
|
||||
// https://www.dingdanxia.com/doc/235/173
|
||||
func (c *Client) WaiMaiMeituanYouxuanGoods(ctx context.Context, notMustParams ...gorequest.Params) (*WaiMaiMeituanYouxuanGoodsResult, error) {
|
||||
// 参数
|
||||
params := gorequest.NewParamsWith(notMustParams...)
|
||||
// 请求
|
||||
request, err := c.request(ctx, apiUrl+"/waimai/meituan_youxuan_goods", params, http.MethodPost)
|
||||
if err != nil {
|
||||
return newWaiMaiMeituanYouxuanGoodsResult(WaiMaiMeituanYouxuanGoodsResponse{}, request.ResponseBody, request), err
|
||||
}
|
||||
// 定义
|
||||
var response WaiMaiMeituanYouxuanGoodsResponse
|
||||
err = gojson.Unmarshal(request.ResponseBody, &response)
|
||||
return newWaiMaiMeituanYouxuanGoodsResult(response, request.ResponseBody, request), err
|
||||
}
|
Loading…
Reference in new issue