From fe269cb0cae1e1b2b264508699e3a071b8404426 Mon Sep 17 00:00:00 2001 From: Ivan Eyara Date: Wed, 21 Aug 2024 16:52:33 -0400 Subject: [PATCH] fix: parameters concatenation format and encode uri POST data --- es/index.js | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/es/index.js b/es/index.js index 6b7c53a..607cbbe 100644 --- a/es/index.js +++ b/es/index.js @@ -18,7 +18,7 @@ class FlowApi { apiKey: this.apiKey, ...params }; - let data = this.getPack(params, method); + let data = this.getPack(params); let sign = this.sign(params); let response; if (method == "GET") { @@ -42,7 +42,7 @@ class FlowApi { } }); } - getPack(params, method) { + getPack(params) { const keys = Object.keys(params) .map(key => key) .sort((a, b) => { @@ -52,13 +52,9 @@ class FlowApi { }); let data = []; keys.map(key => { - if (method == "GET") { - data.push( - encodeURIComponent(key) + "=" + encodeURIComponent(params[key]) - ); - } else { - data.push(key + "=" + params[key]); - } + data.push( + encodeURIComponent(key) + "=" + encodeURIComponent(params[key]) + ); }); return data.join("&"); } @@ -72,9 +68,9 @@ class FlowApi { }); let toSign = []; keys.map(key => { - toSign.push(key + "=" + params[key]); + toSign.push(key + params[key]); }); - toSign = toSign.join("&"); + toSign = toSign.join(""); return CryptoJS.HmacSHA256(toSign, this.secretKey); }