({ data = null, token = "" } = {})
| 64 | } |
| 65 | |
| 66 | function buildSignedHeaders({ data = null, token = "" } = {}) { |
| 67 | const headers = { |
| 68 | fhAppid: APP_ID, |
| 69 | fhNonceStr: randomString(16), |
| 70 | fhTimestamp: Math.floor(Date.now() / 1000), |
| 71 | token, |
| 72 | source: 1, |
| 73 | "Content-Type": "application/json", |
| 74 | OrderUpdate: 1, |
| 75 | visit: "", |
| 76 | }; |
| 77 | const dataSignValue = data && typeof data === "object" ? JSON.stringify(data) : data ? String(data) : ""; |
| 78 | const signKeys = ["fhAppid", "fhNonceStr", "fhTimestamp", dataSignValue].sort(); |
| 79 | const signText = signKeys.reduce((text, key) => { |
| 80 | if (Object.prototype.hasOwnProperty.call(headers, key)) { |
| 81 | return text + key + headers[key]; |
| 82 | } |
| 83 | return text + key; |
| 84 | }, ""); |
| 85 | |
| 86 | return { |
| 87 | ...headers, |
| 88 | fhSign: md5Upper(signText + APP_KEY), |
| 89 | Referer: `https://servicewechat.com/${MINI_APP_ID}/420/page-frame.html`, |
| 90 | "User-Agent": USER_AGENT, |
| 91 | Accept: "application/json, text/plain, */*", |
| 92 | }; |
| 93 | } |
| 94 | |
| 95 | function buildUrl(apiPath, query = {}) { |
| 96 | const params = new URLSearchParams(); |
no test coverage detected