提取B站API统一管理
This commit is contained in:
@@ -2,6 +2,10 @@ package com.yutou.qqbot.bilibili;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.yutou.bilibili.api.LiveAPI;
|
||||
import com.yutou.bilibili.api.LoginAPI;
|
||||
import com.yutou.bilibili.api.SignApi;
|
||||
import com.yutou.bilibili.api.UserApi;
|
||||
import com.yutou.qqbot.QQBotManager;
|
||||
import com.yutou.qqbot.interfaces.ObjectInterface;
|
||||
import com.yutou.qqbot.utlis.*;
|
||||
@@ -16,6 +20,7 @@ import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
public class BiliBiliUtils {
|
||||
@@ -40,7 +45,7 @@ public class BiliBiliUtils {
|
||||
|
||||
public synchronized JSONObject http_get(String url) {
|
||||
try {
|
||||
Log.i("调用url = "+url);
|
||||
Log.i("调用url = " + url);
|
||||
HttpsURLConnection connection = getBiliHttpGet(url, getCookie());
|
||||
BufferedInputStream stream = new BufferedInputStream(connection.getInputStream());
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
@@ -73,9 +78,9 @@ public class BiliBiliUtils {
|
||||
|
||||
public JSONObject http_login_getSid(String url) {
|
||||
try {
|
||||
Log.i("调用url = "+url);
|
||||
Log.i("调用url = " + url);
|
||||
HttpsURLConnection connection = (HttpsURLConnection) new URL(url).openConnection();
|
||||
setConnection(null,connection);
|
||||
setConnection(null, connection);
|
||||
connection.setRequestMethod("GET");
|
||||
connection.connect();
|
||||
BufferedInputStream stream = new BufferedInputStream(connection.getInputStream());
|
||||
@@ -94,12 +99,12 @@ public class BiliBiliUtils {
|
||||
outputStream.close();
|
||||
try {
|
||||
JSONObject json = JSON.parseObject(str);
|
||||
if(cookie!=null){
|
||||
StringBuilder ck=new StringBuilder();
|
||||
if (cookie != null) {
|
||||
StringBuilder ck = new StringBuilder();
|
||||
for (String key : cookie) {
|
||||
ck.append(";").append(key);
|
||||
}
|
||||
json.put("cookie",ck.toString());
|
||||
json.put("cookie", ck.toString());
|
||||
}
|
||||
return json;
|
||||
} catch (Exception e) {
|
||||
@@ -366,14 +371,14 @@ public class BiliBiliUtils {
|
||||
connection.setRequestProperty("Referer", "https://www.bilibili.com");
|
||||
connection.addRequestProperty("Connection", "keep-alive");
|
||||
connection.addRequestProperty("Upgrade-Insecure-Requests", "1");
|
||||
if(!StringUtils.isEmpty(cookie)) {
|
||||
if (!StringUtils.isEmpty(cookie)) {
|
||||
connection.addRequestProperty("Cookie", cookie);
|
||||
}
|
||||
connection.addRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36");
|
||||
}
|
||||
|
||||
public JSONObject getLoginInfo() {
|
||||
JSONObject jsonObject = http_get("https://api.bilibili.com/x/web-interface/nav");
|
||||
JSONObject jsonObject = http_get(UserApi.NAV);
|
||||
if (jsonObject == null) {
|
||||
jsonObject = new JSONObject();
|
||||
jsonObject.put("code", "-1");
|
||||
@@ -389,7 +394,7 @@ public class BiliBiliUtils {
|
||||
/* System.out.println(getLiveRoom(42062));
|
||||
System.out.println("--------------------------------------------");
|
||||
System.out.println(getUserInfo(730732));*/
|
||||
String sign = new BiliBiliUtils(583819556).liveSignIn();
|
||||
JSONObject sign = new BiliBiliUtils(583819556).getUserInfo(96300);
|
||||
System.out.println("sign = " + sign);
|
||||
}
|
||||
|
||||
@@ -402,7 +407,7 @@ public class BiliBiliUtils {
|
||||
body.put("rnd", System.currentTimeMillis() / 1000);
|
||||
body.put("csrf", BiliLogin.getCookieToken(qq));
|
||||
body.put("csrf_token", BiliLogin.getCookieToken(qq));
|
||||
JSONObject post = http_post("https://api.live.bilibili.com/msg/send", HttpTools.toUrlParams(body));
|
||||
JSONObject post = http_post(LiveAPI.LIVE_SEND_DANMU, HttpTools.toUrlParams(body));
|
||||
return post.getInteger("code") == 0;
|
||||
}
|
||||
|
||||
@@ -411,9 +416,9 @@ public class BiliBiliUtils {
|
||||
JSONObject body = new JSONObject();
|
||||
body.put("csrf", BiliLogin.getCookieToken(qq));
|
||||
body.put("csrf_token", BiliLogin.getCookieToken(qq));
|
||||
JSONObject toCoin = http_post("https://api.live.bilibili.com/xlive/revenue/v1/wallet/silver2coin", HttpTools.toUrlParams(body));
|
||||
JSONObject liveSign = http_get("https://api.live.bilibili.com/xlive/web-ucenter/v1/sign/DoSign");
|
||||
JSONObject vipSign = http_post("https://api.bilibili.com/pgc/activity/score/task/sign", null);
|
||||
JSONObject toCoin = http_post(SignApi.LIVE_SIGN_COIN, HttpTools.toUrlParams(body));
|
||||
JSONObject liveSign = http_get(SignApi.LIVE_SIGN);
|
||||
JSONObject vipSign = http_post(SignApi.VIP_SIGN, null);
|
||||
return "银瓜子兑换硬币:" + toCoin.getString("message") + "|" + "直播签到:" + liveSign.getString("message") + "|大会员中心签到:" + vipSign.getString("message");
|
||||
}
|
||||
|
||||
@@ -422,13 +427,14 @@ public class BiliBiliUtils {
|
||||
body.put("room_id", roomId);
|
||||
body.put("csrf", BiliLogin.getCookieToken(qq));
|
||||
body.put("csrf_token", BiliLogin.getCookieToken(qq));
|
||||
return http_post("https://api.live.bilibili.com/room/v1/Room/get_info", HttpTools.toUrlParams(body));
|
||||
return http_post(LiveAPI.LIVE_ROOM_INFO, HttpTools.toUrlParams(body));
|
||||
}
|
||||
|
||||
public JSONObject getUserInfo(int mid) {
|
||||
JSONObject body = new JSONObject();
|
||||
body.put("mid", mid);
|
||||
return http_get("https://api.bilibili.com/x/space/acc/info?" + HttpTools.toUrlParams(body));
|
||||
TreeMap<String, String> body = new TreeMap<>();
|
||||
body.put("mid", mid + "");
|
||||
BiliBiliWbiSign.getWbiSign(body);
|
||||
return http_get(UserApi.USER_INFO_V2 + "?" + HttpTools.toUrlParams(body));
|
||||
}
|
||||
|
||||
public boolean checkLiveRoom(int roomId) {
|
||||
|
||||
Reference in New Issue
Block a user