This repository has been archived by the owner on Apr 1, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bootstrap.php
57 lines (49 loc) · 2.01 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
<?php
use Illuminate\Contracts\Events\Dispatcher;
return function (Dispatcher $events) {
$events->listen(App\Events\PlayerProfileUpdated::class, function ($event) {
$name = $event->player->player_name;
$url[0] = env('QCLOUD_CDN_BASE_URL') . "/$name.json";
$url[1] = env('QCLOUD_CDN_BASE_URL') . "/csl/$name.json";
$url[2] = env('QCLOUD_CDN_BASE_URL') . "/usm/$name.json";
$secretKey = env('QCLOUD_CDN_SECRET_KEY');
$secretId = env('QCLOUD_CDN_SECRET_ID');
$apiBody = [
'Nonce' => rand(),
'Timestamp' => time(NULL),
'Action' => 'RefreshCdnUrl',
'SecretId' => $secretId,
'urls.0' => $url[0],
'urls.1' => $url[1],
'urls.2' => $url[2],
];
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); // 忽略响应
});
};