diff --git a/demo-album/lib/cos-wx-sdk-v5.js b/demo-album/lib/cos-wx-sdk-v5.js index c7ba392..4580e5d 100644 --- a/demo-album/lib/cos-wx-sdk-v5.js +++ b/demo-album/lib/cos-wx-sdk-v5.js @@ -97,6 +97,34 @@ function camSafeUrlEncode(str) { .replace(/\*/g, '%2A'); } +function getObjectKeys(obj, forKey) { + var list = []; + for (var key in obj) { + if (obj.hasOwnProperty(key)) { + list.push(forKey ? camSafeUrlEncode(key).toLowerCase() : key); + } + } + return list.sort(function (a, b) { + a = a.toLowerCase(); + b = b.toLowerCase(); + return a === b ? 0 : (a > b ? 1 : -1); + }); +}; + +var obj2str = function (obj) { + var i, key, val; + var list = []; + var keyList = getObjectKeys(obj); + for (i = 0; i < keyList.length; i++) { + key = keyList[i]; + val = (obj[key] === undefined || obj[key] === null) ? '' : ('' + obj[key]); + key = camSafeUrlEncode(key).toLowerCase(); + val = camSafeUrlEncode(val) || ''; + list.push(key + '=' + val) + } + return list.join('&'); +}; + //测试用的key后面可以去掉 var getAuth = function (opt) { opt = opt || {}; @@ -120,34 +148,6 @@ var getAuth = function (opt) { if (!SecretId) return console.error('missing param SecretId'); if (!SecretKey) return console.error('missing param SecretKey'); - var getObjectKeys = function (obj, forKey) { - var list = []; - for (var key in obj) { - if (obj.hasOwnProperty(key)) { - list.push(forKey ? camSafeUrlEncode(key).toLowerCase() : key); - } - } - return list.sort(function (a, b) { - a = a.toLowerCase(); - b = b.toLowerCase(); - return a === b ? 0 : (a > b ? 1 : -1); - }); - }; - - var obj2str = function (obj) { - var i, key, val; - var list = []; - var keyList = getObjectKeys(obj); - for (i = 0; i < keyList.length; i++) { - key = keyList[i]; - val = (obj[key] === undefined || obj[key] === null) ? '' : ('' + obj[key]); - key = camSafeUrlEncode(key).toLowerCase(); - val = camSafeUrlEncode(val) || ''; - list.push(key + '=' + val) - } - return list.join('&'); - }; - // 签名有效起止时间 var now = Math.round(getSkewTime(opt.SystemClockOffset) / 1000) - 1; var exp = now; @@ -172,7 +172,7 @@ var getAuth = function (opt) { var signKey = CryptoJS.HmacSHA1(qKeyTime, SecretKey).toString(); // 步骤二:构成 FormatString - var formatString = [method, pathname, obj2str(queryParams), obj2str(headers), ''].join('\n'); + var formatString = [method, pathname, util.obj2str(queryParams), util.obj2str(headers), ''].join('\n'); // 步骤三:计算 StringToSign var stringToSign = ['sha1', qSignTime, CryptoJS.SHA1(formatString).toString(), ''].join('\n'); @@ -655,6 +655,7 @@ var util = { throttleOnProgress: throttleOnProgress, getFileSize: getFileSize, getSkewTime: getSkewTime, + obj2str: obj2str, getAuth: getAuth, compareVersion: compareVersion, canFileSlice: canFileSlice, @@ -2338,7 +2339,7 @@ base.init(COS, task); advance.init(COS, task); COS.getAuthorization = util.getAuth; -COS.version = '1.0.10'; +COS.version = '1.0.11'; module.exports = COS; diff --git a/demo/lib/cos-wx-sdk-v5.js b/demo/lib/cos-wx-sdk-v5.js index c7ba392..4580e5d 100644 --- a/demo/lib/cos-wx-sdk-v5.js +++ b/demo/lib/cos-wx-sdk-v5.js @@ -97,6 +97,34 @@ function camSafeUrlEncode(str) { .replace(/\*/g, '%2A'); } +function getObjectKeys(obj, forKey) { + var list = []; + for (var key in obj) { + if (obj.hasOwnProperty(key)) { + list.push(forKey ? camSafeUrlEncode(key).toLowerCase() : key); + } + } + return list.sort(function (a, b) { + a = a.toLowerCase(); + b = b.toLowerCase(); + return a === b ? 0 : (a > b ? 1 : -1); + }); +}; + +var obj2str = function (obj) { + var i, key, val; + var list = []; + var keyList = getObjectKeys(obj); + for (i = 0; i < keyList.length; i++) { + key = keyList[i]; + val = (obj[key] === undefined || obj[key] === null) ? '' : ('' + obj[key]); + key = camSafeUrlEncode(key).toLowerCase(); + val = camSafeUrlEncode(val) || ''; + list.push(key + '=' + val) + } + return list.join('&'); +}; + //测试用的key后面可以去掉 var getAuth = function (opt) { opt = opt || {}; @@ -120,34 +148,6 @@ var getAuth = function (opt) { if (!SecretId) return console.error('missing param SecretId'); if (!SecretKey) return console.error('missing param SecretKey'); - var getObjectKeys = function (obj, forKey) { - var list = []; - for (var key in obj) { - if (obj.hasOwnProperty(key)) { - list.push(forKey ? camSafeUrlEncode(key).toLowerCase() : key); - } - } - return list.sort(function (a, b) { - a = a.toLowerCase(); - b = b.toLowerCase(); - return a === b ? 0 : (a > b ? 1 : -1); - }); - }; - - var obj2str = function (obj) { - var i, key, val; - var list = []; - var keyList = getObjectKeys(obj); - for (i = 0; i < keyList.length; i++) { - key = keyList[i]; - val = (obj[key] === undefined || obj[key] === null) ? '' : ('' + obj[key]); - key = camSafeUrlEncode(key).toLowerCase(); - val = camSafeUrlEncode(val) || ''; - list.push(key + '=' + val) - } - return list.join('&'); - }; - // 签名有效起止时间 var now = Math.round(getSkewTime(opt.SystemClockOffset) / 1000) - 1; var exp = now; @@ -172,7 +172,7 @@ var getAuth = function (opt) { var signKey = CryptoJS.HmacSHA1(qKeyTime, SecretKey).toString(); // 步骤二:构成 FormatString - var formatString = [method, pathname, obj2str(queryParams), obj2str(headers), ''].join('\n'); + var formatString = [method, pathname, util.obj2str(queryParams), util.obj2str(headers), ''].join('\n'); // 步骤三:计算 StringToSign var stringToSign = ['sha1', qSignTime, CryptoJS.SHA1(formatString).toString(), ''].join('\n'); @@ -655,6 +655,7 @@ var util = { throttleOnProgress: throttleOnProgress, getFileSize: getFileSize, getSkewTime: getSkewTime, + obj2str: obj2str, getAuth: getAuth, compareVersion: compareVersion, canFileSlice: canFileSlice, @@ -2338,7 +2339,7 @@ base.init(COS, task); advance.init(COS, task); COS.getAuthorization = util.getAuth; -COS.version = '1.0.10'; +COS.version = '1.0.11'; module.exports = COS; diff --git a/package.json b/package.json index 377a550..488b87d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cos-wx-sdk-v5", - "version": "1.0.10", + "version": "1.0.11", "description": "小程序 SDK for [腾讯云对象存储服务](https://cloud.tencent.com/product/cos)", "main": "demo/lib/cos-wx-sdk-v5.js", "scripts": { diff --git a/src/cos.js b/src/cos.js index b4d8f9b..b20b341 100644 --- a/src/cos.js +++ b/src/cos.js @@ -57,6 +57,6 @@ base.init(COS, task); advance.init(COS, task); COS.getAuthorization = util.getAuth; -COS.version = '1.0.10'; +COS.version = '1.0.11'; module.exports = COS; diff --git a/src/util.js b/src/util.js index 666693c..e874f85 100644 --- a/src/util.js +++ b/src/util.js @@ -17,6 +17,34 @@ function camSafeUrlEncode(str) { .replace(/\*/g, '%2A'); } +function getObjectKeys(obj, forKey) { + var list = []; + for (var key in obj) { + if (obj.hasOwnProperty(key)) { + list.push(forKey ? camSafeUrlEncode(key).toLowerCase() : key); + } + } + return list.sort(function (a, b) { + a = a.toLowerCase(); + b = b.toLowerCase(); + return a === b ? 0 : (a > b ? 1 : -1); + }); +}; + +var obj2str = function (obj) { + var i, key, val; + var list = []; + var keyList = getObjectKeys(obj); + for (i = 0; i < keyList.length; i++) { + key = keyList[i]; + val = (obj[key] === undefined || obj[key] === null) ? '' : ('' + obj[key]); + key = camSafeUrlEncode(key).toLowerCase(); + val = camSafeUrlEncode(val) || ''; + list.push(key + '=' + val) + } + return list.join('&'); +}; + //测试用的key后面可以去掉 var getAuth = function (opt) { opt = opt || {}; @@ -40,34 +68,6 @@ var getAuth = function (opt) { if (!SecretId) return console.error('missing param SecretId'); if (!SecretKey) return console.error('missing param SecretKey'); - var getObjectKeys = function (obj, forKey) { - var list = []; - for (var key in obj) { - if (obj.hasOwnProperty(key)) { - list.push(forKey ? camSafeUrlEncode(key).toLowerCase() : key); - } - } - return list.sort(function (a, b) { - a = a.toLowerCase(); - b = b.toLowerCase(); - return a === b ? 0 : (a > b ? 1 : -1); - }); - }; - - var obj2str = function (obj) { - var i, key, val; - var list = []; - var keyList = getObjectKeys(obj); - for (i = 0; i < keyList.length; i++) { - key = keyList[i]; - val = (obj[key] === undefined || obj[key] === null) ? '' : ('' + obj[key]); - key = camSafeUrlEncode(key).toLowerCase(); - val = camSafeUrlEncode(val) || ''; - list.push(key + '=' + val) - } - return list.join('&'); - }; - // 签名有效起止时间 var now = Math.round(getSkewTime(opt.SystemClockOffset) / 1000) - 1; var exp = now; @@ -92,7 +92,7 @@ var getAuth = function (opt) { var signKey = CryptoJS.HmacSHA1(qKeyTime, SecretKey).toString(); // 步骤二:构成 FormatString - var formatString = [method, pathname, obj2str(queryParams), obj2str(headers), ''].join('\n'); + var formatString = [method, pathname, util.obj2str(queryParams), util.obj2str(headers), ''].join('\n'); // 步骤三:计算 StringToSign var stringToSign = ['sha1', qSignTime, CryptoJS.SHA1(formatString).toString(), ''].join('\n'); @@ -575,6 +575,7 @@ var util = { throttleOnProgress: throttleOnProgress, getFileSize: getFileSize, getSkewTime: getSkewTime, + obj2str: obj2str, getAuth: getAuth, compareVersion: compareVersion, canFileSlice: canFileSlice,