CustomQCloudCredentialProvider.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132
  1. using COSXML.Auth;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6. public class CustomQCloudCredentialProvider : DefaultSessionQCloudCredentialProvider
  7. {
  8. QCloudCredentialProvider cosCredentialProvider = new CustomQCloudCredentialProvider();
  9. // 这里假设开始没有密钥,也可以用初始的临时密钥来初始化
  10. public CustomQCloudCredentialProvider() : base(null, null, 0L, null)
  11. {
  12. ;
  13. }
  14. public override void Refresh()
  15. {
  16. //... 首先通过腾讯云请求临时密钥
  17. string tmpSecretId = COSDownLoad.Instance.successCos.credentials.tmpSecretId; //"临时密钥 SecretId", 临时密钥生成和使用指引参见 https://cloud.tencent.com/document/product/436/14048
  18. string tmpSecretKey = COSDownLoad.Instance.successCos.credentials.tmpSecretKey; //"临时密钥 SecretKey", 临时密钥生成和使用指引参见 https://cloud.tencent.com/document/product/436/14048
  19. string tmpToken = COSDownLoad.Instance.successCos.credentials.sessionToken; //"临时密钥 token", 临时密钥生成和使用指引参见 https://cloud.tencent.com/document/product/436/14048
  20. long tmpStartTime = COSDownLoad.Instance.successCos.startTime;//临时密钥有效开始时间,精确到秒
  21. long tmpExpiredTime = COSDownLoad.Instance.successCos.expiredTime;//临时密钥有效截止时间,精确到秒
  22. // 调用接口更新密钥
  23. SetQCloudCredential(tmpSecretId, tmpSecretKey,
  24. String.Format("{0};{1}", tmpStartTime, tmpExpiredTime), tmpToken);
  25. }
  26. }