LOL 接口信息查询

参考网址:英雄联盟 LCUAPI
League of Legends LCU Docs
LeagueAkari
如何跨服务器查询战绩lol
获取Riot的永久API密钥

LoLHelper.h

#pragma once
#include <map>
#include "hv/http_content.h"
#include "hv/requests.h"
//关于Lcu api 更多信息可参考:https://lcu.kebs.dev/
/*
1.获取LeagueClientUx.exe 进程启动参数,即lcu
2.解析参数--app-port=xxx --remoting-auth-token=
3.绑定端口和token至CLoLHelper对象bind_port_token
4.调用LOLHelper接口查询数据
*/
class CLoLHelper
{
public:
	static CLoLHelper& Instance();

	void bind_port_token(const std::string& port, const std::string& token);
	//查询当前英雄信息
	void query_current_summoner();
	//查询英雄rank信息
	void query_current_summoner_ranked();
	//测试不可用404
	//void query_summoner_ranked_by_summonerId(const std::string& summonerId);
	//void query_summoner_ranked_by_summonername(const std::string& summonername);
	//查询当前summoner战绩
	void query_current_summoner_match(int begin_index = 0, int want_max_number = 200);
	//根据ppuid查询最近战绩,单次最多获取200
	void query_match_by_ppuid(const std::string& puuid,int begin_index = 0,int want_max_number = 200);
	//查询某场对局的具体信息
	void query_game_info(const std::string& gameId);
	//查询最近的summoners信息
	void query_recently_played_summoners();
	//获取区域信息
	void query_region_locale();
	//查询游戏环境信息
	void query_riot_environment();

	// lol-account-verification
	
private:
	http_headers getHeaders();
private:
	std::string m_strport;
	std::string m_strtoken;
};


LoLHelper.cpp

#include "stdafx.h"
#include "LoLHelper.h"
#include "encrypt/base64/zbase64.h"
#include "StringUtil.h"
CLoLHelper& CLoLHelper::Instance()
{
	static CLoLHelper sInstance;
	return sInstance;
}

void CLoLHelper::bind_port_token(const std::string& port, const std::string& token)
{
	m_strport = port;
	m_strtoken = token;
}

http_headers CLoLHelper::getHeaders()
{
	http_headers mapHeaders;
	mapHeaders["Host"] = fmt::format("127.0.0.1:{0}", m_strport);
	std::string token = std::string("riot:") + m_strtoken;
	mapHeaders["Authorization"] = fmt::format("Basic {0}", jeflib::ZBase64::Encode((const unsigned char*)token.c_str(), token.size()));
	mapHeaders["Content-Type"] = "application/json";
	mapHeaders["Connection"] = "keep-alive";
	mapHeaders["User-Agent"] = "Mozilla/5.0";
	mapHeaders["Accept"] = "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9";
	return mapHeaders;
}

void CLoLHelper::query_current_summoner()
{
	std::string url = fmt::format("https://127.0.0.1:{0}/lol-summoner/v1/current-summoner", m_strport);
	auto resp = requests::get(url.c_str(), getHeaders());

	std::string contnet;
	if (resp && resp->status_code == HTTP_STATUS_OK)
		resp->DumpBody(contnet);
	DebugPrint("query_current_summoner url:%s,state_code:%d,content[%s]", url.c_str(),resp ? resp->status_code:-1, contnet.c_str());
}

void CLoLHelper::query_current_summoner_ranked()
{
	std::string url = fmt::format("https://127.0.0.1:{0}/lol-ranked/v1/current-ranked-stats", m_strport);
	auto resp = requests::get(url.c_str(), getHeaders());

	std::string contnet;
	if (resp && resp->status_code == HTTP_STATUS_OK)
		resp->DumpBody(contnet);
	DebugPrint("query_current_summoner_ranked url:%s,state_code:%d,content[%s]", url.c_str(), resp ? resp->status_code : -1, contnet.c_str());
}
/*
void CLoLHelper::query_summoner_ranked_by_summonerId(const std::string& summonerId)
{
	std::string url = fmt::format("https://127.0.0.1:{0}/lol-ranked-stats/v1/stats?summonerId={1}", m_strport, summonerId);
	auto resp = requests::get(url.c_str(), getHeaders());

	std::string contnet;
	if (resp && resp->status_code == HTTP_STATUS_OK)
		resp->DumpBody(contnet);
	DebugPrint("query_summoner_ranked_by_summonerId url:%s,state_code:%d,content[%s]", url.c_str(), resp ? resp->status_code : -1, contnet.c_str());
}

void CLoLHelper::query_summoner_ranked_by_summonername(const std::string& summonername)
{
	std::string url = fmt::format("https://127.0.0.1:{0}//lol-summoner/v1/summoners?name={1}", m_strport, summonername);
	auto resp = requests::get(url.c_str(), getHeaders());

	std::string contnet;
	if (resp && resp->status_code == HTTP_STATUS_OK)
		resp->DumpBody(contnet);
	DebugPrint("query_summoner_ranked_by_summonername url:%s,state_code:%d,content[%s]", url.c_str(), resp ? resp->status_code : -1, contnet.c_str());
}
*/

void CLoLHelper::query_current_summoner_match(int begin_index, int want_max_number)
{
	std::string url = fmt::format("https://127.0.0.1:{0}/lol-match-history/v1/products/lol/current-summoner/matches?begIndex={1}&endIndex={2}", m_strport, begin_index, begin_index + want_max_number - 1);
	auto resp = requests::get(url.c_str(), getHeaders());

	std::string contnet;
	if (resp && resp->status_code == HTTP_STATUS_OK)
		resp->DumpBody(contnet);
	DebugPrint("query_current_summoner_match url:%s,state_code:%d,content[%s]", url.c_str(), resp ? resp->status_code : -1, contnet.c_str());
}

void CLoLHelper::query_match_by_ppuid(const std::string &puuid, int begin_index, int want_max_number)
{
	//index >= begin_index && index <= begin_index+want_max_number
	std::string url = fmt::format("https://127.0.0.1:{0}/lol-match-history/v1/products/lol/{1}/matches?begIndex={2}&endIndex={3}", m_strport, puuid, begin_index, begin_index + want_max_number - 1);
	auto resp = requests::get(url.c_str(), getHeaders());

	std::string contnet;
	if (resp && resp->status_code == HTTP_STATUS_OK)
		resp->DumpBody(contnet);
	DebugPrint("query_match_by_ppuid url:%s,state_code:%d,content[%s]", url.c_str(), resp ? resp->status_code : -1, contnet.c_str());
}

void CLoLHelper::query_region_locale()
{
	std::string url = fmt::format("https://127.0.0.1:{0}/riotclient/region-locale", m_strport);
	auto resp = requests::get(url.c_str(), getHeaders());

	std::string contnet;
	if (resp && resp->status_code == HTTP_STATUS_OK)
		resp->DumpBody(contnet);
	DebugPrint("query_region_locale url:%s,state_code:%d,content[%s]", url.c_str(), resp ? resp->status_code : -1, contnet.c_str());
}

void CLoLHelper::query_riot_environment()
{
	std::string url = fmt::format("https://127.0.0.1:{0}/riotclient/v1/crash-reporting/environment", m_strport);
	auto resp = requests::get(url.c_str(), getHeaders());

	std::string contnet;
	if (resp && resp->status_code == HTTP_STATUS_OK)
		resp->DumpBody(contnet);
	DebugPrint("query_riot_environment url:%s,state_code:%d,content[%s]", url.c_str(), resp ? resp->status_code : -1, contnet.c_str());
}

void CLoLHelper::query_recently_played_summoners()
{
	std::string url = fmt::format("https://127.0.0.1:{0}/lol-match-history/v1/recently-played-summoners", m_strport);
	auto resp = requests::get(url.c_str(), getHeaders());

	std::string contnet;
	if (resp && resp->status_code == HTTP_STATUS_OK)
		resp->DumpBody(contnet);
	DebugPrint("query_recently_played_summoners url:%s,state_code:%d,content[%s]", url.c_str(), resp ? resp->status_code : -1, UTF82ACSTR(contnet));
}

void CLoLHelper::query_game_info(const std::string& gameId)
{
	std::string url = fmt::format("https://127.0.0.1:{0}/lol-match-history/v1/games/{1}", m_strport,gameId);
	auto resp = requests::get(url.c_str(), getHeaders());

	std::string contnet;
	if (resp && resp->status_code == HTTP_STATUS_OK)
		resp->DumpBody(contnet);
	DebugPrint("query_game_info url:%s,state_code:%d,content[%s]", url.c_str(), resp ? resp->status_code : -1, contnet.c_str());
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值