parent
7371dad756
commit
62a5a49783
@ -0,0 +1,67 @@
|
||||
package alipayopen
|
||||
|
||||
import (
|
||||
"crypto/rsa"
|
||||
"crypto/x509"
|
||||
"encoding/pem"
|
||||
"errors"
|
||||
"github.com/dtapps/go-library/utils/golog"
|
||||
"github.com/dtapps/go-library/utils/gophp"
|
||||
"github.com/dtapps/go-library/utils/gorequest"
|
||||
)
|
||||
|
||||
// ClientConfig 实例配置
|
||||
type ClientConfig struct {
|
||||
AppId string // 支付宝分配给开发者的应用ID
|
||||
AppKey string // 支付宝分配给开发者的应用私钥
|
||||
AppRSA2 string // 应用公钥
|
||||
AlipayRSA2 string // 支付宝公钥
|
||||
Aes string // 接口内容加密方式
|
||||
}
|
||||
|
||||
// Client 实例
|
||||
type Client struct {
|
||||
requestClient *gorequest.App // 请求服务
|
||||
privateKey *rsa.PrivateKey // 私钥服务
|
||||
config struct {
|
||||
appId string // 支付宝分配给开发者的应用ID
|
||||
appKey string // 支付宝分配给开发者的应用私钥
|
||||
appRSA2 string // 应用公钥
|
||||
alipayRSA2 string // 支付宝公钥
|
||||
aes string // 接口内容加密方式
|
||||
}
|
||||
log struct {
|
||||
status bool // 状态
|
||||
client *golog.ApiClient // 日志服务
|
||||
}
|
||||
}
|
||||
|
||||
// NewClient 创建实例化
|
||||
func NewClient(config *ClientConfig) (*Client, error) {
|
||||
|
||||
var err error
|
||||
c := &Client{}
|
||||
|
||||
c.config.appId = config.AppId
|
||||
c.config.appKey = config.AppKey
|
||||
c.config.appRSA2 = config.AppRSA2
|
||||
c.config.alipayRSA2 = config.AlipayRSA2
|
||||
c.config.aes = config.Aes
|
||||
|
||||
// 私钥解码
|
||||
block, _ := pem.Decode([]byte("-----BEGIN RSA PRIVATE KEY-----\n" + gophp.ChunkSplit(config.AppKey, 64, "\n") + "-----END RSA PRIVATE KEY-----\n"))
|
||||
if block == nil {
|
||||
return nil, errors.New("签名私钥解码错误")
|
||||
}
|
||||
privateKey, err := x509.ParsePKCS8PrivateKey(block.Bytes)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
c.privateKey = privateKey.(*rsa.PrivateKey)
|
||||
|
||||
// 请求
|
||||
c.requestClient = gorequest.NewHttp()
|
||||
c.requestClient.Uri = apiUrl
|
||||
|
||||
return c, nil
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package alipayopen
|
||||
|
||||
import "github.com/dtapps/go-library/utils/golog"
|
||||
|
||||
// ConfigApiClientFun 日志配置
|
||||
func (c *Client) ConfigApiClientFun(apiClientFun golog.ApiClientFun) {
|
||||
apiClient := apiClientFun()
|
||||
if apiClient != nil {
|
||||
c.log.client = apiClient
|
||||
c.log.status = true
|
||||
}
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package alipayopen
|
||||
|
||||
const (
|
||||
apiUrl = "https://openapi.alipay.com/gateway.do"
|
||||
)
|
||||
|
||||
const (
|
||||
LogTable = "alipayopen"
|
||||
)
|
||||
|
||||
const AuthorizationCode = "authorization_code" // 表示换取使用用户授权码code换取授权令牌
|
||||
const RefreshToken = "refresh_token" // 表示使用refresh_token刷新获取新授权令牌
|
||||
|
||||
type ApiError struct {
|
||||
ErrorResponse struct {
|
||||
Code string `json:"code"`
|
||||
Msg string `json:"msg"`
|
||||
SubCode string `json:"sub_code"`
|
||||
SubMsg string `json:"sub_msg"`
|
||||
} `json:"error_response"`
|
||||
Sign string `json:"sign"`
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
package alipayopen
|
||||
|
||||
import "github.com/dtapps/go-library/utils/golog"
|
||||
|
||||
func (c *Client) GetAppId() string {
|
||||
return c.config.appId
|
||||
}
|
||||
|
||||
func (c *Client) GetAppKey() string {
|
||||
return c.config.appKey
|
||||
}
|
||||
|
||||
func (c *Client) GetAppRSA2() string {
|
||||
return c.config.appRSA2
|
||||
}
|
||||
|
||||
func (c *Client) GetAlipayRSA2() string {
|
||||
return c.config.alipayRSA2
|
||||
}
|
||||
|
||||
func (c *Client) GetAes() string {
|
||||
return c.config.aes
|
||||
}
|
||||
|
||||
func (c *Client) GetLog() *golog.ApiClient {
|
||||
return c.log.client
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package alipayopen
|
||||
|
||||
import (
|
||||
"github.com/dtapps/go-library/utils/gorequest"
|
||||
"github.com/dtapps/go-library/utils/gotime"
|
||||
)
|
||||
|
||||
func (c *Client) newParamsWithType(_method string, param ...gorequest.Params) gorequest.Params {
|
||||
params := gorequest.NewParamsWith(param...)
|
||||
params.Set("app_id", c.GetAppId())
|
||||
params.Set("method", _method)
|
||||
params.Set("format", "JSON")
|
||||
params.Set("charset", "utf-8")
|
||||
params.Set("sign_type", "RSA2")
|
||||
params.Set("timestamp", gotime.Current().SetFormat(gotime.DateTimeFormat))
|
||||
params.Set("version", "1.0")
|
||||
return params
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package alipayopen
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/dtapps/go-library"
|
||||
"github.com/dtapps/go-library/utils/gorequest"
|
||||
"github.com/dtapps/go-library/utils/gostring"
|
||||
)
|
||||
|
||||
func (c *Client) request(ctx context.Context, param map[string]interface{}) (gorequest.Response, error) {
|
||||
|
||||
// 签名
|
||||
params := c.sign(ctx, param)
|
||||
|
||||
// 创建请求
|
||||
client := c.requestClient
|
||||
|
||||
// 设置参数
|
||||
client.SetParams(params)
|
||||
|
||||
// 设置用户代理
|
||||
client.SetUserAgent(gorequest.GetRandomUserAgentSystem())
|
||||
|
||||
// 传入SDk版本
|
||||
client.AfferentSdkUserVersion(go_library.Version())
|
||||
|
||||
// 发起请求
|
||||
request, err := client.Get(ctx)
|
||||
if err != nil {
|
||||
return gorequest.Response{}, err
|
||||
}
|
||||
|
||||
// 记录日志
|
||||
if c.log.status {
|
||||
go c.log.client.MiddlewareCustom(ctx, gostring.ToString(params["method"]), request, go_library.Version())
|
||||
}
|
||||
|
||||
return request, err
|
||||
}
|
@ -0,0 +1,76 @@
|
||||
package alipayopen
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto"
|
||||
"crypto/rand"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/dtapps/go-library/utils/gorequest"
|
||||
"log"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func (c *Client) rsaSign(signContent string, hash crypto.Hash) (string, error) {
|
||||
|
||||
shaNew := hash.New()
|
||||
shaNew.Write([]byte(signContent))
|
||||
hashed := shaNew.Sum(nil)
|
||||
|
||||
signByte, err := c.privateKey.Sign(rand.Reader, hashed, crypto.SHA256)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
sign := base64.StdEncoding.EncodeToString(signByte)
|
||||
|
||||
return sign, nil
|
||||
}
|
||||
|
||||
func (c *Client) sign(ctx context.Context, params gorequest.Params) gorequest.Params {
|
||||
// 排序
|
||||
var keys []string
|
||||
for key := range params {
|
||||
keys = append(keys, key)
|
||||
}
|
||||
sort.Strings(keys)
|
||||
|
||||
// 转换成字符串
|
||||
var signStr = ""
|
||||
for _, key := range keys {
|
||||
if key != "" {
|
||||
signStr += fmt.Sprintf("%s=%s&", key, c.getString(params[key]))
|
||||
}
|
||||
}
|
||||
|
||||
signStr = strings.TrimRight(signStr, "&")
|
||||
|
||||
// 签名
|
||||
sign, err := c.rsaSign(signStr, crypto.SHA256)
|
||||
if err != nil {
|
||||
log.Printf("签名失败:%s\n", err)
|
||||
return nil
|
||||
}
|
||||
params.Set("sign", sign)
|
||||
|
||||
return params
|
||||
}
|
||||
|
||||
func (c *Client) getString(i interface{}) string {
|
||||
switch v := i.(type) {
|
||||
case string:
|
||||
return v
|
||||
case []byte:
|
||||
return string(v)
|
||||
case int:
|
||||
return strconv.Itoa(v)
|
||||
case bool:
|
||||
return strconv.FormatBool(v)
|
||||
default:
|
||||
bytes, _ := json.Marshal(v)
|
||||
return string(bytes)
|
||||
}
|
||||
}
|
@ -1,51 +1,35 @@
|
||||
package dingdanxia
|
||||
|
||||
import (
|
||||
"github.com/dtapps/go-library/utils/dorm"
|
||||
"github.com/dtapps/go-library/utils/golog"
|
||||
"github.com/dtapps/go-library/utils/gorequest"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type ConfigClient struct {
|
||||
ApiKey string // 密钥
|
||||
MongoDb *dorm.MongoClient // 日志数据库
|
||||
PgsqlDb *gorm.DB // 日志数据库
|
||||
DatabaseName string // 库名
|
||||
// ClientConfig 实例配置
|
||||
type ClientConfig struct {
|
||||
ApiKey string // 密钥
|
||||
}
|
||||
|
||||
// Client 实例
|
||||
type Client struct {
|
||||
client *gorequest.App // 请求客户端
|
||||
log *golog.ApiClient // 日志服务
|
||||
config *ConfigClient // 配置
|
||||
requestClient *gorequest.App // 请求服务
|
||||
config struct {
|
||||
apiKey string // 密钥
|
||||
}
|
||||
log struct {
|
||||
status bool // 状态
|
||||
client *golog.ApiClient // 日志服务
|
||||
}
|
||||
}
|
||||
|
||||
func NewClient(config *ConfigClient) (*Client, error) {
|
||||
// NewClient 创建实例化
|
||||
func NewClient(config *ClientConfig) (*Client, error) {
|
||||
|
||||
var err error
|
||||
c := &Client{config: config}
|
||||
c := &Client{}
|
||||
|
||||
c.client = gorequest.NewHttp()
|
||||
c.config.apiKey = config.ApiKey
|
||||
|
||||
if c.config.PgsqlDb != nil {
|
||||
c.log, err = golog.NewApiClient(
|
||||
golog.WithGormClient(c.config.PgsqlDb),
|
||||
golog.WithTableName(logTable),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if c.config.MongoDb != nil {
|
||||
c.log, err = golog.NewApiClient(
|
||||
golog.WithMongoClient(c.config.MongoDb),
|
||||
golog.WithDatabaseName(c.config.DatabaseName),
|
||||
golog.WithCollectionName(logTable),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
c.requestClient = gorequest.NewHttp()
|
||||
|
||||
return c, nil
|
||||
}
|
||||
|
@ -0,0 +1,12 @@
|
||||
package dingdanxia
|
||||
|
||||
import "github.com/dtapps/go-library/utils/golog"
|
||||
|
||||
// ConfigApiClientFun 日志配置
|
||||
func (c *Client) ConfigApiClientFun(apiClientFun golog.ApiClientFun) {
|
||||
apiClient := apiClientFun()
|
||||
if apiClient != nil {
|
||||
c.log.client = apiClient
|
||||
c.log.status = true
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package dingdanxia
|
||||
|
||||
import "github.com/dtapps/go-library/utils/golog"
|
||||
|
||||
func (c *Client) GetApiKey() string {
|
||||
return c.config.apiKey
|
||||
}
|
||||
|
||||
func (c *Client) GetLog() *golog.ApiClient {
|
||||
return c.log.client
|
||||
}
|
@ -0,0 +1,50 @@
|
||||
package dingdanxia
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"github.com/dtapps/go-library/utils/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 // 请求
|
||||
Err error // 错误
|
||||
}
|
||||
|
||||
func newTbkActivityinfoResult(result TbkActivityinfoResponse, body []byte, http gorequest.Response, err error) *TbkActivityinfoResult {
|
||||
return &TbkActivityinfoResult{Result: result, Body: body, Http: http, Err: err}
|
||||
}
|
||||
|
||||
// TbkActivityinfo 官方活动转链,饿了么/口碑活动转链
|
||||
// https://www.dingdanxia.com/doc/122/173
|
||||
func (c *Client) TbkActivityinfo(ctx context.Context, notMustParams ...gorequest.Params) *TbkActivityinfoResult {
|
||||
// 参数
|
||||
params := gorequest.NewParamsWith(notMustParams...)
|
||||
// 请求
|
||||
request, err := c.request(ctx, apiUrl+"/tbk/activityinfo", params, http.MethodPost)
|
||||
// 定义
|
||||
var response TbkActivityinfoResponse
|
||||
err = json.Unmarshal(request.ResponseBody, &response)
|
||||
return newTbkActivityinfoResult(response, request.ResponseBody, request, err)
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
package dingdanxia
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"github.com/dtapps/go-library/utils/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 // 请求
|
||||
Err error // 错误
|
||||
}
|
||||
|
||||
func newWaiMaiMeituanGenerateLinkResult(result WaiMaiMeituanGenerateLinkResponse, body []byte, http gorequest.Response, err error) *WaiMaiMeituanGenerateLinkResult {
|
||||
return &WaiMaiMeituanGenerateLinkResult{Result: result, Body: body, Http: http, Err: err}
|
||||
}
|
||||
|
||||
// WaiMaiMeituanGenerateLink 美团外卖/闪购/酒店/优选CPS转链接口【推荐使用】
|
||||
// https://www.dingdanxia.com/doc/221/173
|
||||
func (c *Client) WaiMaiMeituanGenerateLink(ctx context.Context, notMustParams ...gorequest.Params) *WaiMaiMeituanGenerateLinkResult {
|
||||
// 参数
|
||||
params := gorequest.NewParamsWith(notMustParams...)
|
||||
// 请求
|
||||
request, err := c.request(ctx, apiUrl+"/waimai/meituan_generateLink", params, http.MethodPost)
|
||||
// 定义
|
||||
var response WaiMaiMeituanGenerateLinkResponse
|
||||
err = json.Unmarshal(request.ResponseBody, &response)
|
||||
return newWaiMaiMeituanGenerateLinkResult(response, request.ResponseBody, request, err)
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
package dingdanxia
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"github.com/dtapps/go-library/utils/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 // 请求
|
||||
Err error // 错误
|
||||
}
|
||||
|
||||
func newWaiMaiMeituanYouxuanGoodsResult(result WaiMaiMeituanYouxuanGoodsResponse, body []byte, http gorequest.Response, err error) *WaiMaiMeituanYouxuanGoodsResult {
|
||||
return &WaiMaiMeituanYouxuanGoodsResult{Result: result, Body: body, Http: http, Err: err}
|
||||
}
|
||||
|
||||
// WaiMaiMeituanYouxuanGoods 优选商品查询API【2022年1月17日暂停数据访问】
|
||||
// https://www.dingdanxia.com/doc/235/173
|
||||
func (c *Client) WaiMaiMeituanYouxuanGoods(ctx context.Context, notMustParams ...gorequest.Params) *WaiMaiMeituanYouxuanGoodsResult {
|
||||
// 参数
|
||||
params := gorequest.NewParamsWith(notMustParams...)
|
||||
// 请求
|
||||
request, err := c.request(ctx, apiUrl+"/waimai/meituan_youxuan_goods", params, http.MethodPost)
|
||||
// 定义
|
||||
var response WaiMaiMeituanYouxuanGoodsResponse
|
||||
err = json.Unmarshal(request.ResponseBody, &response)
|
||||
return newWaiMaiMeituanYouxuanGoodsResult(response, request.ResponseBody, request, err)
|
||||
}
|
@ -1,52 +1,38 @@
|
||||
package dingtalk
|
||||
|
||||
import (
|
||||
"github.com/dtapps/go-library/utils/dorm"
|
||||
"github.com/dtapps/go-library/utils/golog"
|
||||
"github.com/dtapps/go-library/utils/gorequest"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type ConfigClient struct {
|
||||
Secret string
|
||||
AccessToken string
|
||||
MongoDb *dorm.MongoClient // 日志数据库
|
||||
PgsqlDb *gorm.DB // 日志数据库
|
||||
DatabaseName string // 库名
|
||||
// ClientConfig 实例配置
|
||||
type ClientConfig struct {
|
||||
Secret string
|
||||
AccessToken string
|
||||
}
|
||||
|
||||
// Client 实例
|
||||
type Client struct {
|
||||
client *gorequest.App // 请求客户端
|
||||
log *golog.ApiClient // 日志服务
|
||||
config *ConfigClient // 配置
|
||||
requestClient *gorequest.App // 请求服务
|
||||
config struct {
|
||||
secret string
|
||||
accessToken string
|
||||
}
|
||||
log struct {
|
||||
status bool // 状态
|
||||
client *golog.ApiClient // 日志服务
|
||||
}
|
||||
}
|
||||
|
||||
func NewClient(config *ConfigClient) (*Client, error) {
|
||||
// NewClient 创建实例化
|
||||
func NewClient(config *ClientConfig) (*Client, error) {
|
||||
|
||||
var err error
|
||||
c := &Client{config: config}
|
||||
c := &Client{}
|
||||
|
||||
c.client = gorequest.NewHttp()
|
||||
c.config.secret = config.Secret
|
||||
c.config.accessToken = config.AccessToken
|
||||
|
||||
if c.config.PgsqlDb != nil {
|
||||
c.log, err = golog.NewApiClient(
|
||||
golog.WithGormClient(c.config.PgsqlDb),
|
||||
golog.WithTableName(logTable),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if c.config.MongoDb != nil {
|
||||
c.log, err = golog.NewApiClient(
|
||||
golog.WithMongoClient(c.config.MongoDb),
|
||||
golog.WithDatabaseName(c.config.DatabaseName),
|
||||
golog.WithCollectionName(logTable),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
c.requestClient = gorequest.NewHttp()
|
||||
|
||||
return c, nil
|
||||
}
|
||||
|
@ -0,0 +1,18 @@
|
||||
package dingtalk
|
||||
|
||||
import "github.com/dtapps/go-library/utils/golog"
|
||||
|
||||
func (c *Client) Config(secret, accessToken string) *Client {
|
||||
c.config.secret = secret
|
||||
c.config.accessToken = accessToken
|
||||
return c
|
||||
}
|
||||
|
||||
// ConfigApiClientFun 日志配置
|
||||
func (c *Client) ConfigApiClientFun(apiClientFun golog.ApiClientFun) {
|
||||
apiClient := apiClientFun()
|
||||
if apiClient != nil {
|
||||
c.log.client = apiClient
|
||||
c.log.status = true
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package dingtalk
|
||||
|
||||
import "github.com/dtapps/go-library/utils/golog"
|
||||
|
||||
func (c *Client) GetSecret() string {
|
||||
return c.config.secret
|
||||
}
|
||||
|
||||
func (c *Client) GetAccessToken() string {
|
||||
return c.config.accessToken
|
||||
}
|
||||
|
||||
func (c *Client) GetLog() *golog.ApiClient {
|
||||
return c.log.client
|
||||
}
|
@ -0,0 +1,12 @@
|
||||
package douyin
|
||||
|
||||
import "github.com/dtapps/go-library/utils/golog"
|
||||
|
||||
// ConfigApiClientFun 日志配置
|
||||
func (c *Client) ConfigApiClientFun(apiClientFun golog.ApiClientFun) {
|
||||
apiClient := apiClientFun()
|
||||
if apiClient != nil {
|
||||
c.log.client = apiClient
|
||||
c.log.status = true
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
package douyin
|
||||
|
||||
const (
|
||||
logTable = "douyin"
|
||||
LogTable = "douyin"
|
||||
)
|
||||
|
@ -0,0 +1,7 @@
|
||||
package douyin
|
||||
|
||||
import "github.com/dtapps/go-library/utils/golog"
|
||||
|
||||
func (c *Client) GetLog() *golog.ApiClient {
|
||||
return c.log.client
|
||||
}
|
@ -1,52 +1,38 @@
|
||||
package eastiot
|
||||
|
||||
import (
|
||||
"github.com/dtapps/go-library/utils/dorm"
|
||||
"github.com/dtapps/go-library/utils/golog"
|
||||
"github.com/dtapps/go-library/utils/gorequest"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type ConfigClient struct {
|
||||
AppId string
|
||||
ApiKey string
|
||||
MongoDb *dorm.MongoClient // 日志数据库
|
||||
PgsqlDb *gorm.DB // 日志数据库
|
||||
DatabaseName string // 库名
|
||||
// ClientConfig 实例配置
|
||||
type ClientConfig struct {
|
||||
AppId string
|
||||
ApiKey string
|
||||
}
|
||||
|
||||
// Client 实例
|
||||
type Client struct {
|
||||
client *gorequest.App // 请求客户端
|
||||
log *golog.ApiClient // 日志服务
|
||||
config *ConfigClient // 配置
|
||||
requestClient *gorequest.App // 请求服务
|
||||
config struct {
|
||||
appId string
|
||||
apiKey string
|
||||
}
|
||||
log struct {
|
||||
status bool // 状态
|
||||
client *golog.ApiClient // 日志服务
|
||||
}
|
||||
}
|
||||
|
||||
func NewClient(config *ConfigClient) (*Client, error) {
|
||||
// NewClient 创建实例化
|
||||
func NewClient(config *ClientConfig) (*Client, error) {
|
||||
|
||||
var err error
|
||||
c := &Client{config: config}
|
||||
c := &Client{}
|
||||
|
||||
c.client = gorequest.NewHttp()
|
||||
c.config.appId = config.AppId
|
||||
c.config.apiKey = config.ApiKey
|
||||
|
||||
if c.config.PgsqlDb != nil {
|
||||
c.log, err = golog.NewApiClient(
|
||||
golog.WithGormClient(c.config.PgsqlDb),
|
||||
golog.WithTableName(logTable),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if c.config.MongoDb != nil {
|
||||
c.log, err = golog.NewApiClient(
|
||||
golog.WithMongoClient(c.config.MongoDb),
|
||||
golog.WithDatabaseName(c.config.DatabaseName),
|
||||
golog.WithCollectionName(logTable),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
c.requestClient = gorequest.NewHttp()
|
||||
|
||||
return c, nil
|
||||
}
|
||||
|
@ -0,0 +1,12 @@
|
||||
package eastiot
|
||||
|
||||
import "github.com/dtapps/go-library/utils/golog"
|
||||
|
||||
// ConfigApiClientFun 日志配置
|
||||
func (c *Client) ConfigApiClientFun(apiClientFun golog.ApiClientFun) {
|
||||
apiClient := apiClientFun()
|
||||
if apiClient != nil {
|
||||
c.log.client = apiClient
|
||||
c.log.status = true
|
||||
}
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
package eastiot
|
||||
|
||||
import "github.com/dtapps/go-library/utils/golog"
|
||||
|
||||
func (c *Client) GetAppId() string {
|
||||
return c.config.appId
|
||||
}
|
||||
|
||||
func (c *Client) GetApiKey() string {
|
||||
return c.config.apiKey
|
||||
}
|
||||
|
||||
func (c *Client) GetLog() *golog.ApiClient {
|
||||
return c.log.client
|
||||
}
|
@ -1,54 +1,42 @@
|
||||
package ejiaofei
|
||||
|
||||
import (
|
||||
"github.com/dtapps/go-library/utils/dorm"
|
||||
"github.com/dtapps/go-library/utils/golog"
|
||||
"github.com/dtapps/go-library/utils/gorequest"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type ConfigClient struct {
|
||||
UserId string
|
||||
Pwd string
|
||||
Key string
|
||||
MongoDb *dorm.MongoClient // 日志数据库
|
||||
PgsqlDb *gorm.DB // 日志数据库
|
||||
DatabaseName string // 库名
|
||||
// ClientConfig 实例配置
|
||||
type ClientConfig struct {
|
||||
UserId string
|
||||
Pwd string
|
||||
Key string
|
||||
}
|
||||
|
||||
// Client 实例
|
||||
type Client struct {
|
||||
client *gorequest.App // 请求客户端
|
||||
log *golog.ApiClient // 日志服务
|
||||
signStr string // 加密信息
|
||||
config *ConfigClient // 配置
|
||||
requestClient *gorequest.App // 请求服务
|
||||
config struct {
|
||||
userId string
|
||||
pwd string
|
||||
key string
|
||||
signStr string // 需要签名的字符串
|
||||
}
|
||||
log struct {
|
||||
status bool // 状态
|
||||
client *golog.ApiClient // 日志服务
|
||||
}
|
||||
}
|
||||
|
||||
func NewClient(config *ConfigClient) (*Client, error) {
|
||||
// NewClient 创建实例化
|
||||
func NewClient(config *ClientConfig) (*Client, error) {
|
||||
|
||||
var err error
|
||||
c := &Client{config: config}
|
||||
c := &Client{}
|
||||
|
||||
c.client = gorequest.NewHttp()
|
||||
c.config.userId = config.UserId
|
||||
c.config.pwd = config.Pwd
|
||||
c.config.key = config.Key
|
||||
|
||||
if c.config.PgsqlDb != nil {
|
||||
c.log, err = golog.NewApiClient(
|
||||
golog.WithGormClient(c.config.PgsqlDb),
|
||||
golog.WithTableName(logTable),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if c.config.MongoDb != nil {
|
||||
c.log, err = golog.NewApiClient(
|
||||
golog.WithMongoClient(c.config.MongoDb),
|
||||
golog.WithDatabaseName(c.config.DatabaseName),
|
||||
golog.WithCollectionName(logTable),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
c.requestClient = gorequest.NewHttp()
|
||||
|
||||
return c, err
|
||||
return c, nil
|
||||
}
|
||||
|
@ -0,0 +1,12 @@
|
||||
package ejiaofei
|
||||
|
||||
import "github.com/dtapps/go-library/utils/golog"
|
||||
|
||||
// ConfigApiClientFun 日志配置
|
||||
func (c *Client) ConfigApiClientFun(apiClientFun golog.ApiClientFun) {
|
||||
apiClient := apiClientFun()
|
||||
if apiClient != nil {
|
||||
c.log.client = apiClient
|
||||
c.log.status = true
|
||||
}
|
||||
}
|
@ -1,13 +1,19 @@
|
||||
package ejiaofei
|
||||
|
||||
func (c *Client) getUserId() string {
|
||||
return c.config.UserId
|
||||
import "github.com/dtapps/go-library/utils/golog"
|
||||
|
||||
func (c *Client) GetUserId() string {
|
||||
return c.config.userId
|
||||
}
|
||||
|
||||
func (c *Client) GetPwd() string {
|
||||
return c.config.pwd
|
||||
}
|
||||
|
||||
func (c *Client) getPwd() string {
|
||||
return c.config.Pwd
|
||||
func (c *Client) GetKey() string {
|
||||
return c.config.key
|
||||
}
|
||||
|
||||
func (c *Client) getKey() string {
|
||||
return c.config.Key
|
||||
func (c *Client) GetLog() *golog.ApiClient {
|
||||
return c.log.client
|
||||
}
|
||||
|
@ -1,51 +1,35 @@
|
||||
package feishu
|
||||
|
||||
import (
|
||||
"github.com/dtapps/go-library/utils/dorm"
|
||||
"github.com/dtapps/go-library/utils/golog"
|
||||
"github.com/dtapps/go-library/utils/gorequest"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type ConfigClient struct {
|
||||
Key string
|
||||
MongoDb *dorm.MongoClient // 日志数据库
|
||||
PgsqlDb *gorm.DB // 日志数据库
|
||||
DatabaseName string // 库名
|
||||
// ClientConfig 实例配置
|
||||
type ClientConfig struct {
|
||||
Key string
|
||||
}
|
||||
|
||||
// Client 实例
|
||||
type Client struct {
|
||||
client *gorequest.App // 请求客户端
|
||||
log *golog.ApiClient // 日志服务
|
||||
config *ConfigClient // 配置
|
||||
requestClient *gorequest.App // 请求服务
|
||||
config struct {
|
||||
key string
|
||||
}
|
||||
log struct {
|
||||
status bool // 状态
|
||||
client *golog.ApiClient // 日志服务
|
||||
}
|
||||
}
|
||||
|
||||
func NewClient(config *ConfigClient) (*Client, error) {
|
||||
// NewClient 创建实例化
|
||||
func NewClient(config *ClientConfig) (*Client, error) {
|
||||
|
||||
var err error
|
||||
c := &Client{config: config}
|
||||
c := &Client{}
|
||||
|
||||
c.client = gorequest.NewHttp()
|
||||
c.config.key = config.Key
|
||||
|
||||
if c.config.PgsqlDb != nil {
|
||||
c.log, err = golog.NewApiClient(
|
||||
golog.WithGormClient(c.config.PgsqlDb),
|
||||
golog.WithTableName(logTable),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if c.config.MongoDb != nil {
|
||||
c.log, err = golog.NewApiClient(
|
||||
golog.WithMongoClient(c.config.MongoDb),
|
||||
golog.WithDatabaseName(c.config.DatabaseName),
|
||||
golog.WithCollectionName(logTable),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
c.requestClient = gorequest.NewHttp()
|
||||
|
||||
return c, nil
|
||||
}
|
||||
|
@ -0,0 +1,17 @@
|
||||
package feishu
|
||||
|
||||
import "github.com/dtapps/go-library/utils/golog"
|
||||
|
||||
func (c *Client) Config(key string) *Client {
|
||||
c.config.key = key
|
||||
return c
|
||||
}
|
||||
|
||||
// ConfigApiClientFun 日志配置
|
||||
func (c *Client) ConfigApiClientFun(apiClientFun golog.ApiClientFun) {
|
||||
apiClient := apiClientFun()
|
||||
if apiClient != nil {
|
||||
c.log.client = apiClient
|
||||
c.log.status = true
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package feishu
|
||||
|
||||
import "github.com/dtapps/go-library/utils/golog"
|
||||
|
||||
func (c *Client) GetKey() string {
|
||||
return c.config.key
|
||||
}
|
||||
|
||||
func (c *Client) GetLog() *golog.ApiClient {
|
||||
return c.log.client
|
||||
}
|
@ -1,80 +1,45 @@
|
||||
package jd
|
||||
|
||||
import (
|
||||
"github.com/dtapps/go-library/utils/dorm"
|
||||
"github.com/dtapps/go-library/utils/golog"
|
||||
"github.com/dtapps/go-library/utils/gorequest"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type ConfigClient struct {
|
||||
AppKey string // 应用Key
|
||||
SecretKey string // 密钥
|
||||
SiteId string // 网站ID/APP ID
|
||||
PositionId string // 推广位id
|
||||
MongoDb *dorm.MongoClient // 日志数据库
|
||||
PgsqlDb *gorm.DB // 日志数据库
|
||||
DatabaseName string // 库名
|
||||
// ClientConfig 实例配置
|
||||
type ClientConfig struct {
|
||||
AppKey string // 应用Key
|
||||
SecretKey string // 密钥
|
||||
SiteId string // 网站ID/APP ID
|
||||
PositionId string // 推广位id
|
||||
}
|
||||
|
||||
// Client 实例
|
||||
type Client struct {
|
||||
client *gorequest.App // 请求客户端
|
||||
log *golog.ApiClient // 日志服务
|
||||
config *ConfigClient // 配置
|
||||
}
|
||||
|
||||
func NewClient(config *ConfigClient) (*Client, error) {
|
||||
|
||||
var err error
|
||||
c := &Client{config: config}
|
||||
|
||||
c.client = gorequest.NewHttp()
|
||||
c.client.Uri = apiUrl
|
||||
|
||||
if c.config.PgsqlDb != nil {
|
||||
c.log, err = golog.NewApiClient(
|
||||
golog.WithGormClient(c.config.PgsqlDb),
|
||||
golog.WithTableName(logTable),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
requestClient *gorequest.App // 请求服务
|
||||
config struct {
|
||||
appKey string // 应用Key
|
||||
secretKey string // 密钥
|
||||
siteId string // 网站ID/APP ID
|
||||
positionId string // 推广位id
|
||||
}
|
||||
if c.config.MongoDb != nil {
|
||||
c.log, err = golog.NewApiClient(
|
||||
golog.WithMongoClient(c.config.MongoDb),
|
||||
golog.WithDatabaseName(c.config.DatabaseName),
|
||||
golog.WithCollectionName(logTable),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
log struct {
|
||||
status bool // 状态
|
||||
client *golog.ApiClient // 日志服务
|
||||
}
|
||||
|
||||
return c, nil
|
||||
}
|
||||
|
||||
// GoodsPriceToInt64 商品券后价
|
||||
func (c *Client) GoodsPriceToInt64(LowestCouponPrice float64) int64 {
|
||||
return int64(LowestCouponPrice * 100)
|
||||
}
|
||||
// NewClient 创建实例化
|
||||
func NewClient(config *ClientConfig) (*Client, error) {
|
||||
|
||||
// GoodsOriginalPriceToInt64 商品原价
|
||||
func (c *Client) GoodsOriginalPriceToInt64(Price float64) int64 {
|
||||
return int64(Price * 100)
|
||||
}
|
||||
c := &Client{}
|
||||
|
||||
// CouponProportionToInt64 佣金比率
|
||||
func (c *Client) CouponProportionToInt64(CommissionShare float64) int64 {
|
||||
return int64(CommissionShare * 10)
|
||||
}
|
||||
c.config.appKey = config.AppKey
|
||||
c.config.secretKey = config.SecretKey
|
||||
c.config.siteId = config.SiteId
|
||||
c.config.positionId = config.PositionId
|
||||
|
||||
// CouponAmountToInt64 优惠券金额
|
||||
func (c *Client) CouponAmountToInt64(Commission float64) int64 {
|
||||
return int64(Commission * 100)
|
||||
}
|
||||
c.requestClient = gorequest.NewHttp()
|
||||
c.requestClient.Uri = apiUrl
|
||||
|
||||
// CommissionIntegralToInt64 佣金积分
|
||||
func (c *Client) CommissionIntegralToInt64(GoodsPrice, CouponProportion int64) int64 {
|
||||
return (GoodsPrice * CouponProportion) / 1000
|
||||
return c, nil
|
||||
}
|
||||
|
@ -0,0 +1,12 @@
|
||||
package jd
|
||||
|
||||
import "github.com/dtapps/go-library/utils/golog"
|
||||
|
||||
// ConfigApiClientFun 日志配置
|
||||
func (c *Client) ConfigApiClientFun(apiClientFun golog.ApiClientFun) {
|
||||
apiClient := apiClientFun()
|
||||
if apiClient != nil {
|
||||
c.log.client = apiClient
|
||||
c.log.status = true
|
||||
}
|
||||
}
|
@ -1,21 +1,27 @@
|
||||
package jd
|
||||
|
||||
import "github.com/dtapps/go-library/utils/golog"
|
||||
|
||||
// GetAppKey 应用Key
|
||||
func (c *Client) GetAppKey() string {
|
||||
return c.config.AppKey
|
||||
return c.config.appKey
|
||||
}
|
||||
|
||||
// GetSecretKey 密钥
|
||||
func (c *Client) GetSecretKey() string {
|
||||
return c.config.SecretKey
|
||||
return c.config.secretKey
|
||||
}
|
||||
|
||||
// GetSiteId 网站ID/APP ID
|
||||
func (c *Client) GetSiteId() string {
|
||||
return c.config.SiteId
|
||||
return c.config.siteId
|
||||
}
|
||||
|
||||
// GetPositionId 推广位id
|
||||
func (c *Client) GetPositionId() string {
|
||||
return c.config.PositionId
|
||||
return c.config.positionId
|
||||
}
|
||||
|
||||
func (c *Client) GetLog() *golog.ApiClient {
|
||||
return c.log.client
|
||||
}
|
||||
|
@ -1,53 +1,38 @@
|
||||
package kashangwl
|
||||
|
||||
import (
|
||||
"github.com/dtapps/go-library/utils/dorm"
|
||||
"github.com/dtapps/go-library/utils/golog"
|
||||
"github.com/dtapps/go-library/utils/gorequest"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type ConfigClient struct {
|
||||
CustomerId int // 商家编号
|
||||
CustomerKey string // 商家密钥
|
||||
MongoDb *dorm.MongoClient // 日志数据库
|
||||
PgsqlDb *gorm.DB // 日志数据库
|
||||
DatabaseName string // 库名
|
||||
// ClientConfig 实例配置
|
||||
type ClientConfig struct {
|
||||
CustomerId int64 // 商家编号
|
||||
CustomerKey string // 商家密钥
|
||||
}
|
||||
|
||||
// Client 卡商网服务
|
||||
// Client 实例
|
||||
type Client struct {
|
||||
client *gorequest.App // 请求客户端
|
||||
log *golog.ApiClient // 日志服务
|
||||
config *ConfigClient // 配置
|
||||
requestClient *gorequest.App // 请求服务
|
||||
config struct {
|
||||
customerId int64 // 商家编号
|
||||
customerKey string // 商家密钥
|
||||
}
|
||||
log struct {
|
||||
status bool // 状态
|
||||
client *golog.ApiClient // 日志服务
|
||||
}
|
||||
}
|
||||
|
||||
func NewClient(config *ConfigClient) (*Client, error) {
|
||||
// NewClient 创建实例化
|
||||
func NewClient(config *ClientConfig) (*Client, error) {
|
||||
|
||||
var err error
|
||||
c := &Client{config: config}
|
||||
c := &Client{}
|
||||
|
||||
c.client = gorequest.NewHttp()
|
||||
c.config.customerId = config.CustomerId
|
||||
c.config.customerKey = config.CustomerKey
|
||||
|
||||
if c.config.PgsqlDb != nil {
|
||||
c.log, err = golog.NewApiClient(
|
||||
golog.WithGormClient(c.config.PgsqlDb),
|
||||
golog.WithTableName(logTable),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if c.config.MongoDb != nil {
|
||||
c.log, err = golog.NewApiClient(
|
||||
golog.WithMongoClient(c.config.MongoDb),
|
||||
golog.WithDatabaseName(c.config.DatabaseName),
|
||||
golog.WithCollectionName(logTable),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
c.requestClient = gorequest.NewHttp()
|
||||
|
||||
return c, nil
|
||||
}
|
||||
|
@ -0,0 +1,12 @@
|
||||
package kashangwl
|
||||
|
||||
import "github.com/dtapps/go-library/utils/golog"
|
||||
|
||||
// ConfigApiClientFun 日志配置
|
||||
func (c *Client) ConfigApiClientFun(apiClientFun golog.ApiClientFun) {
|
||||
apiClient := apiClientFun()
|
||||
if apiClient != nil {
|
||||
c.log.client = apiClient
|
||||
c.log.status = true
|
||||
}
|
||||
}
|
@ -1,9 +1,15 @@
|
||||
package kashangwl
|
||||
|
||||
func (c *Client) GetCustomerId() int {
|
||||
return c.config.CustomerId
|
||||
import "github.com/dtapps/go-library/utils/golog"
|
||||
|
||||
func (c *Client) GetCustomerId() int64 {
|
||||
return c.config.customerId
|
||||
}
|
||||
|
||||
func (c *Client) GetCustomerKey() string {
|
||||
return c.config.CustomerKey
|
||||
return c.config.customerKey
|
||||
}
|
||||
|
||||
func (c *Client) GetLog() *golog.ApiClient {
|
||||
return c.log.client
|
||||
}
|
||||
|
@ -0,0 +1,13 @@
|
||||
package kashangwl
|
||||
|
||||
type SetConfigConfig struct {
|
||||
CustomerId int64 // 商家编号
|
||||
CustomerKey string // 商家密钥
|
||||
}
|
||||
|
||||
// SetConfig 配置
|
||||
func (c *Client) SetConfig(config *SetConfigConfig) *Client {
|
||||
c.config.customerId = config.CustomerId
|
||||
c.config.customerKey = config.CustomerKey
|
||||
return c
|
||||
}
|
@ -1,60 +1,34 @@
|
||||
package kuaishou
|
||||
|
||||
import (
|
||||
"github.com/dtapps/go-library/utils/dorm"
|
||||
"github.com/dtapps/go-library/utils/golog"
|
||||
"github.com/dtapps/go-library/utils/gorequest"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type ConfigClient struct {
|
||||
MongoDb *dorm.MongoClient // 日志数据库
|
||||
PgsqlDb *gorm.DB // 日志数据库
|
||||
DatabaseName string // 库名
|
||||
// ClientConfig 实例配置
|
||||
type ClientConfig struct {
|
||||
}
|
||||
|
||||
// Client 实例
|
||||
type Client struct {
|
||||
ua string
|
||||
client *gorequest.App // 请求客户端
|
||||
log *golog.ApiClient // 日志服务
|
||||
config *ConfigClient // 配置
|
||||
requestClient *gorequest.App // 请求服务
|
||||
config struct {
|
||||
ua string // 用户代理
|
||||
}
|
||||
log struct {
|
||||
status bool // 状态
|
||||
client *golog.ApiClient // 日志服务
|
||||
}
|
||||
}
|
||||
|
||||
func NewClient(config *ConfigClient) (*Client, error) {
|
||||
|
||||
var err error
|
||||
c := &Client{config: config}
|
||||
// NewClient 创建实例化
|
||||
func NewClient(config *ClientConfig) (*Client, error) {
|
||||
|
||||
c.ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36"
|
||||
c := &Client{}
|
||||
|
||||
c.client = gorequest.NewHttp()
|
||||
|
||||
if c.config.PgsqlDb != nil {
|
||||
c.log, err = golog.NewApiClient(
|
||||
golog.WithGormClient(c.config.PgsqlDb),
|
||||
golog.WithTableName(logTable),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if c.config.MongoDb != nil {
|
||||
c.log, err = golog.NewApiClient(
|
||||
golog.WithMongoClient(c.config.MongoDb),
|
||||
golog.WithDatabaseName(c.config.DatabaseName),
|
||||
golog.WithCollectionName(logTable),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
c.config.ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36"
|
||||
|
||||
//if c.config.PgsqlDb != nil {
|
||||
// go c.log.GormMiddleware(request)
|
||||
//}
|
||||
//if c.config.MongoDb != nil {
|
||||
// go c.log.MongoMiddleware(request)
|
||||
//}
|
||||
c.requestClient = gorequest.NewHttp()
|
||||
|
||||
return c, nil
|
||||
}
|
||||
|
@ -0,0 +1,12 @@
|
||||
package kuaishou
|
||||
|
||||
import "github.com/dtapps/go-library/utils/golog"
|
||||
|
||||
// ConfigApiClientFun 日志配置
|
||||
func (c *Client) ConfigApiClientFun(apiClientFun golog.ApiClientFun) {
|
||||
apiClient := apiClientFun()
|
||||
if apiClient != nil {
|
||||
c.log.client = apiClient
|
||||
c.log.status = true
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
package kuaishou
|
||||
|
||||
const (
|
||||
logTable = "kuaishou"
|
||||
LogTable = "kuaishou"
|
||||
)
|
||||
|
@ -0,0 +1,7 @@
|
||||
package kuaishou
|
||||
|
||||
import "github.com/dtapps/go-library/utils/golog"
|
||||
|
||||
func (c *Client) GetLog() *golog.ApiClient {
|
||||
return c.log.client
|
||||
}
|
@ -1,53 +1,38 @@
|
||||
package meituan
|
||||
|
||||
import (
|
||||
"github.com/dtapps/go-library/utils/dorm"
|
||||
"github.com/dtapps/go-library/utils/golog"
|
||||
"github.com/dtapps/go-library/utils/gorequest"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type ConfigClient struct {
|
||||
Secret string // 秘钥
|
||||
AppKey string // 渠道标记
|
||||
MongoDb *dorm.MongoClient // 日志数据库
|
||||
PgsqlDb *gorm.DB // 日志数据库
|
||||
DatabaseName string // 库名
|
||||
// ClientConfig 实例配置
|
||||
type ClientConfig struct {
|
||||
Secret string // 秘钥
|
||||
AppKey string // 渠道标记
|
||||
}
|
||||
|
||||
// Client 美团联盟
|
||||
// Client 实例
|
||||
type Client struct {
|
||||
client *gorequest.App // 请求客户端
|
||||
log *golog.ApiClient // 日志服务
|
||||
config *ConfigClient // 配置
|
||||
requestClient *gorequest.App // 请求服务
|
||||
config struct {
|
||||
secret string // 秘钥
|
||||
appKey string // 渠道标记
|
||||
}
|
||||
log struct {
|
||||
status bool // 状态
|
||||
client *golog.ApiClient // 日志服务
|
||||
}
|
||||
}
|
||||
|
||||
func NewClient(config *ConfigClient) (*Client, error) {
|
||||
// NewClient 创建实例化
|
||||
func NewClient(config *ClientConfig) (*Client, error) {
|
||||
|
||||
var err error
|
||||
c := &Client{config: config}
|
||||
c := &Client{}
|
||||
|
||||
c.client = gorequest.NewHttp()
|
||||
c.config.secret = config.Secret
|
||||
c.config.appKey = config.AppKey
|
||||
|
||||
if c.config.PgsqlDb != nil {
|
||||
c.log, err = golog.NewApiClient(
|
||||
golog.WithGormClient(c.config.PgsqlDb),
|
||||
golog.WithTableName(logTable),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
if c.config.MongoDb != nil {
|
||||
c.log, err = golog.NewApiClient(
|
||||
golog.WithMongoClient(c.config.MongoDb),
|
||||
golog.WithDatabaseName(c.config.DatabaseName),
|
||||
golog.WithCollectionName(logTable),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
c.requestClient = gorequest.NewHttp()
|
||||
|
||||
return c, nil
|
||||
}
|
||||
|
@ -0,0 +1,12 @@
|
||||
package meituan
|
||||
|
||||
import "github.com/dtapps/go-library/utils/golog"
|
||||
|
||||
// ConfigApiClientFun 日志配置
|
||||
func (c *Client) ConfigApiClientFun(apiClientFun golog.ApiClientFun) {
|
||||
apiClient := apiClientFun()
|
||||
if apiClient != nil {
|
||||
c.log.client = apiClient
|
||||
c.log.status = true
|
||||
}
|
||||
}
|
@ -1,5 +1,15 @@
|
||||
package meituan
|
||||
|
||||
import "github.com/dtapps/go-library/utils/golog"
|
||||
|
||||
func (c *Client) GetAppKey() string {
|
||||
return c.config.AppKey
|
||||
return c.config.appKey
|
||||
}
|
||||
|
||||
func (c *Client) GetSecret() string {
|
||||
return c.config.secret
|
||||
}
|
||||
|
||||
func (c *Client) GetLog() *golog.ApiClient {
|
||||
return c.log.client
|
||||
}
|
||||
|
@ -0,0 +1,17 @@
|
||||
package pinduoduo
|
||||
|
||||
import "github.com/dtapps/go-library/utils/golog"
|
||||
|
||||
func (c *Client) ConfigPid(pid string) *Client {
|
||||
c.config.pid = pid
|
||||
return c
|
||||
}
|
||||
|
||||
// ConfigApiClientFun 日志配置
|
||||
func (c *Client) ConfigApiClientFun(apiClientFun golog.ApiClientFun) {
|
||||
apiClient := apiClientFun()
|
||||
if apiClient != nil {
|
||||
c.log.client = apiClient
|
||||
c.log.status = true
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package pinduoduo
|
||||
|
||||
import "github.com/dtapps/go-library/utils/golog"
|
||||
|
||||
func (c *Client) GetClientId() string {
|
||||
return c.config.clientId
|
||||
}
|
||||
|
||||
func (c *Client) GetClientSecret() string {
|
||||
return c.config.clientSecret
|
||||
}
|
||||
|
||||
func (c *Client) GetMediaId() string {
|
||||
return c.config.mediaId
|
||||
}
|
||||
|
||||
func (c *Client) GetPid() string {
|
||||
return c.config.pid
|
||||
}
|
||||
|
||||
func (c *Client) GetLog() *golog.ApiClient {
|
||||
return c.log.client
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue