Compare commits
22 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
58bea0c09a | ||
|
|
50fe34e1c1 | ||
|
|
25c00d5072 | ||
|
|
ee32c8b83d | ||
|
|
12a193fdee | ||
|
|
ca55880beb | ||
|
|
ee9e399a81 | ||
|
|
ed9b0dd248 | ||
|
|
02edbdae8d | ||
|
|
5e75094c16 | ||
|
|
140317e2df | ||
|
|
8e2301eb34 | ||
|
|
c673da89cf | ||
|
|
005cf11b2a | ||
|
|
8195d633a1 | ||
|
|
4741a0bd93 | ||
|
|
f22c9df605 | ||
|
|
82cffdfe29 | ||
|
|
9da1a3bf25 | ||
|
|
2cb005e8ed | ||
|
|
374fdac477 | ||
|
|
595ababfde |
@@ -1,9 +1,9 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/ayflying/utility_go"
|
"github.com/ayflying/utility_go/pkg"
|
||||||
"github.com/gogf/gf/v2/util/gutil"
|
"github.com/gogf/gf/v2/util/gutil"
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
||||||
type {cfg}Cfg struct {
|
type {cfg}Cfg struct {
|
||||||
@@ -23,7 +23,7 @@ func (c *{mod}Mod) Load(_cfg ...string) {
|
|||||||
c.lock.Lock()
|
c.lock.Lock()
|
||||||
defer c.lock.Unlock()
|
defer c.lock.Unlock()
|
||||||
c.cfgArr = make([]*{cfg}Cfg, 0)
|
c.cfgArr = make([]*{cfg}Cfg, 0)
|
||||||
data, err := utility_go.Config.GetFile("{file}")
|
data, err := pkg.Config().GetFile("{file}")
|
||||||
err = data.Scan(&c.cfgArr)
|
err = data.Scan(&c.cfgArr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
|||||||
@@ -124,11 +124,11 @@ var (
|
|||||||
FileUrl: url[v.S3],
|
FileUrl: url[v.S3],
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Proxy := g.Cfg().MustGet(ctx, "update_proxy", "http://192.168.50.170:10808").String()
|
||||||
g.Log().Debugf(ctx, "切换代理进行上传:err=%v", err)
|
g.Log().Debugf(ctx, "切换代理进行上传:err=%v", err)
|
||||||
get, err = client.Proxy("http://192.168.50.114:10808").
|
get, err = client.Proxy(Proxy).Post(ctx, address+"/callback/update", &UpdateReq{
|
||||||
Post(ctx, address+"/callback/update", &UpdateReq{
|
FileUrl: url[v.S3],
|
||||||
FileUrl: url[v.S3],
|
})
|
||||||
})
|
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
g.Log().Error(ctx, err)
|
g.Log().Error(ctx, err)
|
||||||
|
|||||||
@@ -27,26 +27,26 @@ type Cfg struct {
|
|||||||
|
|
||||||
// Deprecated : pkg.Config().GetDbFile(name)
|
// Deprecated : pkg.Config().GetDbFile(name)
|
||||||
func (c *Cfg) GetDbFile(name string) (res *g.Var, err error) {
|
func (c *Cfg) GetDbFile(name string) (res *g.Var, err error) {
|
||||||
pkg.Config().GetDbFile(name)
|
res, err = pkg.Config().GetDbFile(name)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated : pkg.Config().GetFile(name, obj...)
|
// Deprecated : pkg.Config().GetFile(name, obj...)
|
||||||
func (c *Cfg) GetFile(filename string, obj ...Load) (jsonObj *gjson.Json, err error) {
|
func (c *Cfg) GetFile(filename string, obj ...Load) (jsonObj *gjson.Json, err error) {
|
||||||
pkg.Config().GetFile(filename)
|
jsonObj, err = pkg.Config().GetFile(filename)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// getUrlFile 获取远程配置
|
// getUrlFile 获取远程配置
|
||||||
// Deprecated : pkg.Config().GetUrlFile(name)
|
// Deprecated : pkg.Config().GetUrlFile(name)
|
||||||
func (c *Cfg) GetUrlFile(name string) (jsonObj *gjson.Json, err error) {
|
func (c *Cfg) GetUrlFile(name string) (jsonObj *gjson.Json, err error) {
|
||||||
pkg.Config().GetUrlFile(name)
|
jsonObj, err = pkg.Config().GetUrlFile(name)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated : pkg.Config().GetApollo(name, obj)
|
// Deprecated : pkg.Config().GetApollo(name, obj)
|
||||||
func (c *Cfg) GetApollo(name string, obj Load) (jsonObj *gjson.Json, err error) {
|
func (c *Cfg) GetApollo(name string, obj Load) (jsonObj *gjson.Json, err error) {
|
||||||
pkg.Config().GetApollo(name, obj)
|
jsonObj, err = pkg.Config().GetApollo(name, obj)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
7
go.mod
7
go.mod
@@ -4,7 +4,7 @@ go 1.24.0
|
|||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/apolloconfig/agollo/v4 v4.4.0
|
github.com/apolloconfig/agollo/v4 v4.4.0
|
||||||
github.com/ayflying/excel2json v1.1.7
|
github.com/ayflying/excel2json v1.1.9
|
||||||
github.com/elastic/go-elasticsearch/v8 v8.18.0
|
github.com/elastic/go-elasticsearch/v8 v8.18.0
|
||||||
github.com/go-pay/crypto v0.0.1
|
github.com/go-pay/crypto v0.0.1
|
||||||
github.com/go-pay/gopay v1.5.109
|
github.com/go-pay/gopay v1.5.109
|
||||||
@@ -12,7 +12,6 @@ require (
|
|||||||
github.com/goccy/go-json v0.10.5
|
github.com/goccy/go-json v0.10.5
|
||||||
github.com/gogf/gf/contrib/config/apollo/v2 v2.9.0
|
github.com/gogf/gf/contrib/config/apollo/v2 v2.9.0
|
||||||
github.com/gogf/gf/v2 v2.9.0
|
github.com/gogf/gf/v2 v2.9.0
|
||||||
github.com/gorilla/websocket v1.5.3
|
|
||||||
github.com/lionsoul2014/ip2region/binding/golang v0.0.0-20241220152942-06eb5c6e8230
|
github.com/lionsoul2014/ip2region/binding/golang v0.0.0-20241220152942-06eb5c6e8230
|
||||||
github.com/minio/minio-go/v7 v7.0.91
|
github.com/minio/minio-go/v7 v7.0.91
|
||||||
github.com/prometheus/client_golang v1.22.0
|
github.com/prometheus/client_golang v1.22.0
|
||||||
@@ -45,8 +44,11 @@ require (
|
|||||||
github.com/golang/protobuf v1.5.4 // indirect
|
github.com/golang/protobuf v1.5.4 // indirect
|
||||||
github.com/google/uuid v1.6.0 // indirect
|
github.com/google/uuid v1.6.0 // indirect
|
||||||
github.com/googleapis/gax-go/v2 v2.0.5 // indirect
|
github.com/googleapis/gax-go/v2 v2.0.5 // indirect
|
||||||
|
github.com/gorilla/websocket v1.5.3 // indirect
|
||||||
github.com/grokify/html-strip-tags-go v0.1.0 // indirect
|
github.com/grokify/html-strip-tags-go v0.1.0 // indirect
|
||||||
github.com/hashicorp/hcl v1.0.0 // indirect
|
github.com/hashicorp/hcl v1.0.0 // indirect
|
||||||
|
github.com/haxqer/gofunc v0.0.0-20210609183449-586b0cce5fe4 // indirect
|
||||||
|
github.com/haxqer/xthird v0.0.0-20210703071732-ff4f4dbb6e5d // indirect
|
||||||
github.com/klauspost/compress v1.18.0 // indirect
|
github.com/klauspost/compress v1.18.0 // indirect
|
||||||
github.com/klauspost/cpuid/v2 v2.2.10 // indirect
|
github.com/klauspost/cpuid/v2 v2.2.10 // indirect
|
||||||
github.com/magiconair/properties v1.8.9 // indirect
|
github.com/magiconair/properties v1.8.9 // indirect
|
||||||
@@ -60,6 +62,7 @@ require (
|
|||||||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
|
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
|
||||||
github.com/olekukonko/tablewriter v0.0.5 // indirect
|
github.com/olekukonko/tablewriter v0.0.5 // indirect
|
||||||
github.com/pelletier/go-toml v1.9.3 // indirect
|
github.com/pelletier/go-toml v1.9.3 // indirect
|
||||||
|
github.com/pquerna/ffjson v0.0.0-20190930134022-aa0246cd15f7 // indirect
|
||||||
github.com/prometheus/client_model v0.6.1 // indirect
|
github.com/prometheus/client_model v0.6.1 // indirect
|
||||||
github.com/prometheus/common v0.62.0 // indirect
|
github.com/prometheus/common v0.62.0 // indirect
|
||||||
github.com/prometheus/procfs v0.15.1 // indirect
|
github.com/prometheus/procfs v0.15.1 // indirect
|
||||||
|
|||||||
11
go.sum
11
go.sum
@@ -50,8 +50,8 @@ github.com/apolloconfig/agollo/v4 v4.4.0/go.mod h1:6WjI68IzqMk/Y6ghMtrj5AX6Uewo2
|
|||||||
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
|
github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o=
|
||||||
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
|
github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY=
|
||||||
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
|
github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
|
||||||
github.com/ayflying/excel2json v1.1.7 h1:gp4Ls6hNXd1EuT2MEiDQ6yPLaSKIFWkGyaNajMTc59c=
|
github.com/ayflying/excel2json v1.1.9 h1:AKaUFc/FNQXV/53/VSgp3J+2d4PMWhVpTDRj/yx3VOs=
|
||||||
github.com/ayflying/excel2json v1.1.7/go.mod h1:GjXYP2cDzeTgQxssQ3ba8QRa9JsScAeJMwCrZ7QTlQo=
|
github.com/ayflying/excel2json v1.1.9/go.mod h1:GjXYP2cDzeTgQxssQ3ba8QRa9JsScAeJMwCrZ7QTlQo=
|
||||||
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
|
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
|
||||||
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
|
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
|
||||||
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
|
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
|
||||||
@@ -225,6 +225,10 @@ github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO
|
|||||||
github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ=
|
github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ=
|
||||||
github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I=
|
github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I=
|
||||||
github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc=
|
github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc=
|
||||||
|
github.com/haxqer/gofunc v0.0.0-20210609183449-586b0cce5fe4 h1:QQOImHnvEkzqEbozZup+76WLv+W0QhO84GTLHppMY1M=
|
||||||
|
github.com/haxqer/gofunc v0.0.0-20210609183449-586b0cce5fe4/go.mod h1:XQaEUze5QCq3D9oenfHItzPQUD+NGg+0TDt1kJhJAAc=
|
||||||
|
github.com/haxqer/xthird v0.0.0-20210703071732-ff4f4dbb6e5d h1:e2qgvCNjMrp9fNtUQr3gQnK15B0C2CIUjPWMc7jZnbo=
|
||||||
|
github.com/haxqer/xthird v0.0.0-20210703071732-ff4f4dbb6e5d/go.mod h1:9avb74vS4djGUwtueA6V01grbpskLGisSy0jxFZIBY8=
|
||||||
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
|
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
|
||||||
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
|
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
|
||||||
github.com/json-iterator/go v1.1.11/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
github.com/json-iterator/go v1.1.11/go.mod h1:KdQUCv79m/52Kvf8AW2vK1V8akMuk1QjK/uOdHXbAo4=
|
||||||
@@ -296,6 +300,8 @@ github.com/pkg/sftp v1.10.1/go.mod h1:lYOWFsE0bwd1+KfKJaKeuokY15vzFx25BLbzYYoAxZ
|
|||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
|
github.com/posener/complete v1.1.1/go.mod h1:em0nMJCgc9GFtwrmVmEMR/ZL6WyhyjMBndrE9hABlRI=
|
||||||
|
github.com/pquerna/ffjson v0.0.0-20190930134022-aa0246cd15f7 h1:xoIK0ctDddBMnc74udxJYBqlo9Ylnsp1waqjLsnef20=
|
||||||
|
github.com/pquerna/ffjson v0.0.0-20190930134022-aa0246cd15f7/go.mod h1:YARuvh7BUWHNhzDq2OM5tzR2RiCcN2D7sapiKyCel/M=
|
||||||
github.com/prometheus/client_golang v1.22.0 h1:rb93p9lokFEsctTys46VnV1kLCDpVZ0a/Y92Vm0Zc6Q=
|
github.com/prometheus/client_golang v1.22.0 h1:rb93p9lokFEsctTys46VnV1kLCDpVZ0a/Y92Vm0Zc6Q=
|
||||||
github.com/prometheus/client_golang v1.22.0/go.mod h1:R7ljNsLXhuQXYZYtw6GAE9AZg8Y7vEW5scdCXrWRXC0=
|
github.com/prometheus/client_golang v1.22.0/go.mod h1:R7ljNsLXhuQXYZYtw6GAE9AZg8Y7vEW5scdCXrWRXC0=
|
||||||
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||||
@@ -457,6 +463,7 @@ golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e/go.mod h1:qpuaurCH72eLCgpAm/
|
|||||||
golang.org/x/net v0.0.0-20200501053045-e0ff5e5a1de5/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
golang.org/x/net v0.0.0-20200501053045-e0ff5e5a1de5/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
||||||
golang.org/x/net v0.0.0-20200506145744-7e3656a0809f/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
golang.org/x/net v0.0.0-20200506145744-7e3656a0809f/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
||||||
golang.org/x/net v0.0.0-20200513185701-a91f0712d120/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
golang.org/x/net v0.0.0-20200513185701-a91f0712d120/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
||||||
|
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
||||||
golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
||||||
golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
||||||
golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
||||||
|
|||||||
@@ -134,7 +134,8 @@ func (s *sGameAct) Save(ctx context.Context, actId int) (err error) {
|
|||||||
|
|
||||||
//循环获取缓存数据
|
//循环获取缓存数据
|
||||||
err = tools.Redis.RedisScanV2(cacheKey, func(keys []string) (err error) {
|
err = tools.Redis.RedisScanV2(cacheKey, func(keys []string) (err error) {
|
||||||
var add []interface{}
|
var add = make([]*entity.GameAct, 0)
|
||||||
|
var update = make([]*entity.GameAct, 0)
|
||||||
var delKey []string
|
var delKey []string
|
||||||
for _, cacheKey = range keys {
|
for _, cacheKey = range keys {
|
||||||
result := strings.Split(cacheKey, ":")
|
result := strings.Split(cacheKey, ":")
|
||||||
@@ -176,25 +177,51 @@ func (s *sGameAct) Save(ctx context.Context, actId int) (err error) {
|
|||||||
}
|
}
|
||||||
actionData := cacheGet.String()
|
actionData := cacheGet.String()
|
||||||
if data == nil {
|
if data == nil {
|
||||||
//data =
|
add = append(add, &entity.GameAct{
|
||||||
add = append(add, &do.GameAct{
|
|
||||||
ActId: actId,
|
ActId: actId,
|
||||||
Uid: uid,
|
Uid: uid,
|
||||||
Action: actionData,
|
Action: actionData,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
//覆盖数据
|
//覆盖数据
|
||||||
|
data.ActId = actId
|
||||||
|
data.Uid = uid
|
||||||
data.Action = actionData
|
data.Action = actionData
|
||||||
add = append(add, data)
|
update = append(update, data)
|
||||||
}
|
}
|
||||||
//最后删除key
|
//最后删除key
|
||||||
delKey = append(delKey, cacheKey)
|
delKey = append(delKey, cacheKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
//批量写入数据库
|
//批量写入数据库
|
||||||
if len(add) > 0 {
|
if len(delKey) > 0 {
|
||||||
dbRes, err2 := g.Model(Name).Batch(30).Data(add).Save()
|
for _, v := range update {
|
||||||
add = make([]interface{}, 0)
|
v.UpdatedAt = gtime.Now()
|
||||||
|
_, err2 := g.Model(Name).Where(do.GameAct{
|
||||||
|
Uid: v.Uid,
|
||||||
|
ActId: v.ActId,
|
||||||
|
UpdatedAt: v.UpdatedAt,
|
||||||
|
}).Data(v).Update()
|
||||||
|
if err2 != nil {
|
||||||
|
g.Log().Error(ctx, err2)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
////获取多少个数据,删除不是当前修改的数据
|
||||||
|
//count, _ := g.Model(Name).Where(do.GameAct{
|
||||||
|
// Uid: v.Uid,
|
||||||
|
// ActId: v.ActId,
|
||||||
|
//}).Count()
|
||||||
|
//if count > 1 {
|
||||||
|
// g.Model(Name).Where(do.GameAct{
|
||||||
|
// Uid: v.Uid,
|
||||||
|
// ActId: v.ActId,
|
||||||
|
// }).WhereNot("updated_at", v.UpdatedAt).Delete()
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
//dbRes, err2 := g.Model(Name).Batch(50).Data(add).Update()
|
||||||
|
update = make([]*entity.GameAct, 0)
|
||||||
|
dbRes, err2 := g.Model(Name).Batch(50).Data(add).Save()
|
||||||
|
add = make([]*entity.GameAct, 0)
|
||||||
if err2 != nil {
|
if err2 != nil {
|
||||||
g.Log().Error(ctx, err2)
|
g.Log().Error(ctx, err2)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -136,6 +136,10 @@ func (s *sSystemCron) AddCronV2(typ v1.CronType, _func func(context.Context) err
|
|||||||
// @receiver s
|
// @receiver s
|
||||||
// @return err
|
// @return err
|
||||||
func (s *sSystemCron) StartCron() (err error) {
|
func (s *sSystemCron) StartCron() (err error) {
|
||||||
|
//如果没有数据库配置,跳过计划任务执行
|
||||||
|
if g.Cfg().MustGet(gctx.New(), "database") == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
//预防重复启动
|
//预防重复启动
|
||||||
if startTime != nil {
|
if startTime != nil {
|
||||||
return
|
return
|
||||||
|
|||||||
5
modules/websocket/go.mod
Normal file
5
modules/websocket/go.mod
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
module github.com/ayflying/utility_go/modules/websocket
|
||||||
|
|
||||||
|
go 1.24.0
|
||||||
|
|
||||||
|
require github.com/ayflying/utility_go v1.2.26
|
||||||
2
modules/websocket/go.sum
Normal file
2
modules/websocket/go.sum
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
github.com/ayflying/utility_go v1.2.26/go.mod h1:y6qwRUmYk73cH/dTRSzj2mnaQdtrAfFNH4wRFewxlIc=
|
||||||
|
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||||
97
package/pay/oppo/login.go
Normal file
97
package/pay/oppo/login.go
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
package oppo
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"crypto/hmac"
|
||||||
|
"crypto/sha1"
|
||||||
|
"encoding/base64"
|
||||||
|
"github.com/gogf/gf/v2/encoding/gjson"
|
||||||
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
|
"github.com/gogf/gf/v2/os/gtime"
|
||||||
|
"github.com/gogf/gf/v2/util/grand"
|
||||||
|
"io"
|
||||||
|
"net/url"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
const host = "https://iopen.game.heytapmobi.com"
|
||||||
|
|
||||||
|
// oppo参数类型
|
||||||
|
type LoginType struct {
|
||||||
|
Token string `json:"token"`
|
||||||
|
Ssoid string `json:"ssoid"`
|
||||||
|
Channel int `json:"channel"`
|
||||||
|
AdId string `json:"adId"`
|
||||||
|
}
|
||||||
|
|
||||||
|
//登录回复
|
||||||
|
type LoginResType struct {
|
||||||
|
ResultCode string `json:"resultCode" dc:"响应码,成功为 200"`
|
||||||
|
ResultMsg string `json:"resultMsg" dc:"响应信息"`
|
||||||
|
LoginToken string `json:"loginToken" dc:"透传的token"`
|
||||||
|
Ssoid string `json:"ssoid" dc:"透传的ssoid"`
|
||||||
|
//AppKey string `json:"appKey" dc:"秘钥key,因隐私安全规范,该字段目前已不返回信息"`
|
||||||
|
UserName string `json:"userName" dc:"用户ssoid绑定的账户昵称"`
|
||||||
|
//Email string `json:"email" dc:"因隐私安全规范,该字段目前已不返回信息"`
|
||||||
|
//MobileNumber string `json:"mobileNumber" dc:"因隐私安全规范,该字段目前已不返回信息"`
|
||||||
|
//CreateTime string `json:"createTime" dc:"因隐私安全规范,该字段目前已不返回信息"`
|
||||||
|
UserStatus string `json:"userStatus" dc:"用户状态:NORMAL 表示正常"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *OppoType) FileIdInfo(ctx context.Context, oauthToken string, ssoid string) (res *LoginResType, err error) {
|
||||||
|
url := host + "/sdkopen/user/fileIdInfo"
|
||||||
|
header := p.GetHeader(oauthToken)
|
||||||
|
getHtml, err := g.Client().Header(header).Get(ctx, url, g.Map{
|
||||||
|
"token": oauthToken,
|
||||||
|
"fileId": ssoid,
|
||||||
|
})
|
||||||
|
getRes := getHtml.ReadAllString()
|
||||||
|
gjson.DecodeTo(getRes, &res)
|
||||||
|
g.Log().Debugf(ctx, "当前登陆请求的:%v", res)
|
||||||
|
return
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *OppoType) GenParam(oauthToken, oauthTimestamp, oauthNonce string) string {
|
||||||
|
// 注意:拼接的顺序不能有改变,不然会导致联运方验签失败
|
||||||
|
params := []string{
|
||||||
|
"oauthConsumerKey=" + url.QueryEscape(p.AppKey),
|
||||||
|
"oauthToken=" + url.QueryEscape(oauthToken),
|
||||||
|
"oauthSignatureMethod=" + url.QueryEscape("HMAC-SHA1"),
|
||||||
|
"oauthTimestamp=" + url.QueryEscape(oauthTimestamp),
|
||||||
|
"oauthNonce=" + url.QueryEscape(oauthNonce),
|
||||||
|
"oauthVersion=" + url.QueryEscape("1.0"),
|
||||||
|
}
|
||||||
|
return strings.Join(params, "&") + "&"
|
||||||
|
}
|
||||||
|
|
||||||
|
// 生成签名
|
||||||
|
func (p *OppoType) GenOauthSignature(param string) string {
|
||||||
|
oauthSignatureKey := p.AppSecret + "&"
|
||||||
|
mac := hmac.New(sha1.New, []byte(oauthSignatureKey))
|
||||||
|
io.WriteString(mac, param)
|
||||||
|
signature := base64.StdEncoding.EncodeToString(mac.Sum(nil))
|
||||||
|
return url.QueryEscape(signature)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *OppoType) GetHeader(oauthToken string) (headers map[string]string) {
|
||||||
|
|
||||||
|
// 没有做过 urlEncode 的 token,由游戏客户端调用 OPPO SDK 直接获取
|
||||||
|
//oauthToken := "TICKET_Ajnxxxxx"
|
||||||
|
oauthTimestamp := gtime.Now().TimestampStr()
|
||||||
|
oauthNonce := grand.S(5)
|
||||||
|
|
||||||
|
// 生成请求头参数和签名
|
||||||
|
param := p.GenParam(oauthToken, oauthTimestamp, oauthNonce)
|
||||||
|
oauthSignature := p.GenOauthSignature(param)
|
||||||
|
|
||||||
|
// 封装请求头
|
||||||
|
headers = map[string]string{
|
||||||
|
"param": param,
|
||||||
|
"oauthSignature": oauthSignature,
|
||||||
|
}
|
||||||
|
|
||||||
|
//fmt.Println("游戏服务端登录鉴权请求头为:", headers)
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
13
package/pay/oppo/model.go
Normal file
13
package/pay/oppo/model.go
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
package oppo
|
||||||
|
|
||||||
|
// OPPO支付回调参数结构体
|
||||||
|
type PayCallback struct {
|
||||||
|
NotifyId string `json:"notifyId" dc:"回调通知单号,以GC开头,必填,示例:GC20230314657000"`
|
||||||
|
PartnerOrder string `json:"partnerOrder" dc:"开发者订单号,必填,示例:123456"`
|
||||||
|
ProductName string `json:"productName" dc:"商品名称,必填,示例:10元宝"`
|
||||||
|
ProductDesc string `json:"productDesc" dc:"商品描述,必填,示例:10元宝等于1元"`
|
||||||
|
Price int64 `json:"price" dc:"商品价格,单位为分,需要游戏服务端做验证,必填,示例:100"`
|
||||||
|
Count int `json:"count" dc:"商品数量(一般为1),必填,示例:1"`
|
||||||
|
Attach string `json:"attach" dc:"请求支付时上传的附加参数,可能为空,选填"`
|
||||||
|
Sign string `json:"sign" dc:"OPPO服务端签名,需要游戏服务端做验证,必填"`
|
||||||
|
}
|
||||||
41
package/pay/oppo/oppo.go
Normal file
41
package/pay/oppo/oppo.go
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
package oppo
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
|
"github.com/haxqer/xthird/oppo"
|
||||||
|
)
|
||||||
|
|
||||||
|
// 跟充值平台通信的加密key
|
||||||
|
//const PUBLIC_KEY = `dfsdfs`
|
||||||
|
|
||||||
|
type OppoType struct {
|
||||||
|
AppId string `json:"app_id"`
|
||||||
|
AppKey string `json:"app_key"`
|
||||||
|
AppSecret string `json:"app_secret"`
|
||||||
|
PublicKey string `json:"public_key"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func New(cfg *OppoType) *OppoType {
|
||||||
|
|
||||||
|
return &OppoType{
|
||||||
|
AppKey: cfg.AppKey,
|
||||||
|
AppSecret: cfg.AppSecret,
|
||||||
|
PublicKey: cfg.PublicKey,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *OppoType) Verify(ctx context.Context) (err error) {
|
||||||
|
// OPPO公钥. 在官方给的 demo 中. 无需修改,改了就验证不过
|
||||||
|
oppoPublicKey := "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCmreYIkPwVovKR8rLHWlFVw7YDfm9uQOJKL89Smt6ypXGVdrAKKl0wNYc3/jecAoPi2ylChfa2iRu5gunJyNmpWZzlCNRIau55fxGW0XEu553IiprOZcaw5OuYGlf60ga8QT6qToP0/dpiL/ZbmNUO9kUhosIjEu22uFgR+5cYyQIDAQAB"
|
||||||
|
//oppoPublicKey := p.PublicKey
|
||||||
|
// 解析请求参数
|
||||||
|
bodyMap, err := oppo.ParseNotifyToBodyMap(g.RequestFromCtx(ctx).Request)
|
||||||
|
if err != nil {
|
||||||
|
// 解析失败, 处理错误逻辑
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = oppo.VerifySign(oppoPublicKey, bodyMap)
|
||||||
|
return
|
||||||
|
}
|
||||||
103
package/pay/taptap/sign.go
Normal file
103
package/pay/taptap/sign.go
Normal file
@@ -0,0 +1,103 @@
|
|||||||
|
package taptap
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/hmac"
|
||||||
|
"crypto/sha256"
|
||||||
|
"encoding/base64"
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
"sort"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
type pTapTap struct {
|
||||||
|
Secret string `json:"secret" dc:"秘钥"`
|
||||||
|
//OrderId string `json:"order_id" dc:"订单唯一 ID"`
|
||||||
|
ClientId string `json:"client_id" dc:"应用的 Client ID"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func New(clientId string, secret string) *pTapTap {
|
||||||
|
return &pTapTap{
|
||||||
|
Secret: secret,
|
||||||
|
ClientId: clientId,
|
||||||
|
//OrderId: orderId,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sign signs the request.
|
||||||
|
func (p *pTapTap) Sign(req *http.Request, secret string) (string, error) {
|
||||||
|
//获取请求参数
|
||||||
|
//req := g.RequestFromCtx(ctx).Request
|
||||||
|
return Sign(req, secret)
|
||||||
|
}
|
||||||
|
|
||||||
|
//func (p *pTapTap) SignOld(ctx context.Context, method, url string, token string, data any) (sign string, ts int64, nonce string, err error) {
|
||||||
|
// //secret := p.Secret
|
||||||
|
// //ts = gtime.Now().Unix()
|
||||||
|
// //nonce = grand.S(5)
|
||||||
|
// //header := http.Header{
|
||||||
|
// // "Content-Type": {"Content-Type: application/json; charset=utf-8"},
|
||||||
|
// // "X-Tap-Ts": {strconv.FormatInt(ts, 10)},
|
||||||
|
// // "X-Tap-Nonce": {nonce},
|
||||||
|
// //}
|
||||||
|
// //if method == "POST" {
|
||||||
|
// // header.Set("Content-Type", "application/json; charset=utf-8")
|
||||||
|
// //}
|
||||||
|
// ////ctx := context.Background()
|
||||||
|
// //request := g.RequestFromCtx(ctx).Request
|
||||||
|
// //body, _ := json.Marshal(data)
|
||||||
|
// ////req, err := http.NewRequestWithContext(ctx, method, url, strings.NewReader(string(body)))
|
||||||
|
// //req.Header = header
|
||||||
|
// //sign, err = Sign(req, secret)
|
||||||
|
// //if err != nil {
|
||||||
|
// // panic(err)
|
||||||
|
// //}
|
||||||
|
// //req.Header.Set("X-Tap-Sign", sign)
|
||||||
|
// //return
|
||||||
|
//}
|
||||||
|
|
||||||
|
// Sign signs the request.
|
||||||
|
func Sign(req *http.Request, secret string) (string, error) {
|
||||||
|
methodPart := req.Method
|
||||||
|
urlPathAndQueryPart := req.URL.RequestURI()
|
||||||
|
headersPart, err := getHeadersPart(req.Header)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
bodyPart, err := io.ReadAll(req.Body)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
signParts := methodPart + "\n" + urlPathAndQueryPart + "\n" + headersPart + "\n" + string(bodyPart) + "\n"
|
||||||
|
fmt.Println(signParts)
|
||||||
|
h := hmac.New(sha256.New, []byte(secret))
|
||||||
|
h.Write([]byte(signParts))
|
||||||
|
rawSign := h.Sum(nil)
|
||||||
|
sign := base64.StdEncoding.EncodeToString(rawSign)
|
||||||
|
return sign, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// getHeadersPart returns the headers part of the request.
|
||||||
|
func getHeadersPart(header http.Header) (string, error) {
|
||||||
|
var headerKeys []string
|
||||||
|
for k, v := range header {
|
||||||
|
k = strings.ToLower(k)
|
||||||
|
if !strings.HasPrefix(k, "x-tap-") {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if k == "x-tap-sign" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if len(v) > 1 {
|
||||||
|
return "", fmt.Errorf("invalid header, %q has multiple values", k)
|
||||||
|
}
|
||||||
|
headerKeys = append(headerKeys, k)
|
||||||
|
}
|
||||||
|
sort.Strings(headerKeys)
|
||||||
|
headers := make([]string, 0, len(headerKeys))
|
||||||
|
for _, k := range headerKeys {
|
||||||
|
headers = append(headers, fmt.Sprintf("%s:%s", k, header.Get(k)))
|
||||||
|
}
|
||||||
|
return strings.Join(headers, "\n"), nil
|
||||||
|
}
|
||||||
129
package/pay/taptap/taptap.go
Normal file
129
package/pay/taptap/taptap.go
Normal file
@@ -0,0 +1,129 @@
|
|||||||
|
package taptap
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"context"
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"github.com/gogf/gf/v2/encoding/gjson"
|
||||||
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
|
"github.com/gogf/gf/v2/net/gclient"
|
||||||
|
"github.com/gogf/gf/v2/os/gctx"
|
||||||
|
"github.com/gogf/gf/v2/os/gtime"
|
||||||
|
"github.com/gogf/gf/v2/util/grand"
|
||||||
|
"io"
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
type GetPayData struct {
|
||||||
|
Data struct {
|
||||||
|
Order struct {
|
||||||
|
Order
|
||||||
|
} `json:"order"`
|
||||||
|
} `json:"data"`
|
||||||
|
Success bool `json:"success"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Order struct {
|
||||||
|
OrderID string `json:"order_id"` // 订单唯一 ID
|
||||||
|
PurchaseToken string `json:"purchase_token"` // 用于订单核销的 token
|
||||||
|
ClientID string `json:"client_id"` // 应用的 Client ID
|
||||||
|
OpenID string `json:"open_id"` // 用户的开放平台 ID
|
||||||
|
UserRegion string `json:"user_region"` // 用户地区
|
||||||
|
GoodsOpenID string `json:"goods_open_id"` // 商品唯一 ID
|
||||||
|
GoodsName string `json:"goods_name"` // 商品名称
|
||||||
|
Status PaymentStatus `json:"status"` // 订单状态
|
||||||
|
Amount string `json:"amount"` // 金额(本币金额 x 1,000,000)
|
||||||
|
Currency string `json:"currency"` // 币种
|
||||||
|
CreateTime string `json:"create_time"` // 创建时间
|
||||||
|
PayTime string `json:"pay_time"` // 支付时间
|
||||||
|
Extra string `json:"extra"` // 商户自定义数据,如角色信息等,长度不超过 255 UTF-8 字符
|
||||||
|
}
|
||||||
|
type PaymentStatus string
|
||||||
|
|
||||||
|
const (
|
||||||
|
ChargePending PaymentStatus = "charge.pending" // 待支付
|
||||||
|
ChargeSucceeded PaymentStatus = "charge.succeeded" //支付成功
|
||||||
|
ChargeConfirmed PaymentStatus = "charge.confirmed" //已核销
|
||||||
|
ChargeOverdue PaymentStatus = "charge.overdue" //支付超时关闭
|
||||||
|
RefundPending PaymentStatus = "refund.pending" //退款中
|
||||||
|
RefundSucceeded PaymentStatus = "refund.succeeded" //退款成功
|
||||||
|
RefundFailed PaymentStatus = "refund.failed" //退款失败
|
||||||
|
RefundRejected PaymentStatus = "refund.rejected" //退款被拒绝
|
||||||
|
)
|
||||||
|
|
||||||
|
// 查询订单信息
|
||||||
|
func (p *pTapTap) Info(ctx context.Context, order string) (getPayData *GetPayData, err error) {
|
||||||
|
url := fmt.Sprintf("https://cloud-payment.tapapis.cn/order/v1/info?client_id=%v&order_id=%v", p.ClientId, order)
|
||||||
|
getPayData, err = p.get(ctx, url)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 验证并核销订单
|
||||||
|
func (p *pTapTap) Verify(ctx context.Context, req any) (getPayData *GetPayData, err error) {
|
||||||
|
url := fmt.Sprintf("https://cloud-payment.tapapis.cn/order/v1/verify?client_id=%v", p.ClientId)
|
||||||
|
getPayData, err = p.get(ctx, url, req)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *pTapTap) get(ctx context.Context, url string, _data ...any) (getPayData *GetPayData, err error) {
|
||||||
|
|
||||||
|
var _get *gclient.Response
|
||||||
|
|
||||||
|
var header = map[string]string{
|
||||||
|
"Content-Type": "Content-Type: application/json; charset=utf-8",
|
||||||
|
"X-Tap-Nonce": grand.S(6),
|
||||||
|
"X-Tap-Ts": gtime.Now().TimestampStr(),
|
||||||
|
}
|
||||||
|
ctx2 := context.Background()
|
||||||
|
var method = "GET"
|
||||||
|
if len(_data) > 0 {
|
||||||
|
method = "POST"
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//temp := []byte(`{"event_type":"charge.succeeded","order":{"order_id":"1790288650833465345","purchase_token":"rT2Et9p0cfzq4fwjrTsGSacq0jQExFDqf5gTy1alp+Y=","client_id":"o6nD4iNavjQj75zPQk","open_id":"4+Axcl2RFgXbt6MZwdh++w==","user_region":"US","goods_open_id":"com.goods.open_id","goods_name":"TestGoodsName","status":"charge.succeeded","amount":"19000000000","currency":"USD","create_time":"1716168000","pay_time":"1716168000","extra":"1111111111111111111"}}`)
|
||||||
|
var body io.Reader
|
||||||
|
if len(_data) > 0 {
|
||||||
|
body = bytes.NewBuffer(gjson.MustEncode(_data[0]))
|
||||||
|
} else {
|
||||||
|
body = bytes.NewBuffer([]byte{})
|
||||||
|
}
|
||||||
|
req, _ := http.NewRequestWithContext(ctx2, method, url, body)
|
||||||
|
for k, v := range header {
|
||||||
|
req.Header.Set(k, v)
|
||||||
|
}
|
||||||
|
sign, err2 := p.Sign(req, p.Secret)
|
||||||
|
if err2 != nil {
|
||||||
|
err = err2
|
||||||
|
return
|
||||||
|
}
|
||||||
|
req.Header.Set("X-Tap-Sign", sign)
|
||||||
|
header["X-Tap-Sign"] = sign
|
||||||
|
if len(_data) == 0 {
|
||||||
|
_get, err = g.Client().Header(header).ContentJson().Get(gctx.New(), url)
|
||||||
|
} else {
|
||||||
|
_get, err = g.Client().Header(header).ContentJson().Post(gctx.New(), url, _data[0])
|
||||||
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
getPayData = &GetPayData{}
|
||||||
|
resData := _get.ReadAll()
|
||||||
|
g.Dump(resData)
|
||||||
|
if err = json.Unmarshal(resData, &getPayData); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if !getPayData.Success {
|
||||||
|
err = errors.New(string(resData))
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
63
package/pay/xiaomi/helper.go
Normal file
63
package/pay/xiaomi/helper.go
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
package xiaomi
|
||||||
|
|
||||||
|
import (
|
||||||
|
"crypto/hmac"
|
||||||
|
"crypto/sha1"
|
||||||
|
"encoding/hex"
|
||||||
|
"fmt"
|
||||||
|
"sort"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
// SignatureHelper 签名辅助类
|
||||||
|
type SignatureHelper struct{}
|
||||||
|
|
||||||
|
// hmacSHA1 计算HMAC-SHA1哈希值
|
||||||
|
func hmacSHA1(data, key string) string {
|
||||||
|
h := hmac.New(sha1.New, []byte(key))
|
||||||
|
h.Write([]byte(data))
|
||||||
|
return hex.EncodeToString(h.Sum(nil))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sign 计算hmac-sha1签名
|
||||||
|
func (m *MiPay) Sign(params map[string]string, secretKey string) string {
|
||||||
|
if _, ok := params["signature"]; ok {
|
||||||
|
delete(params, "signature")
|
||||||
|
}
|
||||||
|
for k, v := range params {
|
||||||
|
if v == "" || v == "0" {
|
||||||
|
delete(params, k)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sortString := m.buildSortString(params)
|
||||||
|
signature := hmacSHA1(sortString, secretKey)
|
||||||
|
return signature
|
||||||
|
}
|
||||||
|
|
||||||
|
// VerifySignature 验证签名
|
||||||
|
func (m *MiPay) VerifySignature(params map[string]string, signature, secretKey string) bool {
|
||||||
|
tmpSign := m.Sign(params, secretKey)
|
||||||
|
return tmpSign == signature
|
||||||
|
}
|
||||||
|
|
||||||
|
// buildSortString 构造排序字符串
|
||||||
|
func (m *MiPay) buildSortString(params map[string]string) string {
|
||||||
|
if len(params) == 0 {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
// 按键排序
|
||||||
|
keys := make([]string, 0, len(params))
|
||||||
|
for k := range params {
|
||||||
|
keys = append(keys, k)
|
||||||
|
}
|
||||||
|
sort.Strings(keys)
|
||||||
|
|
||||||
|
// 构建排序字符串
|
||||||
|
var fields []string
|
||||||
|
for _, k := range keys {
|
||||||
|
fields = append(fields, fmt.Sprintf("%s=%s", k, params[k]))
|
||||||
|
}
|
||||||
|
|
||||||
|
return strings.Join(fields, "&")
|
||||||
|
}
|
||||||
20
package/pay/xiaomi/model.go
Normal file
20
package/pay/xiaomi/model.go
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
package xiaomi
|
||||||
|
|
||||||
|
import "github.com/gogf/gf/v2/os/gtime"
|
||||||
|
|
||||||
|
type PayCallback struct {
|
||||||
|
AppID string `json:"appId" dc:"游戏ID" required:"true"`
|
||||||
|
CPOrderID string `json:"cpOrderId" dc:"开发商订单ID" required:"true"`
|
||||||
|
CPUserInfo string `json:"cpUserInfo" dc:"开发商透传信息" required:"false"`
|
||||||
|
OrderConsumeType int `json:"orderConsumeType" dc:"订单类型:10:普通订单 11:直充直消订单" required:"false"`
|
||||||
|
OrderID string `json:"orderId" dc:"游戏平台订单ID" required:"true"`
|
||||||
|
OrderStatus string `json:"orderStatus" dc:"订单状态,TRADE_SUCCESS代表成功" required:"true"`
|
||||||
|
PayFee int `json:"payFee" dc:"支付金额,单位为分,即0.01米币。(请务必使用payFee字段值与游戏发起订单金额做校验,确保订单金额一致性)" required:"true"`
|
||||||
|
PayTime *gtime.Time `json:"payTime" dc:"支付时间,格式yyyy-MM-dd HH:mm:ss" required:"true"`
|
||||||
|
ProductCode string `json:"productCode" dc:"商品代码" required:"true"`
|
||||||
|
ProductCount int `json:"productCount" dc:"商品数量" required:"true"`
|
||||||
|
ProductName string `json:"productName" dc:"商品名称" required:"true"`
|
||||||
|
UID string `json:"uid" dc:"用户ID" required:"true"`
|
||||||
|
PartnerGiftConsume int64 `json:"partnerGiftConsume" dc:"使用游戏券金额(如果订单使用游戏券则有,long型),如果有则参与签名" required:"false"`
|
||||||
|
Signature string `json:"signature" dc:"签名,签名方法见后面说明" required:"true"`
|
||||||
|
}
|
||||||
29
package/pay/xiaomi/xiaomi.go
Normal file
29
package/pay/xiaomi/xiaomi.go
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
package xiaomi
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
|
"github.com/gogf/gf/v2/os/gctx"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Config 小米支付配置信息
|
||||||
|
type Config struct {
|
||||||
|
AppID string `json:"app_id"` // 应用ID
|
||||||
|
AppSecret string `json:"app_secret"` // 应用密钥
|
||||||
|
//PrivateKey string // 商户私钥(如需证书)
|
||||||
|
//MIAPIURL string // 小米支付API基础地址
|
||||||
|
//IsSandbox bool // 是否沙箱环境
|
||||||
|
}
|
||||||
|
|
||||||
|
// Miipay 小米支付客户端
|
||||||
|
type MiPay struct {
|
||||||
|
config *Config
|
||||||
|
}
|
||||||
|
|
||||||
|
func New() *MiPay {
|
||||||
|
_cfg, _ := g.Cfg().Get(gctx.New(), "pay.xiaomi")
|
||||||
|
var cfg *Config
|
||||||
|
_cfg.Scan(&cfg)
|
||||||
|
return &MiPay{
|
||||||
|
config: cfg,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -270,7 +270,7 @@ func (s *Mod) GetPath(url string) (filePath string) {
|
|||||||
return url[len(get+bucketName)+1:]
|
return url[len(get+bucketName)+1:]
|
||||||
}
|
}
|
||||||
|
|
||||||
// 复制文件
|
// CopyObject 复制文件
|
||||||
func (s *Mod) CopyObject(bucketName string, dstStr string, srcStr string) (err error) {
|
func (s *Mod) CopyObject(bucketName string, dstStr string, srcStr string) (err error) {
|
||||||
|
|
||||||
// 原始文件
|
// 原始文件
|
||||||
@@ -288,3 +288,15 @@ func (s *Mod) CopyObject(bucketName string, dstStr string, srcStr string) (err e
|
|||||||
_, err = s.client.CopyObject(ctx, dst, src)
|
_, err = s.client.CopyObject(ctx, dst, src)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Rename 重命名文件
|
||||||
|
func (s *Mod) Rename(bucketName string, name string, newName string) (err error) {
|
||||||
|
// 复制文件到新的名称
|
||||||
|
err = s.CopyObject(bucketName, name, newName)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 删除原始文件
|
||||||
|
err = s.RemoveObject(bucketName, name)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|||||||
@@ -3,121 +3,270 @@ package drive
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"github.com/gogf/gf/v2/container/gvar"
|
"github.com/gogf/gf/v2/container/gvar"
|
||||||
|
"github.com/gogf/gf/v2/crypto/gmd5"
|
||||||
|
"github.com/gogf/gf/v2/encoding/gjson"
|
||||||
"github.com/gogf/gf/v2/os/gcache"
|
"github.com/gogf/gf/v2/os/gcache"
|
||||||
|
"github.com/gogf/gf/v2/os/gctx"
|
||||||
"github.com/gogf/gf/v2/os/gfile"
|
"github.com/gogf/gf/v2/os/gfile"
|
||||||
|
"github.com/gogf/gf/v2/os/gtime"
|
||||||
"github.com/gogf/gf/v2/util/gconv"
|
"github.com/gogf/gf/v2/util/gconv"
|
||||||
"path"
|
"path"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
fileIndex = "index.txt"
|
||||||
|
)
|
||||||
|
|
||||||
|
type FileIndex struct {
|
||||||
|
File string `json:"file"`
|
||||||
|
Duration time.Duration `json:"duration"`
|
||||||
|
}
|
||||||
|
type FileData struct {
|
||||||
|
Data interface{} `json:"data"`
|
||||||
|
Time int64 `json:"time"`
|
||||||
|
}
|
||||||
|
|
||||||
type AdapterFile struct {
|
type AdapterFile struct {
|
||||||
FilePath string
|
FilePath string
|
||||||
|
Lock sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a AdapterFile) Set(ctx context.Context, key interface{}, value interface{}, duration time.Duration) error {
|
func (a *AdapterFile) Key2Name(key interface{}) string {
|
||||||
arr := strings.Split(":", gconv.String(key))
|
md5Str, _ := gmd5.Encrypt(key)
|
||||||
fileName := path.Join(arr...)
|
fileName := path.Join(md5Str[0:2], md5Str[2:4], md5Str[4:6], md5Str[16:])
|
||||||
return gfile.PutBytes(fileName, gconv.Bytes(value))
|
fileNameAll := path.Join(a.FilePath, fileName)
|
||||||
|
|
||||||
|
return fileNameAll
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a AdapterFile) SetMap(ctx context.Context, data map[interface{}]interface{}, duration time.Duration) error {
|
func (a *AdapterFile) AddIndex(FileName interface{}, duration time.Duration) {
|
||||||
|
var isEdit bool
|
||||||
|
|
||||||
|
var setTime int64
|
||||||
|
if duration == 0 {
|
||||||
|
setTime = 0
|
||||||
|
} else {
|
||||||
|
setTime = gtime.Now().Add(duration).Unix()
|
||||||
|
}
|
||||||
|
saveArr := []string{
|
||||||
|
gconv.String(FileName),
|
||||||
|
strconv.FormatInt(setTime, 10),
|
||||||
|
}
|
||||||
|
saveStr := strings.Join(saveArr, "|")
|
||||||
|
|
||||||
|
gfile.ReadLines(fileIndex, func(text string) (err error) {
|
||||||
|
arr := strings.Split(text, "|")
|
||||||
|
if arr[0] == FileName {
|
||||||
|
isEdit = true
|
||||||
|
gfile.ReplaceFile(text, saveStr, fileIndex)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return
|
||||||
|
})
|
||||||
|
|
||||||
|
if isEdit {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
gfile.PutContentsAppend(fileIndex, saveStr+"\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *AdapterFile) DelIndex(FileName interface{}) {
|
||||||
|
//var save bool
|
||||||
|
gfile.ReadLines(fileIndex, func(text string) (err error) {
|
||||||
|
arr := strings.Split(text, "|")
|
||||||
|
if arr[0] == FileName {
|
||||||
|
//save = true
|
||||||
|
err = gfile.ReplaceFile(text+"\n", "", fileIndex)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
return
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *AdapterFile) Set(ctx context.Context, key interface{}, value interface{}, duration time.Duration) (err error) {
|
||||||
|
fileNameAll := a.Key2Name(key)
|
||||||
|
var send = &FileData{
|
||||||
|
Data: value,
|
||||||
|
Time: gtime.Now().Add(duration).Unix(),
|
||||||
|
}
|
||||||
|
err = gfile.PutBytes(fileNameAll, gjson.MustEncode(send))
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
a.AddIndex(key, duration)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *AdapterFile) SetMap(ctx context.Context, data map[interface{}]interface{}, duration time.Duration) (err error) {
|
||||||
|
for k, v := range data {
|
||||||
|
//fileNameAll := a.Key2Name(k)
|
||||||
|
//var send = &FileData{
|
||||||
|
// Data: v,
|
||||||
|
// Time: gtime.Now().Add(duration).Unix(),
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//err = gfile.PutBytes(fileNameAll, gconv.Bytes(send))
|
||||||
|
a.Set(ctx, k, v, duration)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *AdapterFile) SetIfNotExist(ctx context.Context, key interface{}, value interface{}, duration time.Duration) (ok bool, err error) {
|
||||||
|
err = a.Set(ctx, key, value, duration)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *AdapterFile) SetIfNotExistFunc(ctx context.Context, key interface{}, f gcache.Func, duration time.Duration) (ok bool, err error) {
|
||||||
//TODO implement me
|
//TODO implement me
|
||||||
panic("implement me")
|
panic("implement me")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a AdapterFile) SetIfNotExist(ctx context.Context, key interface{}, value interface{}, duration time.Duration) (ok bool, err error) {
|
func (a *AdapterFile) SetIfNotExistFuncLock(ctx context.Context, key interface{}, f gcache.Func, duration time.Duration) (ok bool, err error) {
|
||||||
//TODO implement me
|
//TODO implement me
|
||||||
panic("implement me")
|
panic("implement me")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a AdapterFile) SetIfNotExistFunc(ctx context.Context, key interface{}, f gcache.Func, duration time.Duration) (ok bool, err error) {
|
func (a *AdapterFile) Get(ctx context.Context, key interface{}) (res *gvar.Var, err error) {
|
||||||
|
var data *FileData
|
||||||
|
name := a.Key2Name(key)
|
||||||
|
if !gfile.IsFile(name) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
file := gfile.GetBytes(name)
|
||||||
|
gjson.DecodeTo(file, &data)
|
||||||
|
if data.Time < time.Now().Unix() {
|
||||||
|
a.Remove(ctx, key)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
res = gvar.New(data.Data)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *AdapterFile) GetOrSet(ctx context.Context, key interface{}, value interface{}, duration time.Duration) (result *gvar.Var, err error) {
|
||||||
|
a.Set(ctx, key, value, duration)
|
||||||
|
result, err = a.Get(ctx, key)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *AdapterFile) GetOrSetFunc(ctx context.Context, key interface{}, f gcache.Func, duration time.Duration) (result *gvar.Var, err error) {
|
||||||
|
value := f
|
||||||
|
a.Set(ctx, key, value, duration)
|
||||||
|
result, err = a.Get(ctx, key)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *AdapterFile) GetOrSetFuncLock(ctx context.Context, key interface{}, f gcache.Func, duration time.Duration) (result *gvar.Var, err error) {
|
||||||
|
a.Lock.Lock()
|
||||||
|
defer a.Lock.Unlock()
|
||||||
|
result, err = a.GetOrSetFunc(ctx, key, f, duration)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *AdapterFile) Contains(ctx context.Context, key interface{}) (bool, error) {
|
||||||
|
return gfile.IsFile(a.FilePath), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *AdapterFile) Size(ctx context.Context) (size int, err error) {
|
||||||
|
size = int(gfile.Size(a.FilePath))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *AdapterFile) Data(ctx context.Context) (data map[interface{}]interface{}, err error) {
|
||||||
//TODO implement me
|
//TODO implement me
|
||||||
panic("implement me")
|
panic("implement me")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a AdapterFile) SetIfNotExistFuncLock(ctx context.Context, key interface{}, f gcache.Func, duration time.Duration) (ok bool, err error) {
|
func (a *AdapterFile) Keys(ctx context.Context) (keys []interface{}, err error) {
|
||||||
|
keys = make([]interface{}, 0)
|
||||||
|
gfile.ReadLines(fileIndex, func(text string) (err error) {
|
||||||
|
arr := strings.Split(text, "|")
|
||||||
|
keys = append(keys, arr[0])
|
||||||
|
return
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *AdapterFile) Values(ctx context.Context) (values []interface{}, err error) {
|
||||||
//TODO implement me
|
//TODO implement me
|
||||||
panic("implement me")
|
panic("implement me")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a AdapterFile) Get(ctx context.Context, key interface{}) (*gvar.Var, error) {
|
func (a *AdapterFile) Update(ctx context.Context, key interface{}, value interface{}) (oldValue *gvar.Var, exist bool, err error) {
|
||||||
|
fileNameAll := a.Key2Name(key)
|
||||||
|
getFile := gfile.GetBytes(fileNameAll)
|
||||||
|
var data *FileData
|
||||||
|
gconv.Scan(getFile, &data)
|
||||||
|
oldValue.Set(data.Data)
|
||||||
|
|
||||||
|
var send = &FileData{
|
||||||
|
Data: value,
|
||||||
|
Time: data.Time,
|
||||||
|
}
|
||||||
|
|
||||||
|
err = gfile.PutBytes(fileNameAll, gconv.Bytes(send))
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
a.AddIndex(key, time.Duration(data.Time-gtime.Now().Unix()))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func (a *AdapterFile) UpdateExpire(ctx context.Context, key interface{}, duration time.Duration) (oldDuration time.Duration, err error) {
|
||||||
//TODO implement me
|
//TODO implement me
|
||||||
panic("implement me")
|
panic("implement me")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a AdapterFile) GetOrSet(ctx context.Context, key interface{}, value interface{}, duration time.Duration) (result *gvar.Var, err error) {
|
func (a *AdapterFile) GetExpire(ctx context.Context, key interface{}) (time.Duration, error) {
|
||||||
//TODO implement me
|
//TODO implement me
|
||||||
panic("implement me")
|
panic("implement me")
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a AdapterFile) GetOrSetFunc(ctx context.Context, key interface{}, f gcache.Func, duration time.Duration) (result *gvar.Var, err error) {
|
func (a *AdapterFile) Remove(ctx context.Context, keys ...interface{}) (lastValue *gvar.Var, err error) {
|
||||||
//TODO implement me
|
for _, v := range keys {
|
||||||
panic("implement me")
|
fileNameAll := a.Key2Name(v)
|
||||||
|
lastValue, err = a.Get(ctx, fileNameAll)
|
||||||
|
err = gfile.RemoveFile(fileNameAll)
|
||||||
|
//删除索引文件
|
||||||
|
a.DelIndex(v)
|
||||||
|
}
|
||||||
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a AdapterFile) GetOrSetFuncLock(ctx context.Context, key interface{}, f gcache.Func, duration time.Duration) (result *gvar.Var, err error) {
|
func (a *AdapterFile) Clear(ctx context.Context) error {
|
||||||
//TODO implement me
|
return gfile.RemoveAll(a.FilePath)
|
||||||
panic("implement me")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a AdapterFile) Contains(ctx context.Context, key interface{}) (bool, error) {
|
func (a *AdapterFile) Close(ctx context.Context) error {
|
||||||
//TODO implement me
|
return nil
|
||||||
panic("implement me")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a AdapterFile) Size(ctx context.Context) (size int, err error) {
|
|
||||||
//TODO implement me
|
|
||||||
panic("implement me")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a AdapterFile) Data(ctx context.Context) (data map[interface{}]interface{}, err error) {
|
|
||||||
//TODO implement me
|
|
||||||
panic("implement me")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a AdapterFile) Keys(ctx context.Context) (keys []interface{}, err error) {
|
|
||||||
//TODO implement me
|
|
||||||
panic("implement me")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a AdapterFile) Values(ctx context.Context) (values []interface{}, err error) {
|
|
||||||
//TODO implement me
|
|
||||||
panic("implement me")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a AdapterFile) Update(ctx context.Context, key interface{}, value interface{}) (oldValue *gvar.Var, exist bool, err error) {
|
|
||||||
//TODO implement me
|
|
||||||
panic("implement me")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a AdapterFile) UpdateExpire(ctx context.Context, key interface{}, duration time.Duration) (oldDuration time.Duration, err error) {
|
|
||||||
//TODO implement me
|
|
||||||
panic("implement me")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a AdapterFile) GetExpire(ctx context.Context, key interface{}) (time.Duration, error) {
|
|
||||||
//TODO implement me
|
|
||||||
panic("implement me")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a AdapterFile) Remove(ctx context.Context, keys ...interface{}) (lastValue *gvar.Var, err error) {
|
|
||||||
//TODO implement me
|
|
||||||
panic("implement me")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a AdapterFile) Clear(ctx context.Context) error {
|
|
||||||
//TODO implement me
|
|
||||||
panic("implement me")
|
|
||||||
}
|
|
||||||
|
|
||||||
func (a AdapterFile) Close(ctx context.Context) error {
|
|
||||||
//TODO implement me
|
|
||||||
panic("implement me")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewAdapterFile(filePath string) gcache.Adapter {
|
func NewAdapterFile(filePath string) gcache.Adapter {
|
||||||
return &AdapterFile{
|
fileIndex = path.Join(filePath, fileIndex)
|
||||||
|
|
||||||
|
//清空过期文件目录
|
||||||
|
delKeys := make([]interface{}, 0)
|
||||||
|
gfile.ReadLines(fileIndex, func(text string) error {
|
||||||
|
arr := strings.Split(text, "|")
|
||||||
|
if gtime.Now().Unix() > gconv.Int64(arr[1]) {
|
||||||
|
delKeys = append(delKeys, arr[0])
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
|
||||||
|
obj := &AdapterFile{
|
||||||
FilePath: filePath,
|
FilePath: filePath,
|
||||||
}
|
}
|
||||||
|
if len(delKeys) > 0 {
|
||||||
|
obj.Remove(gctx.New(), delKeys...)
|
||||||
|
}
|
||||||
|
|
||||||
|
return obj
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
"github.com/gogf/gf/v2/container/gvar"
|
"github.com/gogf/gf/v2/container/gvar"
|
||||||
"github.com/gogf/gf/v2/encoding/gjson"
|
"github.com/gogf/gf/v2/encoding/gjson"
|
||||||
"github.com/gogf/gf/v2/frame/g"
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
|
"github.com/gogf/gf/v2/os/gctx"
|
||||||
"github.com/gogf/gf/v2/os/gfile"
|
"github.com/gogf/gf/v2/os/gfile"
|
||||||
"github.com/gogf/gf/v2/os/gres"
|
"github.com/gogf/gf/v2/os/gres"
|
||||||
"github.com/gogf/gf/v2/text/gstr"
|
"github.com/gogf/gf/v2/text/gstr"
|
||||||
@@ -86,14 +87,22 @@ func (c *Cfg) GetFile(filename string, _pathStr ...string) (jsonObj *gjson.Json,
|
|||||||
bytes = gres.GetContent(filePath) // 从打包资源中获取内容
|
bytes = gres.GetContent(filePath) // 从打包资源中获取内容
|
||||||
}
|
}
|
||||||
|
|
||||||
//如果还是没有读取到配置,从当前目录返回上级读取
|
for range 5 {
|
||||||
if bytes == nil {
|
//如果还是没有读取到配置,从当前目录返回上级读取
|
||||||
// 拼接完整的文件路径
|
if bytes == nil {
|
||||||
filePath = "../../" + pathStr + filename + ".json"
|
// 上级拼接完整的文件路径
|
||||||
if gfile.IsFile(filePath) {
|
filePath = "../" + filePath
|
||||||
bytes = gfile.GetBytes(filePath) // 读取物理文件内容
|
if gfile.IsFile(filePath) {
|
||||||
|
bytes = gfile.GetBytes(filePath) // 读取物理文件内容
|
||||||
|
//找到配置了,跳过
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if bytes == nil {
|
||||||
|
g.Log().Errorf(gctx.New(), "未读取到配置文件:%v", filePath)
|
||||||
|
}
|
||||||
|
|
||||||
// 解析 JSON 内容并返回结果
|
// 解析 JSON 内容并返回结果
|
||||||
jsonObj, err = gjson.DecodeToJson(bytes)
|
jsonObj, err = gjson.DecodeToJson(bytes)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import (
|
|||||||
"github.com/elastic/go-elasticsearch/v8/typedapi/types"
|
"github.com/elastic/go-elasticsearch/v8/typedapi/types"
|
||||||
"github.com/gogf/gf/v2/frame/g"
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
"github.com/gogf/gf/v2/os/gctx"
|
"github.com/gogf/gf/v2/os/gctx"
|
||||||
|
"github.com/gogf/gf/v2/util/gconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -23,6 +24,13 @@ type Elastic struct {
|
|||||||
name string
|
name string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type elkBulk struct {
|
||||||
|
Index struct {
|
||||||
|
Index string `json:"_index"`
|
||||||
|
Id string `json:"_id"`
|
||||||
|
} `json:"index"`
|
||||||
|
}
|
||||||
|
|
||||||
func NewV1(name string) *Elastic {
|
func NewV1(name string) *Elastic {
|
||||||
var cfg elasticsearch.Config
|
var cfg elasticsearch.Config
|
||||||
_cfg := g.Cfg().MustGetWithEnv(gctx.New(), "elasticsearch")
|
_cfg := g.Cfg().MustGetWithEnv(gctx.New(), "elasticsearch")
|
||||||
@@ -52,7 +60,7 @@ func NewV1(name string) *Elastic {
|
|||||||
// fmt.Printf("index:%#v\n", resp.Index)
|
// fmt.Printf("index:%#v\n", resp.Index)
|
||||||
//}
|
//}
|
||||||
|
|
||||||
// Set 索引文档
|
// Set 添加文档索引文档
|
||||||
func (s *Elastic) Set(ctx context.Context, key string, data interface{}) (err error) {
|
func (s *Elastic) Set(ctx context.Context, key string, data interface{}) (err error) {
|
||||||
// 添加文档
|
// 添加文档
|
||||||
_, err = s.client.Index(s.name).Id(key).Document(data).Do(ctx)
|
_, err = s.client.Index(s.name).Id(key).Document(data).Do(ctx)
|
||||||
@@ -61,11 +69,20 @@ func (s *Elastic) Set(ctx context.Context, key string, data interface{}) (err er
|
|||||||
|
|
||||||
// SetBulk 批量添加文档
|
// SetBulk 批量添加文档
|
||||||
func (s *Elastic) SetBulk(ctx context.Context, data []any) (err error) {
|
func (s *Elastic) SetBulk(ctx context.Context, data []any) (err error) {
|
||||||
var save *bulk.Request
|
var save bulk.Request
|
||||||
save = &bulk.Request{
|
save = make(bulk.Request, 0)
|
||||||
data,
|
for _, v := range data {
|
||||||
|
val := gconv.Map(v)
|
||||||
|
var saveIndex = elkBulk{}
|
||||||
|
saveIndex.Index.Index = s.name
|
||||||
|
if _, ok := val["uuid"]; ok {
|
||||||
|
saveIndex.Index.Id = val["uuid"].(string)
|
||||||
|
}
|
||||||
|
save = append(save, saveIndex)
|
||||||
|
save = append(save, v)
|
||||||
}
|
}
|
||||||
s.client.Bulk().Index(s.name).Request(save).Do(ctx)
|
//save = data
|
||||||
|
_, err = s.client.Bulk().Index(s.name).Request(&save).Do(ctx)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import (
|
|||||||
"github.com/ayflying/utility_go/pkg/notice"
|
"github.com/ayflying/utility_go/pkg/notice"
|
||||||
"github.com/ayflying/utility_go/pkg/rank"
|
"github.com/ayflying/utility_go/pkg/rank"
|
||||||
"github.com/ayflying/utility_go/pkg/s3"
|
"github.com/ayflying/utility_go/pkg/s3"
|
||||||
"github.com/ayflying/utility_go/pkg/websocket"
|
//"github.com/ayflying/utility_go/pkg/websocket"
|
||||||
"github.com/gogf/gf/v2/os/gcache"
|
"github.com/gogf/gf/v2/os/gcache"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -32,9 +32,9 @@ func Rank() *rank.Mod {
|
|||||||
return rank.New()
|
return rank.New()
|
||||||
}
|
}
|
||||||
|
|
||||||
func Websocket() *websocket.SocketV1 {
|
//func Websocket() *websocket.SocketV1 {
|
||||||
return websocket.NewV1()
|
// return websocket.NewV1()
|
||||||
}
|
//}
|
||||||
|
|
||||||
func Config() *config.Cfg {
|
func Config() *config.Cfg {
|
||||||
return config.NewV1()
|
return config.NewV1()
|
||||||
|
|||||||
80
pkg/s3/s3.go
80
pkg/s3/s3.go
@@ -24,13 +24,14 @@ var (
|
|||||||
|
|
||||||
// DataType 定义了 S3 配置的数据结构,用于存储访问 S3 所需的各种信息
|
// DataType 定义了 S3 配置的数据结构,用于存储访问 S3 所需的各种信息
|
||||||
type DataType struct {
|
type DataType struct {
|
||||||
AccessKey string `json:"access_key"` // 访问 S3 的密钥 ID
|
AccessKey string `json:"access_key"` // 访问 S3 的密钥 ID
|
||||||
SecretKey string `json:"secret_key"` // 访问 S3 的密钥
|
SecretKey string `json:"secret_key"` // 访问 S3 的密钥
|
||||||
Address string `json:"address"` // S3 服务的地址
|
Address string `json:"address"` // S3 服务的地址
|
||||||
Ssl bool `json:"ssl"` // 是否使用 SSL 加密连接
|
Ssl bool `json:"ssl"` // 是否使用 SSL 加密连接
|
||||||
Url string `json:"url"` // S3 服务的访问 URL
|
Url string `json:"url"` // S3 服务的访问 URL
|
||||||
BucketName string `json:"bucket_name"` // 默认存储桶名称
|
BucketName string `json:"bucket_name"` // 默认存储桶名称
|
||||||
BucketNameCdn string `json:"bucket_name_cdn"` // CDN 存储桶名称
|
BucketNameCdn string `json:"bucket_name_cdn"` // CDN 存储桶名称
|
||||||
|
Provider string `json:"provider"` // S3 服务的提供方
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mod 定义了 S3 模块的结构体,包含一个 S3 客户端实例和配置信息
|
// Mod 定义了 S3 模块的结构体,包含一个 S3 客户端实例和配置信息
|
||||||
@@ -64,6 +65,7 @@ func New(_name ...string) *Mod {
|
|||||||
&minio.Options{
|
&minio.Options{
|
||||||
Creds: credentials.NewStaticV4(cfg.AccessKey, cfg.SecretKey, ""),
|
Creds: credentials.NewStaticV4(cfg.AccessKey, cfg.SecretKey, ""),
|
||||||
Secure: cfg.Ssl,
|
Secure: cfg.Ssl,
|
||||||
|
//BucketLookup: minio.BucketLookupPath,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -133,11 +135,13 @@ func (s *Mod) ListBuckets() []minio.BucketInfo {
|
|||||||
func (s *Mod) PutObject(f io.Reader, name string, bucketName string, _size ...int64) (res minio.UploadInfo, err error) {
|
func (s *Mod) PutObject(f io.Reader, name string, bucketName string, _size ...int64) (res minio.UploadInfo, err error) {
|
||||||
// 初始化文件大小为 -1,表示将读取文件至结束
|
// 初始化文件大小为 -1,表示将读取文件至结束
|
||||||
var size = int64(-1)
|
var size = int64(-1)
|
||||||
if len(_size) > 0 {
|
//if len(_size) > 0 {
|
||||||
size = _size[0]
|
// size = _size[0]
|
||||||
}
|
//}
|
||||||
// 调用 S3 客户端上传文件,设置内容类型为 "application/octet-stream"
|
// 调用 S3 客户端上传文件,设置内容类型为 "application/octet-stream"
|
||||||
res, err = s.client.PutObject(ctx, bucketName, name, f, size, minio.PutObjectOptions{ContentType: "application/octet-stream"})
|
res, err = s.client.PutObject(ctx, bucketName, name, f, size, minio.PutObjectOptions{
|
||||||
|
//ContentType: "application/octet-stream",
|
||||||
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// 记录上传错误日志
|
// 记录上传错误日志
|
||||||
g.Log().Error(ctx, err)
|
g.Log().Error(ctx, err)
|
||||||
@@ -146,8 +150,22 @@ func (s *Mod) PutObject(f io.Reader, name string, bucketName string, _size ...in
|
|||||||
}
|
}
|
||||||
|
|
||||||
// RemoveObject 从指定存储桶中删除指定名称的文件
|
// RemoveObject 从指定存储桶中删除指定名称的文件
|
||||||
|
// Deprecation: to新方法 RemoveObjectV2
|
||||||
func (s *Mod) RemoveObject(name string, bucketName string) (err error) {
|
func (s *Mod) RemoveObject(name string, bucketName string) (err error) {
|
||||||
opts := minio.RemoveObjectOptions{
|
opts := minio.RemoveObjectOptions{
|
||||||
|
ForceDelete: true,
|
||||||
|
//GovernanceBypass: true,
|
||||||
|
//VersionID: "myversionid",
|
||||||
|
}
|
||||||
|
// 调用 S3 客户端删除文件
|
||||||
|
err = s.client.RemoveObject(ctx, bucketName, name, opts)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveObjectV2 从指定存储桶中删除指定名称的文件
|
||||||
|
func (s *Mod) RemoveObjectV2(bucketName string, name string) (err error) {
|
||||||
|
opts := minio.RemoveObjectOptions{
|
||||||
|
ForceDelete: true,
|
||||||
//GovernanceBypass: true,
|
//GovernanceBypass: true,
|
||||||
//VersionID: "myversionid",
|
//VersionID: "myversionid",
|
||||||
}
|
}
|
||||||
@@ -187,9 +205,15 @@ func (s *Mod) GetUrl(filePath string, defaultFile ...string) (url string) {
|
|||||||
filePath = defaultFile[0]
|
filePath = defaultFile[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.cfg.Ssl {
|
//switch s.cfg.Provider {
|
||||||
url = get + filePath
|
//case "qiniu":
|
||||||
} else {
|
// url = get + path.Join(bucketName, filePath)
|
||||||
|
//default:
|
||||||
|
// url = get + filePath
|
||||||
|
//}
|
||||||
|
url = get + filePath
|
||||||
|
|
||||||
|
if !s.cfg.Ssl {
|
||||||
url = get + path.Join(bucketName, filePath)
|
url = get + path.Join(bucketName, filePath)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -205,21 +229,43 @@ func (s *Mod) GetPath(url string) (filePath string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CopyObject 在指定存储桶内复制文件
|
// CopyObject 在指定存储桶内复制文件
|
||||||
// 支持指定源文件和目标文件路径
|
// bucketName 存储桶名称
|
||||||
|
// dstStr 目标文件路径
|
||||||
|
// srcStr 源文件路径
|
||||||
|
// 返回操作过程中可能出现的错误
|
||||||
func (s *Mod) CopyObject(bucketName string, dstStr string, srcStr string) (err error) {
|
func (s *Mod) CopyObject(bucketName string, dstStr string, srcStr string) (err error) {
|
||||||
// 定义目标文件选项
|
// 定义目标文件的复制选项,包含存储桶名称和目标文件路径
|
||||||
var dst = minio.CopyDestOptions{
|
var dst = minio.CopyDestOptions{
|
||||||
Bucket: bucketName,
|
Bucket: bucketName,
|
||||||
Object: dstStr,
|
Object: dstStr,
|
||||||
}
|
}
|
||||||
|
|
||||||
// 定义源文件选项
|
// 定义源文件的复制选项,包含存储桶名称和源文件路径
|
||||||
var src = minio.CopySrcOptions{
|
var src = minio.CopySrcOptions{
|
||||||
Bucket: bucketName,
|
Bucket: bucketName,
|
||||||
Object: srcStr,
|
Object: srcStr,
|
||||||
}
|
}
|
||||||
|
|
||||||
// 调用 S3 客户端复制文件
|
// 调用 S3 客户端的 CopyObject 方法,将源文件复制到目标位置
|
||||||
|
// 忽略返回的复制信息,仅关注是否发生错误
|
||||||
_, err = s.client.CopyObject(ctx, dst, src)
|
_, err = s.client.CopyObject(ctx, dst, src)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Rename 重命名文件
|
||||||
|
func (s *Mod) Rename(bucketName string, oldName string, newName string) (err error) {
|
||||||
|
// 复制文件到新的名称
|
||||||
|
g.Log().Debugf(nil, "仓库=%v,rename %s to %s", bucketName, oldName, newName)
|
||||||
|
err = s.CopyObject(bucketName, newName, oldName)
|
||||||
|
if err != nil {
|
||||||
|
g.Log().Error(ctx, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 删除原始文件
|
||||||
|
err = s.RemoveObjectV2(bucketName, oldName)
|
||||||
|
if err != nil {
|
||||||
|
g.Log().Error(ctx, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user