function getSortedParameter (parameterObject){ let attributes = []; parameterObject = parameterObject ? parameterObject:{}; for(let attr in parameterObject){ attributes.push(attr); } attributes.sort(); let paramStr = ""; attributes.forEach(element=>{ paramStr += element + "=" + parameterObject[element] + "&" }); return paramStr; }
let me = {}; me["body"] = "test"; me["mch_id"] = "10000100"; me["appid"] = "wxd930ea5d5a258f4f"; me["nonce_str"] = "ibuaiVcKdpRxkhJA"; let signStr = getSortedParameter(me); //signStr:appid=wxd930ea5d5a258f4f&body=test&device_info=1000&mch_id=10000100&nonce_str=ibuaiVcKdpRxkhJA&