12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- package jobcron
-
- import (
- "Kya_New/service/login_service"
- "fmt"
- "github.com/astaxie/beego"
- "github.com/qiniu/api.v7/auth/qbox"
- "github.com/qiniu/api.v7/storage"
- "github.com/robfig/cron"
- )
-
- var qnTokenCronJob *cron.Cron
-
- func init() {
- qnTokenCronJob := cron.New()
- qnTokenCronJob.AddFunc("@every 1h50m", func() {
- go RequestQNToken()
- })
- }
- func RequestQNToken() {
- accessKey := beego.AppConfig.String("qiniu_accesskey")
- fmt.Println("accessKey", accessKey)
- secretKey := beego.AppConfig.String("qiniu_secretkey")
- fmt.Println("secretKey", secretKey)
- bucket := beego.AppConfig.String("qiniu_bucket")
- fmt.Println("bucket", bucket)
- putPolicy := storage.PutPolicy{
- Scope: bucket,
- ReturnBody: `{"url":"$(key)","hash":"$(etag)","state":"SUCCESS"}`,
- }
- fmt.Println("putPolicy", putPolicy)
- putPolicy.Expires = 7200
- mac := qbox.NewMac(accessKey, secretKey)
- fmt.Println("mac", mac)
- upToken := putPolicy.UploadToken(mac)
- fmt.Println("new qiniu upToken", upToken)
- redisClient := login_service.RedisClient()
- defer redisClient.Close()
- redisClient.Set("qn_token", upToken, 0)
- }
-
- func BeginRerequestTwoQNTokenCronJob() {
- fmt.Println("七牛开始啦")
- //qnTokenCronJob.Start()
- }
|