整一个B站私信自动发送系统(Spring Cloud Alibaba + Vue)(一)
环境
Spring Cloud Alibaba 2.2.7 + MyBatis Plus + MySQL 5.7
摸鱼产物,所以没有做的很严谨
框架参考:https://www.cnblogs.com/sefuture/p/16261588.html
界面
简单的私信发送界面如下

数据库
这边仅展示三张业务表
message_list:私信列表
message_detail:私信详情
ship_list:舰长列表

功能
由于B站不对个人提供开放接口,所以这边对于B站数据的获取,实际上就是模仿用户发起请求
获取舰长数据
package com.grey.demo.demobusinessservice.http; import com.alibaba.fastjson.JSONObject; import com.grey.demo.demobusinessservice.ship.entity.bilibili.JsonRootBean; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.*; import org.springframework.stereotype.Component; import org.springframework.web.client.RestTemplate; import org.springframework.web.util.UriComponentsBuilder; /** * 舰长相关类 * * @author 话离小小灰 * @since 2022/8/10 */ @Component public class HttpShipData { private static Logger LOGGER = LogManager.getLogger(HttpUserData.class); // https://api.live.bilibili.com/xlive/app-room/v2/guardTab/topList @Value("${bilibili.getShip}") private String getShipUrl; /** * 获取当前舰长列表 * @param roomId 房间号 * @param uid 用户uid(主播的) * @param page 页数 * @param pageSize 每页数据量 * @return 舰长数据 */ public JsonRootBean getShipList(String roomId, String uid, Integer page, Integer pageSize) { // 封装参数,roomid:房间号,page:页数,ruid:用户uid UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(getShipUrl) .queryParam("roomid", roomId) .queryParam("page", page) .queryParam("ruid", uid) .queryParam("page_size", pageSize); RestTemplate restTemplate = new RestTemplate(); //使用exchange请求接口 HttpHeaders headers = new HttpHeaders(); headers.set("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36"); HttpEntity<JSONObject> httpEntity = new HttpEntity<>(null, headers); ResponseEntity<JSONObject> response = restTemplate.exchange(builder.build().toUri(), HttpMethod.GET, httpEntity, JSONObject.class); JsonRootBean result = new JsonRootBean(); if (response.getStatusCode().equals(HttpStatus.OK) && response.getBody() != null) { result = response.getBody().toJavaObject(JsonRootBean.class); } return result; } }
摸鱼被发现了,改天继续……

浙公网安备 33010602011771号