• 英雄联盟客户端本地会起一个http服务端,客户端是CEF做的,整个就是一个浏览器,显示的内容也就是加载了html而已
  • 所有的操作都是通过请求http接口完成的,请求的接口就是本地的http服务,那么本地的http服务端又是请求到哪的呢?
  • 那么下面介绍的接口才是真正请求到的地方,也就是英雄联盟的服务器接口

刷新sgp

1) 接口 HTTP POST (刷新Authorization)

/session-external/v1/session/refresh

2) 请求参数(JSON):

1
2
3
{
"lst":"eyJraWQiOiJzMSIsImFsZyI6IlJTNTEyIn0.eyJzY3AiOiJMT0wiLCJzdWIiOiI5M2RhN2Y0Zi0zMGQwLTU5MjEtODFjYi04OThjZWU3NGFkYjYiLCJwcm9kdWN0IjoiTE9MIiwicGFydGlkIjoiMjY0NTYxMzkwOCIsImxpZCI6bnVsbCwiY25hbWUiOiJsY3UiLCJoYmMiOiJuYW4iLCJhY3RpZCI6MzA0OTYxNzA5ODg0NDkyOCwiaXNzIjoiaHR0cHM6XC9cL3Nlc3Npb24tandrcy0xMjUzMjk4MTg1LmNvcy5hcC1zaGFuZ2hhaS5teXFjbG91ZC5jb20iLCJyaWQiOiJrQ0hoZUdfdlAyVSIsInJmYSI6MTY5MDA0Mzk2MCwic2lkIjoiM2I5NTYwMGQtZmZiYy00NDkxLWIxMzMtNTY1NTBkMjBmZTgzIiwiYnlwYXNzIjpmYWxzZSwiZmVkZXJhdGVkX2lkZW50aXR5X3Byb3ZpZGVycyI6W10sInJlZyI6IkhOMyIsImRhdCI6eyJyIjoiSE4zIiwidSI6MzA0OTYxNzA5ODg0NDkyOH0sInJmbyI6MzAwLCJleHAiOjE2OTAwNDQyNjAsImlhdCI6MTY5MDA0MzY2MCwianRpIjoiNGYwM2ZlMDQtMWIzZi00NTY1LWI1NDItNjIxMDgzZWIzZDU2IiwiY2lkIjoibHNzIiwic2l0IjoxNjkwMDQyNDA5fQ.Pyq3GC4QLqtvdWCAy3EAN60zjKKghkQ_vxqM-lcMFly9Itv8ehEE_2nkbsDuxAjGk9E0V3FC3ItAnVpeS-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ZoRhEOmVfMnp2TL9D2nJ1J6rdSKea4CIrfnA0cxyQEif6_h-fjPHxCNxBridWmjAgCr4q7M4D7SlFOuDrxqoJkRjtr6DzAS4bw2_nJB2-f9a8NvqheH0IJfYaCzs5rvO9vDf0WNeYWcRMls8HVj3riUKRe4uROQECLdmwolEE833_Vc8ddKUcOBITG3tgcdbQriaZhAv87r8X_4rfDfpqmdPMadITyqjrn7CRbluIhAlAZOkYJQ1yMStzDdcLYT5dU0G16ZI_Uv1diUxbA1FIYZmHqXctye9JSMSru1uGeIDPA"

查询账号

1) 接口 HTTP GET (通过游戏名查询账号信息)

/summoner-ledge/v1/regions/HN1/summoners/name/没心态的繁星

2) 请求参数(JSON):

1
无需参数

3) 返回结果:

1
2
3
4
5
6
7
8
9
10
11
12
{
"puuid": "78112bcf-910b-5ea9-9955-41a7cff614f1",
"accountId": "4132621593",
"name": "没心态的繁星",
"profileIconId": 4030,
"level": 657,
"expPoints": 2304,
"levelAndXpVersion": 6603,
"lastGameDate": "1691587524402",
"privacy": "PUBLIC",
"expToNextLevel": 2880
}

查询历史战绩

1) 接口 HTTP GET (通过puuid获取战绩)

/match-history-query/v1/products/lol/player/{puuid}/SUMMARY?startIndex=0&count=20

2) 请求参数(JSON):

1
无需参数

3) 返回结果:

1
太多了 自己看吧

查询对局

1) 接口 HTTP GET (通过puuid获取战绩)

/gsm/v1/ledge/spectator/region/HN3/puuid/{puuid}

2) 请求参数(JSON):

1
无需参数

3) 返回结果:

1
返回的是正在进行的对局信息,10个人 进行多久了 什么模式等等 自己看吧

代码实现

给你们看看我这边用php实现的部分代码

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
/**
* 通过游戏名查询账号信息
*
* @return ResponseInterface
* @throws \RedisException
*/
public function name(): ResponseInterface
{
$params = $this->request->all();
$validator = $this->validationFactory->make(
$params,
[
'name' => 'required|string|max:64',
'areaId' => 'required|int|min:1|max:32',
],
);
if ($validator->fails()) {
$errorMessage = $validator->errors()->first();
return $this->error($errorMessage);
}

$name = $params['name'];
$areaId = (int)$params['areaId'];

// 先从缓存取
$key = 'area:' . $areaId . ':summoner:' . $name;
$summoner = $this->redis->get($key);
if (false === $summoner) {
// 没有尝试从数据库取
$summoner = $this->sgpService->getSummonerByName($name, $areaId);
if (false === $summoner) {
$summoner = $this->sgpService->queryByName($name, $areaId);
if (false === $summoner) {
return $this->error('此召唤师没有找到');
} else {
// 写入缓存
$this->redis->setex($key, 60 * 5, json_encode($summoner));
// 写入数据库
$this->sgpService->savaSummoner($summoner, $areaId);
return $this->success($summoner);
}
} else {
// 写入缓存
$this->redis->setex($key, 60 * 5, json_encode($summoner));
return $this->success($summoner);
}
} elseif ('' === $summoner) {
// 有key无值
return $this->error('召唤师不存在');
} else {
$summoner = json_decode($summoner, true);
return $this->success($summoner);
}
}
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
/**
* 通过游戏名查询账号信息
*
* @param string $name
* @param int $areaId
* @return false|mixed
*/
public function queryByName(string $name, int $areaId): mixed
{
$result = $this->getHost($areaId);
if ( !$result ) {
return false;
}
list($host, $route) = $result;

$uri = $host . '/summoner-ledge/v1/regions/' . $route . '/summoners/name/' . urlencode($name);

$jwt = $this->getJwt($areaId);
try {
$response = $this->getClient()->get($uri, $this->getHeaders($jwt));
return json_decode($response->getBody()->getContents(), true);
} catch (GuzzleException $e) {
// TODO 日志
var_dump($e->getMessage());
return false;
}
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
/**
* 获取sgp通用请求头
*
* @param string $jwt
* @return array[]
*/
private function getHeaders(string $jwt)
{
return [
'headers' => [
'Authorization' => 'Bearer ' . $jwt,
]
];
}

鉴权

请求头

Authorization: Bearer {jwt}

  • 上面已经给出了刷新jwt的接口,jwt过期时间貌似是5分钟过期,不太记得了,建议2~3分钟刷新一下

那么第一次的jwt接口从哪里得到呢?

  • 用抓包工具抓

资料

以下是关于英雄联盟接口的一些资料,看看有没有用得上的吧

https://prod-rso.lol.qq.com:3000/.well-known/openid-configuration

LOL服务器架构

LCU架构探析

LCU接口文档(可能需要翻墙)

League of Legends LCU Docs(可能需要翻墙)

国服客户端html页面

英雄列表

LOL前端开发手册

赛事接口

END