add 视频页面

update 用户管理
This commit is contained in:
2024-11-18 18:27:49 +08:00
parent 6e2cea8186
commit b15d1c917f
25 changed files with 780 additions and 135 deletions

View File

@@ -33,9 +33,9 @@ public interface LoginApi {
Call<FileBody<String>> getCorrespond(@Path("correspondPath") String correspondPath);
@GET("/x/passport-login/web/cookie/refresh")
Call<HttpBody<LoginInfoBean>> refreshCookie(@Query("csrf") String csrf
Call<HttpBody<LoginInfoBean>> refreshCookie(@Query("csrf") String bili_jct
, @Query("refresh_csrf") String refresh_csrf
, @Query("source") String source
, @Query("refresh_token") String ac_time_value
, @Query("refresh_token") String refresh_token
);
}

View File

@@ -25,6 +25,10 @@ public class LiveSuperChatDatabaseBean extends AbsDatabasesBean {
private String message_trans;
@JSONField(name = "message_font_color")
private String message_font_color;
@JSONField(name = "background_bottom_color")
private String backgroundBottomColor;
@JSONField(name = "user_name_color")
private String userNameColor;
@JSONField(name ="user_name")
private String userName;
@JSONField(name ="user_avatar")
@@ -40,9 +44,13 @@ public class LiveSuperChatDatabaseBean extends AbsDatabasesBean {
uid = bean.getUid();
start_time = bean.getStart_time();
end_time = bean.getEnd_time();
userName= bean.getUserName();
userAvatar = bean.getUserAvatar();
message = bean.getMessage();
message_trans = bean.getMessage_trans();
message_font_color = bean.getMessage_font_color();
backgroundBottomColor=bean.getBackground_bottom_color();
userNameColor=bean.getUserNameColor();
}

View File

@@ -21,7 +21,10 @@ public class WSSuperChatMessage extends WSData{
private String message_trans;
private String message_font_color;
private String userName;
private String userNameColor;
private String userAvatar;
private String background_bottom_color;
public static void main(String[] args) {
@@ -42,5 +45,7 @@ public class WSSuperChatMessage extends WSData{
setMessage_font_color(data.getString("message_font_color"));
setUserName(data.getJSONObject("user_info").getString("uname"));
setUserAvatar(data.getJSONObject("user_info").getString("face"));
setUserNameColor(data.getJSONObject("user_info").getString("name_color"));
setBackground_bottom_color(data.getString("background_bottom_color"));
}
}

View File

@@ -36,8 +36,17 @@ public class BiliBiliLoginDatabase extends SQLiteManager {
public BiliBiliLoginDatabase initData(LoginCookieDatabaseBean cookie, LoginUserDatabaseBean user) {
this.cookie = cookie;
cookie.setTableName(getDataBean().get(0).getTableName());
add(cookie);
add(user);
LoginCookieDatabaseBean old = getCookie(cookie.getDedeUserID());
if (old == null) {
add(cookie);
add(user);
}else{
cookie.setSql_time(old.getSql_time());
LoginUserDatabaseBean oldUser = getUser(cookie.getDedeUserID());
user.setSql_time(oldUser.getSql_time());
update(cookie);
update(user);
}
return this;
}
@@ -54,7 +63,8 @@ public class BiliBiliLoginDatabase extends SQLiteManager {
return null;
}
public List<LoginCookieDatabaseBean> getAllCookies(){
public List<LoginCookieDatabaseBean> getAllCookies() {
return super.get(cookie.getTableName(), LoginCookieDatabaseBean.class);
}
@@ -75,7 +85,7 @@ public class BiliBiliLoginDatabase extends SQLiteManager {
JSONArray jsonArray = super.getJSONArray(new LoginUserDatabaseBean(null).getTableName());
List<LoginUserDatabaseBean> list = new ArrayList<>();
for (Object o : jsonArray) {
JSONObject json= (JSONObject) o;
JSONObject json = (JSONObject) o;
list.add(new LoginUserDatabaseBean(json.to(UserInfoBean.class)));
}
return list;

View File

@@ -86,21 +86,32 @@ public class BiliLiveDatabase extends SQLiteManager {
}
private void addData(WSData bean) {
addData(bean, null);
}
private void addData(WSData bean, Long saveTime) {
AbsDatabasesBean data = null;
if (bean instanceof WSDanmuData) {
add(new LiveDanmuDatabaseBean((WSDanmuData) bean));
data = new LiveDanmuDatabaseBean((WSDanmuData) bean);
} else if (bean instanceof WSInteractWord) {
add(new LiveInteractWordDatabaseBean((WSInteractWord) bean));
data = new LiveInteractWordDatabaseBean((WSInteractWord) bean);
} else if (bean instanceof WSSendGift) {
add(new LiveGiftDatabaseBean((WSSendGift) bean));
data = new LiveGiftDatabaseBean((WSSendGift) bean);
} else if (bean instanceof WSSuperChatMessage) {
add(new LiveSuperChatDatabaseBean((WSSuperChatMessage) bean));
data = new LiveSuperChatDatabaseBean((WSSuperChatMessage) bean);
} else if (bean instanceof WSGuardBuy) {
add(new LiveGuardBuyBean((WSGuardBuy) bean));
data = new LiveGuardBuyBean((WSGuardBuy) bean);
}
if (saveTime != null && data != null) {
data.setSql_time(new Date(saveTime));
}
if (data != null) {
add(data);
}
}
public void addSource(WSData bean) {
Log.i("BiliLiveDatabase.addSource",config.getRoomId());
Log.i("BiliLiveDatabase.addSource", config.getRoomId());
add(new LiveSourceDatabaseBean(bean));
addData(bean);
}
@@ -138,7 +149,8 @@ public class BiliLiveDatabase extends SQLiteManager {
}
return super.get(tableName, where, clazz);
}
public void resetSQL(){
public void resetSQL() {
List<AbsDatabasesBean> list = List.of(
new LiveInfoDatabaseBean(),
new LiveDanmuDatabaseBean(),
@@ -152,16 +164,18 @@ public class BiliLiveDatabase extends SQLiteManager {
}
recreateSql(list);
}
public void resetData(){
public void resetData() {
List<LiveSourceDatabaseBean> list = get(new LiveSourceDatabaseBean().getTableName(), LiveSourceDatabaseBean.class);
for (LiveSourceDatabaseBean item : list) {
WSData data = WSData.parse(JSONObject.parseObject(item.getJson()));
addData(data);
addData(data, item.getSql_time().getTime());
}
}
public static void main(String[] args) {
BiliLiveDatabase biliLiveDatabase = new BiliLiveDatabase(LiveRoomConfig.buildConfig("5265"));
// biliLiveDatabase.resetSQL();
BiliLiveDatabase biliLiveDatabase = new BiliLiveDatabase(LiveRoomConfig.buildConfig("7688602"));
biliLiveDatabase.resetSQL();
biliLiveDatabase.resetData();
}

View File

@@ -2,7 +2,9 @@ package com.yutou.biliapi.net;
import com.yutou.biliapi.api.LoginApi;
import com.yutou.biliapi.bean.login.LoginCookieDatabaseBean;
import com.yutou.biliapi.bean.login.LoginInfoBean;
import com.yutou.common.okhttp.FileBody;
import com.yutou.common.okhttp.HttpBody;
import com.yutou.common.utils.Log;
import com.yutou.common.utils.WebClient;
import org.apache.commons.io.FileUtils;
@@ -73,18 +75,26 @@ public class BiliCookieManager {
return htmlContent;
}
public static void resetCookie(LoginCookieDatabaseBean cookie) {
public static boolean resetCookie(LoginCookieDatabaseBean cookie) {
try {
LoginApi api = BiliLoginNetApiManager.getInstance().getLoginApi(cookie.getDedeUserID());
String correspondPath = getCorrespondPath(String.format("refresh_%d", System.currentTimeMillis()));
System.out.println("correspondPath = " + correspondPath);
Response<FileBody<String>> body = api.getCorrespond(correspondPath).execute();
if(body.code()==404){
return false;
}
System.out.println("body.code() = " + body.code());
String string = IOUtils.toString(body.body().getInputStream(), StandardCharsets.UTF_8);
String refreshCsrf = getRefreshCsrf(string);
System.out.println("body = " + refreshCsrf);
Response<HttpBody<LoginInfoBean>> newCookie = api.refreshCookie(cookie.getBiliJct(), refreshCsrf, "main_web", cookie.getRefreshToken()).execute();
LoginCookieDatabaseBean nc = BiliLoginNetApiManager.getInstance().getCookie(newCookie.headers(), newCookie.body());
nc.setGourl(cookie.getGourl());
return true;
} catch (Exception e) {
e.printStackTrace();
Log.e(e);
return false;
}
}
}

View File

@@ -82,46 +82,48 @@ public class BiliLoginNetApiManager extends BaseApi {
try {
Response<HttpBody<LoginInfoBean>> response = loginApi.loginQRCode(oauthKey).execute();
Headers headers = response.headers();
HttpBody<LoginInfoBean> httpBody = response.body();
if (httpBody.getData().getCode() == 0) {
JSONObject ck = new JSONObject();
List<String> list = headers.values("set-cookie");
for (String cookie : list) {
String[] split = cookie.split(";");
for (String string : split) {
if (!ck.containsKey(string) && StringUtils.hasText(string) && string.contains("=")) {
String key = string.split("=")[0].trim();
String value = string.split("=")[1].trim();
if (key.contains("Expires")) {
SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMMM yyyy HH:mm:ss z", Locale.ENGLISH);
sdf.setTimeZone(TimeZone.getDefault());
Date date = sdf.parse(value, new ParsePosition(0));
value = String.valueOf(date.getTime() / 1000);
}
ck.put(key, value);
}
}
}
if (!list.isEmpty()) {
ck.put("gourl", bd);
LoginCookieDatabaseBean cookie = JSONObject.parseObject(ck.toString(), LoginCookieDatabaseBean.class);
cookie.setRefreshToken(httpBody.getData().getRefresh_token());
cancel();
callback.onResponse(headers, LOGIN_SUCCESS, "ok", cookie, ck.toString());
LoginCookieDatabaseBean cookie = getCookie(response.headers(), response.body());
if (cookie != null) {
cookie.setGourl(bd);
cancel();
callback.onResponse(response.headers(), LOGIN_SUCCESS, "ok", cookie, JSONObject.toJSONString(cookie));
} else {
callback.onFailure(new RuntimeException("cookie为空"));
cancel();
}
}
} catch (IOException e) {
} catch (
IOException e) {
cancel();
throw new RuntimeException(e);
}
}
}, 1000, 3000);
}
}
public LoginCookieDatabaseBean getCookie(Headers headers, HttpBody<LoginInfoBean> httpBody) {
if (httpBody.getData().getCode() == 0) {
JSONObject ck = new JSONObject();
List<String> list = headers.values("set-cookie");
for (String cookie : list) {
String[] split = cookie.split(";");
for (String string : split) {
if (!ck.containsKey(string) && StringUtils.hasText(string) && string.contains("=")) {
String key = string.split("=")[0].trim();
String value = string.split("=")[1].trim();
if (key.contains("Expires")) {
SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMMM yyyy HH:mm:ss z", Locale.ENGLISH);
sdf.setTimeZone(TimeZone.getDefault());
Date date = sdf.parse(value, new ParsePosition(0));
value = String.valueOf(date.getTime() / 1000);
}
ck.put(key, value);
}
}
}
LoginCookieDatabaseBean cookie = JSONObject.parseObject(ck.toString(), LoginCookieDatabaseBean.class);
cookie.setRefreshToken(httpBody.getData().getRefresh_token());
return cookie;
} else {
return null;
}
}
}