Skip to content

Commit

Permalink
0.2.6 修复安卓7版本虎牙弹幕
Browse files Browse the repository at this point in the history
  • Loading branch information
guyijie1211 committed Mar 23, 2022
1 parent f05e8f2 commit 2db2928
Showing 1 changed file with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package com.sunnyweather.android.logic.danmu;

import android.util.Log;

import androidx.lifecycle.MutableLiveData;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONField;
import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import com.sunnyweather.android.ui.liveRoom.LiveRoomViewModel;

import java.io.ByteArrayInputStream;
Expand All @@ -29,6 +29,9 @@
import java.util.zip.DataFormatException;
import java.util.zip.Inflater;

import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.io.Decoders;
import io.jsonwebtoken.security.Keys;
import okhttp3.Request;
import okhttp3.WebSocket;
import okio.ByteString;
Expand Down Expand Up @@ -146,14 +149,13 @@ public static Map<String, Object> getWebSocketJwtParamsMap(String appId, String
header.put("typ", "JWT");

//生成JWT凭证
Algorithm algorithm = Algorithm.HMAC256(secret); //开发者密钥
String sToken = JWT.create()
.withHeader(header) //JWT声明
.withIssuedAt(iat) //jwt凭证生成时间
.withExpiresAt(exp) //jwt凭证超时时间
.withClaim("appId", appId) //开发者ID
.sign(algorithm);

String sToken = Jwts.builder()
.setHeader(header)
.setIssuedAt(iat)
.setExpiration(exp)
.claim("appId", appId)
.signWith(Keys.hmacShaKeyFor(secret.getBytes(StandardCharsets.UTF_8)))
.compact();

Map<String, Object> authMap = new HashMap<String, Object>();
authMap.put("iat", currentTimeMillis / 1000); //jwt凭证生成时间戳(秒)
Expand Down

0 comments on commit 2db2928

Please sign in to comment.