123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- 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")
- 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)
- 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()
- }
|