-
Notifications
You must be signed in to change notification settings - Fork 39
/
bootstrap.php
89 lines (73 loc) · 2.98 KB
/
bootstrap.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
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
<?php
use App\Services\Plugin;
use Illuminate\Contracts\Events\Dispatcher;
return function (Dispatcher $events) {
$events->listen(App\Events\PlayerProfileUpdated::class, function ($event) {
$baseUrl = env('QCLOUD_CDN_BASE_URL');
$secretKey = env('QCLOUD_CDN_SECRET_KEY');
$secretId = env('QCLOUD_CDN_SECRET_ID');
$usm = plugin('usm-api');
$legacy = plugin('legacy-api');
$yggdrasil = plugin('yggdrasil-api');
$name = $event->player->name;
$urls = [
$baseUrl . '/' . $name . '.json',
$baseUrl . '/csl/' . $name . '.json',
];
if (isset($usm) && $usm->isEnabled()) {
$urls[] = $baseUrl . '/usm/' . $name . '.json';
}
if (isset($legacy) && $legacy->isEnabled()) {
array_push(
$urls,
$baseUrl . '/skin/' . $name . '.png',
$baseUrl . '/cape/' . $name . '.png'
);
}
if (isset($yggdrasil) && $yggdrasil->isEnabled()) {
$uuid = DB::table('uuid')->where('name', $name)->value('uuid');
array_push(
$urls,
$baseUrl . '/api/yggdrasil/sessionserver/session/minecraft/profile/' . $uuid,
$baseUrl . '/api/yggdrasil/sessionserver/session/minecraft/profile/' . $uuid . '?unsigned=false',
$baseUrl . '/api/yggdrasil/sessionserver/session/minecraft/profile/' . $uuid . '?unsigned=true');
}
$apiBody = [
'Nonce' => rand(),
'Timestamp' => time(),
'Action' => 'RefreshCdnUrl',
'SecretId' => $secretId
];
for ($i = 0; $i < count($urls); $i++) {
$apiBody['urls.' . $i] = $urls[$i];
}
ksort($apiBody);
$sigTxt = 'POSTcdn.api.qcloud.com/v2/index.php?';
$isFirst = true;
foreach ($apiBody as $key => $value) {
if (! $isFirst) {
$sigTxt = $sigTxt.'&';
}
$isFirst = false;
// 拼接签名原文时,如果参数名称中携带"_",需要替换成"."
if (strpos($key, '_')) {
$key = str_replace('_', '.', $key);
}
$sigTxt = $sigTxt . $key . '=' . $value;
}
$signature = base64_encode(hash_hmac('sha1', $sigTxt, $secretKey, true));
$requestUrl = 'Signature=' . urlencode($signature);
foreach ($apiBody as $key => $value) {
$requestUrl = $requestUrl . '&' . $key . '=' . urlencode($value);
}
// 开始发出请求
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $requestUrl);
curl_setopt($ch, CURLOPT_URL, 'https://cdn.api.qcloud.com/v2/index.php');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_exec($ch); // 忽略响应
});
};