MCPcopy Create free account
hub / github.com/develop202/migu_video / refreshToken

Function refreshToken

utils/refreshToken.js:22–67  ·  view source on GitHub ↗

* 刷新token * @param {string} userId - 用户ID * @param {string} token - 用户token * @returns {} - 是否成功

(userId, token)

Source from the content-addressed store, hash-verified

20 * @returns {} - 是否成功
21 */
22async 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
69export default refreshToken

Callers 1

updateFunction · 0.85

Calls 5

AESencryptFunction · 0.90
getStringMD5Function · 0.90
RSAencryptFunction · 0.90
fetchUrlFunction · 0.90
encodeURLEncoderFunction · 0.85

Tested by

no test coverage detected