-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
147 lines (141 loc) · 5.51 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
//
// Created by zeng on 24-6-24.
//
#include "Entity/Global/Config.h"
#include "Entity/Global/Logger.h"
#include "Entity/Net/Multipart.h"
#include "Entity/ThreadPool/ProcessingMessageThreadPool.h"
#include "Util/BiliUtil/BiliLiveSession.h"
#include "Util/BiliUtil/BiliLogin.h"
#include "Util/BiliUtil/BiliRequestHeader.h"
#include <boost/asio/io_context.hpp>
#include <boost/beast/http/dynamic_body.hpp>
#include <cstdlib>
int main()
{
// 判断cookie/bili_cookie.json是否存在
std::string_view cookiePath = "./cookie/bili_cookie.json";
if (!std::filesystem::exists(cookiePath))
{
BiliLogin login;
if (!login.GetLoginQRCode())
{
LOG_MESSAGE(LogLevel::Error, "Failed to get login QRCode");
return EXIT_FAILURE;
}
}
else if (!BiliRequestHeader::GetInstance()->LoadBiliCookieByPath(cookiePath))
{
LOG_MESSAGE(LogLevel::Error, "Failed to load cookie");
return EXIT_FAILURE;
}
if (!Config::GetInstance()->LoadFromJson("./Config/configure.json"))
{
LOG_MESSAGE(LogLevel::Error, "Failed to load config file");
return EXIT_FAILURE;
}
Logger::GetInstance()->SetLogLevel(Config::GetInstance()->GetLogLevel());
Logger::GetInstance()->SetLogPath(Config::GetInstance()->GetLogPath());
LOG_MESSAGE(LogLevel::Debug, FORMAT("Config: ({})", Config::GetInstance()->ToString()));
ProcessingMessageThreadPool::GetInstance()->Start();
boost::asio::io_context ioc;
std::make_shared<BiliLiveSession>(ioc)->run();
ioc.run();
// while (true)
// {
// }
return EXIT_SUCCESS;
}
// int main()
// {
// // 判断cookie/bili_cookie.json是否存在
// std::string_view cookiePath = "./cookie/bili_cookie.json";
// if (!std::filesystem::exists(cookiePath))
// {
// BiliLogin login;
// if (!login.GetLoginQRCode())
// {
// LOG_MESSAGE(LogLevel::Error, "Failed to get login QRCode");
// return EXIT_FAILURE;
// }
// }
// else if (!BiliRequestHeader::GetInstance()->LoadBiliCookieByPath(cookiePath))
// {
// LOG_MESSAGE(LogLevel::Error, "Failed to load cookie");
// return EXIT_FAILURE;
// }
//
// if (!Config::GetInstance()->LoadFromJson("./Config/configure.json"))
// {
// LOG_MESSAGE(LogLevel::Error, "Failed to load config file");
// return EXIT_FAILURE;
// }
// Logger::GetInstance()->SetLogLevel(Config::GetInstance()->GetLogLevel());
// Logger::GetInstance()->SetLogPath(Config::GetInstance()->GetLogPath());
// LOG_MESSAGE(LogLevel::Debug, FORMAT("Config: ({})", Config::GetInstance()->ToString()));
//
// Url url{"api.live.bilibili.com", 443, "/msg/send"};
// LOG_VAR(LogLevel::Debug, url.ToString());
//
// boost::asio::io_context ioc; // IO上下文
// boost::asio::ssl::context ctx(boost::asio::ssl::context::tlsv12_client); // SSL上下文
// boost::asio::ip::tcp::resolver resolver(ioc); // DNS解析器
//
// // 解析域名和端口
// const auto results = resolver.resolve(url.GetHost(), std::to_string(url.GetPort()));
// // 创建SSL流并连接
// boost::asio::io_context iocHttp;
// boost::asio::ssl::stream<boost::asio::ip::tcp::socket> stream(iocHttp, ctx);
// boost::asio::connect(stream.next_layer(), results.begin(), results.end());
// stream.handshake(boost::asio::ssl::stream_base::client);
// Multipart multipart{
// {"bubble", "5"},
// {"msg", "圈宝,可爱"},
// {"color", "4546550"},
// // {"mode", "1"},
// {"room_type", "0"},
// // {"jumpfrom", "71002"},
// // {"reply_mid", "0"},
// // {"reply_attr", "0"},
// // {"replay_dmid", ""},
// // {"statistics", "{\"appId\":100,\"platform\":5}"},
// {"fontsize", "25"},
// {"rnd", std::to_string(std::time(nullptr))},
// {"roomid", std::to_string(Config::GetInstance()->GetRoomId())},
// {"csrf", BiliRequestHeader::GetInstance()->GetBiliCookie().GetBiliJct()},
// {"csrf_token", BiliRequestHeader::GetInstance()->GetBiliCookie().GetBiliJct()}};
// // 构建POST请求
// boost::beast::http::request<boost::beast::http::string_body> req{
// boost::beast::http::verb::post, url.GetTarget(), 11};
// req.set(boost::beast::http::field::host, url.GetHost());
// req.set(boost::beast::http::field::user_agent,
// BiliRequestHeader::GetInstance()->GetUserAgent());
// req.set(boost::beast::http::field::content_type,
// multipart.GetSerializeMultipartFormdataGetContentType());
// // 设置cookie
// req.set(boost::beast::http::field::cookie,
// BiliRequestHeader::GetInstance()->GetBiliCookie().ToString());
// //
// req.body() = multipart.GetSerializeMultipartFormdata();
// req.prepare_payload();
// // 发送请求
// boost::beast::http::write(stream, req);
//
//
// // This buffer is used for reading and must be persisted
// boost::beast::flat_buffer buffer;
//
// // Declare a container to hold the response
// boost::beast::http::response<boost::beast::http::dynamic_body> res;
//
// // Receive the HTTP response
// boost::beast::http::read(stream, buffer, res);
//
// // Write the message to standard out
// std::cout << res << std::endl;
//
// // Gracefully close the socket
// boost::beast::error_code ec;
//
// return true;
// }