dev_该合并了 #8

Merged
yutou merged 83 commits from dev_ into master 2024-01-17 17:23:44 +08:00
12 changed files with 97 additions and 30 deletions
Showing only changes of commit 4dce74eaf8 - Show all commits

View File

@ -0,0 +1,8 @@
package com.yutou.bilibili;
public class BaseAPI {
public static final String BASE_URL = "https://api.bilibili.com/";
public static final String MCBBS_PNG = "https://www.mcbbs.net/template/mcbbs/image/special_photo_bg.png";
public static final String ACCESS_TOKEN = "https://passport.bilibili.com/login/app/third";
}

View File

@ -0,0 +1,9 @@
package com.yutou.bilibili.api;
public class LiveAPI {
public static final String LIVE_SEND_DANMU="https://api.live.bilibili.com/msg/send";
public static final String LIVE_ROOM_INFO = "https://api.live.bilibili.com/room/v1/Room/get_info";
public static final String LIVE_TASK_PROGRESS = "https://api.live.bilibili.com/xlive/app-ucenter/v1/userTask/GetUserTaskProgress";
public static final String LIVE_SET_TASK_PROGRESS = "https://api.live.bilibili.com/xlive/app-ucenter/v1/userTask/UserTaskReceiveRewards";
}

View File

@ -0,0 +1,7 @@
package com.yutou.bilibili.api;
public class LoginAPI {
public static final String LOGIN_QRCODE = "https://passport.bilibili.com/x/passport-login/web/qrcode/generate";
public static final String LOGIN_QRCODE_POLL="https://passport.bilibili.com/x/passport-login/web/qrcode/poll";
}

View File

@ -0,0 +1,9 @@
package com.yutou.bilibili.api;
public class MangaApi {
public static final String SIGN = "https://manga.bilibili.com/twirp/activity.v1.Activity/ClockIn";
public static final String LIST_PRODUCT_DATE = "https://manga.bilibili.com/twirp/pointshop.v1.Pointshop/ListProduct";
public static final String USER_POINT = "https://manga.bilibili.com/twirp/pointshop.v1.Pointshop/GetUserPoint";
public static final String PAY_MISSION = "https://manga.bilibili.com/twirp/pointshop.v1.Pointshop/Exchange";
}

View File

@ -0,0 +1,7 @@
package com.yutou.bilibili.api;
public class SignApi {
public static final String LIVE_SIGN_COIN = "https://api.live.bilibili.com/xlive/revenue/v1/wallet/silver2coin";
public static final String LIVE_SIGN = "https://api.live.bilibili.com/xlive/web-ucenter/v1/sign/DoSign";
public static final String VIP_SIGN = "https://api.bilibili.com/pgc/activity/score/task/sign";
}

View File

@ -0,0 +1,10 @@
package com.yutou.bilibili.api;
public class UserApi {
@Deprecated
public static final String USER_INFO = "https://api.bilibili.com/x/space/acc/info";
public static final String USER_INFO_V2="https://api.bilibili.com/x/space/wbi/acc/info";
public static final String NAV = "https://api.bilibili.com/x/web-interface/nav";
}

View File

@ -0,0 +1,6 @@
package com.yutou.bilibili.api;
public class VideoApi {
public static final String VIDEO_AI = "https://api.bilibili.com/x/web-interface/view/conclusion/get";
}

View File

@ -1,6 +1,9 @@
package com.yutou.qqbot.bilibili; package com.yutou.qqbot.bilibili;
import com.alibaba.fastjson2.JSONObject; import com.alibaba.fastjson2.JSONObject;
import com.yutou.bilibili.BaseAPI;
import com.yutou.bilibili.api.LiveAPI;
import com.yutou.bilibili.api.VideoApi;
import com.yutou.qqbot.QQBotManager; import com.yutou.qqbot.QQBotManager;
import com.yutou.qqbot.models.BiliBili.BiliVideo; import com.yutou.qqbot.models.BiliBili.BiliVideo;
import com.yutou.qqbot.utlis.AppTools; import com.yutou.qqbot.utlis.AppTools;
@ -27,9 +30,9 @@ public class BiliBiliAppUtils {
public String getAccessToken() { public String getAccessToken() {
try { try {
String tmpUrl = "https://www.mcbbs.net/template/mcbbs/image/special_photo_bg.png"; String tmpUrl = BaseAPI.MCBBS_PNG;
String sign = AppTools.getMD5("api=" + tmpUrl + AppSec); String sign = AppTools.getMD5("api=" + tmpUrl + AppSec);
JSONObject get = biliUtils.http_get(" https://passport.bilibili.com/login/app/third?appkey=" + AppKey + "&api=" + tmpUrl + "&sign=" + sign); JSONObject get = biliUtils.http_get(BaseAPI.ACCESS_TOKEN+"?appkey=" + AppKey + "&api=" + tmpUrl + "&sign=" + sign);
assert get != null; assert get != null;
String uri = get.getJSONObject("data").getString("confirm_uri"); String uri = get.getJSONObject("data").getString("confirm_uri");
HttpsURLConnection connection = biliUtils.getBiliHttpGet(uri, biliUtils.getCookie()); HttpsURLConnection connection = biliUtils.getBiliHttpGet(uri, biliUtils.getCookie());
@ -103,7 +106,7 @@ public class BiliBiliAppUtils {
} }
public AppUserTask getTaskProgress() { public AppUserTask getTaskProgress() {
JSONObject task = biliUtils.http_get("https://api.live.bilibili.com/xlive/app-ucenter/v1/userTask/GetUserTaskProgress"); JSONObject task = biliUtils.http_get(LiveAPI.LIVE_TASK_PROGRESS);
System.out.println("task = " + task); System.out.println("task = " + task);
assert task != null; assert task != null;
return task.getObject("data", AppUserTask.class); return task.getObject("data", AppUserTask.class);
@ -115,7 +118,7 @@ public class BiliBiliAppUtils {
map.put("reward_index", index + ""); map.put("reward_index", index + "");
JSONObject httpGet = biliUtils.http( JSONObject httpGet = biliUtils.http(
"https://api.live.bilibili.com/xlive/app-ucenter/v1/userTask/UserTaskReceiveRewards", LiveAPI.LIVE_SET_TASK_PROGRESS,
BiliBiliUtils.HTTP.POST, BiliBiliUtils.HTTP.POST,
HttpTools.toUrlParams(sign(map)), HttpTools.toUrlParams(sign(map)),
getHeaderMap(), getHeaderMap(),
@ -151,7 +154,8 @@ public class BiliBiliAppUtils {
body.put("up_mid",videoInfo.getJSONObject("data").getJSONObject("owner").getString("mid")); body.put("up_mid",videoInfo.getJSONObject("data").getJSONObject("owner").getString("mid"));
body.put("bvid",videoInfo.getJSONObject("data").getString("bvid")); body.put("bvid",videoInfo.getJSONObject("data").getString("bvid"));
BiliBiliWbiSign.getWbiSign(body); BiliBiliWbiSign.getWbiSign(body);
JSONObject object = BiliBiliUtils.getInstance(QQBotManager.defQQ).http_get("https://api.bilibili.com/x/web-interface/view/conclusion/get"+"?"+HttpTools.toUrlParams(body)); JSONObject object = BiliBiliUtils.getInstance(QQBotManager.defQQ)
.http_get(VideoApi.VIDEO_AI +"?"+HttpTools.toUrlParams(body));
if(object.getInteger("code")==0){ if(object.getInteger("code")==0){
if(object.getJSONObject("data").getInteger("code")==0) { if(object.getJSONObject("data").getInteger("code")==0) {
return object.getJSONObject("data").getJSONObject("model_result").getString("summary"); return object.getJSONObject("data").getJSONObject("model_result").getString("summary");

View File

@ -2,6 +2,7 @@ package com.yutou.qqbot.bilibili;
import com.alibaba.fastjson2.JSONArray; import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject; import com.alibaba.fastjson2.JSONObject;
import com.yutou.bilibili.api.MangaApi;
import com.yutou.qqbot.QQBotManager; import com.yutou.qqbot.QQBotManager;
import com.yutou.qqbot.interfaces.ObjectInterface; import com.yutou.qqbot.interfaces.ObjectInterface;
import com.yutou.qqbot.utlis.HttpTools; import com.yutou.qqbot.utlis.HttpTools;
@ -20,11 +21,11 @@ public class BiliBiliManga {
public static JSONObject sign() { public static JSONObject sign() {
JSONObject body = new JSONObject(); JSONObject body = new JSONObject();
body.put("platform", "android"); body.put("platform", "android");
return BiliBiliUtils.getInstance(QQBotManager.defQQ).http_post("https://manga.bilibili.com/twirp/activity.v1.Activity/ClockIn", HttpTools.toUrlParams(body)); return BiliBiliUtils.getInstance(QQBotManager.defQQ).http_post(MangaApi.SIGN, HttpTools.toUrlParams(body));
} }
private static JSONObject getListProductDate() { private static JSONObject getListProductDate() {
return BiliBiliUtils.getInstance(QQBotManager.defQQ).http_post("https://manga.bilibili.com/twirp/pointshop.v1.Pointshop/ListProduct", ""); return BiliBiliUtils.getInstance(QQBotManager.defQQ).http_post(MangaApi.LIST_PRODUCT_DATE, "");
} }
private static boolean isPayMission = false; private static boolean isPayMission = false;
@ -65,7 +66,7 @@ public class BiliBiliManga {
} }
public static int getMyPoint() { public static int getMyPoint() {
JSONObject user = biliUtils.http_post("https://manga.bilibili.com/twirp/pointshop.v1.Pointshop/GetUserPoint", ""); JSONObject user = biliUtils.http_post(MangaApi.USER_POINT, "");
if (user != null && user.getInteger("code") == 0) { if (user != null && user.getInteger("code") == 0) {
return user.getJSONObject("data").getInteger("point"); return user.getJSONObject("data").getInteger("point");
} }
@ -133,7 +134,7 @@ public class BiliBiliManga {
mission.schedule(new TimerTask() { mission.schedule(new TimerTask() {
@Override @Override
public void run() { public void run() {
JSONObject post = biliUtils.http_post("https://manga.bilibili.com/twirp/pointshop.v1.Pointshop/Exchange", HttpTools.toUrlParams(data)); JSONObject post = biliUtils.http_post(MangaApi.PAY_MISSION, HttpTools.toUrlParams(data));
if (post == null) { if (post == null) {
anInterface.out("网络请求失败,请查看日志"); anInterface.out("网络请求失败,请查看日志");
cancel(); cancel();

View File

@ -2,6 +2,10 @@ package com.yutou.qqbot.bilibili;
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONObject; 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.QQBotManager;
import com.yutou.qqbot.interfaces.ObjectInterface; import com.yutou.qqbot.interfaces.ObjectInterface;
import com.yutou.qqbot.utlis.*; import com.yutou.qqbot.utlis.*;
@ -16,6 +20,7 @@ import java.net.URL;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.TreeMap;
import java.util.zip.GZIPInputStream; import java.util.zip.GZIPInputStream;
public class BiliBiliUtils { public class BiliBiliUtils {
@ -373,7 +378,7 @@ public class BiliBiliUtils {
} }
public JSONObject getLoginInfo() { public JSONObject getLoginInfo() {
JSONObject jsonObject = http_get("https://api.bilibili.com/x/web-interface/nav"); JSONObject jsonObject = http_get(UserApi.NAV);
if (jsonObject == null) { if (jsonObject == null) {
jsonObject = new JSONObject(); jsonObject = new JSONObject();
jsonObject.put("code", "-1"); jsonObject.put("code", "-1");
@ -389,7 +394,7 @@ public class BiliBiliUtils {
/* System.out.println(getLiveRoom(42062)); /* System.out.println(getLiveRoom(42062));
System.out.println("--------------------------------------------"); System.out.println("--------------------------------------------");
System.out.println(getUserInfo(730732));*/ System.out.println(getUserInfo(730732));*/
String sign = new BiliBiliUtils(583819556).liveSignIn(); JSONObject sign = new BiliBiliUtils(583819556).getUserInfo(96300);
System.out.println("sign = " + sign); System.out.println("sign = " + sign);
} }
@ -402,7 +407,7 @@ public class BiliBiliUtils {
body.put("rnd", System.currentTimeMillis() / 1000); body.put("rnd", System.currentTimeMillis() / 1000);
body.put("csrf", BiliLogin.getCookieToken(qq)); body.put("csrf", BiliLogin.getCookieToken(qq));
body.put("csrf_token", 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; return post.getInteger("code") == 0;
} }
@ -411,9 +416,9 @@ public class BiliBiliUtils {
JSONObject body = new JSONObject(); JSONObject body = new JSONObject();
body.put("csrf", BiliLogin.getCookieToken(qq)); body.put("csrf", BiliLogin.getCookieToken(qq));
body.put("csrf_token", 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 toCoin = http_post(SignApi.LIVE_SIGN_COIN, HttpTools.toUrlParams(body));
JSONObject liveSign = http_get("https://api.live.bilibili.com/xlive/web-ucenter/v1/sign/DoSign"); JSONObject liveSign = http_get(SignApi.LIVE_SIGN);
JSONObject vipSign = http_post("https://api.bilibili.com/pgc/activity/score/task/sign", null); JSONObject vipSign = http_post(SignApi.VIP_SIGN, null);
return "银瓜子兑换硬币:" + toCoin.getString("message") + "|" + "直播签到:" + liveSign.getString("message") + "|大会员中心签到:" + vipSign.getString("message"); return "银瓜子兑换硬币:" + toCoin.getString("message") + "|" + "直播签到:" + liveSign.getString("message") + "|大会员中心签到:" + vipSign.getString("message");
} }
@ -422,13 +427,14 @@ public class BiliBiliUtils {
body.put("room_id", roomId); body.put("room_id", roomId);
body.put("csrf", BiliLogin.getCookieToken(qq)); body.put("csrf", BiliLogin.getCookieToken(qq));
body.put("csrf_token", 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) { public JSONObject getUserInfo(int mid) {
JSONObject body = new JSONObject(); TreeMap<String, String> body = new TreeMap<>();
body.put("mid", mid); body.put("mid", mid + "");
return http_get("https://api.bilibili.com/x/space/acc/info?" + HttpTools.toUrlParams(body)); BiliBiliWbiSign.getWbiSign(body);
return http_get(UserApi.USER_INFO_V2 + "?" + HttpTools.toUrlParams(body));
} }
public boolean checkLiveRoom(int roomId) { public boolean checkLiveRoom(int roomId) {

View File

@ -3,6 +3,7 @@ package com.yutou.qqbot.bilibili;
import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray; import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject; import com.alibaba.fastjson2.JSONObject;
import com.yutou.bilibili.api.LoginAPI;
import com.yutou.qqbot.QQBotManager; import com.yutou.qqbot.QQBotManager;
import com.yutou.qqbot.utlis.*; import com.yutou.qqbot.utlis.*;
@ -25,7 +26,7 @@ public class BiliLogin {
} }
public JSONObject login() { public JSONObject login() {
JSONObject login = JSON.parseObject(HttpTools.get("https://passport.bilibili.com/x/passport-login/web/qrcode/generate")); JSONObject login = JSON.parseObject(HttpTools.get(LoginAPI.LOGIN_QRCODE));
JSONObject json = new JSONObject(); JSONObject json = new JSONObject();
System.out.println("login = " + login); System.out.println("login = " + login);
json.put("code", login.getInteger("code")); json.put("code", login.getInteger("code"));
@ -50,7 +51,7 @@ public class BiliLogin {
cancel(); cancel();
return; return;
} }
JSONObject json = biliUtils.http_login_getSid("https://passport.bilibili.com/x/passport-login/web/qrcode/poll?qrcode_key=" + oauthKey); JSONObject json = biliUtils.http_login_getSid(LoginAPI.LOGIN_QRCODE_POLL + "?qrcode_key=" + oauthKey);
Log.i("B站登陆", json.toJSONString()); Log.i("B站登陆", json.toJSONString());
if (json.getInteger("code") == 0 && json.getJSONObject("data").getInteger("code") == 0) { if (json.getInteger("code") == 0 && json.getJSONObject("data").getInteger("code") == 0) {

View File

@ -26,7 +26,6 @@ public class BiliBiliWbiSign {
return getWbiSign(body); return getWbiSign(body);
} }
body.put("wts", String.valueOf(System.currentTimeMillis() / 1000)); body.put("wts", String.valueOf(System.currentTimeMillis() / 1000));
body.put("wts", "1705394671");
String params = HttpTools.toUrlParams(body); String params = HttpTools.toUrlParams(body);
System.out.println("params = " + params); System.out.println("params = " + params);
body.put("w_rid", AppTools.getMD5(params + genMixinKey(rawWbiKey))); body.put("w_rid", AppTools.getMD5(params + genMixinKey(rawWbiKey)));