qiliu_job.go 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package jobcron
  2. import (
  3. "Kya_New/service/login_service"
  4. "fmt"
  5. "github.com/astaxie/beego"
  6. "github.com/qiniu/api.v7/auth/qbox"
  7. "github.com/qiniu/api.v7/storage"
  8. "github.com/robfig/cron"
  9. )
  10. var qnTokenCronJob *cron.Cron
  11. func init() {
  12. qnTokenCronJob := cron.New()
  13. qnTokenCronJob.AddFunc("@every 1h50m", func() {
  14. go RequestQNToken()
  15. })
  16. }
  17. func RequestQNToken() {
  18. accessKey := beego.AppConfig.String("qiniu_accesskey")
  19. fmt.Println("accessKey", accessKey)
  20. secretKey := beego.AppConfig.String("qiniu_secretkey")
  21. fmt.Println("secretKey", secretKey)
  22. bucket := beego.AppConfig.String("qiniu_bucket")
  23. fmt.Println("bucket", bucket)
  24. putPolicy := storage.PutPolicy{
  25. Scope: bucket,
  26. ReturnBody: `{"url":"$(key)","hash":"$(etag)","state":"SUCCESS"}`,
  27. }
  28. fmt.Println("putPolicy", putPolicy)
  29. putPolicy.Expires = 7200
  30. mac := qbox.NewMac(accessKey, secretKey)
  31. fmt.Println("mac", mac)
  32. upToken := putPolicy.UploadToken(mac)
  33. fmt.Println("new qiniu upToken", upToken)
  34. redisClient := login_service.RedisClient()
  35. defer redisClient.Close()
  36. redisClient.Set("qn_token", upToken, 0)
  37. }
  38. func BeginRerequestTwoQNTokenCronJob() {
  39. fmt.Println("七牛开始啦")
  40. //qnTokenCronJob.Start()
  41. }