-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbccclient.php
More file actions
91 lines (82 loc) · 2.39 KB
/
Copy pathbccclient.php
File metadata and controls
91 lines (82 loc) · 2.39 KB
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
90
91
<?php
require_once('algorithms.php');
class BccResponse {
public $response = '';
public $headers = '';
public $status = '';
}
function httpSendRequest(
$url,
$headers,
$method = 'GET',
$body
= NULL
) {
$curlp = curl_init();
curl_setopt($curlp, CURLOPT_URL, $url);
curl_setopt($curlp, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curlp, CURLOPT_CUSTOMREQUEST, $method);
if ($body != NULL) {
$bodyStr = json_encode($body);
curl_setopt($curlp, CURLOPT_POSTFIELDS, $bodyStr);
}
curl_setopt($curlp, CURLINFO_HEADER_OUT, 1);
curl_setopt($curlp, CURLOPT_RETURNTRANSFER, 1);
$rp = curl_exec($curlp);
$result = new BccResponse();
$result->response = $rp;
$result->headers = curl_getinfo($curlp, CURLINFO_HEADER_OUT);
$result->status = curl_getinfo($curlp, CURLINFO_HTTP_CODE);
curl_close($curlp);
return $result;
}
function getBccList($accessId, $secretKey, $region) {
$method = 'GET';
$host = "bcc.{$region}.baidubce.com";
$path = '/v2/instance';
$timeStamp = time();
$bceTime = getCanonicalTime($timeStamp);
$url = "http://{$host}{$path}";
$params = [];
$headers = [
'host' => $host,
'x-bce-date' => $bceTime,
];
$headersToSign = ['host', 'x-bce-date'];
$authorization = generateAuthorization($accessId, $secretKey,
$timeStamp, $path,
$params, $method, $headers, $headersToSign);
$httpHeaders = [
"Host: {$host}",
"Authorization: {$authorization}",
"x-bce-date: {$bceTime}",
];
$response = httpSendRequest($url,
$httpHeaders);
return $response;
}
function getBccInfo($accessId, $secretKey, $region, $instance) {
$method = 'GET';
$host = "bcc.{$region}.baidubce.com";
$path = "/v2/instance/{$instance}";
$timeStamp = time();
$bceTime = getCanonicalTime($timeStamp);
$url = "http://{$host}{$path}";
$params = [];
$headers = [
'host' => $host,
'x-bce-date' => $bceTime,
];
$headersToSign = ['host', 'x-bce-date'];
$authorization = generateAuthorization($accessId, $secretKey,
$timeStamp, $path,
$params, $method, $headers, $headersToSign);
$httpHeaders = [
"Host: {$host}",
"Authorization: {$authorization}",
"x-bce-date: {$bceTime}",
];
$response = httpSendRequest($url,
$httpHeaders);
return $response;
}