Skip to content

Commit

Permalink
接口地址变更、userAgent的配置项失效
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuweitung committed Jul 18, 2021
1 parent ad8701c commit e92ba5c
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
| isShare | [0,1] | 是否分享(手机端每日任务),默认`开启` |
| bananaPriority | [0,1] | 投蕉优先级,0:优先给每日香蕉榜投蕉(TOP50),1:优先给关注的up投蕉,默认`0` |
| followUpPriority | [uid,...] | 关注up的投蕉优先级,up的uid可以进入up的主页获取 |
| userAgent | String | UA标识,AcFun/6.39.0 (iPhone; iOS 14.3; Scale/2.00) |
| ~~userAgent~~ | ~~String~~ | ~~UA标识,AcFun/6.39.0 (iPhone; iOS 14.3; Scale/2.00)~~ |
| skipUpList | [uid,...] | 跳过投蕉点赞弹幕up列表,一般是一些喜欢刷屏的up(我说的就是你`萌次元`|

## 参考说明
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.zhuweitung</groupId>
<artifactId>banana-helper</artifactId>
<version>0.2.7</version>
<version>0.2.8</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/zhuweitung/ProjectInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class ProjectInfo {

private static String updateDate = "2021-04-18";
private static String projectRepo = "https://github.com/zhuweitung/banana-helper.git";
private static String releaseVersion = "0.2.7";
private static String releaseVersion = "0.2.8";
private static String updateInfo = "";
private static String acfunMemberUrl = "https://www.acfun.cn/u/625724";

Expand Down
12 changes: 6 additions & 6 deletions src/main/java/com/zhuweitung/api/AcFunApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,28 +26,28 @@ public enum AcFunApi {
/**
* 获取香蕉榜
*/
GET_BANANALIST("获取香蕉榜", "https://api-ipv6.acfunchina.com/rest/app/rank/channel"),
GET_BANANALIST("获取香蕉榜", "https://www.acfun.cn/rest/pc-direct/rank/channel"),
/**
* 每日签到
*/
DAILY_SIGN("每日签到", "https://api-ipv6.acfunchina.com/rest/app/user/signIn"),
DAILY_SIGN("每日签到", "https://www.acfun.cn/rest/pc-direct/user/signIn"),

/**
* 视频发送弹幕
*/
VIDEO_SENDDANMU("视频发送弹幕", "https://api-ipv6.acfunchina.com/rest/app/new-danmaku/add"),
VIDEO_SENDDANMU("视频发送弹幕", "https://www.acfun.cn/rest/pc-direct/new-danmaku/add"),
/**
* 视频投蕉
*/
VIDEO_THROWBANANA("视频投蕉", "https://api-ipv6.acfunchina.com/rest/app/banana/throwBanana"),
VIDEO_THROWBANANA("视频投蕉", "https://www.acfun.cn/rest/pc-direct/banana/throwBanana"),
/**
* 视频点赞
*/
VIDEO_LIKE("视频点赞", "https://api.kuaishouzt.com/rest/zt/interact/add"),
VIDEO_LIKE("视频点赞", "https://kuaishouzt.com/rest/zt/interact/add"),
/**
* 视频取消点赞
*/
VIDEO_UNLIKE("视频取消点赞", "https://api.kuaishouzt.com/rest/zt/interact/delete"),
VIDEO_UNLIKE("视频取消点赞", "https://kuaishouzt.com/rest/zt/interact/delete"),
/**
* 视频分享
*/
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/com/zhuweitung/api/AcFunApiHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ public static int throwBanana(int laveNum, VideoBase videoBase) {
params.put("resourceId", videoBase.getAc() + "");
params.put("count", PER_VIDEO_BANANA_NUM + "");
params.put("resourceType", videoBase.getType() + "");
JsonObject responseJson = HttpUtil.doPost(AcFunApi.VIDEO_THROWBANANA.getUrl(), params);
Properties properties = new Properties();
properties.setProperty("referer", "https://www.acfun.cn/v/ac" + videoBase.getAc());
JsonObject responseJson = HttpUtil.doPost(AcFunApi.VIDEO_THROWBANANA.getUrl(), params, properties);
int responseCode = responseJson.get("result").getAsInt();
if (responseCode == 0) {
log.info("在视频:{},给{}喂了{}根大香蕉~", videoBase.getTitle(), videoBase.getUpName(), PER_VIDEO_BANANA_NUM);
Expand Down Expand Up @@ -178,7 +180,9 @@ public static void danmu(VideoBase videoBase) {
params.put("subChannelName", videoBase.getSubChannelName() + "");
params.put("type", "douga");
params.put("videoId", videoBase.getId() + "");
JsonObject responseJson = HttpUtil.doPost(AcFunApi.VIDEO_SENDDANMU.getUrl(), params);
Properties properties = new Properties();
properties.setProperty("referer", "https://www.acfun.cn/v/ac" + videoBase.getAc());
JsonObject responseJson = HttpUtil.doPost(AcFunApi.VIDEO_SENDDANMU.getUrl(), params, properties);
int responseCode = responseJson.get("result").getAsInt();
if (responseCode == 0) {
log.info("给视频:{} 发了条弹幕 {}", videoBase.getTitle(), danmu.getBody());
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/com/zhuweitung/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public void init() {
}

Config.CONFIG = new Gson().fromJson(configJson, Config.class);
HttpUtil.setUserAgent(Config.getInstance().getUserAgent());
// HttpUtil.setUserAgent(Config.getInstance().getUserAgent());
log.info(Config.getInstance().toString());
}

Expand All @@ -115,7 +115,6 @@ public String toString() {
";是否分享:" + (isShare == 1 ? "是" : "否") +
";投蕉策略为:" + (bananaPriority == 0 ? "每日香蕉榜优先" : "关注up优先") +
";关注up的投蕉优先级为:" + followUpPriority.toString() +
";UA是:" + userAgent +
";跳过投蕉点赞弹幕up列表为:" + skipUpList.toString() +
"}";
}
Expand Down
42 changes: 39 additions & 3 deletions src/main/java/com/zhuweitung/util/HttpUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.net.URI;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

/**
* @author zhuweitung
Expand All @@ -48,7 +49,7 @@ public class HttpUtil {

static Cookie cookie = Cookie.getInstance();

private static String userAgent = "AcFun/6.39.0 (iPhone; iOS 14.3; Scale/2.00)";
private static String userAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36 Edg/91.0.864.70";

private static CloseableHttpClient httpClient = null;

Expand All @@ -75,11 +76,9 @@ public static void setUserAgent(String userAgent) {
public static Map<String, String> getDefaultHeaders() {
Map<String, String> headers = new HashMap<>();
headers.put("user-agent", userAgent);
headers.put("devicetype", "0");
headers.put("accept-language", "zh-Hans-CN;q=1, en-CN;q=0.9, ja-CN;q=0.8, zh-Hant-HK;q=0.7, io-Latn-CN;q=0.6");
headers.put("accept", "application/json");
headers.put("content-type", "application/x-www-form-urlencoded");
headers.put("acPlatform", "IPHONE");
return headers;
}

Expand Down Expand Up @@ -113,6 +112,26 @@ public static JsonObject doPost(String url, Map<String, String> params) {
return doPost(url, requestBody.toString());
}

/**
* @description post请求
* @param url
* @param params
* @param extHeaders
* @return com.google.gson.JsonObject
* @author zhuweitung
* @date 2021/7/18
*/
public static JsonObject doPost(String url, Map<String, String> params, Properties extHeaders) {
StringBuilder requestBody = new StringBuilder();
for (Map.Entry<String, String> entry : params.entrySet()) {
if (requestBody.length() > 0) {
requestBody.append("&");
}
requestBody.append(entry.getKey()).append("=").append(entry.getValue());
}
return doPost(url, requestBody.toString(), extHeaders);
}

/**
* @description post请求
* @param url
Expand All @@ -125,6 +144,23 @@ public static JsonObject doPost(String url, String requestBody) {
return doPost(url, requestBody, getDefaultHeaders());
}

/**
* @description post请求
* @param url
* @param requestBody
* @param extHeaders
* @return com.google.gson.JsonObject
* @author zhuweitung
* @date 2021/7/18
*/
public static JsonObject doPost(String url, String requestBody, Properties extHeaders) {
Map<String, String> headers = getDefaultHeaders();
for (String key : extHeaders.stringPropertyNames()) {
headers.put(key, extHeaders.getProperty(key));
}
return doPost(url, requestBody, headers);
}

/**
* @description post请求
* @param url
Expand Down

0 comments on commit e92ba5c

Please sign in to comment.