(key, path, body)
| 88 | |
| 89 | // Post请求构建 |
| 90 | getPostHeader(key, path, body) { |
| 91 | const crypto = require('crypto'); |
| 92 | function calculateContentMD5(requestBody) { |
| 93 | const byteArray = Buffer.from(requestBody, 'utf8'); |
| 94 | const md5Digest = crypto.createHash('md5').update(byteArray).digest(); |
| 95 | const md5Base64 = md5Digest.toString('base64'); |
| 96 | return md5Base64; |
| 97 | } |
| 98 | let currentDate = new Date(); |
| 99 | let formattedDate = this.formatDate(currentDate, 0); |
| 100 | let parts = formattedDate.split(" "); |
| 101 | formattedDate = `${parts[0]}, ${parts[2]} ${parts[1]} ${parts[3]} ${parts[4]} GMT`; |
| 102 | let date = new Date(formattedDate) |
| 103 | let timestamp = date.getTime(); |
| 104 | let content_md5 = calculateContentMD5(body); |
| 105 | let uuid = this.generateUUID(); |
| 106 | let signature = this.calculateHmacSha256("POST", "application/json; charset=utf-8", content_md5, "application/json; charset=utf-8", formattedDate, key, uuid, timestamp, path) |
| 107 | let headers = { |
| 108 | 'date': formattedDate, |
| 109 | 'x-ca-signature': signature, |
| 110 | 'x-ca-appcode': 'SWGeelyCode', |
| 111 | 'x-ca-nonce': uuid, |
| 112 | 'x-ca-key': key, |
| 113 | 'ca_version': 1, |
| 114 | 'accept': 'application/json; charset=utf-8', |
| 115 | 'usetoken': 1, |
| 116 | 'content-md5': content_md5, |
| 117 | 'x-ca-timestamp': timestamp, |
| 118 | 'x-ca-signature-headers': 'x-ca-nonce,x-ca-timestamp,x-ca-key', |
| 119 | 'x-refresh-token': true, |
| 120 | 'user-agent': 'ALIYUN-ANDROID-UA', |
| 121 | 'token': this.token, |
| 122 | 'deviceSN': this.deviceSN, |
| 123 | 'txCookie': '', |
| 124 | 'appId': 'galaxy-app', |
| 125 | 'appVersion': '1.27.0', |
| 126 | 'platform': 'Android', |
| 127 | 'Cache-Control': 'no-cache', |
| 128 | 'sweet_security_info': '{"appVersion":"1.27.0","platform":"android"}' , |
| 129 | 'methodtype': '6', |
| 130 | 'contenttype': 'application/json', |
| 131 | 'Content-Type': 'application/json; charset=utf-8', |
| 132 | 'Content-Length': '87', |
| 133 | 'Connection': 'Keep-Alive', |
| 134 | 'Accept-Encoding': 'gzip', |
| 135 | } |
| 136 | if (key == 204179735) { |
| 137 | headers["usetoken"] = true |
| 138 | headers["host"] = `galaxy-user-api.geely.com` |
| 139 | delete headers["x-refresh-token"] |
| 140 | headers["taenantid"] = 569001701001 |
| 141 | headers["svcsid"] = "" |
| 142 | } else { |
| 143 | headers["usetoken"] = 1 |
| 144 | headers["host"] = `galaxy-app.geely.com` |
| 145 | headers["x-refresh-token"] = true |
| 146 | } |
| 147 | return headers; |
no test coverage detected