* 刷新token * @param {string} userId - 用户ID * @param {string} token - 用户token * @returns {} - 是否成功
(userId, token)
| 20 | * @returns {} - 是否成功 |
| 21 | */ |
| 22 | async function refreshToken(userId, token) { |
| 23 | |
| 24 | if (userId == null || userId == undefined || token == null || token == undefined) { |
| 25 | return false |
| 26 | } |
| 27 | |
| 28 | // 请求体data加密前 |
| 29 | const time = Math.floor(Date.now() / 1000) |
| 30 | const baseData = `{"userToken":"${token}","autoDelay":true,"deviceId":"","userId":"${userId}","timestamp":"${time}"}` |
| 31 | |
| 32 | // 请求体加密 |
| 33 | const encryData = AESencrypt(baseData) |
| 34 | const data = '{"data":"' + encryData + '"}' |
| 35 | |
| 36 | // 签名 |
| 37 | const str = getStringMD5(data) |
| 38 | const sign = encodeURLEncoder(RSAencrypt(str)) |
| 39 | |
| 40 | const headers = { |
| 41 | userId: userId, |
| 42 | userToken: token, |
| 43 | "Content-Type": "appsication/json; charset=utf-8" |
| 44 | } |
| 45 | |
| 46 | const baseURL = "https://migu-app-umnb.miguvideo.com/login/token_refresh_migu_plus" |
| 47 | const params = `?clientId=27fb3129-5a54-45bc-8af1-7dc8f1155501&sign=${sign}&signType=RSA` |
| 48 | |
| 49 | try { |
| 50 | // 发送请求 |
| 51 | const respResult = await fetchUrl(baseURL + params, { |
| 52 | headers: headers, |
| 53 | method: "post", |
| 54 | body: data |
| 55 | }) |
| 56 | |
| 57 | // 处理响应结果 |
| 58 | if (respResult.resultCode == "REFRESH_TOKEN_SUCCESS") { |
| 59 | // console.log(respResult) |
| 60 | return true |
| 61 | } |
| 62 | console.dir(respResult, { depth: null }) |
| 63 | } catch (error) { |
| 64 | } |
| 65 | |
| 66 | return false |
| 67 | } |
| 68 | |
| 69 | export default refreshToken |
no test coverage detected