(data, postAndJSON = false, appKey = SIGN_APP_KEY)
| 89 | } |
| 90 | |
| 91 | function 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 | |
| 113 | function uuid() { |
| 114 | if (crypto.randomUUID) return crypto.randomUUID(); |
no test coverage detected