package jobcron import ( "SCRM/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") secretKey := beego.AppConfig.String("qiniu_secretkey") bucket := beego.AppConfig.String("qiniu_bucket") putPolicy := storage.PutPolicy{ Scope: bucket, ReturnBody: `{"url":"$(key)","hash":"$(etag)","state":"SUCCESS"}`, } putPolicy.Expires = 7200 mac := qbox.NewMac(accessKey, secretKey) upToken := putPolicy.UploadToken(mac) fmt.Println("new qiniu token: ", upToken) redisClient := service.RedisClient() defer redisClient.Close() redisClient.Set("qn_token", upToken, 0) } func BeginRerequestQNTokenCronJob() { qnTokenCronJob.Start() }