MCPcopy Create free account
hub / github.com/smallfawn/QLScriptPublic / signString

Function signString

wxapp/hisense_aijia.js:91–111  ·  view source on GitHub ↗
(data, postAndJSON = false, appKey = SIGN_APP_KEY)

Source from the content-addressed store, hash-verified

89}
90
91function signString(data, postAndJSON = false, appKey = SIGN_APP_KEY) {
92 const secret = getSignSecret(appKey);
93 let text = "";
94 if (postAndJSON) {
95 text = typeof data === "string" ? data : JSON.stringify(data || {});
96 } else if (typeof data === "string") {
97 text = data;
98 } else {
99 text = Object.keys(data || {})
100 .map((key) => {
101 let value = data[key];
102 if (value === "" || value === null || value === undefined) return "";
103 if (typeof value === "object") value = JSON.stringify(value);
104 return `${key}=${value}`;
105 })
106 .filter(Boolean)
107 .sort()
108 .join("&");
109 }
110 return crypto.createHash("md5").update(`${text}${secret}`).digest("base64");
111}
112
113function uuid() {
114 if (crypto.randomUUID) return crypto.randomUUID();

Callers 1

buildSignFunction · 0.85

Calls 1

getSignSecretFunction · 0.85

Tested by

no test coverage detected