cos.js 818 B

12345678910111213141516171819202122
  1. var COS = require('./cos-wx-sdk-v5');
  2. var config = require('../config');
  3. var cos = new COS({
  4. getAuthorization: function (options, callback) {
  5. wx.request({
  6. method: 'GET',
  7. url: config.stsUrl, // 服务端签名,参考 server 目录下的两个签名例子
  8. dataType: 'json',
  9. success: function (result) {
  10. var data = result.data;
  11. callback({
  12. TmpSecretId: data.credentials && data.credentials.tmpSecretId,
  13. TmpSecretKey: data.credentials && data.credentials.tmpSecretKey,
  14. XCosSecurityToken: data.credentials && data.credentials.sessionToken,
  15. ExpiredTime: data.expiredTime,
  16. });
  17. }
  18. });
  19. },
  20. });
  21. module.exports = cos;