adjust
This commit is contained in:
parent
dc6f0981df
commit
04521ba59a
@ -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
|
||||||
|
@ -63,99 +63,94 @@ 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) {
|
mt.Table.Wxconfig.Traverse(func(w *mt.Wxconfig) bool {
|
||||||
// uploader := fileuploader.ImageUploader{Client: wp.client}
|
info, _ := wp.mediaInfo.Load(w.GetGameid())
|
||||||
mt.Table.Wxconfig.Traverse(func(w *mt.Wxconfig) bool {
|
if info == nil {
|
||||||
filename := q5.SafeToString(w.GetGameid()) + ".jpg"
|
info = &mediaidInfo{}
|
||||||
fullfilename := fmt.Sprintf("../res/gamepics/%s", filename)
|
}
|
||||||
|
|
||||||
body := &bytes.Buffer{}
|
if q5.GetDaySeconds(info.time, 8) == q5.GetDaySeconds(nowtime, 8) && len(info.mediaId) != 0 {
|
||||||
writer := multipart.NewWriter(body)
|
|
||||||
accesstoken, ok := wp.accessTokens.Load(w.GetGameid())
|
|
||||||
if !ok || len(accesstoken.Token) == 0 {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
file, err := os.Open(fullfilename)
|
|
||||||
if err != nil {
|
|
||||||
f5.GetSysLog().Error("file error1:%s", filename)
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
defer file.Close()
|
|
||||||
|
|
||||||
part, err := writer.CreateFormFile("media", fullfilename)
|
|
||||||
if err != nil {
|
|
||||||
f5.GetSysLog().Debug("createFormFile err:%v", err.Error())
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
_, err = io.Copy(part, file)
|
|
||||||
if err != nil {
|
|
||||||
f5.GetSysLog().Debug("io.copy err:%v", err.Error())
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
writer.Close()
|
|
||||||
|
|
||||||
refreshed := false
|
|
||||||
f5.GetHttpCliMgr().SendGoStylePost(
|
|
||||||
"https://api.weixin.qq.com/cgi-bin/media/upload",
|
|
||||||
map[string]string{
|
|
||||||
"access_token": accesstoken.Token,
|
|
||||||
"type": "image",
|
|
||||||
},
|
|
||||||
writer.FormDataContentType(),
|
|
||||||
body.String(),
|
|
||||||
func(hcr f5.HttpCliResponse) {
|
|
||||||
if hcr.GetErr() != nil {
|
|
||||||
f5.GetSysLog().Debug("upload err:%s", hcr.GetErr().Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
f5.GetSysLog().Debug("upload rsp:%s", hcr.GetRawData())
|
|
||||||
rspObj := struct {
|
|
||||||
Type string `json:"type"`
|
|
||||||
MediaId string `json:"media_id"`
|
|
||||||
Time int64 `json:"created_at"`
|
|
||||||
}{}
|
|
||||||
|
|
||||||
if json.Unmarshal([]byte(hcr.GetRawData()), &rspObj) != nil || len(rspObj.MediaId) == 0 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
wp.mediaInfo.Store(w.GetGameid(), 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
|
filename := q5.SafeToString(w.GetGameid()) + ".jpg"
|
||||||
}
|
fullfilename := fmt.Sprintf("../res/gamepics/%s", filename)
|
||||||
|
|
||||||
if wp.mediaInfo.GetSize() == 0 {
|
body := &bytes.Buffer{}
|
||||||
|
writer := multipart.NewWriter(body)
|
||||||
|
accesstoken, ok := wp.accessTokens.Load(w.GetGameid())
|
||||||
|
if !ok || len(accesstoken.Token) == 0 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
file, err := os.Open(fullfilename)
|
||||||
|
if err != nil {
|
||||||
|
f5.GetSysLog().Error("file error1:%s", filename)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
|
||||||
|
part, err := writer.CreateFormFile("media", fullfilename)
|
||||||
|
if err != nil {
|
||||||
|
f5.GetSysLog().Debug("createFormFile err:%v", err.Error())
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
_, err = io.Copy(part, file)
|
||||||
|
if err != nil {
|
||||||
|
f5.GetSysLog().Debug("io.copy err:%v", err.Error())
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
writer.Close()
|
||||||
|
|
||||||
|
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(
|
||||||
|
desurl,
|
||||||
|
map[string]string{
|
||||||
|
"access_token": accesstoken.Token,
|
||||||
|
"type": "image",
|
||||||
|
},
|
||||||
|
writer.FormDataContentType(),
|
||||||
|
body.String(),
|
||||||
|
func(hcr f5.HttpCliResponse) {
|
||||||
|
if hcr.GetErr() != nil {
|
||||||
|
f5.GetSysLog().Debug("upload err:%s", hcr.GetErr().Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
f5.GetSysLog().Debug("upload rsp:%s", hcr.GetRawData())
|
||||||
|
rspObj := struct {
|
||||||
|
Type string `json:"type"`
|
||||||
|
MediaId string `json:"media_id"`
|
||||||
|
Time int64 `json:"created_at"`
|
||||||
|
}{}
|
||||||
|
|
||||||
|
if json.Unmarshal([]byte(hcr.GetRawData()), &rspObj) != nil || len(rspObj.MediaId) == 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
})
|
||||||
|
|
||||||
|
return true
|
||||||
|
})
|
||||||
|
|
||||||
|
if wp.mediaInfo.GetSize() != gamecout {
|
||||||
time.Sleep(time.Second)
|
time.Sleep(time.Second)
|
||||||
} else {
|
} else {
|
||||||
time.Sleep(time.Minute)
|
time.Sleep(time.Minute)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user