This commit is contained in:
yangduo 2025-02-24 13:59:58 +08:00
parent dc6f0981df
commit 04521ba59a
2 changed files with 89 additions and 89 deletions

View File

@ -24,11 +24,16 @@ type expireSession struct {
SessionTime int64 SessionTime int64
Time int64 Time int64
} }
type mediaidInfo struct {
mediaId string
time int64
}
type wxpay struct { type wxpay struct {
gamesGoods q5.ConcurrentMap[int64, map[int64]GoodsInfo] //[gameid, [goodsid]goodsinfo] gamesGoods q5.ConcurrentMap[int64, map[int64]GoodsInfo] //[gameid, [goodsid]goodsinfo]
accessTokens q5.ConcurrentMap[int64, TokenInfo] //[gameid, TokenInfo] accessTokens q5.ConcurrentMap[int64, TokenInfo] //[gameid, TokenInfo]
expireInfo q5.ConcurrentMap[string, *expireSession] //[accountid, expireSession] expireInfo q5.ConcurrentMap[string, *expireSession] //[accountid, expireSession]
mediaInfo q5.ConcurrentMap[int64, string] //[gameid, mediaid] mediaInfo q5.ConcurrentMap[int64, mediaidInfo] //[gameid, mediainfo]
refreshflag bool refreshflag bool
ctx context.Context ctx context.Context
client *core.Client client *core.Client

View File

@ -63,13 +63,25 @@ func (wp *wxpay) initMch() {
} }
func (wp *wxpay) checkGameMediaId() { func (wp *wxpay) checkGameMediaId() {
wp.mediaInfo = q5.ConcurrentMap[int64, string]{} wp.mediaInfo = q5.ConcurrentMap[int64, mediaidInfo]{}
uploadtime := int64(0) gamecout := 0
mt.Table.Wxconfig.Traverse(func(w *mt.Wxconfig) bool {
gamecout++
return true
})
for { for {
nowtime := f5.GetApp().GetRealSeconds() nowtime := f5.GetApp().GetRealSeconds()
if wp.mediaInfo.GetSize() == 0 || q5.GetDaySeconds(uploadtime, 8) != q5.GetDaySeconds(nowtime, 8) {
// uploader := fileuploader.ImageUploader{Client: wp.client}
mt.Table.Wxconfig.Traverse(func(w *mt.Wxconfig) bool { mt.Table.Wxconfig.Traverse(func(w *mt.Wxconfig) bool {
info, _ := wp.mediaInfo.Load(w.GetGameid())
if info == nil {
info = &mediaidInfo{}
}
if q5.GetDaySeconds(info.time, 8) == q5.GetDaySeconds(nowtime, 8) && len(info.mediaId) != 0 {
return true
}
filename := q5.SafeToString(w.GetGameid()) + ".jpg" filename := q5.SafeToString(w.GetGameid()) + ".jpg"
fullfilename := fmt.Sprintf("../res/gamepics/%s", filename) fullfilename := fmt.Sprintf("../res/gamepics/%s", filename)
@ -99,9 +111,13 @@ func (wp *wxpay) checkGameMediaId() {
} }
writer.Close() writer.Close()
refreshed := false desurl := "https://api.weixin.qq.com/cgi-bin/media/upload"
urls := mt.Table.Config.GetWxUrl()
if len(urls) > 0 {
desurl = fmt.Sprintf("https://%s/cgi-bin/media/upload", urls[0])
}
f5.GetHttpCliMgr().SendGoStylePost( f5.GetHttpCliMgr().SendGoStylePost(
"https://api.weixin.qq.com/cgi-bin/media/upload", desurl,
map[string]string{ map[string]string{
"access_token": accesstoken.Token, "access_token": accesstoken.Token,
"type": "image", "type": "image",
@ -125,37 +141,16 @@ func (wp *wxpay) checkGameMediaId() {
return return
} }
wp.mediaInfo.Store(w.GetGameid(), rspObj.MediaId) info.mediaId = rspObj.MediaId
info.time = nowtime
wp.mediaInfo.Store(w.GetGameid(), *info)
f5.GetSysLog().Debug("upload refresh media ok:%s, %s", filename, rspObj.MediaId) f5.GetSysLog().Debug("upload refresh media ok:%s, %s", filename, rspObj.MediaId)
refreshed = true
}) })
if refreshed {
return true
}
// file, err := os.Open(fullfilename)
// if err != nil {
// f5.GetSysLog().Error("file error:%s", filename)
// return false
// }
// defer file.Close()
// resp, result, err := uploader.Upload(wp.ctx, file, filename, consts.ImageJPG)
// if err == nil {
// wp.mediaInfo.Store(w.GetGameid(), *resp.MediaId)
// f5.GetSysLog().Debug("refresh media ok:%s, %s", filename, *resp.MediaId)
// } else {
// f5.GetSysLog().Error("refresh media err:%s, %s", filename, result.Response.Status)
// }
return true return true
}) })
uploadtime = nowtime if wp.mediaInfo.GetSize() != gamecout {
}
if wp.mediaInfo.GetSize() == 0 {
time.Sleep(time.Second) time.Sleep(time.Second)
} else { } else {
time.Sleep(time.Minute) time.Sleep(time.Minute)