调试提示 29行 var key = Object.keys(obj); 对象不支持此属性或方法! 是length的问题吗? 该如何修改! 还有其他问题吗?
[JavaScript] 纯文本查看 复制代码 function genSignSource(url, methods, params, body, timestamp) {
var signOriginSource = {
url: url,
method: methods,
timestamp: timestamp
};
var saltArr = ["a", "o", "l", "i", "g", "e", "i", "A", "O", "L", "I", "G", "E", "I"];
if (params) {
if (typeof params == "string") {
signOriginSource = paramsStrSort(params)
} else {
if (typeof params == "object") {
signOriginSource = $.extend(signOriginSource, params)
}
}
}
if (body) {
if (typeof body == "string") {
signOriginSource.body = body
} else {
if (typeof body == "object") {
signOriginSource.body = JSON.stringify(body)
}
}
}
signOriginSource = paramsStrSort(signOriginSource);
function paramsStrSort(obj) {
var oriObj = "";
var key = Object.keys(obj);
var keyArr = key.sort();
for (var index = 0; index < keyArr.length; index++) {
var key = keyArr[index];
var salt = saltArr[index % saltArr.length];
oriObj += salt + key + "=" + obj[key] + "&"
}
oriObj = oriObj.substring(0, oriObj.length - 1);
return oriObj
}
var sourceLen = signOriginSource.length;
var offset = Math.floor(sourceLen / 3);
signOriginSource = signOriginSource.substring(offset) + signOriginSource.substring(0, offset);
}
|