Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
bitgetlimited
GitHub Repository: bitgetlimited/v3-bitget-api-sdk
Path: blob/master/bitget-php-sdk-api/src/internal/Utils.php
518 views
1
<?php
2
3
4
namespace bitget\internal;
5
6
7
class Utils
8
{
9
public static function getSign($timestamp, $method, $requestPath, $body, $apiSecret): string
10
{
11
if ($body != null) {
12
$message = (string)$timestamp . strtoupper($method) . $requestPath . (string)$body;
13
} else {
14
$message = (string)$timestamp . strtoupper($method) . $requestPath;
15
}
16
17
return base64_encode(hash_hmac('sha256', $message, $apiSecret, true));
18
}
19
20
public static function getSignByRSA($timestamp, $method, $requestPath, $body, $apiSecret):string
21
{
22
$rsaUtil = new RsaUtil(null, $apiSecret);
23
if ($body != null) {
24
$message = (string)$timestamp . strtoupper($method) . $requestPath . (string)$body;
25
} else {
26
$message = (string)$timestamp . strtoupper($method) . $requestPath;
27
}
28
29
// print_r("fuck rsa\n");
30
print_r($rsaUtil->sign($message) . "\n");
31
return $rsaUtil->sign($message);
32
}
33
34
// 获取IOS格式时间戳
35
public static function getTimestamp(): int
36
{
37
return time() * 1000;
38
}
39
40
public static function printLog(string $msg, string $type): void
41
{
42
$time = date("Y-m-d H:i:s");
43
print_r("[" . $time . "] [" . $type . "] " . $msg . "\n");
44
}
45
46
}
47