parent
5750f7eb2c
commit
b77d14b664
@ -1,31 +0,0 @@
|
|||||||
module github.com/dtapps/go-library/service/dingdanxia
|
|
||||||
|
|
||||||
go 1.18
|
|
||||||
|
|
||||||
require (
|
|
||||||
github.com/dtapps/go-library/utils/gohttp v0.0.0-20220320035257-384fd01c7e13
|
|
||||||
github.com/go-redis/redis/v8 v8.11.5
|
|
||||||
go.mongodb.org/mongo-driver v1.8.4
|
|
||||||
go.uber.org/zap v1.21.0
|
|
||||||
gorm.io/gorm v1.23.3
|
|
||||||
)
|
|
||||||
|
|
||||||
require (
|
|
||||||
github.com/cespare/xxhash/v2 v2.1.2 // indirect
|
|
||||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
|
|
||||||
github.com/go-stack/stack v1.8.0 // indirect
|
|
||||||
github.com/golang/snappy v0.0.1 // indirect
|
|
||||||
github.com/jinzhu/inflection v1.0.0 // indirect
|
|
||||||
github.com/jinzhu/now v1.1.4 // indirect
|
|
||||||
github.com/klauspost/compress v1.13.6 // indirect
|
|
||||||
github.com/pkg/errors v0.9.1 // indirect
|
|
||||||
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
|
|
||||||
github.com/xdg-go/scram v1.0.2 // indirect
|
|
||||||
github.com/xdg-go/stringprep v1.0.2 // indirect
|
|
||||||
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
|
|
||||||
go.uber.org/atomic v1.7.0 // indirect
|
|
||||||
go.uber.org/multierr v1.6.0 // indirect
|
|
||||||
golang.org/x/crypto v0.0.0-20201216223049-8b5274cf687f // indirect
|
|
||||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
|
|
||||||
golang.org/x/text v0.3.6 // indirect
|
|
||||||
)
|
|
@ -0,0 +1,47 @@
|
|||||||
|
package dingdanxia
|
||||||
|
|
||||||
|
import (
|
||||||
|
"dtapps/dta/library/utils/gohttp"
|
||||||
|
"encoding/json"
|
||||||
|
"gitee.com/dtapps/go-library/utils/gotime"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 日志
|
||||||
|
type mongoZap struct {
|
||||||
|
Url string `json:"url" bson:"url"`
|
||||||
|
Params interface{} `json:"params" bson:"params"`
|
||||||
|
Method string `json:"method" bson:"method"`
|
||||||
|
Header interface{} `json:"header" bson:"header"`
|
||||||
|
Status string `json:"status" bson:"status"`
|
||||||
|
StatusCode int `json:"status_code" bson:"status_code"`
|
||||||
|
Body interface{} `json:"body" bson:"body"`
|
||||||
|
ContentLength int64 `json:"content_length" bson:"content_length"`
|
||||||
|
CreateTime string `json:"create_time" bson:"create_time"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mongoZap) Database() string {
|
||||||
|
return "zap_logs"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mongoZap) TableName() string {
|
||||||
|
return "dingdanxia_" + gotime.Current().SetFormat("200601")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (app *App) mongoLog(url string, params map[string]interface{}, method string, request gohttp.Response) {
|
||||||
|
if app.Mongo.Db == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var body map[string]interface{}
|
||||||
|
_ = json.Unmarshal(request.Body, &body)
|
||||||
|
app.Mongo.Model(&mongoZap{}).InsertOne(mongoZap{
|
||||||
|
Url: url,
|
||||||
|
Params: params,
|
||||||
|
Method: method,
|
||||||
|
Header: request.Header,
|
||||||
|
Status: request.Status,
|
||||||
|
StatusCode: request.StatusCode,
|
||||||
|
Body: body,
|
||||||
|
ContentLength: request.ContentLength,
|
||||||
|
CreateTime: gotime.Current().Format(),
|
||||||
|
})
|
||||||
|
}
|
@ -0,0 +1,53 @@
|
|||||||
|
package dingdanxia
|
||||||
|
|
||||||
|
import (
|
||||||
|
"dtapps/dta/library/utils/gohttp"
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
type WaimaiMeituanPrivilegeResponse struct {
|
||||||
|
Code int `json:"code"`
|
||||||
|
Msg string `json:"msg"`
|
||||||
|
Data struct {
|
||||||
|
H5 string `json:"h5"`
|
||||||
|
ShortH5 string `json:"short_h5"`
|
||||||
|
Deeplink string `json:"deeplink"`
|
||||||
|
H5Evoke string `json:"h5_evoke"`
|
||||||
|
Tkl string `json:"tkl"`
|
||||||
|
WeAppInfo struct {
|
||||||
|
AppId string `json:"app_id"`
|
||||||
|
PagePath string `json:"page_path"`
|
||||||
|
MiniCode string `json:"miniCode"`
|
||||||
|
} `json:"we_app_info"`
|
||||||
|
Qrcode string `json:"qrcode"`
|
||||||
|
} `json:"data"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type WaimaiMeituanPrivilegeResult struct {
|
||||||
|
Result WaimaiMeituanPrivilegeResponse // 结果
|
||||||
|
Body []byte // 内容
|
||||||
|
Http gohttp.Response // 请求
|
||||||
|
Err error // 错误
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewWaimaiMeituanPrivilegeResult(result WaimaiMeituanPrivilegeResponse, body []byte, http gohttp.Response, err error) *WaimaiMeituanPrivilegeResult {
|
||||||
|
return &WaimaiMeituanPrivilegeResult{Result: result, Body: body, Http: http, Err: err}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WaimaiMeituanPrivilege 美团外卖CPS推广API接口
|
||||||
|
// https://www.dingdanxia.com/doc/174/173
|
||||||
|
func (app *App) WaimaiMeituanPrivilege(sid string, generateWeApp, qrcode bool) *WaimaiMeituanPrivilegeResult {
|
||||||
|
// 参数
|
||||||
|
param := NewParams()
|
||||||
|
param.Set("sid", sid)
|
||||||
|
param.Set("generate_we_app", generateWeApp)
|
||||||
|
param.Set("qrcode", qrcode)
|
||||||
|
params := app.NewParamsWith(param)
|
||||||
|
// 请求
|
||||||
|
request, err := app.request("https://api.tbk.dingdanxia.com/waimai/meituan_privilege", params, http.MethodPost)
|
||||||
|
// 定义
|
||||||
|
var response WaimaiMeituanPrivilegeResponse
|
||||||
|
err = json.Unmarshal(request.Body, &response)
|
||||||
|
return NewWaimaiMeituanPrivilegeResult(response, request.Body, request, err)
|
||||||
|
}
|
@ -0,0 +1,52 @@
|
|||||||
|
package dingdanxia
|
||||||
|
|
||||||
|
import (
|
||||||
|
"dtapps/dta/library/utils/gohttp"
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
type WaimaiMeituanSgPrivilegeResponse struct {
|
||||||
|
Code int `json:"code"`
|
||||||
|
Msg string `json:"msg"`
|
||||||
|
Data struct {
|
||||||
|
H5 string `json:"h5"`
|
||||||
|
Deeplink string `json:"deeplink"`
|
||||||
|
H5Evoke string `json:"h5_evoke"`
|
||||||
|
ShortH5 string `json:"short_h5"`
|
||||||
|
WeAppInfo struct {
|
||||||
|
AppId string `json:"app_id"`
|
||||||
|
PagePath string `json:"page_path"`
|
||||||
|
MiniCode string `json:"miniCode"`
|
||||||
|
} `json:"we_app_info"`
|
||||||
|
Qrcode string `json:"qrcode"`
|
||||||
|
} `json:"data"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type WaimaiMeituanSgPrivilegeResult struct {
|
||||||
|
Result WaimaiMeituanSgPrivilegeResponse // 结果
|
||||||
|
Body []byte // 内容
|
||||||
|
Http gohttp.Response // 请求
|
||||||
|
Err error // 错误
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewWaimaiMeituanSgPrivilegeResult(result WaimaiMeituanSgPrivilegeResponse, body []byte, http gohttp.Response, err error) *WaimaiMeituanSgPrivilegeResult {
|
||||||
|
return &WaimaiMeituanSgPrivilegeResult{Result: result, Body: body, Http: http, Err: err}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WaimaiMeituanSgPrivilege 美团闪购CPS推广API接口
|
||||||
|
// https://www.dingdanxia.com/doc/195/173
|
||||||
|
func (app *App) WaimaiMeituanSgPrivilege(sid string, generateWeApp, qrcode bool) *WaimaiMeituanSgPrivilegeResult {
|
||||||
|
// 参数
|
||||||
|
param := NewParams()
|
||||||
|
param.Set("sid", sid)
|
||||||
|
param.Set("generate_we_app", generateWeApp)
|
||||||
|
param.Set("qrcode", qrcode)
|
||||||
|
params := app.NewParamsWith(param)
|
||||||
|
// 请求
|
||||||
|
request, err := app.request("https://api.tbk.dingdanxia.com/waimai/meituan_sg_privilege", params, http.MethodPost)
|
||||||
|
// 定义
|
||||||
|
var response WaimaiMeituanSgPrivilegeResponse
|
||||||
|
err = json.Unmarshal(request.Body, &response)
|
||||||
|
return NewWaimaiMeituanSgPrivilegeResult(response, request.Body, request, err)
|
||||||
|
}
|
@ -1,31 +0,0 @@
|
|||||||
module github.com/dtapps/go-library/service/dingtalk
|
|
||||||
|
|
||||||
go 1.18
|
|
||||||
|
|
||||||
require (
|
|
||||||
github.com/dtapps/go-library/utils/gohttp v0.0.0-20220320035257-384fd01c7e13
|
|
||||||
github.com/go-redis/redis/v8 v8.11.5
|
|
||||||
go.mongodb.org/mongo-driver v1.8.4
|
|
||||||
go.uber.org/zap v1.21.0
|
|
||||||
gorm.io/gorm v1.23.3
|
|
||||||
)
|
|
||||||
|
|
||||||
require (
|
|
||||||
github.com/cespare/xxhash/v2 v2.1.2 // indirect
|
|
||||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
|
|
||||||
github.com/go-stack/stack v1.8.0 // indirect
|
|
||||||
github.com/golang/snappy v0.0.1 // indirect
|
|
||||||
github.com/jinzhu/inflection v1.0.0 // indirect
|
|
||||||
github.com/jinzhu/now v1.1.4 // indirect
|
|
||||||
github.com/klauspost/compress v1.13.6 // indirect
|
|
||||||
github.com/pkg/errors v0.9.1 // indirect
|
|
||||||
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
|
|
||||||
github.com/xdg-go/scram v1.0.2 // indirect
|
|
||||||
github.com/xdg-go/stringprep v1.0.2 // indirect
|
|
||||||
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
|
|
||||||
go.uber.org/atomic v1.7.0 // indirect
|
|
||||||
go.uber.org/multierr v1.6.0 // indirect
|
|
||||||
golang.org/x/crypto v0.0.0-20201216223049-8b5274cf687f // indirect
|
|
||||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
|
|
||||||
golang.org/x/text v0.3.6 // indirect
|
|
||||||
)
|
|
@ -0,0 +1,47 @@
|
|||||||
|
package dingtalk
|
||||||
|
|
||||||
|
import (
|
||||||
|
"dtapps/dta/library/utils/gohttp"
|
||||||
|
"encoding/json"
|
||||||
|
"gitee.com/dtapps/go-library/utils/gotime"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 日志
|
||||||
|
type mongoZap struct {
|
||||||
|
Url string `json:"url" bson:"url"`
|
||||||
|
Params interface{} `json:"params" bson:"params"`
|
||||||
|
Method string `json:"method" bson:"method"`
|
||||||
|
Header interface{} `json:"header" bson:"header"`
|
||||||
|
Status string `json:"status" bson:"status"`
|
||||||
|
StatusCode int `json:"status_code" bson:"status_code"`
|
||||||
|
Body interface{} `json:"body" bson:"body"`
|
||||||
|
ContentLength int64 `json:"content_length" bson:"content_length"`
|
||||||
|
CreateTime string `json:"create_time" bson:"create_time"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mongoZap) Database() string {
|
||||||
|
return "zap_logs"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mongoZap) TableName() string {
|
||||||
|
return "dingtalk_" + gotime.Current().SetFormat("200601")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (app *App) mongoLog(url string, params map[string]interface{}, method string, request gohttp.Response) {
|
||||||
|
if app.Mongo.Db == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var body map[string]interface{}
|
||||||
|
_ = json.Unmarshal(request.Body, &body)
|
||||||
|
app.Mongo.Model(&mongoZap{}).InsertOne(mongoZap{
|
||||||
|
Url: url,
|
||||||
|
Params: params,
|
||||||
|
Method: method,
|
||||||
|
Header: request.Header,
|
||||||
|
Status: request.Status,
|
||||||
|
StatusCode: request.StatusCode,
|
||||||
|
Body: body,
|
||||||
|
ContentLength: request.ContentLength,
|
||||||
|
CreateTime: gotime.Current().Format(),
|
||||||
|
})
|
||||||
|
}
|
@ -1,32 +0,0 @@
|
|||||||
module github.com/dtapps/go-library/service/eastiot
|
|
||||||
|
|
||||||
go 1.18
|
|
||||||
|
|
||||||
require (
|
|
||||||
github.com/dtapps/go-library/utils/gohttp v0.0.0-20220320035257-384fd01c7e13
|
|
||||||
github.com/dtapps/go-library/utils/gomd5 v0.0.0-20220320035257-384fd01c7e13
|
|
||||||
github.com/go-redis/redis/v8 v8.11.5
|
|
||||||
go.mongodb.org/mongo-driver v1.8.4
|
|
||||||
go.uber.org/zap v1.21.0
|
|
||||||
gorm.io/gorm v1.23.3
|
|
||||||
)
|
|
||||||
|
|
||||||
require (
|
|
||||||
github.com/cespare/xxhash/v2 v2.1.2 // indirect
|
|
||||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
|
|
||||||
github.com/go-stack/stack v1.8.0 // indirect
|
|
||||||
github.com/golang/snappy v0.0.1 // indirect
|
|
||||||
github.com/jinzhu/inflection v1.0.0 // indirect
|
|
||||||
github.com/jinzhu/now v1.1.4 // indirect
|
|
||||||
github.com/klauspost/compress v1.13.6 // indirect
|
|
||||||
github.com/pkg/errors v0.9.1 // indirect
|
|
||||||
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
|
|
||||||
github.com/xdg-go/scram v1.0.2 // indirect
|
|
||||||
github.com/xdg-go/stringprep v1.0.2 // indirect
|
|
||||||
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
|
|
||||||
go.uber.org/atomic v1.7.0 // indirect
|
|
||||||
go.uber.org/multierr v1.6.0 // indirect
|
|
||||||
golang.org/x/crypto v0.0.0-20201216223049-8b5274cf687f // indirect
|
|
||||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
|
|
||||||
golang.org/x/text v0.3.6 // indirect
|
|
||||||
)
|
|
@ -0,0 +1,47 @@
|
|||||||
|
package eastiot
|
||||||
|
|
||||||
|
import (
|
||||||
|
"dtapps/dta/library/utils/gohttp"
|
||||||
|
"encoding/json"
|
||||||
|
"gitee.com/dtapps/go-library/utils/gotime"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 日志
|
||||||
|
type mongoZap struct {
|
||||||
|
Url string `json:"url" bson:"url"`
|
||||||
|
Params interface{} `json:"params" bson:"params"`
|
||||||
|
Method string `json:"method" bson:"method"`
|
||||||
|
Header interface{} `json:"header" bson:"header"`
|
||||||
|
Status string `json:"status" bson:"status"`
|
||||||
|
StatusCode int `json:"status_code" bson:"status_code"`
|
||||||
|
Body interface{} `json:"body" bson:"body"`
|
||||||
|
ContentLength int64 `json:"content_length" bson:"content_length"`
|
||||||
|
CreateTime string `json:"create_time" bson:"create_time"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mongoZap) Database() string {
|
||||||
|
return "zap_logs"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mongoZap) TableName() string {
|
||||||
|
return "eastiot_" + gotime.Current().SetFormat("200601")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (app *App) mongoLog(url string, params map[string]interface{}, method string, request gohttp.Response) {
|
||||||
|
if app.Mongo.Db == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var body map[string]interface{}
|
||||||
|
_ = json.Unmarshal(request.Body, &body)
|
||||||
|
app.Mongo.Model(&mongoZap{}).InsertOne(mongoZap{
|
||||||
|
Url: url,
|
||||||
|
Params: params,
|
||||||
|
Method: method,
|
||||||
|
Header: request.Header,
|
||||||
|
Status: request.Status,
|
||||||
|
StatusCode: request.StatusCode,
|
||||||
|
Body: body,
|
||||||
|
ContentLength: request.ContentLength,
|
||||||
|
CreateTime: gotime.Current().Format(),
|
||||||
|
})
|
||||||
|
}
|
@ -1,32 +0,0 @@
|
|||||||
module github.com/dtapps/go-library/service/ejiaofei
|
|
||||||
|
|
||||||
go 1.18
|
|
||||||
|
|
||||||
require (
|
|
||||||
github.com/dtapps/go-library/utils/gohttp v0.0.0-20220320040709-ad8a5f0e9e40
|
|
||||||
github.com/dtapps/go-library/utils/gomd5 v0.0.0-20220320040709-ad8a5f0e9e40
|
|
||||||
github.com/go-redis/redis/v8 v8.11.5
|
|
||||||
go.mongodb.org/mongo-driver v1.8.4
|
|
||||||
go.uber.org/zap v1.21.0
|
|
||||||
gorm.io/gorm v1.23.3
|
|
||||||
)
|
|
||||||
|
|
||||||
require (
|
|
||||||
github.com/cespare/xxhash/v2 v2.1.2 // indirect
|
|
||||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
|
|
||||||
github.com/go-stack/stack v1.8.0 // indirect
|
|
||||||
github.com/golang/snappy v0.0.1 // indirect
|
|
||||||
github.com/jinzhu/inflection v1.0.0 // indirect
|
|
||||||
github.com/jinzhu/now v1.1.4 // indirect
|
|
||||||
github.com/klauspost/compress v1.13.6 // indirect
|
|
||||||
github.com/pkg/errors v0.9.1 // indirect
|
|
||||||
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
|
|
||||||
github.com/xdg-go/scram v1.0.2 // indirect
|
|
||||||
github.com/xdg-go/stringprep v1.0.2 // indirect
|
|
||||||
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
|
|
||||||
go.uber.org/atomic v1.7.0 // indirect
|
|
||||||
go.uber.org/multierr v1.6.0 // indirect
|
|
||||||
golang.org/x/crypto v0.0.0-20201216223049-8b5274cf687f // indirect
|
|
||||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
|
|
||||||
golang.org/x/text v0.3.6 // indirect
|
|
||||||
)
|
|
@ -0,0 +1,44 @@
|
|||||||
|
package ejiaofei
|
||||||
|
|
||||||
|
import (
|
||||||
|
"dtapps/dta/library/utils/gohttp"
|
||||||
|
"gitee.com/dtapps/go-library/utils/gotime"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 日志
|
||||||
|
type mongoZap struct {
|
||||||
|
Url string `json:"url" bson:"url"`
|
||||||
|
Params interface{} `json:"params" bson:"params"`
|
||||||
|
Method string `json:"method" bson:"method"`
|
||||||
|
Header interface{} `json:"header" bson:"header"`
|
||||||
|
Status string `json:"status" bson:"status"`
|
||||||
|
StatusCode int `json:"status_code" bson:"status_code"`
|
||||||
|
Body interface{} `json:"body" bson:"body"`
|
||||||
|
ContentLength int64 `json:"content_length" bson:"content_length"`
|
||||||
|
CreateTime string `json:"create_time" bson:"create_time"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mongoZap) Database() string {
|
||||||
|
return "zap_logs"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mongoZap) TableName() string {
|
||||||
|
return "ejiaofei_" + gotime.Current().SetFormat("200601")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (app *App) mongoLog(url string, params map[string]interface{}, method string, request gohttp.Response) {
|
||||||
|
if app.Mongo.Db == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
app.Mongo.Model(&mongoZap{}).InsertOne(mongoZap{
|
||||||
|
Url: url,
|
||||||
|
Params: params,
|
||||||
|
Method: method,
|
||||||
|
Header: request.Header,
|
||||||
|
Status: request.Status,
|
||||||
|
StatusCode: request.StatusCode,
|
||||||
|
Body: string(request.Body),
|
||||||
|
ContentLength: request.ContentLength,
|
||||||
|
CreateTime: gotime.Current().Format(),
|
||||||
|
})
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
package feishu
|
||||||
|
|
||||||
|
import (
|
||||||
|
"dtapps/dta/library/utils/gohttp"
|
||||||
|
"dtapps/dta/library/utils/gomongo"
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
type App struct {
|
||||||
|
Key string
|
||||||
|
Mongo gomongo.App // 日志数据库
|
||||||
|
}
|
||||||
|
|
||||||
|
func (app *App) request(url string, params map[string]interface{}) (body []byte, err error) {
|
||||||
|
// 请求参数
|
||||||
|
paramsStr, err := json.Marshal(params)
|
||||||
|
// 请求
|
||||||
|
postJson, err := gohttp.PostJson(url, paramsStr)
|
||||||
|
// 日志
|
||||||
|
go app.mongoLog(url, params, http.MethodPost, postJson)
|
||||||
|
return postJson.Body, err
|
||||||
|
}
|
@ -0,0 +1,47 @@
|
|||||||
|
package feishu
|
||||||
|
|
||||||
|
import (
|
||||||
|
"dtapps/dta/library/utils/gohttp"
|
||||||
|
"encoding/json"
|
||||||
|
"gitee.com/dtapps/go-library/utils/gotime"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 日志
|
||||||
|
type mongoZap struct {
|
||||||
|
Url string `json:"url" bson:"url"`
|
||||||
|
Params interface{} `json:"params" bson:"params"`
|
||||||
|
Method string `json:"method" bson:"method"`
|
||||||
|
Header interface{} `json:"header" bson:"header"`
|
||||||
|
Status string `json:"status" bson:"status"`
|
||||||
|
StatusCode int `json:"status_code" bson:"status_code"`
|
||||||
|
Body interface{} `json:"body" bson:"body"`
|
||||||
|
ContentLength int64 `json:"content_length" bson:"content_length"`
|
||||||
|
CreateTime string `json:"create_time" bson:"create_time"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mongoZap) Database() string {
|
||||||
|
return "zap_logs"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mongoZap) TableName() string {
|
||||||
|
return "feishu_" + gotime.Current().SetFormat("200601")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (app *App) mongoLog(url string, params map[string]interface{}, method string, request gohttp.Response) {
|
||||||
|
if app.Mongo.Db == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var body map[string]interface{}
|
||||||
|
_ = json.Unmarshal(request.Body, &body)
|
||||||
|
app.Mongo.Model(&mongoZap{}).InsertOne(mongoZap{
|
||||||
|
Url: url,
|
||||||
|
Params: params,
|
||||||
|
Method: method,
|
||||||
|
Header: request.Header,
|
||||||
|
Status: request.Status,
|
||||||
|
StatusCode: request.StatusCode,
|
||||||
|
Body: body,
|
||||||
|
ContentLength: request.ContentLength,
|
||||||
|
CreateTime: gotime.Current().Format(),
|
||||||
|
})
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
package feishu
|
||||||
|
|
||||||
|
// Params 请求参数
|
||||||
|
type Params map[string]interface{}
|
||||||
|
|
||||||
|
func NewParams() Params {
|
||||||
|
p := make(Params)
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (app *App) NewParamsWith(params ...Params) Params {
|
||||||
|
p := make(Params)
|
||||||
|
for _, v := range params {
|
||||||
|
p.SetParams(v)
|
||||||
|
}
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p Params) Set(key string, value interface{}) {
|
||||||
|
p[key] = value
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p Params) SetParams(params Params) {
|
||||||
|
for key, value := range params {
|
||||||
|
p[key] = value
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,36 @@
|
|||||||
|
package feishu
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
type WebhookSendResponse struct {
|
||||||
|
Errcode int64 `json:"errcode"`
|
||||||
|
Errmsg string `json:"errmsg"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
MediaId string `json:"media_id"`
|
||||||
|
CreatedAt string `json:"created_at"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type WebhookSendResult struct {
|
||||||
|
Result WebhookSendResponse // 结果
|
||||||
|
Body []byte // 内容
|
||||||
|
Err error // 错误
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewWebhookSendResult(result WebhookSendResponse, body []byte, err error) *WebhookSendResult {
|
||||||
|
return &WebhookSendResult{Result: result, Body: body, Err: err}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WebhookSend https://open.feishu.cn/document/ukTMukTMukTM/ucTM5YjL3ETO24yNxkjN
|
||||||
|
func (app *App) WebhookSend(notMustParams ...Params) *WebhookSendResult {
|
||||||
|
// 参数
|
||||||
|
params := app.NewParamsWith(notMustParams...)
|
||||||
|
// 请求
|
||||||
|
body, err := app.request(fmt.Sprintf("https://open.feishu.cn/open-apis/bot/v2/hook/%s", app.Key), params)
|
||||||
|
// 定义
|
||||||
|
var response WebhookSendResponse
|
||||||
|
err = json.Unmarshal(body, &response)
|
||||||
|
return NewWebhookSendResult(response, body, err)
|
||||||
|
}
|
@ -1,3 +0,0 @@
|
|||||||
module github.com/dtapps/go-library/service
|
|
||||||
|
|
||||||
go 1.18
|
|
@ -1,8 +0,0 @@
|
|||||||
module github.com/dtapps/go-library/service/ip
|
|
||||||
|
|
||||||
go 1.18
|
|
||||||
|
|
||||||
require (
|
|
||||||
github.com/dtapps/go-library/utils/gostring v0.0.0-20220320035257-384fd01c7e13
|
|
||||||
golang.org/x/text v0.3.7
|
|
||||||
)
|
|
@ -0,0 +1,108 @@
|
|||||||
|
package ip
|
||||||
|
|
||||||
|
import (
|
||||||
|
"dtapps/dta/library/service/ip/ip2region"
|
||||||
|
v4 "dtapps/dta/library/service/ip/v4"
|
||||||
|
v6 "dtapps/dta/library/service/ip/v6"
|
||||||
|
)
|
||||||
|
|
||||||
|
func (app *App) InitLog() {
|
||||||
|
if app.Pgsql.Db == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err := app.Pgsql.Db.AutoMigrate(&postgresqlIpv4{}, &postgresqlIpv6{})
|
||||||
|
if err != nil {
|
||||||
|
panic(err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ipv4 数据库
|
||||||
|
type postgresqlIpv4 struct {
|
||||||
|
Id int64
|
||||||
|
Ip string `gorm:"type:cidr"` // 输入的ip地址
|
||||||
|
Country string `gorm:"type:text"` // 国家
|
||||||
|
Province string `gorm:"type:text"` // 省份
|
||||||
|
City string `gorm:"type:text"` // 城市
|
||||||
|
Area string `gorm:"type:text"` // 区域
|
||||||
|
Isp string `gorm:"type:text"` // 运营商
|
||||||
|
Idc string `gorm:"type:text"` // 运营商
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *postgresqlIpv4) TableName() string {
|
||||||
|
return "ip_v4"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (app *App) postgresqlIpv4Log(res v4.Result, resInfo ip2region.IpInfo) {
|
||||||
|
if app.Pgsql.Db == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var query postgresqlIpv4
|
||||||
|
app.Pgsql.Db.Where("ip = ?", resInfo.IP).Select("id").Take(&query)
|
||||||
|
if query.Id == 0 {
|
||||||
|
app.Pgsql.Db.Create(&postgresqlIpv4{
|
||||||
|
Ip: resInfo.IP,
|
||||||
|
Country: resInfo.Country,
|
||||||
|
Province: resInfo.Province,
|
||||||
|
City: resInfo.City,
|
||||||
|
Isp: resInfo.ISP,
|
||||||
|
Idc: res.Area,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
app.Pgsql.Db.Model(&postgresqlIpv4{}).
|
||||||
|
Where("ip = ?", res.IP).
|
||||||
|
Select("country", "province", "city", "isp", "idc").
|
||||||
|
Updates(postgresqlIpv4{
|
||||||
|
Country: resInfo.Country,
|
||||||
|
Province: resInfo.Province,
|
||||||
|
City: resInfo.City,
|
||||||
|
Isp: resInfo.ISP,
|
||||||
|
Idc: res.Area,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ipv6 数据库
|
||||||
|
type postgresqlIpv6 struct {
|
||||||
|
Id int64
|
||||||
|
Ip string `gorm:"type:cidr"` // 输入的ip地址
|
||||||
|
Country string `gorm:"type:text"` // 国家
|
||||||
|
Province string `gorm:"type:text"` // 省份
|
||||||
|
City string `gorm:"type:text"` // 城市
|
||||||
|
Area string `gorm:"type:text"` // 区域
|
||||||
|
Isp string `gorm:"type:text"` // 运营商
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *postgresqlIpv6) TableName() string {
|
||||||
|
return "ip_v6"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (app *App) postgresqlIpv6Log(res v6.Result) {
|
||||||
|
if app.Pgsql.Db == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var query postgresqlIpv6
|
||||||
|
app.Pgsql.Db.Where("ip = ?", res.IP).Select("id").Take(&query)
|
||||||
|
if query.Id == 0 {
|
||||||
|
app.Pgsql.Db.Create(&postgresqlIpv6{
|
||||||
|
Ip: res.IP,
|
||||||
|
Country: res.Country,
|
||||||
|
Province: res.Province,
|
||||||
|
City: res.City,
|
||||||
|
Area: res.Area,
|
||||||
|
Isp: res.Isp,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
app.Pgsql.Db.Model(&postgresqlIpv6{}).
|
||||||
|
Where("ip = ?", res.IP).
|
||||||
|
Select("country", "area").
|
||||||
|
Select("country", "province", "city", "area", "isp").
|
||||||
|
Updates(postgresqlIpv6{
|
||||||
|
Country: res.Country,
|
||||||
|
Province: res.Province,
|
||||||
|
City: res.City,
|
||||||
|
Area: res.Area,
|
||||||
|
Isp: res.Isp,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
@ -1,31 +0,0 @@
|
|||||||
module github.com/dtapps/go-library/service/jd
|
|
||||||
|
|
||||||
go 1.18
|
|
||||||
|
|
||||||
require (
|
|
||||||
github.com/dtapps/go-library/utils/gohttp v0.0.0-20220320040709-ad8a5f0e9e40
|
|
||||||
github.com/go-redis/redis/v8 v8.11.5
|
|
||||||
go.mongodb.org/mongo-driver v1.8.4
|
|
||||||
go.uber.org/zap v1.21.0
|
|
||||||
gorm.io/gorm v1.23.3
|
|
||||||
)
|
|
||||||
|
|
||||||
require (
|
|
||||||
github.com/cespare/xxhash/v2 v2.1.2 // indirect
|
|
||||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
|
|
||||||
github.com/go-stack/stack v1.8.0 // indirect
|
|
||||||
github.com/golang/snappy v0.0.1 // indirect
|
|
||||||
github.com/jinzhu/inflection v1.0.0 // indirect
|
|
||||||
github.com/jinzhu/now v1.1.4 // indirect
|
|
||||||
github.com/klauspost/compress v1.13.6 // indirect
|
|
||||||
github.com/pkg/errors v0.9.1 // indirect
|
|
||||||
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
|
|
||||||
github.com/xdg-go/scram v1.0.2 // indirect
|
|
||||||
github.com/xdg-go/stringprep v1.0.2 // indirect
|
|
||||||
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
|
|
||||||
go.uber.org/atomic v1.7.0 // indirect
|
|
||||||
go.uber.org/multierr v1.6.0 // indirect
|
|
||||||
golang.org/x/crypto v0.0.0-20201216223049-8b5274cf687f // indirect
|
|
||||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
|
|
||||||
golang.org/x/text v0.3.6 // indirect
|
|
||||||
)
|
|
@ -0,0 +1,71 @@
|
|||||||
|
package jd
|
||||||
|
|
||||||
|
import "encoding/json"
|
||||||
|
|
||||||
|
type UnionOpenActivityQueryResultResponse struct {
|
||||||
|
JdUnionOpenActivityQueryResponce struct {
|
||||||
|
Code string `json:"code"`
|
||||||
|
QueryResult string `json:"queryResult"`
|
||||||
|
} `json:"jd_union_open_activity_query_responce"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type UnionOpenActivityQueryQueryResult struct {
|
||||||
|
Code int `json:"code"`
|
||||||
|
Data []struct {
|
||||||
|
ActStatus int `json:"actStatus"`
|
||||||
|
Advantage string `json:"advantage"`
|
||||||
|
CategoryList []struct {
|
||||||
|
CategoryId int `json:"categoryId"`
|
||||||
|
Type int `json:"type"`
|
||||||
|
} `json:"categoryList,omitempty"`
|
||||||
|
Content string `json:"content"`
|
||||||
|
DownloadCode string `json:"downloadCode"`
|
||||||
|
DownloadUrl string `json:"downloadUrl"`
|
||||||
|
EndTime int64 `json:"endTime"`
|
||||||
|
Id int `json:"id"`
|
||||||
|
ImgList []struct {
|
||||||
|
ImgName string `json:"imgName"`
|
||||||
|
ImgUrl string `json:"imgUrl"`
|
||||||
|
WidthHeight string `json:"widthHeight"`
|
||||||
|
} `json:"imgList,omitempty"`
|
||||||
|
PlatformType int `json:"platformType"`
|
||||||
|
PromotionEndTime int64 `json:"promotionEndTime,omitempty"`
|
||||||
|
PromotionStartTime int64 `json:"promotionStartTime,omitempty"`
|
||||||
|
Recommend int `json:"recommend,omitempty"`
|
||||||
|
StartTime int64 `json:"startTime"`
|
||||||
|
Tag string `json:"tag"`
|
||||||
|
Title string `json:"title"`
|
||||||
|
UpdateTime int64 `json:"updateTime"`
|
||||||
|
UrlM string `json:"urlM"`
|
||||||
|
UrlPC string `json:"urlPC"`
|
||||||
|
} `json:"data"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
RequestId string `json:"requestId"`
|
||||||
|
TotalCount int `json:"totalCount"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type UnionOpenActivityQueryResult struct {
|
||||||
|
Responce UnionOpenActivityQueryResultResponse // 结果
|
||||||
|
Result UnionOpenActivityQueryQueryResult // 结果
|
||||||
|
Body []byte // 内容
|
||||||
|
Err error // 错误
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewUnionOpenActivityQueryResult(responce UnionOpenActivityQueryResultResponse, result UnionOpenActivityQueryQueryResult, body []byte, err error) *UnionOpenActivityQueryResult {
|
||||||
|
return &UnionOpenActivityQueryResult{Responce: responce, Result: result, Body: body, Err: err}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnionOpenActivityQuery 活动查询接口
|
||||||
|
// https://union.jd.com/openplatform/api/v2?apiName=jd.union.open.activity.query
|
||||||
|
func (app *App) UnionOpenActivityQuery(notMustParams ...Params) *UnionOpenActivityQueryResult {
|
||||||
|
// 参数
|
||||||
|
params := NewParamsWithType("jd.union.open.activity.query", notMustParams...)
|
||||||
|
// 请求
|
||||||
|
body, err := app.request(params)
|
||||||
|
// 定义
|
||||||
|
var responce UnionOpenActivityQueryResultResponse
|
||||||
|
var result UnionOpenActivityQueryQueryResult
|
||||||
|
err = json.Unmarshal(body, &responce)
|
||||||
|
err = json.Unmarshal([]byte(responce.JdUnionOpenActivityQueryResponce.QueryResult), &result)
|
||||||
|
return NewUnionOpenActivityQueryResult(responce, result, body, err)
|
||||||
|
}
|
@ -0,0 +1 @@
|
|||||||
|
package jd
|
@ -0,0 +1 @@
|
|||||||
|
package jd
|
@ -0,0 +1,68 @@
|
|||||||
|
package jd
|
||||||
|
|
||||||
|
import "encoding/json"
|
||||||
|
|
||||||
|
type UnionOpenGoodsBigfieldQueryResultResponse struct {
|
||||||
|
JdUnionOpenGoodsBigfieldQueryResponce struct {
|
||||||
|
Code string `json:"code"`
|
||||||
|
QueryResult string `json:"queryResult"`
|
||||||
|
} `json:"jd_union_open_goods_bigfield_query_responce"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type UnionOpenGoodsBigfieldQueryQueryResult struct {
|
||||||
|
Code int `json:"code"`
|
||||||
|
Data []struct {
|
||||||
|
BaseBigFieldInfo struct {
|
||||||
|
WareQD string `json:"wareQD"`
|
||||||
|
Wdis string `json:"wdis"`
|
||||||
|
} `json:"baseBigFieldInfo"`
|
||||||
|
CategoryInfo struct {
|
||||||
|
Cid1 int `json:"cid1"`
|
||||||
|
Cid1Name string `json:"cid1Name"`
|
||||||
|
Cid2 int `json:"cid2"`
|
||||||
|
Cid2Name string `json:"cid2Name"`
|
||||||
|
Cid3 int `json:"cid3"`
|
||||||
|
Cid3Name string `json:"cid3Name"`
|
||||||
|
} `json:"categoryInfo"`
|
||||||
|
DetailImages string `json:"detailImages"`
|
||||||
|
ImageInfo struct {
|
||||||
|
ImageList []struct {
|
||||||
|
Url string `json:"url"`
|
||||||
|
} `json:"imageList"`
|
||||||
|
} `json:"imageInfo"`
|
||||||
|
MainSkuId int64 `json:"mainSkuId"`
|
||||||
|
Owner string `json:"owner"`
|
||||||
|
ProductId int64 `json:"productId"`
|
||||||
|
SkuId int64 `json:"skuId"`
|
||||||
|
SkuName string `json:"skuName"`
|
||||||
|
SkuStatus int `json:"skuStatus"`
|
||||||
|
} `json:"data"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
RequestId string `json:"requestId"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type UnionOpenGoodsBigfieldQueryResult struct {
|
||||||
|
Responce UnionOpenGoodsBigfieldQueryResultResponse // 结果
|
||||||
|
Result UnionOpenGoodsBigfieldQueryQueryResult // 结果
|
||||||
|
Body []byte // 内容
|
||||||
|
Err error // 错误
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewUnionOpenGoodsBigfieldQueryResult(responce UnionOpenGoodsBigfieldQueryResultResponse, result UnionOpenGoodsBigfieldQueryQueryResult, body []byte, err error) *UnionOpenGoodsBigfieldQueryResult {
|
||||||
|
return &UnionOpenGoodsBigfieldQueryResult{Responce: responce, Result: result, Body: body, Err: err}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnionOpenGoodsBigfieldQuery 商品详情查询接口
|
||||||
|
// https://union.jd.com/openplatform/api/v2?apiName=jd.union.open.goods.bigfield.query
|
||||||
|
func (app *App) UnionOpenGoodsBigfieldQuery(notMustParams ...Params) *UnionOpenGoodsBigfieldQueryResult {
|
||||||
|
// 参数
|
||||||
|
params := NewParamsWithType("jd.union.open.goods.bigfield.query", notMustParams...)
|
||||||
|
// 请求
|
||||||
|
body, err := app.request(params)
|
||||||
|
// 定义
|
||||||
|
var responce UnionOpenGoodsBigfieldQueryResultResponse
|
||||||
|
var result UnionOpenGoodsBigfieldQueryQueryResult
|
||||||
|
err = json.Unmarshal(body, &responce)
|
||||||
|
err = json.Unmarshal([]byte(responce.JdUnionOpenGoodsBigfieldQueryResponce.QueryResult), &result)
|
||||||
|
return NewUnionOpenGoodsBigfieldQueryResult(responce, result, body, err)
|
||||||
|
}
|
@ -0,0 +1,129 @@
|
|||||||
|
package jd
|
||||||
|
|
||||||
|
import "encoding/json"
|
||||||
|
|
||||||
|
type UnionOpenGoodsMaterialQueryResultResponse struct {
|
||||||
|
JdUnionOpenGoodsMaterialQueryResponce struct {
|
||||||
|
Code string `json:"code"`
|
||||||
|
QueryResult string `json:"queryResult"`
|
||||||
|
} `json:"jd_union_open_goods_material_query_responce"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type UnionOpenGoodsMaterialQueryQueryResult struct {
|
||||||
|
Code int `json:"code"`
|
||||||
|
Data []struct {
|
||||||
|
BrandCode string `json:"brandCode"`
|
||||||
|
BrandName string `json:"brandName"`
|
||||||
|
CategoryInfo struct {
|
||||||
|
Cid1 int `json:"cid1"`
|
||||||
|
Cid1Name string `json:"cid1Name"`
|
||||||
|
Cid2 int `json:"cid2"`
|
||||||
|
Cid2Name string `json:"cid2Name"`
|
||||||
|
Cid3 int `json:"cid3"`
|
||||||
|
Cid3Name string `json:"cid3Name"`
|
||||||
|
} `json:"categoryInfo"`
|
||||||
|
Comments int `json:"comments"`
|
||||||
|
CommissionInfo struct {
|
||||||
|
Commission float64 `json:"commission"`
|
||||||
|
CommissionShare float64 `json:"commissionShare"`
|
||||||
|
CouponCommission float64 `json:"couponCommission"`
|
||||||
|
PlusCommissionShare float64 `json:"plusCommissionShare"`
|
||||||
|
} `json:"commissionInfo"`
|
||||||
|
CouponInfo struct {
|
||||||
|
CouponList []struct {
|
||||||
|
BindType int `json:"bindType"`
|
||||||
|
Discount float64 `json:"discount"`
|
||||||
|
GetEndTime int64 `json:"getEndTime"`
|
||||||
|
GetStartTime int64 `json:"getStartTime"`
|
||||||
|
IsBest int `json:"isBest"`
|
||||||
|
Link string `json:"link"`
|
||||||
|
PlatformType int `json:"platformType"`
|
||||||
|
Quota float64 `json:"quota"`
|
||||||
|
UseEndTime int64 `json:"useEndTime"`
|
||||||
|
UseStartTime int64 `json:"useStartTime"`
|
||||||
|
} `json:"couponList"`
|
||||||
|
} `json:"couponInfo"`
|
||||||
|
DeliveryType int `json:"deliveryType"`
|
||||||
|
ForbidTypes []int `json:"forbidTypes"`
|
||||||
|
GoodCommentsShare float64 `json:"goodCommentsShare"`
|
||||||
|
ImageInfo struct {
|
||||||
|
ImageList []struct {
|
||||||
|
Url string `json:"url"`
|
||||||
|
} `json:"imageList"`
|
||||||
|
WhiteImage string `json:"whiteImage,omitempty"`
|
||||||
|
} `json:"imageInfo"`
|
||||||
|
InOrderCount30Days int `json:"inOrderCount30Days"`
|
||||||
|
InOrderCount30DaysSku int `json:"inOrderCount30DaysSku"`
|
||||||
|
IsHot int `json:"isHot"`
|
||||||
|
JxFlags []int `json:"jxFlags,omitempty"`
|
||||||
|
MaterialUrl string `json:"materialUrl"`
|
||||||
|
Owner string `json:"owner"`
|
||||||
|
PinGouInfo struct {
|
||||||
|
PingouEndTime int64 `json:"pingouEndTime,omitempty"`
|
||||||
|
PingouPrice float64 `json:"pingouPrice,omitempty"`
|
||||||
|
PingouStartTime int64 `json:"pingouStartTime,omitempty"`
|
||||||
|
PingouTmCount int `json:"pingouTmCount,omitempty"`
|
||||||
|
PingouUrl string `json:"pingouUrl,omitempty"`
|
||||||
|
} `json:"pinGouInfo"`
|
||||||
|
PriceInfo struct {
|
||||||
|
LowestCouponPrice float64 `json:"lowestCouponPrice"`
|
||||||
|
LowestPrice float64 `json:"lowestPrice"`
|
||||||
|
LowestPriceType int `json:"lowestPriceType"`
|
||||||
|
Price float64 `json:"price"`
|
||||||
|
} `json:"priceInfo"`
|
||||||
|
PromotionInfo struct {
|
||||||
|
ClickURL string `json:"clickURL"`
|
||||||
|
} `json:"promotionInfo"`
|
||||||
|
ResourceInfo struct {
|
||||||
|
EliteId int `json:"eliteId"`
|
||||||
|
EliteName string `json:"eliteName"`
|
||||||
|
} `json:"resourceInfo"`
|
||||||
|
ShopInfo struct {
|
||||||
|
ShopId int `json:"shopId"`
|
||||||
|
ShopLabel string `json:"shopLabel"`
|
||||||
|
ShopLevel float64 `json:"shopLevel"`
|
||||||
|
ShopName string `json:"shopName"`
|
||||||
|
AfsFactorScoreRankGrade string `json:"afsFactorScoreRankGrade,omitempty"`
|
||||||
|
AfterServiceScore string `json:"afterServiceScore,omitempty"`
|
||||||
|
CommentFactorScoreRankGrade string `json:"commentFactorScoreRankGrade,omitempty"`
|
||||||
|
LogisticsFactorScoreRankGrade string `json:"logisticsFactorScoreRankGrade,omitempty"`
|
||||||
|
LogisticsLvyueScore string `json:"logisticsLvyueScore,omitempty"`
|
||||||
|
ScoreRankRate string `json:"scoreRankRate,omitempty"`
|
||||||
|
UserEvaluateScore string `json:"userEvaluateScore,omitempty"`
|
||||||
|
} `json:"shopInfo"`
|
||||||
|
SkuId int64 `json:"skuId"`
|
||||||
|
SkuName string `json:"skuName"`
|
||||||
|
Spuid int64 `json:"spuid"`
|
||||||
|
VideoInfo struct {
|
||||||
|
} `json:"videoInfo"`
|
||||||
|
} `json:"data"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
RequestId string `json:"requestId"`
|
||||||
|
TotalCount int `json:"totalCount"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type UnionOpenGoodsMaterialQueryResult struct {
|
||||||
|
Responce UnionOpenGoodsMaterialQueryResultResponse // 结果
|
||||||
|
Result UnionOpenGoodsMaterialQueryQueryResult // 结果
|
||||||
|
Body []byte // 内容
|
||||||
|
Err error // 错误
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewUnionOpenGoodsMaterialQueryResult(responce UnionOpenGoodsMaterialQueryResultResponse, result UnionOpenGoodsMaterialQueryQueryResult, body []byte, err error) *UnionOpenGoodsMaterialQueryResult {
|
||||||
|
return &UnionOpenGoodsMaterialQueryResult{Responce: responce, Result: result, Body: body, Err: err}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnionOpenGoodsMaterialQuery 猜你喜欢商品推荐
|
||||||
|
// https://union.jd.com/openplatform/api/v2?apiName=jd.union.open.goods.material.query
|
||||||
|
func (app *App) UnionOpenGoodsMaterialQuery(notMustParams ...Params) *UnionOpenGoodsMaterialQueryResult {
|
||||||
|
// 参数
|
||||||
|
params := NewParamsWithType("jd.union.open.goods.material.query", notMustParams...)
|
||||||
|
// 请求
|
||||||
|
body, err := app.request(params)
|
||||||
|
// 定义
|
||||||
|
var responce UnionOpenGoodsMaterialQueryResultResponse
|
||||||
|
var result UnionOpenGoodsMaterialQueryQueryResult
|
||||||
|
err = json.Unmarshal(body, &responce)
|
||||||
|
err = json.Unmarshal([]byte(responce.JdUnionOpenGoodsMaterialQueryResponce.QueryResult), &result)
|
||||||
|
return NewUnionOpenGoodsMaterialQueryResult(responce, result, body, err)
|
||||||
|
}
|
@ -0,0 +1,92 @@
|
|||||||
|
package jd
|
||||||
|
|
||||||
|
import "encoding/json"
|
||||||
|
|
||||||
|
type UnionOpenOrderQueryResultResponse struct {
|
||||||
|
JdUnionOpenOrderQueryResponce struct {
|
||||||
|
Code string `json:"code"`
|
||||||
|
QueryResult string `json:"queryResult"`
|
||||||
|
} `json:"jd_union_open_order_query_responce"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type UnionOpenOrderQueryQueryResult struct {
|
||||||
|
Code int `json:"code"`
|
||||||
|
Data []struct {
|
||||||
|
Ext1 string `json:"ext1"`
|
||||||
|
FinishTime int64 `json:"finishTime"`
|
||||||
|
OrderEmt int `json:"orderEmt"`
|
||||||
|
OrderId int64 `json:"orderId"`
|
||||||
|
OrderTime int64 `json:"orderTime"`
|
||||||
|
ParentId int `json:"parentId"`
|
||||||
|
PayMonth int `json:"payMonth"`
|
||||||
|
Plus int `json:"plus"`
|
||||||
|
PopId int `json:"popId"`
|
||||||
|
SkuList []struct {
|
||||||
|
ActualCosPrice float64 `json:"actualCosPrice"`
|
||||||
|
ActualFee float64 `json:"actualFee"`
|
||||||
|
Cid1 int `json:"cid1"`
|
||||||
|
Cid2 int `json:"cid2"`
|
||||||
|
Cid3 int `json:"cid3"`
|
||||||
|
CommissionRate float64 `json:"commissionRate"`
|
||||||
|
CpActId int `json:"cpActId"`
|
||||||
|
EstimateCosPrice float64 `json:"estimateCosPrice"`
|
||||||
|
EstimateFee float64 `json:"estimateFee"`
|
||||||
|
Ext1 string `json:"ext1"`
|
||||||
|
FinalRate float64 `json:"finalRate"`
|
||||||
|
FrozenSkuNum int `json:"frozenSkuNum"`
|
||||||
|
GiftCouponKey string `json:"giftCouponKey"`
|
||||||
|
GiftCouponOcsAmount float64 `json:"giftCouponOcsAmount"`
|
||||||
|
PayMonth int `json:"payMonth"`
|
||||||
|
Pid string `json:"pid"`
|
||||||
|
PopId int `json:"popId"`
|
||||||
|
PositionId int `json:"positionId"`
|
||||||
|
Price float64 `json:"price"`
|
||||||
|
ProPriceAmount float64 `json:"proPriceAmount"`
|
||||||
|
SiteId int `json:"siteId"`
|
||||||
|
SkuId int64 `json:"skuId"`
|
||||||
|
SkuName string `json:"skuName"`
|
||||||
|
SkuNum int `json:"skuNum"`
|
||||||
|
SkuReturnNum int `json:"skuReturnNum"`
|
||||||
|
SubSideRate float64 `json:"subSideRate"`
|
||||||
|
SubUnionId string `json:"subUnionId"`
|
||||||
|
SubsidyRate float64 `json:"subsidyRate"`
|
||||||
|
TraceType int `json:"traceType"`
|
||||||
|
UnionAlias string `json:"unionAlias"`
|
||||||
|
UnionRole int `json:"unionRole"`
|
||||||
|
UnionTag string `json:"unionTag"`
|
||||||
|
UnionTrafficGroup int `json:"unionTrafficGroup"`
|
||||||
|
ValidCode int `json:"validCode"`
|
||||||
|
} `json:"skuList"`
|
||||||
|
UnionId int `json:"unionId"`
|
||||||
|
ValidCode int `json:"validCode"`
|
||||||
|
} `json:"data"`
|
||||||
|
HasMore bool `json:"hasMore"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
RequestId string `json:"requestId"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type UnionOpenOrderQueryResult struct {
|
||||||
|
Responce UnionOpenOrderQueryResultResponse // 结果
|
||||||
|
Result UnionOpenOrderQueryQueryResult // 结果
|
||||||
|
Body []byte // 内容
|
||||||
|
Err error // 错误
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewUnionOpenOrderQueryResult(responce UnionOpenOrderQueryResultResponse, result UnionOpenOrderQueryQueryResult, body []byte, err error) *UnionOpenOrderQueryResult {
|
||||||
|
return &UnionOpenOrderQueryResult{Responce: responce, Result: result, Body: body, Err: err}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnionOpenOrderQuery 订单查询接口
|
||||||
|
// https://union.jd.com/openplatform/api/v2?apiName=jd.union.open.order.query
|
||||||
|
func (app *App) UnionOpenOrderQuery(notMustParams ...Params) *UnionOpenOrderQueryResult {
|
||||||
|
// 参数
|
||||||
|
params := NewParamsWithType("jd.union.open.order.query", notMustParams...)
|
||||||
|
// 请求
|
||||||
|
body, err := app.request(params)
|
||||||
|
// 定义
|
||||||
|
var responce UnionOpenOrderQueryResultResponse
|
||||||
|
var result UnionOpenOrderQueryQueryResult
|
||||||
|
err = json.Unmarshal(body, &responce)
|
||||||
|
err = json.Unmarshal([]byte(responce.JdUnionOpenOrderQueryResponce.QueryResult), &result)
|
||||||
|
return NewUnionOpenOrderQueryResult(responce, result, body, err)
|
||||||
|
}
|
@ -0,0 +1,101 @@
|
|||||||
|
package jd
|
||||||
|
|
||||||
|
import "encoding/json"
|
||||||
|
|
||||||
|
type UnionOpenOrderRowQueryResultResponse struct {
|
||||||
|
JdUnionOpenOrderRowQueryResponce struct {
|
||||||
|
Code string `json:"code"`
|
||||||
|
QueryResult string `json:"queryResult"`
|
||||||
|
} `json:"jd_union_open_order_row_query_responce"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type UnionOpenOrderRowQueryQueryResult struct {
|
||||||
|
Code int `json:"code"`
|
||||||
|
Data []struct {
|
||||||
|
ActualCosPrice float64 `json:"actualCosPrice"`
|
||||||
|
ActualFee float64 `json:"actualFee"`
|
||||||
|
BalanceExt string `json:"balanceExt"`
|
||||||
|
CategoryInfo struct {
|
||||||
|
Cid1 int `json:"cid1"`
|
||||||
|
Cid2 int `json:"cid2"`
|
||||||
|
Cid3 int `json:"cid3"`
|
||||||
|
} `json:"categoryInfo"`
|
||||||
|
ChannelId int `json:"channelId"`
|
||||||
|
Cid1 int `json:"cid1"`
|
||||||
|
Cid2 int `json:"cid2"`
|
||||||
|
Cid3 int `json:"cid3"`
|
||||||
|
CommissionRate float64 `json:"commissionRate"`
|
||||||
|
CpActId int `json:"cpActId"`
|
||||||
|
EstimateCosPrice float64 `json:"estimateCosPrice"`
|
||||||
|
EstimateFee float64 `json:"estimateFee"`
|
||||||
|
ExpressStatus int `json:"expressStatus"`
|
||||||
|
Ext1 string `json:"ext1"`
|
||||||
|
FinalRate float64 `json:"finalRate"`
|
||||||
|
FinishTime string `json:"finishTime"`
|
||||||
|
GiftCouponKey string `json:"giftCouponKey"`
|
||||||
|
GiftCouponOcsAmount float64 `json:"giftCouponOcsAmount"`
|
||||||
|
GoodsInfo struct {
|
||||||
|
MainSkuId int `json:"mainSkuId"`
|
||||||
|
ProductId int `json:"productId"`
|
||||||
|
ShopId int `json:"shopId"`
|
||||||
|
} `json:"goodsInfo"`
|
||||||
|
Id string `json:"id"`
|
||||||
|
ModifyTime string `json:"modifyTime"`
|
||||||
|
OrderEmt int `json:"orderEmt"`
|
||||||
|
OrderId int64 `json:"orderId"`
|
||||||
|
OrderTime string `json:"orderTime"`
|
||||||
|
ParentId int `json:"parentId"`
|
||||||
|
PayMonth int `json:"payMonth"`
|
||||||
|
Pid string `json:"pid"`
|
||||||
|
Plus int `json:"plus"`
|
||||||
|
PopId int `json:"popId"`
|
||||||
|
PositionId int `json:"positionId"`
|
||||||
|
Price float64 `json:"price"`
|
||||||
|
ProPriceAmount float64 `json:"proPriceAmount"`
|
||||||
|
Rid int `json:"rid"`
|
||||||
|
SiteId int `json:"siteId"`
|
||||||
|
SkuFrozenNum int `json:"skuFrozenNum"`
|
||||||
|
SkuId int64 `json:"skuId"`
|
||||||
|
SkuName string `json:"skuName"`
|
||||||
|
SkuNum int `json:"skuNum"`
|
||||||
|
SkuReturnNum int `json:"skuReturnNum"`
|
||||||
|
SubSideRate float64 `json:"subSideRate"`
|
||||||
|
SubUnionId string `json:"subUnionId"`
|
||||||
|
SubsidyRate float64 `json:"subsidyRate"`
|
||||||
|
TraceType int `json:"traceType"`
|
||||||
|
UnionAlias string `json:"unionAlias"`
|
||||||
|
UnionId int `json:"unionId"`
|
||||||
|
UnionRole int `json:"unionRole"`
|
||||||
|
UnionTag string `json:"unionTag"`
|
||||||
|
ValidCode int `json:"validCode"`
|
||||||
|
} `json:"data"`
|
||||||
|
HasMore bool `json:"hasMore"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
RequestId string `json:"requestId"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type UnionOpenOrderRowQueryResult struct {
|
||||||
|
Responce UnionOpenOrderRowQueryResultResponse // 结果
|
||||||
|
Result UnionOpenOrderRowQueryQueryResult // 结果
|
||||||
|
Body []byte // 内容
|
||||||
|
Err error // 错误
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewUnionOpenOrderRowQueryResult(responce UnionOpenOrderRowQueryResultResponse, result UnionOpenOrderRowQueryQueryResult, body []byte, err error) *UnionOpenOrderRowQueryResult {
|
||||||
|
return &UnionOpenOrderRowQueryResult{Responce: responce, Result: result, Body: body, Err: err}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnionOpenOrderRowQuery 订单行查询接口
|
||||||
|
// https://union.jd.com/openplatform/api/v2?apiName=jd.union.open.order.row.query
|
||||||
|
func (app *App) UnionOpenOrderRowQuery(notMustParams ...Params) *UnionOpenOrderRowQueryResult {
|
||||||
|
// 参数
|
||||||
|
params := NewParamsWithType("jd.union.open.order.row.query", notMustParams...)
|
||||||
|
// 请求
|
||||||
|
body, err := app.request(params)
|
||||||
|
// 定义
|
||||||
|
var responce UnionOpenOrderRowQueryResultResponse
|
||||||
|
var result UnionOpenOrderRowQueryQueryResult
|
||||||
|
err = json.Unmarshal(body, &responce)
|
||||||
|
err = json.Unmarshal([]byte(responce.JdUnionOpenOrderRowQueryResponce.QueryResult), &result)
|
||||||
|
return NewUnionOpenOrderRowQueryResult(responce, result, body, err)
|
||||||
|
}
|
@ -0,0 +1,46 @@
|
|||||||
|
package jd
|
||||||
|
|
||||||
|
import "encoding/json"
|
||||||
|
|
||||||
|
type UnionOpenPromotionBySubUnionIdGetResultResponse struct {
|
||||||
|
JdUnionOpenPromotionBySubUnionIdGetResponce struct {
|
||||||
|
Code string `json:"code"`
|
||||||
|
GetResult string `json:"getResult"`
|
||||||
|
} `json:"jd_union_open_promotion_common_get_responce"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type UnionOpenPromotionBySubUnionIdGetGetResult struct {
|
||||||
|
Code int `json:"code"`
|
||||||
|
Data struct {
|
||||||
|
ClickURL string `json:"clickURL"`
|
||||||
|
JCommand string `json:"jCommand"`
|
||||||
|
} `json:"data"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
RequestId string `json:"requestId"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type UnionOpenPromotionBySubUnionIdGetResult struct {
|
||||||
|
Responce UnionOpenPromotionBySubUnionIdGetResultResponse // 结果
|
||||||
|
Result UnionOpenPromotionBySubUnionIdGetGetResult // 结果
|
||||||
|
Body []byte // 内容
|
||||||
|
Err error // 错误
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewUnionOpenPromotionBySubUnionIdGetResult(responce UnionOpenPromotionBySubUnionIdGetResultResponse, result UnionOpenPromotionBySubUnionIdGetGetResult, body []byte, err error) *UnionOpenPromotionBySubUnionIdGetResult {
|
||||||
|
return &UnionOpenPromotionBySubUnionIdGetResult{Responce: responce, Result: result, Body: body, Err: err}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnionOpenPromotionBySubUnionIdGet 社交媒体获取推广链接接口【申请】
|
||||||
|
// https://union.jd.com/openplatform/api/v2?apiName=jd.union.open.promotion.bysubunionid.get
|
||||||
|
func (app *App) UnionOpenPromotionBySubUnionIdGet(notMustParams ...Params) *UnionOpenPromotionBySubUnionIdGetResult {
|
||||||
|
// 参数
|
||||||
|
params := NewParamsWithType("jd.union.open.promotion.bysubunionid.get", notMustParams...)
|
||||||
|
// 请求
|
||||||
|
body, err := app.request(params)
|
||||||
|
// 定义
|
||||||
|
var responce UnionOpenPromotionBySubUnionIdGetResultResponse
|
||||||
|
var result UnionOpenPromotionBySubUnionIdGetGetResult
|
||||||
|
err = json.Unmarshal(body, &responce)
|
||||||
|
err = json.Unmarshal([]byte(responce.JdUnionOpenPromotionBySubUnionIdGetResponce.GetResult), &result)
|
||||||
|
return NewUnionOpenPromotionBySubUnionIdGetResult(responce, result, body, err)
|
||||||
|
}
|
@ -0,0 +1 @@
|
|||||||
|
package jd
|
@ -0,0 +1 @@
|
|||||||
|
package jd
|
@ -0,0 +1 @@
|
|||||||
|
package jd
|
@ -0,0 +1 @@
|
|||||||
|
package jd
|
@ -0,0 +1 @@
|
|||||||
|
package jd
|
@ -0,0 +1,47 @@
|
|||||||
|
package jd
|
||||||
|
|
||||||
|
import (
|
||||||
|
"dtapps/dta/library/utils/gohttp"
|
||||||
|
"encoding/json"
|
||||||
|
"gitee.com/dtapps/go-library/utils/gotime"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 日志
|
||||||
|
type mongoZap struct {
|
||||||
|
Url string `json:"url" bson:"url"`
|
||||||
|
Params interface{} `json:"params" bson:"params"`
|
||||||
|
Method string `json:"method" bson:"method"`
|
||||||
|
Header interface{} `json:"header" bson:"header"`
|
||||||
|
Status string `json:"status" bson:"status"`
|
||||||
|
StatusCode int `json:"status_code" bson:"status_code"`
|
||||||
|
Body interface{} `json:"body" bson:"body"`
|
||||||
|
ContentLength int64 `json:"content_length" bson:"content_length"`
|
||||||
|
CreateTime string `json:"create_time" bson:"create_time"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mongoZap) Database() string {
|
||||||
|
return "zap_logs"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mongoZap) TableName() string {
|
||||||
|
return "jd_" + gotime.Current().SetFormat("200601")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (app *App) mongoLog(url string, params map[string]interface{}, method string, request gohttp.Response) {
|
||||||
|
if app.Mongo.Db == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var body map[string]interface{}
|
||||||
|
_ = json.Unmarshal(request.Body, &body)
|
||||||
|
app.Mongo.Model(&mongoZap{}).InsertOne(mongoZap{
|
||||||
|
Url: url,
|
||||||
|
Params: params,
|
||||||
|
Method: method,
|
||||||
|
Header: request.Header,
|
||||||
|
Status: request.Status,
|
||||||
|
StatusCode: request.StatusCode,
|
||||||
|
Body: body,
|
||||||
|
ContentLength: request.ContentLength,
|
||||||
|
CreateTime: gotime.Current().Format(),
|
||||||
|
})
|
||||||
|
}
|
@ -0,0 +1,144 @@
|
|||||||
|
package jobs
|
||||||
|
|
||||||
|
import "gitee.com/dtapps/go-library/utils/goip"
|
||||||
|
|
||||||
|
var TypeIp = map[string]string{
|
||||||
|
// 微信支付查询
|
||||||
|
TypeWechatPayPrepaidRefill: "",
|
||||||
|
TypeWechatPayPower: "",
|
||||||
|
TypeWechatPayKashangwl: "",
|
||||||
|
TypeWechatPayEastiot: "",
|
||||||
|
TypeWechatPayEjiaofei: "",
|
||||||
|
TypeWechatPayMovie: "",
|
||||||
|
|
||||||
|
// 接口支付申请
|
||||||
|
TypeApiPaySubmitPrepaidRefill: "",
|
||||||
|
TypeApiPaySubmitPower: "",
|
||||||
|
TypeApiPaySubmitKashangwl: "",
|
||||||
|
TypeApiPaySubmitEastiot: "47.112.146.193",
|
||||||
|
TypeApiPaySubmitEjiaofei: "47.112.146.193",
|
||||||
|
TypeApiPaySubmitMovie: "",
|
||||||
|
|
||||||
|
// 接口支付查询
|
||||||
|
TypeApiPayQueryPrepaidRefill: "",
|
||||||
|
TypeApiPayQueryPower: "",
|
||||||
|
TypeApiPayQueryKashangwl: "",
|
||||||
|
TypeApiPayQueryEastiot: "47.112.146.193",
|
||||||
|
TypeApiPayQueryEjiaofei: "",
|
||||||
|
TypeApiPayQueryMovie: "",
|
||||||
|
TypeApiPayQueryPinduoduo: "",
|
||||||
|
TypeApiPayQueryMeituan: "",
|
||||||
|
|
||||||
|
// 微信支付退款申请
|
||||||
|
TypeWechatRefundsSubmitPrepaidRefill: "",
|
||||||
|
TypeWechatRefundsSubmitPower: "",
|
||||||
|
TypeWechatRefundsSubmitKashangwl: "",
|
||||||
|
TypeWechatRefundsSubmitEastiot: "",
|
||||||
|
TypeWechatRefundsSubmitEjiaofei: "",
|
||||||
|
TypeWechatRefundsSubmitMovie: "",
|
||||||
|
|
||||||
|
// 微信支付退款查询
|
||||||
|
TypeWechatRefundsQueryPrepaidRefill: "",
|
||||||
|
TypeWechatRefundsQueryPower: "",
|
||||||
|
TypeWechatRefundsQueryKashangwl: "",
|
||||||
|
TypeWechatRefundsQueryEastiot: "",
|
||||||
|
TypeWechatRefundsQueryEjiaofei: "",
|
||||||
|
TypeWechatRefundsQueryMovie: "",
|
||||||
|
|
||||||
|
// 返拥
|
||||||
|
TypeGoldenBeansIssuePrepaidRefill: "",
|
||||||
|
TypeGoldenBeansIssuePower: "",
|
||||||
|
TypeGoldenBeansIssueKashangwl: "",
|
||||||
|
TypeGoldenBeansIssueEastiot: "",
|
||||||
|
TypeGoldenBeansIssueMovie: "",
|
||||||
|
TypeGoldenBeansIssueRewardedvideo: "",
|
||||||
|
|
||||||
|
// 冻结返拥金豆
|
||||||
|
TypeGoldenBeansFrozenPinduoduo: "",
|
||||||
|
TypeGoldenBeansFrozenMeituan: "",
|
||||||
|
|
||||||
|
// 解冻返拥金豆正常发放
|
||||||
|
TypeGoldenBeansThawSuccessPinduoduo: "",
|
||||||
|
TypeGoldenBeansThawSuccessMeituan: "",
|
||||||
|
|
||||||
|
// 解冻返拥金豆扣款
|
||||||
|
TypeGoldenBeansThawErrorPinduoduo: "",
|
||||||
|
TypeGoldenBeansThawErrorMeituan: "",
|
||||||
|
|
||||||
|
// 抵扣金豆退款
|
||||||
|
TypeGoldenBeansRefundsPrepaidRefill: "",
|
||||||
|
TypeGoldenBeansRefundsPower: "",
|
||||||
|
|
||||||
|
// 金豆退款
|
||||||
|
TypeGoldenBeansRefundsEjiaofei: "",
|
||||||
|
|
||||||
|
// 客服进度
|
||||||
|
TypeCustomerAutoPrepaidRefill: "",
|
||||||
|
TypeCustomerAutoPower: "",
|
||||||
|
TypeCustomerAutoKashangwl: "",
|
||||||
|
TypeCustomerAutoEjiaofei: "",
|
||||||
|
TypeCustomerAutoMovie: "",
|
||||||
|
|
||||||
|
// 订单同步
|
||||||
|
TypeSyncOrderPinduoduo: "",
|
||||||
|
TypeSyncOrderMeituan: "",
|
||||||
|
|
||||||
|
// 商品同步
|
||||||
|
TypeSyncGoodsEastiot: "47.112.146.193",
|
||||||
|
TypeSyncGoodsTypeEastiot: "47.112.146.193",
|
||||||
|
TypeSyncGoodsPriceAllKashangwl: "",
|
||||||
|
TypeSyncGoodsPriceSingleKashangwl: "",
|
||||||
|
TypeCheckGoodsAllPinduoduo: "",
|
||||||
|
TypeCheckGoodsSinglePinduoduo: "",
|
||||||
|
|
||||||
|
// 微信更新
|
||||||
|
TypeSyncWechat: "119.3.235.113,119.3.132.197,47.112.146.193",
|
||||||
|
|
||||||
|
// 商家金豆转换
|
||||||
|
TypeGoldenBeanConversionUserGoldenBean: "",
|
||||||
|
TypeGoldenBeanConversionUserDeductGoldenBean: "",
|
||||||
|
|
||||||
|
// 企业自定义
|
||||||
|
TypeNewServiceAgentIssue: "",
|
||||||
|
TypeNewServiceAgentIssueNext: "",
|
||||||
|
|
||||||
|
// 团队
|
||||||
|
TypeTeamInv: "",
|
||||||
|
|
||||||
|
// 修复商家账号数量
|
||||||
|
TypeRepairMerchantAccountQuantityTesting: "",
|
||||||
|
TypeRepairMerchantAccountQuantityLevel: "",
|
||||||
|
|
||||||
|
// 观察接口
|
||||||
|
TypeApiPayObservationPrepaidRefill: "",
|
||||||
|
TypeApiPayObservationPower: "",
|
||||||
|
TypeApiPayObservationKashangwl: "",
|
||||||
|
TypeApiPayObservationEjiaofei: "47.112.146.193",
|
||||||
|
TypeApiPayObservationMovie: "",
|
||||||
|
TypeApiPayObservationPinduoduo: "",
|
||||||
|
TypeApiPayObservationMeituan: "",
|
||||||
|
TypeApiPayObservationWechat: "",
|
||||||
|
TypeApiPayObservationWechatRefunds: "",
|
||||||
|
TypeApiPayObservationWechatWithdrawal: "",
|
||||||
|
|
||||||
|
// 微信提现
|
||||||
|
TypeWechatPayWithdrawalSubmit: "47.112.146.193",
|
||||||
|
TypeWechatPayWithdrawalQuery: "",
|
||||||
|
TypeWechatPayWithdrawalRefunds: "",
|
||||||
|
}
|
||||||
|
|
||||||
|
func (app *App) Ip(Type string) string {
|
||||||
|
return TypeIp[Type]
|
||||||
|
}
|
||||||
|
|
||||||
|
func (app *App) RefreshIp() {
|
||||||
|
xip := goip.GetOutsideIp()
|
||||||
|
if app.OutsideIp == "" || app.OutsideIp == "0.0.0.0" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if app.OutsideIp == xip {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
app.Db.Where("ips = ?", app.OutsideIp).Delete(&TaskIp{}) // 删除
|
||||||
|
app.OutsideIp = xip
|
||||||
|
}
|
@ -0,0 +1,379 @@
|
|||||||
|
package jobs
|
||||||
|
|
||||||
|
import (
|
||||||
|
"dtapps/dta/library/utils/goredis"
|
||||||
|
"fmt"
|
||||||
|
"gitee.com/dtapps/go-library/utils/gojson"
|
||||||
|
"gitee.com/dtapps/go-library/utils/gotime"
|
||||||
|
"gitee.com/dtapps/go-library/utils/gouuid"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
type App struct {
|
||||||
|
RunVersion int `json:"run_version"` // 运行版本
|
||||||
|
Os string `json:"os"` // 系统类型
|
||||||
|
Arch string `json:"arch"` // 系统架构
|
||||||
|
MaxProCs int `json:"max_pro_cs"` // CPU核数
|
||||||
|
Version string `json:"version"` // GO版本
|
||||||
|
MacAddrS string `json:"mac_addr_s"` // Mac地址
|
||||||
|
InsideIp string `json:"inside_ip"` // 内网ip
|
||||||
|
OutsideIp string `json:"outside_ip"` // 外网ip
|
||||||
|
MainService int `json:"main_service"` // 主要服务
|
||||||
|
AddIpService int `json:"add_ip_service"` // 添加IP
|
||||||
|
Db *gorm.DB // 数据库
|
||||||
|
Redis goredis.App // 缓存数据库服务
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add 添加任务
|
||||||
|
func (app *App) Add(Type string, params interface{}, frequency int64) int64 {
|
||||||
|
return app.Db.Create(&Task{
|
||||||
|
Status: TASK_IN,
|
||||||
|
Params: gojson.JsonEncodeNoError(params),
|
||||||
|
StatusDesc: "首次添加任务",
|
||||||
|
Frequency: frequency,
|
||||||
|
RunId: gouuid.GetUuId(),
|
||||||
|
Type: Type,
|
||||||
|
CreatedIp: app.OutsideIp,
|
||||||
|
UpdatedIp: app.OutsideIp,
|
||||||
|
CreatedAt: gotime.Current().Format(),
|
||||||
|
UpdatedAt: gotime.Current().Format(),
|
||||||
|
}).RowsAffected
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddCustomId 添加任务
|
||||||
|
func (app *App) AddCustomId(Type string, params interface{}, frequency int64, customId string) int64 {
|
||||||
|
query := app.TaskCustomIdTake(Type, customId)
|
||||||
|
if query.Id != 0 {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
return app.Db.Create(&Task{
|
||||||
|
Status: TASK_IN,
|
||||||
|
Params: gojson.JsonEncodeNoError(params),
|
||||||
|
StatusDesc: "首次添加任务",
|
||||||
|
Frequency: frequency,
|
||||||
|
RunId: gouuid.GetUuId(),
|
||||||
|
CustomId: customId,
|
||||||
|
Type: Type,
|
||||||
|
CreatedIp: app.OutsideIp,
|
||||||
|
UpdatedIp: app.OutsideIp,
|
||||||
|
CreatedAt: gotime.Current().Format(),
|
||||||
|
UpdatedAt: gotime.Current().Format(),
|
||||||
|
}).RowsAffected
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddCustomIdMaxNumber 添加任务并设置最大数量
|
||||||
|
func (app *App) AddCustomIdMaxNumber(Type string, params interface{}, frequency int64, customId string, maxNumber int64) int64 {
|
||||||
|
query := app.TaskCustomIdTakeStatus(Type, customId, TASK_IN)
|
||||||
|
if query.Id != 0 {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
return app.Db.Create(&Task{
|
||||||
|
Status: TASK_IN,
|
||||||
|
Params: gojson.JsonEncodeNoError(params),
|
||||||
|
StatusDesc: "首次添加任务",
|
||||||
|
Frequency: frequency,
|
||||||
|
MaxNumber: maxNumber,
|
||||||
|
RunId: gouuid.GetUuId(),
|
||||||
|
CustomId: customId,
|
||||||
|
Type: Type,
|
||||||
|
CreatedIp: app.OutsideIp,
|
||||||
|
UpdatedIp: app.OutsideIp,
|
||||||
|
CreatedAt: gotime.Current().Format(),
|
||||||
|
UpdatedAt: gotime.Current().Format(),
|
||||||
|
}).RowsAffected
|
||||||
|
}
|
||||||
|
|
||||||
|
type TaskParams = Task
|
||||||
|
|
||||||
|
// AddInOrder 添加订单可执行任务
|
||||||
|
func (app *App) AddInOrder(Type string, params interface{}, frequency int64) int64 {
|
||||||
|
var param TaskParams
|
||||||
|
param.Type = Type
|
||||||
|
param.Frequency = frequency
|
||||||
|
param.ParamsType = ParamsOrderType
|
||||||
|
return app.AddIn(param, params)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddInOrderCustomId 添加订单可执行任务
|
||||||
|
func (app *App) AddInOrderCustomId(Type string, params interface{}, frequency int64, customId string) int64 {
|
||||||
|
query := app.TaskCustomIdTakeStatus(Type, customId, TASK_IN)
|
||||||
|
if query.Id != 0 {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
var param TaskParams
|
||||||
|
param.Type = Type
|
||||||
|
param.Frequency = frequency
|
||||||
|
param.CustomId = customId
|
||||||
|
param.ParamsType = ParamsOrderType
|
||||||
|
return app.AddIn(param, params)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddInOrderCustomIdSpecifyIp 添加订单可执行任务
|
||||||
|
func (app *App) AddInOrderCustomIdSpecifyIp(Type string, params interface{}, frequency int64, customId, specifyIp string) int64 {
|
||||||
|
query := app.TaskCustomIdTakeStatus(Type, customId, TASK_IN)
|
||||||
|
if query.Id != 0 {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
var param TaskParams
|
||||||
|
param.Type = Type
|
||||||
|
param.Frequency = frequency
|
||||||
|
param.CustomId = customId
|
||||||
|
param.SpecifyIp = specifyIp
|
||||||
|
param.ParamsType = ParamsOrderType
|
||||||
|
return app.AddIn(param, params)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddInMerchantGoldenBean 添加商家金豆可执行任务
|
||||||
|
func (app *App) AddInMerchantGoldenBean(Type string, params interface{}, frequency int64) int64 {
|
||||||
|
var param TaskParams
|
||||||
|
param.Type = Type
|
||||||
|
param.Frequency = frequency
|
||||||
|
param.ParamsType = ParamsMerchantGoldenBeanType
|
||||||
|
return app.AddIn(param, params)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddInTeamInv 添加团队邀请可执行任务
|
||||||
|
func (app *App) AddInTeamInv(Type string, params interface{}, frequency int64) int64 {
|
||||||
|
var param TaskParams
|
||||||
|
param.Type = Type
|
||||||
|
param.Frequency = frequency
|
||||||
|
param.ParamsType = ParamsTeamInvType
|
||||||
|
return app.AddIn(param, params)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddInNewService 添加企业自定义可执行任务
|
||||||
|
func (app *App) AddInNewService(Type string, params interface{}, frequency int64) int64 {
|
||||||
|
var param TaskParams
|
||||||
|
param.Type = Type
|
||||||
|
param.Frequency = frequency
|
||||||
|
param.ParamsType = ParamsNewServiceType
|
||||||
|
return app.AddIn(param, params)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddInNewServiceNext 添加企业自定义下一步可执行任务
|
||||||
|
func (app *App) AddInNewServiceNext(param TaskParams, params interface{}) int64 {
|
||||||
|
param.ParamsType = ParamsNewServiceNextType
|
||||||
|
return app.AddIn(param, params)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddInRepairMerchantAccountQuantity 添加可执行任务
|
||||||
|
func (app *App) AddInRepairMerchantAccountQuantity() int64 {
|
||||||
|
var param TaskParams
|
||||||
|
param.Type = TypeRepairMerchantAccountQuantityTesting
|
||||||
|
param.Frequency = 90000
|
||||||
|
return app.AddIn(param, map[string]interface{}{})
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddInRepairMerchantAccountQuantityLevel 添加修复商家账号数量下一步可执行任务
|
||||||
|
func (app *App) AddInRepairMerchantAccountQuantityLevel(param TaskParams, params interface{}) int64 {
|
||||||
|
param.ParamsType = ParamsRepairMerchantAccountQuantityLevelType
|
||||||
|
return app.AddIn(param, params)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddInOrderCustomIdObservation 添加观察接口任务
|
||||||
|
func (app *App) AddInOrderCustomIdObservation(Type string, customId string) int64 {
|
||||||
|
query := app.TaskCustomIdTakeStatus(Type, customId, TASK_IN)
|
||||||
|
if query.Id != 0 {
|
||||||
|
return query.Id
|
||||||
|
}
|
||||||
|
var param TaskParams
|
||||||
|
param.Type = Type
|
||||||
|
param.Frequency = 3600
|
||||||
|
param.MaxNumber = 24 * 5 // 一个星期
|
||||||
|
param.CustomId = customId
|
||||||
|
param.ParamsType = ParamsOrderType
|
||||||
|
return app.AddIn(param, ParamsOrderId{
|
||||||
|
OrderId: customId,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddInOrderCustomIdObservationClone 观察接口关闭
|
||||||
|
func (app *App) AddInOrderCustomIdObservationClone(Type string, customId string) int64 {
|
||||||
|
query := app.TaskCustomIdTakeStatus(Type, customId, TASK_IN)
|
||||||
|
if query.Id == 0 {
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
return app.Edit(query.Id).Select("status", "status_desc", "run_id", "updated_ip", "updated_at").Updates(Task{
|
||||||
|
Status: TASK_SUCCESS,
|
||||||
|
StatusDesc: "已完成,停止观察",
|
||||||
|
RunId: gouuid.GetUuId(),
|
||||||
|
UpdatedIp: app.OutsideIp,
|
||||||
|
UpdatedAt: gotime.Current().Format(),
|
||||||
|
}).RowsAffected
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddIn 添加可执行任务
|
||||||
|
// params.Type 任务类型
|
||||||
|
// params.Frequency 任务频率
|
||||||
|
// params.CustomId 自定义编号
|
||||||
|
// params 任务参数
|
||||||
|
func (app *App) AddIn(param TaskParams, params interface{}) int64 {
|
||||||
|
param.Status = TASK_IN
|
||||||
|
param.StatusDesc = "首次添加任务"
|
||||||
|
param.RunId = gouuid.GetUuId()
|
||||||
|
param.Params = gojson.JsonEncodeNoError(params)
|
||||||
|
param.CreatedIp = app.OutsideIp
|
||||||
|
param.UpdatedIp = app.OutsideIp
|
||||||
|
param.CreatedAt = gotime.Current().Format()
|
||||||
|
param.UpdatedAt = gotime.Current().Format()
|
||||||
|
return app.Db.Create(¶m).RowsAffected
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddWaitNewServiceNext 添加企业自定义下一步等待执行任务
|
||||||
|
func (app *App) AddWaitNewServiceNext(param TaskParams, params interface{}) int64 {
|
||||||
|
param.ParamsType = ParamsNewServiceNextType
|
||||||
|
return app.AddWait(param, params)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddWaitRepairMerchantAccountQuantityLevel 添加修复商家账号数量下一步等待执行任务
|
||||||
|
func (app *App) AddWaitRepairMerchantAccountQuantityLevel(param TaskParams, params interface{}) int64 {
|
||||||
|
param.ParamsType = ParamsRepairMerchantAccountQuantityLevelType
|
||||||
|
return app.AddWait(param, params)
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddInKashangwlPriceCustomId 添加刷新卡商网价格任务
|
||||||
|
func (app *App) AddInKashangwlPriceCustomId(productId int64) int64 {
|
||||||
|
query := app.TaskCustomIdTakeStatus(TypeSyncGoodsPriceSingleKashangwl, fmt.Sprintf("%v", productId), TASK_IN)
|
||||||
|
if query.Id != 0 {
|
||||||
|
return query.Id
|
||||||
|
}
|
||||||
|
var param TaskParams
|
||||||
|
param.Type = TypeSyncGoodsPriceSingleKashangwl
|
||||||
|
param.Frequency = 1800
|
||||||
|
param.CustomId = fmt.Sprintf("%v", productId)
|
||||||
|
param.ParamsType = ParamsKashangwlType
|
||||||
|
return app.AddIn(param, ParamsKashangwlId{
|
||||||
|
ProductID: productId,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// AddWait 添加等待执行任务
|
||||||
|
// params.Type 任务类型
|
||||||
|
// params.Frequency 任务频率
|
||||||
|
// params.CustomId 自定义编号
|
||||||
|
// params.CustomSequence 自定义顺序
|
||||||
|
// params 任务参数
|
||||||
|
func (app *App) AddWait(param TaskParams, params interface{}) int64 {
|
||||||
|
param.Status = TASK_WAIT
|
||||||
|
param.StatusDesc = "首次添加任务"
|
||||||
|
param.RunId = gouuid.GetUuId()
|
||||||
|
param.Params = gojson.JsonEncodeNoError(params)
|
||||||
|
param.CreatedIp = app.OutsideIp
|
||||||
|
param.UpdatedIp = app.OutsideIp
|
||||||
|
param.CreatedAt = gotime.Current().Format()
|
||||||
|
param.UpdatedAt = gotime.Current().Format()
|
||||||
|
return app.Db.Create(¶m).RowsAffected
|
||||||
|
}
|
||||||
|
|
||||||
|
// Edit 任务修改
|
||||||
|
func (app *App) Edit(id int64) *gorm.DB {
|
||||||
|
return app.Db.Model(&Task{}).Where("id = ?", id)
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateFrequency 更新任务频率
|
||||||
|
func (app *App) UpdateFrequency(id, frequency int64) *gorm.DB {
|
||||||
|
return app.Edit(id).Updates(map[string]interface{}{
|
||||||
|
"frequency": frequency,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Start 任务启动
|
||||||
|
func (app *App) Start(customId string, customSequence int64) int64 {
|
||||||
|
return app.Db.Model(&Task{}).
|
||||||
|
Where("custom_id = ?", customId).
|
||||||
|
Where("custom_sequence = ?", customSequence).
|
||||||
|
Where("status = ?", TASK_WAIT).
|
||||||
|
Select("status", "status_desc", "updated_ip", "updated_at").Updates(Task{
|
||||||
|
Status: TASK_IN,
|
||||||
|
StatusDesc: "启动任务",
|
||||||
|
UpdatedIp: app.OutsideIp,
|
||||||
|
UpdatedAt: gotime.Current().Format(),
|
||||||
|
}).RowsAffected
|
||||||
|
}
|
||||||
|
|
||||||
|
// RunAddLog 任务执行日志
|
||||||
|
func (app *App) RunAddLog(id int64, runId string) int64 {
|
||||||
|
return app.Db.Create(&TaskLogRun{
|
||||||
|
TaskId: id,
|
||||||
|
RunId: runId,
|
||||||
|
InsideIp: app.InsideIp,
|
||||||
|
OutsideIp: app.OutsideIp,
|
||||||
|
Os: app.Os,
|
||||||
|
Arch: app.Arch,
|
||||||
|
Gomaxprocs: app.MaxProCs,
|
||||||
|
GoVersion: app.Version,
|
||||||
|
MacAddrs: app.MacAddrS,
|
||||||
|
CreatedAt: gotime.Current().Format(),
|
||||||
|
}).RowsAffected
|
||||||
|
}
|
||||||
|
|
||||||
|
type CronParamsResp struct {
|
||||||
|
ParamsOrderId
|
||||||
|
ParamsMerchantUserIdOpenid
|
||||||
|
ParamsTaskId
|
||||||
|
ParamsTaskIdNext
|
||||||
|
ParamsWechat
|
||||||
|
ParamsTeamInv
|
||||||
|
ParamsRepairMerchantAccountQuantityLevel
|
||||||
|
}
|
||||||
|
|
||||||
|
// Run 任务执行
|
||||||
|
func (app *App) Run(info Task, status int, desc string) {
|
||||||
|
// 请求函数记录
|
||||||
|
app.Db.Create(&TaskLog{
|
||||||
|
TaskId: info.Id,
|
||||||
|
StatusCode: status,
|
||||||
|
Desc: desc,
|
||||||
|
Version: app.RunVersion,
|
||||||
|
CreatedAt: gotime.Current().Format(),
|
||||||
|
})
|
||||||
|
if status == 0 {
|
||||||
|
app.Edit(info.Id).Select("run_id").Updates(Task{
|
||||||
|
RunId: gouuid.GetUuId(),
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 任务
|
||||||
|
if status == http.StatusOK {
|
||||||
|
// 执行成功
|
||||||
|
app.Edit(info.Id).Select("status_desc", "number", "run_id", "updated_ip", "updated_at", "result").Updates(Task{
|
||||||
|
StatusDesc: "执行成功",
|
||||||
|
Number: info.Number + 1,
|
||||||
|
RunId: gouuid.GetUuId(),
|
||||||
|
UpdatedIp: app.OutsideIp,
|
||||||
|
UpdatedAt: gotime.Current().Format(),
|
||||||
|
Result: desc,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if status == http.StatusCreated {
|
||||||
|
// 执行成功、提前结束
|
||||||
|
app.Edit(info.Id).Select("status", "status_desc", "number", "updated_ip", "updated_at", "result").Updates(Task{
|
||||||
|
Status: TASK_SUCCESS,
|
||||||
|
StatusDesc: "结束执行",
|
||||||
|
Number: info.Number + 1,
|
||||||
|
UpdatedIp: app.OutsideIp,
|
||||||
|
UpdatedAt: gotime.Current().Format(),
|
||||||
|
Result: desc,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if status == http.StatusInternalServerError {
|
||||||
|
// 执行失败
|
||||||
|
app.Edit(info.Id).Select("status_desc", "number", "run_id", "updated_ip", "updated_at", "result").Updates(Task{
|
||||||
|
StatusDesc: "执行失败",
|
||||||
|
Number: info.Number + 1,
|
||||||
|
RunId: gouuid.GetUuId(),
|
||||||
|
UpdatedIp: app.OutsideIp,
|
||||||
|
UpdatedAt: gotime.Current().Format(),
|
||||||
|
Result: desc,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
if info.MaxNumber != 0 {
|
||||||
|
if info.Number+1 >= info.MaxNumber {
|
||||||
|
// 关闭执行
|
||||||
|
app.Edit(info.Id).Select("status").Updates(Task{
|
||||||
|
Status: TASK_TIMEOUT,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,35 @@
|
|||||||
|
package jobs
|
||||||
|
|
||||||
|
import (
|
||||||
|
"dtapps/dta/library/utils/goredis"
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Lock 上锁
|
||||||
|
func (app *App) Lock(info Task, id any) string {
|
||||||
|
cacheName := fmt.Sprintf("cron:%v:%v", info.Type, id)
|
||||||
|
judgeCache := app.Redis.NewStringOperation().Get(cacheName).UnwrapOr("")
|
||||||
|
if judgeCache != "" {
|
||||||
|
return judgeCache
|
||||||
|
}
|
||||||
|
app.Redis.NewStringOperation().Set(cacheName, fmt.Sprintf("已在%v机器上锁成功", app.OutsideIp), goredis.WithExpire(time.Millisecond*time.Duration(info.Frequency)*3))
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unlock Lock 解锁
|
||||||
|
func (app *App) Unlock(info Task, id any) {
|
||||||
|
cacheName := fmt.Sprintf("cron:%v:%v", info.Type, id)
|
||||||
|
app.Redis.NewStringOperation().Del(cacheName)
|
||||||
|
}
|
||||||
|
|
||||||
|
// LockForever 永远上锁
|
||||||
|
func (app *App) LockForever(info Task, id any) string {
|
||||||
|
cacheName := fmt.Sprintf("cron:%v:%v", info.Type, id)
|
||||||
|
judgeCache := app.Redis.NewStringOperation().Get(cacheName).UnwrapOr("")
|
||||||
|
if judgeCache != "" {
|
||||||
|
return judgeCache
|
||||||
|
}
|
||||||
|
app.Redis.NewStringOperation().Set(cacheName, fmt.Sprintf("已在%v机器永远上锁成功", app.OutsideIp))
|
||||||
|
return ""
|
||||||
|
}
|
@ -0,0 +1,169 @@
|
|||||||
|
package jobs
|
||||||
|
|
||||||
|
import (
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
TASK_IN = "IN" // 任务运行
|
||||||
|
TASK_SUCCESS = "SUCCESS" // 任务完成
|
||||||
|
TASK_ERROR = "ERROR" // 任务异常
|
||||||
|
TASK_TIMEOUT = "TIMEOUT" // 任务超时
|
||||||
|
TASK_WAIT = "WAIT" // 任务等待
|
||||||
|
)
|
||||||
|
|
||||||
|
// Task 任务
|
||||||
|
type Task struct {
|
||||||
|
Id int64
|
||||||
|
Status string `gorm:"type:text" json:"status"` // 状态码
|
||||||
|
Params string `gorm:"type:text" json:"params"` // 参数
|
||||||
|
ParamsType string `gorm:"type:text" json:"params_type"` // 参数类型
|
||||||
|
StatusDesc string `gorm:"type:text" json:"status_desc"` // 状态描述
|
||||||
|
Frequency int64 `gorm:"type:bigint" json:"frequency"` // 频率(秒单位)
|
||||||
|
Number int64 `gorm:"type:bigint" json:"number"` // 当前次数
|
||||||
|
MaxNumber int64 `gorm:"type:bigint" json:"max_number"` // 最大次数
|
||||||
|
RunId string `gorm:"type:text" json:"run_id"` // 执行编号
|
||||||
|
CustomId string `gorm:"type:text" json:"custom_id"` // 自定义编号
|
||||||
|
CustomSequence int64 `gorm:"type:bigint" json:"custom_sequence"` // 自定义顺序
|
||||||
|
Type string `gorm:"type:text" json:"type"` // 类型
|
||||||
|
CreatedIp string `gorm:"type:text" json:"created_ip"` // 创建外网IP
|
||||||
|
SpecifyIp string `gorm:"type:text" json:"specify_ip"` // 指定外网IP
|
||||||
|
UpdatedIp string `gorm:"type:text" json:"updated_ip"` // 更新外网IP
|
||||||
|
Result string `gorm:"type:text" json:"result"` // 结果
|
||||||
|
CreatedAt string `gorm:"type:text" json:"created_at"` // 创建时间
|
||||||
|
UpdatedAt string `gorm:"type:text" json:"updated_at"` // 更新时间
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Task) TableName() string {
|
||||||
|
return "task"
|
||||||
|
}
|
||||||
|
|
||||||
|
// TaskTake 查询任务
|
||||||
|
func (app *App) TaskTake(customId string) (result Task) {
|
||||||
|
app.Db.Where("custom_id = ?", customId).Where("status = ?", TASK_IN).Take(&result)
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
// TaskCustomIdTake 查询任务
|
||||||
|
func (app *App) TaskCustomIdTake(Type, customId string) (result Task) {
|
||||||
|
app.Db.Where("type = ?", Type).Where("custom_id = ?", customId).Take(&result)
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
// TaskCustomIdTakeStatus 查询任务
|
||||||
|
func (app *App) TaskCustomIdTakeStatus(Type, customId, status string) (result Task) {
|
||||||
|
app.Db.Where("type = ?", Type).Where("custom_id = ?", customId).Where("status = ?", status).Take(&result)
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
// TaskFind 查询任务
|
||||||
|
func (app *App) TaskFind(frequency int) (results []Task) {
|
||||||
|
app.Db.Table("task").Select("task.*").Where("task.frequency = ?", frequency).Where("task.status = ?", TASK_IN).Where("task_ip.ips = ?", app.OutsideIp).Order("task.id asc").Joins("left join task_ip on task_ip.task_type = task.type").Find(&results)
|
||||||
|
return app.taskFindCheck(results)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查任务
|
||||||
|
func (app *App) taskFindCheck(lists []Task) (results []Task) {
|
||||||
|
for _, v := range lists {
|
||||||
|
if v.SpecifyIp == "" {
|
||||||
|
results = append(results, v)
|
||||||
|
} else {
|
||||||
|
if app.OutsideIp == v.SpecifyIp {
|
||||||
|
results = append(results, v)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return results
|
||||||
|
}
|
||||||
|
|
||||||
|
// TaskLog 任务日志
|
||||||
|
type TaskLog struct {
|
||||||
|
Id int64
|
||||||
|
TaskId int64 `gorm:"type:bigint" json:"task_id"` // 任务编号
|
||||||
|
StatusCode int `gorm:"type:bigint" json:"status_code"` // 状态码
|
||||||
|
Desc string `gorm:"type:text" json:"desc"` // 结果
|
||||||
|
Version int `gorm:"type:bigint" json:"version"` // 版本
|
||||||
|
CreatedAt string `gorm:"type:text" json:"created_at"` // 创建时间
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *TaskLog) TableName() string {
|
||||||
|
return "task_log"
|
||||||
|
}
|
||||||
|
|
||||||
|
// TaskLogRun 任务执行日志
|
||||||
|
type TaskLogRun struct {
|
||||||
|
Id int64
|
||||||
|
TaskId int64 `gorm:"type:bigint" json:"task_id"` // 任务编号
|
||||||
|
RunId string `gorm:"type:text" json:"run_id"` // 执行编号
|
||||||
|
OutsideIp string `gorm:"type:text" json:"outside_ip"` // 外网ip
|
||||||
|
InsideIp string `gorm:"type:text" json:"inside_ip"` // 内网ip
|
||||||
|
Os string `gorm:"type:text" json:"os"` // 系统类型
|
||||||
|
Arch string `gorm:"type:text" json:"arch"` // 系统架构
|
||||||
|
Gomaxprocs int `gorm:"type:bigint" json:"gomaxprocs"` // CPU核数
|
||||||
|
GoVersion string `gorm:"type:text" json:"go_version"` // GO版本
|
||||||
|
MacAddrs string `gorm:"type:text" json:"mac_addrs"` // Mac地址
|
||||||
|
CreatedAt string `gorm:"type:text" json:"created_at"` // 创建时间
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *TaskLogRun) TableName() string {
|
||||||
|
return "task_log_run"
|
||||||
|
}
|
||||||
|
|
||||||
|
// TaskLogRunTake 查询任务执行日志
|
||||||
|
func (app *App) TaskLogRunTake(taskId int64, runId string) (result TaskLogRun) {
|
||||||
|
app.Db.Select("id", "os", "arch", "outside_ip", "created_at").Where("task_id = ?", taskId).Where("run_id = ?", runId).Take(&result)
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
// TaskIp 任务Ip
|
||||||
|
type TaskIp struct {
|
||||||
|
Id int64
|
||||||
|
TaskType string `gorm:"type:text" json:"task_type"` // 任务编号
|
||||||
|
Ips string `gorm:"type:text" json:"ips"` // 任务IP
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *TaskIp) TableName() string {
|
||||||
|
return "task_ip"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (app *App) TaskIpUpdate(taskType, ips string) int64 {
|
||||||
|
var query TaskIp
|
||||||
|
app.Db.Where("task_type = ?", taskType).Where("ips = ?", ips).Take(&query)
|
||||||
|
if query.Id != 0 {
|
||||||
|
return query.Id
|
||||||
|
}
|
||||||
|
return app.Db.Create(&TaskIp{
|
||||||
|
TaskType: taskType,
|
||||||
|
Ips: ips,
|
||||||
|
}).RowsAffected
|
||||||
|
}
|
||||||
|
|
||||||
|
// TaskIpInit 实例任务ip
|
||||||
|
func (app *App) TaskIpInit(ips map[string]string) bool {
|
||||||
|
if app.OutsideIp == "" || app.OutsideIp == "0.0.0.0" {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
app.Db.Where("ips = ?", app.OutsideIp).Delete(&TaskIp{}) // 删除
|
||||||
|
for k, v := range ips {
|
||||||
|
if v == "" {
|
||||||
|
app.TaskIpUpdate(k, app.OutsideIp)
|
||||||
|
} else {
|
||||||
|
find := strings.Contains(v, ",")
|
||||||
|
if find == true {
|
||||||
|
// 包含
|
||||||
|
parts := strings.Split(v, ",")
|
||||||
|
for _, vv := range parts {
|
||||||
|
if vv == app.OutsideIp {
|
||||||
|
app.TaskIpUpdate(k, app.OutsideIp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 不包含
|
||||||
|
if v == app.OutsideIp {
|
||||||
|
app.TaskIpUpdate(k, app.OutsideIp)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
@ -0,0 +1,168 @@
|
|||||||
|
package jobs
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
var ParamsOrderType = "order"
|
||||||
|
|
||||||
|
// ParamsOrderId 订单任务
|
||||||
|
type ParamsOrderId struct {
|
||||||
|
OrderId string `json:"order_id,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
var ParamsMerchantGoldenBeanType = "merchant.golden_bean"
|
||||||
|
|
||||||
|
// ParamsMerchantUserIdOpenid 商家金豆任务
|
||||||
|
type ParamsMerchantUserIdOpenid struct {
|
||||||
|
MerchantUserId int64 `json:"merchant_user_id,omitempty"`
|
||||||
|
Openid string `json:"openid,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
var ParamsNewServiceType = "new_service"
|
||||||
|
|
||||||
|
// ParamsTaskId 企业自定义任务
|
||||||
|
type ParamsTaskId struct {
|
||||||
|
TaskId int64 `json:"task_id,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
var ParamsNewServiceNextType = "new_service.next"
|
||||||
|
|
||||||
|
// ParamsTaskIdNext 企业自定义下一步任务
|
||||||
|
type ParamsTaskIdNext struct {
|
||||||
|
TaskId int64 `json:"task_id,omitempty"`
|
||||||
|
MerchantUserId int64 `json:"merchant_user_id,omitempty"`
|
||||||
|
CurrentNumber int `json:"current_number,omitempty"`
|
||||||
|
MaxNumber int `json:"max_number,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
var ParamsWechatType = "wechat"
|
||||||
|
|
||||||
|
// ParamsWechat 微信任务
|
||||||
|
type ParamsWechat struct {
|
||||||
|
Appid string `json:"appid,omitempty"`
|
||||||
|
Type string `json:"type,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
var ParamsTeamInvType = "team.inv"
|
||||||
|
|
||||||
|
// ParamsTeamInv 团队邀请任务
|
||||||
|
type ParamsTeamInv struct {
|
||||||
|
MerchantUserId int64 `json:"merchant_user_id,omitempty"`
|
||||||
|
Openid string `json:"openid,omitempty"`
|
||||||
|
ShareOpenid string `json:"share_openid,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
var ParamsRepairMerchantAccountQuantityLevelType = "repair.merchant.account.quantity.level"
|
||||||
|
|
||||||
|
// ParamsRepairMerchantAccountQuantityLevel 修复商家账号数量下一步任务
|
||||||
|
type ParamsRepairMerchantAccountQuantityLevel struct {
|
||||||
|
Level int `json:"level,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
|
var ParamsKashangwlType = "kashangwl"
|
||||||
|
|
||||||
|
type ParamsKashangwlId struct {
|
||||||
|
ProductID int64 `json:"product_id"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// Params 任务参数
|
||||||
|
func Params(v Task) (response CronParamsResp, err error) {
|
||||||
|
switch v.ParamsType {
|
||||||
|
case ParamsOrderType:
|
||||||
|
// 订单任务
|
||||||
|
var resp ParamsOrderId
|
||||||
|
err = json.Unmarshal([]byte(v.Params), &resp)
|
||||||
|
if err != nil {
|
||||||
|
return response, errors.New(fmt.Sprintf("解析失败,%v", err))
|
||||||
|
}
|
||||||
|
if resp.OrderId == "" {
|
||||||
|
return response, errors.New("参数不存在")
|
||||||
|
}
|
||||||
|
response.ParamsOrderId.OrderId = resp.OrderId
|
||||||
|
return response, nil
|
||||||
|
case ParamsMerchantGoldenBeanType:
|
||||||
|
// 商家金豆任务
|
||||||
|
var resp ParamsMerchantUserIdOpenid
|
||||||
|
err = json.Unmarshal([]byte(v.Params), &resp)
|
||||||
|
if err != nil {
|
||||||
|
return response, errors.New(fmt.Sprintf("解析失败,%v", err))
|
||||||
|
}
|
||||||
|
if resp.MerchantUserId == 0 || resp.Openid == "" {
|
||||||
|
return response, errors.New("参数不存在")
|
||||||
|
}
|
||||||
|
response.ParamsMerchantUserIdOpenid.MerchantUserId = resp.MerchantUserId
|
||||||
|
response.ParamsMerchantUserIdOpenid.Openid = resp.Openid
|
||||||
|
return response, nil
|
||||||
|
case ParamsNewServiceType:
|
||||||
|
// 企业自定义任务
|
||||||
|
var resp ParamsTaskId
|
||||||
|
err = json.Unmarshal([]byte(v.Params), &resp)
|
||||||
|
if err != nil {
|
||||||
|
return response, errors.New(fmt.Sprintf("解析失败,%v", err))
|
||||||
|
}
|
||||||
|
if resp.TaskId == 0 {
|
||||||
|
return response, errors.New("参数不存在")
|
||||||
|
}
|
||||||
|
response.ParamsTaskId.TaskId = resp.TaskId
|
||||||
|
return response, nil
|
||||||
|
case ParamsNewServiceNextType:
|
||||||
|
// 企业自定义下一步任务
|
||||||
|
var resp ParamsTaskIdNext
|
||||||
|
err = json.Unmarshal([]byte(v.Params), &resp)
|
||||||
|
if err != nil {
|
||||||
|
return response, errors.New(fmt.Sprintf("解析失败,%v", err))
|
||||||
|
}
|
||||||
|
if resp.TaskId == 0 || resp.MerchantUserId == 0 || resp.CurrentNumber == 0 || resp.MaxNumber == 0 {
|
||||||
|
return response, errors.New("参数不存在")
|
||||||
|
}
|
||||||
|
response.ParamsTaskIdNext.TaskId = resp.TaskId
|
||||||
|
response.ParamsTaskIdNext.MerchantUserId = resp.MerchantUserId
|
||||||
|
response.ParamsTaskIdNext.CurrentNumber = resp.CurrentNumber
|
||||||
|
response.ParamsTaskIdNext.MaxNumber = resp.MaxNumber
|
||||||
|
return response, nil
|
||||||
|
case ParamsWechatType:
|
||||||
|
// 微信任务
|
||||||
|
var resp ParamsWechat
|
||||||
|
err = json.Unmarshal([]byte(v.Params), &resp)
|
||||||
|
if err != nil {
|
||||||
|
return response, errors.New(fmt.Sprintf("解析失败,%v", err))
|
||||||
|
}
|
||||||
|
if resp.Appid == "" || resp.Type == "" {
|
||||||
|
return response, errors.New("参数不存在")
|
||||||
|
}
|
||||||
|
response.ParamsWechat.Appid = resp.Appid
|
||||||
|
response.ParamsWechat.Type = resp.Type
|
||||||
|
return response, nil
|
||||||
|
case ParamsTeamInvType:
|
||||||
|
// 团队邀请任务
|
||||||
|
var resp ParamsTeamInv
|
||||||
|
err = json.Unmarshal([]byte(v.Params), &resp)
|
||||||
|
if err != nil {
|
||||||
|
return response, errors.New(fmt.Sprintf("解析失败,%v", err))
|
||||||
|
}
|
||||||
|
if resp.MerchantUserId == 0 || resp.Openid == "" || resp.ShareOpenid == "" {
|
||||||
|
return response, errors.New("参数不存在")
|
||||||
|
}
|
||||||
|
response.ParamsTeamInv.MerchantUserId = resp.MerchantUserId
|
||||||
|
response.ParamsTeamInv.Openid = resp.Openid
|
||||||
|
response.ParamsTeamInv.ShareOpenid = resp.ShareOpenid
|
||||||
|
return response, nil
|
||||||
|
case ParamsRepairMerchantAccountQuantityLevelType:
|
||||||
|
// 修复商家账号数量下一步任务
|
||||||
|
var resp ParamsRepairMerchantAccountQuantityLevel
|
||||||
|
err = json.Unmarshal([]byte(v.Params), &resp)
|
||||||
|
if err != nil {
|
||||||
|
return response, errors.New(fmt.Sprintf("解析失败,%v", err))
|
||||||
|
}
|
||||||
|
if resp.Level == 0 {
|
||||||
|
return response, errors.New("参数不存在")
|
||||||
|
}
|
||||||
|
response.ParamsRepairMerchantAccountQuantityLevel.Level = resp.Level
|
||||||
|
return response, nil
|
||||||
|
default:
|
||||||
|
return response, nil
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,161 @@
|
|||||||
|
package jobs
|
||||||
|
|
||||||
|
const (
|
||||||
|
// 微信支付查询
|
||||||
|
TypeWechatPayPrepaidRefill = "wechat.pay.prepaid_refill" //【话费充值】
|
||||||
|
TypeWechatPayPower = "wechat.pay.power" //【电费充值】
|
||||||
|
TypeWechatPayKashangwl = "wechat.pay.kashangwl" //【特惠充值】
|
||||||
|
TypeWechatPayEastiot = "wechat.pay.eastiot" //【东方物联】
|
||||||
|
TypeWechatPayEjiaofei = "wechat.pay.ejiaofei" //【易缴费】
|
||||||
|
TypeWechatPayMovie = "wechat.pay.movie" //【守兔】
|
||||||
|
|
||||||
|
// 接口支付申请
|
||||||
|
TypeApiPaySubmitPrepaidRefill = "api.pay.submit.prepaid_refill" //【话费充值】
|
||||||
|
TypeApiPaySubmitPower = "api.pay.submit.power" //【电费充值】
|
||||||
|
TypeApiPaySubmitKashangwl = "api.pay.submit.kashangwl" //【特惠充值】
|
||||||
|
TypeApiPaySubmitEastiot = "api.pay.submit.eastiot" //【东方物联】
|
||||||
|
TypeApiPaySubmitEjiaofei = "api.pay.submit.ejiaofei" //【易缴费】
|
||||||
|
TypeApiPaySubmitMovie = "api.pay.submit.movie" //【守兔】
|
||||||
|
|
||||||
|
// 接口支付查询
|
||||||
|
TypeApiPayQueryPrepaidRefill = "api.pay.query.prepaid_refill" //【话费充值】
|
||||||
|
TypeApiPayQueryPower = "api.pay.query.power" //【电费充值】
|
||||||
|
TypeApiPayQueryKashangwl = "api.pay.query.kashangwl" //【特惠充值】
|
||||||
|
TypeApiPayQueryEastiot = "api.pay.query.eastiot" //【东方物联】
|
||||||
|
TypeApiPayQueryEjiaofei = "api.pay.query.ejiaofei" //【易缴费】
|
||||||
|
TypeApiPayQueryMovie = "api.pay.query.movie" //【守兔】
|
||||||
|
TypeApiPayQueryPinduoduo = "api.pay.query.pinduoduo" //【拼多多】
|
||||||
|
TypeApiPayQueryMeituan = "api.pay.query.meituan" //【美团】
|
||||||
|
|
||||||
|
// 微信支付退款申请
|
||||||
|
TypeWechatRefundsSubmitPrepaidRefill = "wechat.refunds.submit.prepaid_refill" //【话费充值】
|
||||||
|
TypeWechatRefundsSubmitPower = "wechat.refunds.submit.power" //【电费充值】
|
||||||
|
TypeWechatRefundsSubmitKashangwl = "wechat.refunds.submit.kashangwl" //【特惠充值】
|
||||||
|
TypeWechatRefundsSubmitEastiot = "wechat.refunds.submit.eastiot" //【东方物联】
|
||||||
|
TypeWechatRefundsSubmitEjiaofei = "wechat.refunds.submit.ejiaofei" //【易缴费】
|
||||||
|
TypeWechatRefundsSubmitMovie = "wechat.refunds.submit.movie" //【守兔】
|
||||||
|
|
||||||
|
// 微信支付退款查询
|
||||||
|
TypeWechatRefundsQueryPrepaidRefill = "wechat.refunds.query.prepaid_refill" //【话费充值】
|
||||||
|
TypeWechatRefundsQueryPower = "wechat.refunds.query.power" //【电费充值】
|
||||||
|
TypeWechatRefundsQueryKashangwl = "wechat.refunds.query.kashangwl" //【特惠充值】
|
||||||
|
TypeWechatRefundsQueryEastiot = "wechat.refunds.query.eastiot" //【东方物联】
|
||||||
|
TypeWechatRefundsQueryEjiaofei = "wechat.refunds.query.ejiaofei" //【易缴费】
|
||||||
|
TypeWechatRefundsQueryMovie = "wechat.refunds.query.movie" //【守兔】
|
||||||
|
|
||||||
|
// 返拥
|
||||||
|
TypeGoldenBeansIssuePrepaidRefill = "golden_beans.issue.prepaid_refill" //【话费充值】
|
||||||
|
TypeGoldenBeansIssuePower = "golden_beans.issue.power" //【电费充值】
|
||||||
|
TypeGoldenBeansIssueKashangwl = "golden_beans.issue.kashangwl" //【特惠充值】
|
||||||
|
TypeGoldenBeansIssueEastiot = "golden_beans.issue.eastiot" //【东方物联】
|
||||||
|
TypeGoldenBeansIssueMovie = "golden_beans.issue.movie" //【守兔】
|
||||||
|
TypeGoldenBeansIssueRewardedvideo = "golden_beans.issue.rewardedvideo" //【激励视频】
|
||||||
|
|
||||||
|
// TypeGoldenBeansFrozenPinduoduo 【拼多多】冻结返拥金豆
|
||||||
|
TypeGoldenBeansFrozenPinduoduo = "golden_beans.frozen.pinduoduo"
|
||||||
|
// TypeGoldenBeansFrozenMeituan 【美团】冻结返拥金豆
|
||||||
|
TypeGoldenBeansFrozenMeituan = "golden_beans.frozen.meituan"
|
||||||
|
|
||||||
|
// TypeGoldenBeansThawSuccessPinduoduo 【拼多多】解冻返拥金豆正常发放
|
||||||
|
TypeGoldenBeansThawSuccessPinduoduo = "golden_beans.thaw.success.pinduoduo"
|
||||||
|
// TypeGoldenBeansThawSuccessMeituan 【美团】解冻返拥金豆正常发放
|
||||||
|
TypeGoldenBeansThawSuccessMeituan = "golden_beans.thaw.success.meituan"
|
||||||
|
|
||||||
|
// TypeGoldenBeansThawErrorPinduoduo 【拼多多】解冻返拥金豆扣款
|
||||||
|
TypeGoldenBeansThawErrorPinduoduo = "golden_beans.thaw.error.pinduoduo"
|
||||||
|
// TypeGoldenBeansThawErrorMeituan 【美团】解冻返拥金豆扣款
|
||||||
|
TypeGoldenBeansThawErrorMeituan = "golden_beans.thaw.error.meituan"
|
||||||
|
|
||||||
|
// 抵扣金豆退款
|
||||||
|
TypeGoldenBeansRefundsPrepaidRefill = "golden_beans.refunds.prepaid_refill" //【话费充值】
|
||||||
|
TypeGoldenBeansRefundsPower = "golden_beans.refunds.power" //【电费充值】
|
||||||
|
|
||||||
|
// 金豆退款
|
||||||
|
TypeGoldenBeansRefundsEjiaofei = "golden_beans.refunds.ejiaofei" //【易缴费】
|
||||||
|
|
||||||
|
// 客服进度
|
||||||
|
TypeCustomerAutoPrepaidRefill = "customer.auto.prepaid_refill" //【话费充值】
|
||||||
|
TypeCustomerAutoPower = "customer.auto.power" //【电费充值】
|
||||||
|
TypeCustomerAutoKashangwl = "customer.auto.kashangwl" //【特惠充值】
|
||||||
|
TypeCustomerAutoEjiaofei = "customer.auto.ejiaofei" //【易缴费】
|
||||||
|
TypeCustomerAutoMovie = "customer.auto.movie" //【守兔】
|
||||||
|
|
||||||
|
// 订单同步
|
||||||
|
TypeSyncOrderPinduoduo = "sync.order.pinduoduo" //【拼多多】
|
||||||
|
TypeSyncOrderMeituan = "sync.order.meituan" //【美团】
|
||||||
|
|
||||||
|
// 商品同步
|
||||||
|
TypeSyncGoodsEastiot = "sync.goods.eastiot" //【东方物联】
|
||||||
|
TypeSyncGoodsTypeEastiot = "sync.goods.type.eastiot" //【东方物联】
|
||||||
|
TypeSyncGoodsPriceAllKashangwl = "sync.goods.price.all.kashangwl" //【特惠充值】
|
||||||
|
TypeSyncGoodsPriceSingleKashangwl = "sync.goods.price.single.kashangwl" //【特惠充值】
|
||||||
|
TypeCheckGoodsAllPinduoduo = "check.goods.all.pinduoduo" //【拼多多】
|
||||||
|
TypeCheckGoodsSinglePinduoduo = "check.goods.single.pinduoduo" //【拼多多】
|
||||||
|
|
||||||
|
// 微信更新
|
||||||
|
TypeSyncWechat = "sync.wechat" //【微信】token/ticket同步
|
||||||
|
|
||||||
|
// 商家金豆转换
|
||||||
|
TypeGoldenBeanConversionUserGoldenBean = "admin.golden_bean.conversion.user.golden_bean" //【商家金豆】转用户金豆
|
||||||
|
TypeGoldenBeanConversionUserDeductGoldenBean = "admin.golden_bean.conversion.user.deduct.golden_bean" //【商家金豆】转用户抵扣金豆
|
||||||
|
|
||||||
|
// 企业自定义
|
||||||
|
TypeNewServiceAgentIssue = "new_service.agent.issue" //【企业自定义】【代理商】下发检查
|
||||||
|
TypeNewServiceAgentIssueNext = "new_service.agent.issue.next" //【企业自定义】【代理商】下发到商家
|
||||||
|
|
||||||
|
// 团队
|
||||||
|
TypeTeamInv = "team.inv" //【团队邀请】
|
||||||
|
|
||||||
|
// 修复商家账号数量
|
||||||
|
TypeRepairMerchantAccountQuantityTesting = "repair_merchant.account.quantity.testing" //【修复】【商家账号】【数量】查询出等级进行下一步
|
||||||
|
TypeRepairMerchantAccountQuantityLevel = "repair_merchant.account.quantity.level" //【修复】【商家账号】【数量】通过等级来修复
|
||||||
|
|
||||||
|
// 观察接口
|
||||||
|
TypeApiPayObservationPrepaidRefill = "api.pay.observation.prepaid_refill" //{600}【话费充值】
|
||||||
|
TypeApiPayObservationPower = "api.pay.observation.power" //{600}【电费充值】
|
||||||
|
TypeApiPayObservationKashangwl = "api.pay.observation.kashangwl" //{600}【特惠充值】
|
||||||
|
TypeApiPayObservationEjiaofei = "api.pay.observation.ejiaofei" //{600}【易缴费】
|
||||||
|
TypeApiPayObservationMovie = "api.pay.observation.movie" //{600}【守兔】
|
||||||
|
TypeApiPayObservationPinduoduo = "api.pay.observation.pinduoduo" //{600}【拼多多】
|
||||||
|
TypeApiPayObservationMeituan = "api.pay.observation.meituan" //{600}【美团】
|
||||||
|
TypeApiPayObservationWechat = "api.pay.observation.wechat" //{600}【微信支付】
|
||||||
|
TypeApiPayObservationWechatRefunds = "api.pay.observation.wechat.refunds" //{600}【微信支付退款】
|
||||||
|
TypeApiPayObservationWechatWithdrawal = "api.pay.observation.wechat.withdrawal" //{600}【微信支付提现】
|
||||||
|
|
||||||
|
// 微信提现
|
||||||
|
TypeWechatPayWithdrawalSubmit = "wechat.pay.withdrawal.submit" // 微信支付提现申请
|
||||||
|
TypeWechatPayWithdrawalQuery = "wechat.pay.withdrawal.query" // 微信支付提现查询
|
||||||
|
TypeWechatPayWithdrawalRefunds = "wechat.pay.withdrawal.refunds" // 微信支付提现退款
|
||||||
|
)
|
||||||
|
|
||||||
|
func GetTypeWechatPay(Type string) string {
|
||||||
|
return "wechat.pay." + Type
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetTypeApiPaySubmit(Type string) string {
|
||||||
|
return "api.pay.submit." + Type
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetTypeApiPayQuery(Type string) string {
|
||||||
|
return "api.pay.query." + Type
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetTypeWechatRefundsSubmit(Type string) string {
|
||||||
|
return "wechat.refunds.submit." + Type
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetTypeWechatRefundsQuery(Type string) string {
|
||||||
|
return "wechat.refunds.query." + Type
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetTypeGoldenBeansIssue(Type string) string {
|
||||||
|
return "golden_beans.issue." + Type
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetTypeGoldenBeansRefunds(Type string) string {
|
||||||
|
return "golden_beans.refunds." + Type
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetTypeCustomerAuto(Type string) string {
|
||||||
|
return "customer.auto." + Type
|
||||||
|
}
|
@ -0,0 +1,34 @@
|
|||||||
|
package kashangwl
|
||||||
|
|
||||||
|
import "encoding/json"
|
||||||
|
|
||||||
|
type ApiCustomerResponse struct {
|
||||||
|
Code string `json:"code"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
Data struct {
|
||||||
|
Id int `json:"id"` // 商家编号
|
||||||
|
Name string `json:"name"` // 商家名称
|
||||||
|
Balance string `json:"balance"` // 余额
|
||||||
|
} `json:"data"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ApiCustomerResult struct {
|
||||||
|
Result ApiCustomerResponse // 结果
|
||||||
|
Body []byte // 内容
|
||||||
|
Err error // 错误
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewApiCustomerResult(result ApiCustomerResponse, body []byte, err error) *ApiCustomerResult {
|
||||||
|
return &ApiCustomerResult{Result: result, Body: body, Err: err}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ApiCustomer 获取商家信息
|
||||||
|
// http://doc.cqmeihu.cn/sales/merchant-info.html
|
||||||
|
func (app *App) ApiCustomer() *ApiCustomerResult {
|
||||||
|
// 请求
|
||||||
|
body, err := app.request("http://www.kashangwl.com/api/customer", map[string]interface{}{})
|
||||||
|
// 定义
|
||||||
|
var response ApiCustomerResponse
|
||||||
|
err = json.Unmarshal(body, &response)
|
||||||
|
return NewApiCustomerResult(response, body, err)
|
||||||
|
}
|
@ -0,0 +1,40 @@
|
|||||||
|
package kashangwl
|
||||||
|
|
||||||
|
import "encoding/json"
|
||||||
|
|
||||||
|
type ApiProductRechargeParamsResponse struct {
|
||||||
|
Code string `json:"code"`
|
||||||
|
Message string `json:"message"`
|
||||||
|
Data struct {
|
||||||
|
RechargeAccountLabel string `json:"recharge_account_label"`
|
||||||
|
RechargeParams []struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
Options string `json:"options"`
|
||||||
|
} `json:"recharge_params"`
|
||||||
|
} `json:"data"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type ApiProductRechargeParamsResult struct {
|
||||||
|
Result ApiProductRechargeParamsResponse // 结果
|
||||||
|
Body []byte // 内容
|
||||||
|
Err error // 错误
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewApiProductRechargeParamsResult(result ApiProductRechargeParamsResponse, body []byte, err error) *ApiProductRechargeParamsResult {
|
||||||
|
return &ApiProductRechargeParamsResult{Result: result, Body: body, Err: err}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ApiProductRechargeParams 接口说明
|
||||||
|
// 获取商品的充值参数(仅支持充值类商品)
|
||||||
|
// http://doc.cqmeihu.cn/sales/ProductParams.html
|
||||||
|
func (app App) ApiProductRechargeParams(notMustParams ...Params) *ApiProductRechargeParamsResult {
|
||||||
|
// 参数
|
||||||
|
params := app.NewParamsWith(notMustParams...)
|
||||||
|
// 请求
|
||||||
|
body, err := app.request("http://www.kashangwl.com/api/product/recharge-params", params)
|
||||||
|
// 定义
|
||||||
|
var response ApiProductRechargeParamsResponse
|
||||||
|
err = json.Unmarshal(body, &response)
|
||||||
|
return NewApiProductRechargeParamsResult(response, body, err)
|
||||||
|
}
|
@ -1,33 +0,0 @@
|
|||||||
module github.com/dtapps/go-library/service/kashangwl
|
|
||||||
|
|
||||||
go 1.18
|
|
||||||
|
|
||||||
require (
|
|
||||||
github.com/dtapps/go-library/utils/gohttp v0.0.0-20220320040709-ad8a5f0e9e40
|
|
||||||
github.com/dtapps/go-library/utils/goparams v0.0.0-20220320040709-ad8a5f0e9e40
|
|
||||||
github.com/go-redis/redis/v8 v8.11.5
|
|
||||||
go.mongodb.org/mongo-driver v1.8.4
|
|
||||||
go.uber.org/zap v1.21.0
|
|
||||||
gorm.io/gorm v1.23.3
|
|
||||||
)
|
|
||||||
|
|
||||||
require (
|
|
||||||
github.com/cespare/xxhash/v2 v2.1.2 // indirect
|
|
||||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
|
|
||||||
github.com/go-stack/stack v1.8.0 // indirect
|
|
||||||
github.com/golang/snappy v0.0.1 // indirect
|
|
||||||
github.com/jinzhu/inflection v1.0.0 // indirect
|
|
||||||
github.com/jinzhu/now v1.1.4 // indirect
|
|
||||||
github.com/klauspost/compress v1.13.6 // indirect
|
|
||||||
github.com/nilorg/sdk v0.0.0-20210429091026-95b6cdc95c84 // indirect
|
|
||||||
github.com/pkg/errors v0.9.1 // indirect
|
|
||||||
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
|
|
||||||
github.com/xdg-go/scram v1.0.2 // indirect
|
|
||||||
github.com/xdg-go/stringprep v1.0.2 // indirect
|
|
||||||
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
|
|
||||||
go.uber.org/atomic v1.7.0 // indirect
|
|
||||||
go.uber.org/multierr v1.6.0 // indirect
|
|
||||||
golang.org/x/crypto v0.0.0-20201216223049-8b5274cf687f // indirect
|
|
||||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
|
|
||||||
golang.org/x/text v0.3.6 // indirect
|
|
||||||
)
|
|
@ -0,0 +1,47 @@
|
|||||||
|
package kashangwl
|
||||||
|
|
||||||
|
import (
|
||||||
|
"dtapps/dta/library/utils/gohttp"
|
||||||
|
"encoding/json"
|
||||||
|
"gitee.com/dtapps/go-library/utils/gotime"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 日志
|
||||||
|
type mongoZap struct {
|
||||||
|
Url string `json:"url" bson:"url"`
|
||||||
|
Params interface{} `json:"params" bson:"params"`
|
||||||
|
Method string `json:"method" bson:"method"`
|
||||||
|
Header interface{} `json:"header" bson:"header"`
|
||||||
|
Status string `json:"status" bson:"status"`
|
||||||
|
StatusCode int `json:"status_code" bson:"status_code"`
|
||||||
|
Body interface{} `json:"body" bson:"body"`
|
||||||
|
ContentLength int64 `json:"content_length" bson:"content_length"`
|
||||||
|
CreateTime string `json:"create_time" bson:"create_time"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mongoZap) Database() string {
|
||||||
|
return "zap_logs"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mongoZap) TableName() string {
|
||||||
|
return "kashangwl_" + gotime.Current().SetFormat("200601")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (app *App) mongoLog(url string, params map[string]interface{}, method string, request gohttp.Response) {
|
||||||
|
if app.Mongo.Db == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var body map[string]interface{}
|
||||||
|
_ = json.Unmarshal(request.Body, &body)
|
||||||
|
app.Mongo.Model(&mongoZap{}).InsertOne(mongoZap{
|
||||||
|
Url: url,
|
||||||
|
Params: params,
|
||||||
|
Method: method,
|
||||||
|
Header: request.Header,
|
||||||
|
Status: request.Status,
|
||||||
|
StatusCode: request.StatusCode,
|
||||||
|
Body: body,
|
||||||
|
ContentLength: request.ContentLength,
|
||||||
|
CreateTime: gotime.Current().Format(),
|
||||||
|
})
|
||||||
|
}
|
@ -1,40 +0,0 @@
|
|||||||
package kashangwl
|
|
||||||
|
|
||||||
import "encoding/json"
|
|
||||||
|
|
||||||
type ProductRechargeParamsResponse struct {
|
|
||||||
Code string `json:"code"`
|
|
||||||
Message string `json:"message"`
|
|
||||||
Data struct {
|
|
||||||
RechargeAccountLabel string `json:"recharge_account_label"`
|
|
||||||
RechargeParams []struct {
|
|
||||||
Name string `json:"name"`
|
|
||||||
Type string `json:"type"`
|
|
||||||
Options string `json:"options"`
|
|
||||||
} `json:"recharge_params"`
|
|
||||||
} `json:"data"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type ProductRechargeParamsResult struct {
|
|
||||||
Result ProductRechargeParamsResponse // 结果
|
|
||||||
Body []byte // 内容
|
|
||||||
Err error // 错误
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewProductRechargeParamsResult(result ProductRechargeParamsResponse, body []byte, err error) *ProductRechargeParamsResult {
|
|
||||||
return &ProductRechargeParamsResult{Result: result, Body: body, Err: err}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ProductRechargeParams 接口说明
|
|
||||||
// 获取商品的充值参数(仅支持充值类商品)
|
|
||||||
// http://doc.cqmeihu.cn/sales/ProductParams.html
|
|
||||||
func (app App) ProductRechargeParams(notMustParams ...Params) *ProductRechargeParamsResult {
|
|
||||||
// 参数
|
|
||||||
params := app.NewParamsWith(notMustParams...)
|
|
||||||
// 请求
|
|
||||||
body, err := app.request("http://www.kashangwl.com/api/product/recharge-params", params)
|
|
||||||
// 定义
|
|
||||||
var response ProductRechargeParamsResponse
|
|
||||||
err = json.Unmarshal(body, &response)
|
|
||||||
return NewProductRechargeParamsResult(response, body, err)
|
|
||||||
}
|
|
@ -0,0 +1,40 @@
|
|||||||
|
package leshuazf
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
type DataAreaResponse struct {
|
||||||
|
RespCode string `json:"respCode"`
|
||||||
|
RespMsg string `json:"respMsg"`
|
||||||
|
ReqSerialNo string `json:"reqSerialNo"`
|
||||||
|
Data []struct {
|
||||||
|
AreaName string `json:"areaName"`
|
||||||
|
AreaCode string `json:"areaCode"`
|
||||||
|
ParentAreaCode string `json:"parentAreaCode"`
|
||||||
|
} `json:"data"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type DataAreaResult struct {
|
||||||
|
Result DataAreaResponse // 结果
|
||||||
|
Body []byte // 内容
|
||||||
|
Err error // 错误
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewDataAreaResult(result DataAreaResponse, body []byte, err error) *DataAreaResult {
|
||||||
|
return &DataAreaResult{Result: result, Body: body, Err: err}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DataArea 代理商通过地区信息来查地区详细信息
|
||||||
|
// https://www.yuque.com/leshuazf/doc/dbmxyi#YwJl7
|
||||||
|
func (app *App) DataArea(notMustParams ...Params) *DataAreaResult {
|
||||||
|
// 参数
|
||||||
|
params := app.NewParamsWith(notMustParams...)
|
||||||
|
// 请求
|
||||||
|
body, err := app.request("data/area", params, http.MethodPost)
|
||||||
|
// 定义
|
||||||
|
var response DataAreaResponse
|
||||||
|
err = json.Unmarshal(body, &response)
|
||||||
|
return NewDataAreaResult(response, body, err)
|
||||||
|
}
|
@ -0,0 +1,53 @@
|
|||||||
|
package leshuazf
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
type DataBankBranch2Response struct {
|
||||||
|
RespCode string `json:"respCode"`
|
||||||
|
RespMsg string `json:"respMsg"`
|
||||||
|
ReqSerialNo string `json:"reqSerialNo"`
|
||||||
|
Data struct {
|
||||||
|
Total int `json:"total"`
|
||||||
|
Page int `json:"page"`
|
||||||
|
PageSize int `json:"pageSize"`
|
||||||
|
List []struct {
|
||||||
|
UnionpayCode string `json:"unionpayCode"`
|
||||||
|
FinInstitutionCode string `json:"finInstitutionCode"`
|
||||||
|
BankArea string `json:"bankArea"`
|
||||||
|
BankCity string `json:"bankCity"`
|
||||||
|
BranchName string `json:"branchName"`
|
||||||
|
CftAreaCode string `json:"cftAreaCode"`
|
||||||
|
CftCityCode string `json:"cftCityCode"`
|
||||||
|
UnionAreaCode interface{} `json:"unionAreaCode"`
|
||||||
|
UnionCityCode interface{} `json:"unionCityCode"`
|
||||||
|
FinInstitutionName string `json:"finInstitutionName"`
|
||||||
|
BankName string `json:"bankName"`
|
||||||
|
} `json:"list"`
|
||||||
|
} `json:"data"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type DataBankBranch2Result struct {
|
||||||
|
Result DataBankBranch2Response // 结果
|
||||||
|
Body []byte // 内容
|
||||||
|
Err error // 错误
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewDataBankBranch2Result(result DataBankBranch2Response, body []byte, err error) *DataBankBranch2Result {
|
||||||
|
return &DataBankBranch2Result{Result: result, Body: body, Err: err}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DataBankBranch2 代理商通过联行号来查支行信息
|
||||||
|
// https://www.yuque.com/leshuazf/doc/dbmxyi#QYl0c
|
||||||
|
func (app *App) DataBankBranch2(notMustParams ...Params) *DataBankBranch2Result {
|
||||||
|
// 参数
|
||||||
|
params := app.NewParamsWith(notMustParams...)
|
||||||
|
// 请求
|
||||||
|
body, err := app.request("data/bankbranch2", params, http.MethodPost)
|
||||||
|
// 定义
|
||||||
|
var response DataBankBranch2Response
|
||||||
|
err = json.Unmarshal(body, &response)
|
||||||
|
return NewDataBankBranch2Result(response, body, err)
|
||||||
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
package leshuazf
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
type DataMccResponse struct {
|
||||||
|
RespCode string `json:"respCode"`
|
||||||
|
RespMsg string `json:"respMsg"`
|
||||||
|
ReqSerialNo string `json:"reqSerialNo"`
|
||||||
|
Data []struct {
|
||||||
|
GrandpaCode string `json:"grandpaCode"`
|
||||||
|
GrandpaText string `json:"grandpaText"`
|
||||||
|
} `json:"data"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type DataMccResult struct {
|
||||||
|
Result DataMccResponse // 结果
|
||||||
|
Body []byte // 内容
|
||||||
|
Err error // 错误
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewDataMccResult(result DataMccResponse, body []byte, err error) *DataMccResult {
|
||||||
|
return &DataMccResult{Result: result, Body: body, Err: err}
|
||||||
|
}
|
||||||
|
|
||||||
|
// DataMcc 代理商通过MccCode来查商户类别明细
|
||||||
|
// https://www.yuque.com/leshuazf/doc/dbmxyi#jRTHN
|
||||||
|
func (app *App) DataMcc(notMustParams ...Params) *DataMccResult {
|
||||||
|
// 参数
|
||||||
|
params := app.NewParamsWith(notMustParams...)
|
||||||
|
// 请求
|
||||||
|
body, err := app.request("data/mcc", params, http.MethodPost)
|
||||||
|
// 定义
|
||||||
|
var response DataMccResponse
|
||||||
|
err = json.Unmarshal(body, &response)
|
||||||
|
return NewDataMccResult(response, body, err)
|
||||||
|
}
|
@ -0,0 +1,47 @@
|
|||||||
|
package leshuazf
|
||||||
|
|
||||||
|
import (
|
||||||
|
"dtapps/dta/library/utils/gohttp"
|
||||||
|
"encoding/json"
|
||||||
|
"gitee.com/dtapps/go-library/utils/gotime"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 日志
|
||||||
|
type mongoZap struct {
|
||||||
|
Url string `json:"url" bson:"url"`
|
||||||
|
Params interface{} `json:"params" bson:"params"`
|
||||||
|
Method string `json:"method" bson:"method"`
|
||||||
|
Header interface{} `json:"header" bson:"header"`
|
||||||
|
Status string `json:"status" bson:"status"`
|
||||||
|
StatusCode int `json:"status_code" bson:"status_code"`
|
||||||
|
Body interface{} `json:"body" bson:"body"`
|
||||||
|
ContentLength int64 `json:"content_length" bson:"content_length"`
|
||||||
|
CreateTime string `json:"create_time" bson:"create_time"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mongoZap) Database() string {
|
||||||
|
return "zap_logs"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mongoZap) TableName() string {
|
||||||
|
return "leshuazf_" + gotime.Current().SetFormat("200601")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (app *App) mongoLog(url string, params map[string]interface{}, method string, request gohttp.Response) {
|
||||||
|
if app.Mongo.Db == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var body map[string]interface{}
|
||||||
|
_ = json.Unmarshal(request.Body, &body)
|
||||||
|
app.Mongo.Model(&mongoZap{}).InsertOne(mongoZap{
|
||||||
|
Url: url,
|
||||||
|
Params: params,
|
||||||
|
Method: method,
|
||||||
|
Header: request.Header,
|
||||||
|
Status: request.Status,
|
||||||
|
StatusCode: request.StatusCode,
|
||||||
|
Body: body,
|
||||||
|
ContentLength: request.ContentLength,
|
||||||
|
CreateTime: gotime.Current().Format(),
|
||||||
|
})
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
package leshuazf
|
||||||
|
|
||||||
|
// Params 请求参数
|
||||||
|
type Params map[string]interface{}
|
||||||
|
|
||||||
|
func NewParams() Params {
|
||||||
|
p := make(Params)
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (app *App) NewParamsWith(params ...Params) Params {
|
||||||
|
p := make(Params)
|
||||||
|
for _, v := range params {
|
||||||
|
p.SetParams(v)
|
||||||
|
}
|
||||||
|
return p
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p Params) Set(key string, value interface{}) {
|
||||||
|
p[key] = value
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p Params) SetParams(params Params) {
|
||||||
|
for key, value := range params {
|
||||||
|
p[key] = value
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1 @@
|
|||||||
|
package leshuazf
|
@ -0,0 +1,21 @@
|
|||||||
|
package leshuazf
|
||||||
|
|
||||||
|
import (
|
||||||
|
"dtapps/dta/library/utils/gobase64"
|
||||||
|
"encoding/json"
|
||||||
|
"gitee.com/dtapps/go-library/utils/gomd5"
|
||||||
|
"sort"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 数据签名
|
||||||
|
// https://www.yuque.com/leshuazf/doc/dbmxyi#Nr9Ps
|
||||||
|
func (app *App) getSign(params map[string]interface{}) string {
|
||||||
|
// 参数按照参数名的字典升序排列
|
||||||
|
var keys []string
|
||||||
|
for k := range params {
|
||||||
|
keys = append(keys, k)
|
||||||
|
}
|
||||||
|
sort.Strings(keys)
|
||||||
|
str, _ := json.Marshal(keys) // data字符串值
|
||||||
|
return gobase64.Encode(gomd5.ToLower("lepos" + app.KeyAgent + string(str)))
|
||||||
|
}
|
@ -1,32 +0,0 @@
|
|||||||
module github.com/dtapps/go-library/service/meituan
|
|
||||||
|
|
||||||
go 1.18
|
|
||||||
|
|
||||||
require (
|
|
||||||
github.com/dtapps/go-library/utils/gohttp v0.0.0-20220320040709-ad8a5f0e9e40
|
|
||||||
github.com/dtapps/go-library/utils/gotime v0.0.0-20220320040709-ad8a5f0e9e40
|
|
||||||
github.com/go-redis/redis/v8 v8.11.5
|
|
||||||
go.mongodb.org/mongo-driver v1.8.4
|
|
||||||
go.uber.org/zap v1.21.0
|
|
||||||
gorm.io/gorm v1.23.3
|
|
||||||
)
|
|
||||||
|
|
||||||
require (
|
|
||||||
github.com/cespare/xxhash/v2 v2.1.2 // indirect
|
|
||||||
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
|
|
||||||
github.com/go-stack/stack v1.8.0 // indirect
|
|
||||||
github.com/golang/snappy v0.0.1 // indirect
|
|
||||||
github.com/jinzhu/inflection v1.0.0 // indirect
|
|
||||||
github.com/jinzhu/now v1.1.4 // indirect
|
|
||||||
github.com/klauspost/compress v1.13.6 // indirect
|
|
||||||
github.com/pkg/errors v0.9.1 // indirect
|
|
||||||
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
|
|
||||||
github.com/xdg-go/scram v1.0.2 // indirect
|
|
||||||
github.com/xdg-go/stringprep v1.0.2 // indirect
|
|
||||||
github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect
|
|
||||||
go.uber.org/atomic v1.7.0 // indirect
|
|
||||||
go.uber.org/multierr v1.6.0 // indirect
|
|
||||||
golang.org/x/crypto v0.0.0-20201216223049-8b5274cf687f // indirect
|
|
||||||
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
|
|
||||||
golang.org/x/text v0.3.6 // indirect
|
|
||||||
)
|
|
@ -0,0 +1,47 @@
|
|||||||
|
package meituan
|
||||||
|
|
||||||
|
import (
|
||||||
|
"dtapps/dta/library/utils/gohttp"
|
||||||
|
"encoding/json"
|
||||||
|
"gitee.com/dtapps/go-library/utils/gotime"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 日志
|
||||||
|
type mongoZap struct {
|
||||||
|
Url string `json:"url" bson:"url"`
|
||||||
|
Params interface{} `json:"params" bson:"params"`
|
||||||
|
Method string `json:"method" bson:"method"`
|
||||||
|
Header interface{} `json:"header" bson:"header"`
|
||||||
|
Status string `json:"status" bson:"status"`
|
||||||
|
StatusCode int `json:"status_code" bson:"status_code"`
|
||||||
|
Body interface{} `json:"body" bson:"body"`
|
||||||
|
ContentLength int64 `json:"content_length" bson:"content_length"`
|
||||||
|
CreateTime string `json:"create_time" bson:"create_time"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mongoZap) Database() string {
|
||||||
|
return "zap_logs"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mongoZap) TableName() string {
|
||||||
|
return "meituan_" + gotime.Current().SetFormat("200601")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (app *App) mongoLog(url string, params map[string]interface{}, method string, request gohttp.Response) {
|
||||||
|
if app.Mongo.Db == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var body map[string]interface{}
|
||||||
|
_ = json.Unmarshal(request.Body, &body)
|
||||||
|
app.Mongo.Model(&mongoZap{}).InsertOne(mongoZap{
|
||||||
|
Url: url,
|
||||||
|
Params: params,
|
||||||
|
Method: method,
|
||||||
|
Header: request.Header,
|
||||||
|
Status: request.Status,
|
||||||
|
StatusCode: request.StatusCode,
|
||||||
|
Body: body,
|
||||||
|
ContentLength: request.ContentLength,
|
||||||
|
CreateTime: gotime.Current().Format(),
|
||||||
|
})
|
||||||
|
}
|
@ -0,0 +1,36 @@
|
|||||||
|
package gitee
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GetAccessToken 请求参数
|
||||||
|
type GetAccessToken struct {
|
||||||
|
Code string
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetAccessTokenResult 返回参数
|
||||||
|
type GetAccessTokenResult struct {
|
||||||
|
AccessToken string `json:"access_token"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetAccessToken OAuth2 获取 AccessToken 认证步骤 https://gitee.com/api/v5/oauth_doc#/list-item-2
|
||||||
|
func (app *App) GetAccessToken(param GetAccessToken) (result GetAccessTokenResult, err error) {
|
||||||
|
url := fmt.Sprintf("https://gitee.com/oauth/token?grant_type=authorization_code&code=%s&client_id=%s&redirect_uri=%s&client_secret=%s", param.Code, app.ClientID, app.RedirectUri, app.ClientSecret)
|
||||||
|
|
||||||
|
// api params
|
||||||
|
params := map[string]interface{}{}
|
||||||
|
|
||||||
|
// common params
|
||||||
|
|
||||||
|
// request
|
||||||
|
body, err := app.request(url, params, "POST")
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err = json.Unmarshal(body, &result); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
@ -0,0 +1,53 @@
|
|||||||
|
package gitee
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// UserResult 返回参数
|
||||||
|
type UserResult struct {
|
||||||
|
Id int64 `json:"id"`
|
||||||
|
Login string `json:"login"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
AvatarUrl string `json:"avatar_url"`
|
||||||
|
Url string `json:"url"`
|
||||||
|
HtmlUrl string `json:"html_url"`
|
||||||
|
FollowersUrl string `json:"followers_url"`
|
||||||
|
FollowingUrl string `json:"following_url"`
|
||||||
|
GistsUrl string `json:"gists_url"`
|
||||||
|
StarredUrl string `json:"starred_url"`
|
||||||
|
SubscriptionsUrl string `json:"subscriptions_url"`
|
||||||
|
OrganizationsUrl string `json:"organizations_url"`
|
||||||
|
ReposUrl string `json:"repos_url"`
|
||||||
|
EventsUrl string `json:"events_url"`
|
||||||
|
ReceivedEventsUrl string `json:"received_events_url"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
Blog string `json:"blog"`
|
||||||
|
Weibo string `json:"weibo"`
|
||||||
|
Bio string `json:"bio"`
|
||||||
|
PublicRepos int `json:"public_repos"`
|
||||||
|
PublicGists int `json:"public_gists"`
|
||||||
|
Followers int `json:"followers"`
|
||||||
|
Following int `json:"following"`
|
||||||
|
Stared int `json:"stared"`
|
||||||
|
Watched int `json:"watched"`
|
||||||
|
CreatedAt time.Time `json:"created_at"`
|
||||||
|
UpdatedAt time.Time `json:"updated_at"`
|
||||||
|
Email string `json:"email"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// User 获取授权用户的资料 https://gitee.com/api/v5/swagger#/getV5User
|
||||||
|
func (app *App) User() (result UserResult, err error) {
|
||||||
|
// request
|
||||||
|
body, err := app.request(fmt.Sprintf("https://gitee.com/api/v5/user?access_token=%s", app.AccessToken), map[string]interface{}{}, "GET")
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err = json.Unmarshal(body, &result); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
package gitee
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"io/ioutil"
|
||||||
|
|
||||||
|
"net/http"
|
||||||
|
// "strconv"
|
||||||
|
)
|
||||||
|
|
||||||
|
// App 基本配置
|
||||||
|
type App struct {
|
||||||
|
ClientID string
|
||||||
|
ClientSecret string
|
||||||
|
RedirectUri string
|
||||||
|
AccessToken string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (app *App) request(url string, params map[string]interface{}, method string) (resp []byte, err error) {
|
||||||
|
// 请求参数
|
||||||
|
marshal, _ := json.Marshal(params)
|
||||||
|
var req *http.Request
|
||||||
|
req, err = http.NewRequest(method, url, bytes.NewReader(marshal))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
httpClient := &http.Client{}
|
||||||
|
var response *http.Response
|
||||||
|
response, err = httpClient.Do(req)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理成功
|
||||||
|
defer response.Body.Close()
|
||||||
|
resp, err = ioutil.ReadAll(response.Body)
|
||||||
|
|
||||||
|
return resp, err
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
package gitee
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
// GetRedirectUri 获取登录地址
|
||||||
|
func (app *App) GetRedirectUri() string {
|
||||||
|
return fmt.Sprintf("https://gitee.com/oauth/authorize?client_id=%s&redirect_uri=%s&response_type=code", app.ClientID, app.RedirectUri)
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
package gitee
|
||||||
|
|
||||||
|
const (
|
||||||
|
GiteeOAuth2AuthorizeServer = "https://gitee.com/oauth/authorize"
|
||||||
|
GiteeOAuth2TokenServer = "https://gitee.com/oauth/token"
|
||||||
|
)
|
@ -0,0 +1,29 @@
|
|||||||
|
package workwechat
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
// AuthAccessTokenResult 返回参数
|
||||||
|
type AuthAccessTokenResult struct {
|
||||||
|
Errcode int `json:"errcode"`
|
||||||
|
Errmsg string `json:"errmsg"`
|
||||||
|
AccessToken string `json:"access_token"`
|
||||||
|
ExpiresIn int `json:"expires_in"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// AuthAccessToken 获取access_token https://open.work.weixin.qq.com/api/doc/90000/90135/91039
|
||||||
|
func (app *App) AuthAccessToken() (result AuthAccessTokenResult, err error) {
|
||||||
|
url := fmt.Sprintf("https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=%s&corpsecret=%s", app.AppID, app.Secret)
|
||||||
|
|
||||||
|
// request
|
||||||
|
body, err := app.request(url, map[string]interface{}{}, "GET")
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err = json.Unmarshal(body, &result); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
package workwechat
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"io/ioutil"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
// App 基本配置
|
||||||
|
type App struct {
|
||||||
|
AppID string
|
||||||
|
AgentID int
|
||||||
|
Secret string
|
||||||
|
RedirectUri string
|
||||||
|
AccessToken string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (app *App) request(url string, params map[string]interface{}, method string) (resp []byte, err error) {
|
||||||
|
// 请求参数
|
||||||
|
marshal, _ := json.Marshal(params)
|
||||||
|
var req *http.Request
|
||||||
|
req, err = http.NewRequest(method, url, bytes.NewReader(marshal))
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
httpClient := &http.Client{}
|
||||||
|
var response *http.Response
|
||||||
|
response, err = httpClient.Do(req)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 处理成功
|
||||||
|
defer response.Body.Close()
|
||||||
|
resp, err = ioutil.ReadAll(response.Body)
|
||||||
|
|
||||||
|
return resp, err
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
package workwechat
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
// GetRedirectUri 构造网页授权链接 https://work.weixin.qq.com/api/doc/90000/90135/91022
|
||||||
|
func (app *App) GetRedirectUri() string {
|
||||||
|
return fmt.Sprintf("https://open.weixin.qq.com/connect/oauth2/authorize?appid=%s&redirect_uri=%s&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect", app.AppID, app.RedirectUri)
|
||||||
|
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue