Completed
Pull Request — master (#266)
by r
12:56
created

accessToken.php ➔ getAkSk()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 2
dl 0
loc 11
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
require "../autoload.php";
4
5
$cli = new \Qiniu\Http\Client();
6
7
$url = 'https://acc.qbox.me/oauth2/token';
8
$param = array(
9
        'grant_type' => 'password',
10
        'username' => "[email protected]",
11
        'password' => urlencode(''),
12
);
13
$param = http_build_query($param);
14
$headers = array(
15
    'Content-Type' => 'application/x-www-form-urlencoded'
16
);
17
18
//https://developer.qiniu.com/af/manual/1600/get-account-management-credentials-and-secret-lock
19
$resp = $cli::post($url, $param, $headers);
20
21
$res = json_decode($resp->body, true);
22
23
echo '----------------------------token:\n';
24
var_dump($res);
25
26
27
//$res2 = createChildAccount("[email protected]", 'xxxxxtest', $res['access_token']);
28
//echo '----------------------------create child account:\n';
29
//var_dump($res2);
30
31
//https://developer.qiniu.com/af/manual/1534/create-a-account-user-create-child
32
function createChildAccount($email, $pwd, $aToken) {
33
    $headers = array(
34
        'Authorization' => 'Bearer ' . $aToken
35
    );
36
    $param = 'email=' . $email . '&password=' . $pwd;
37
38
    $cli = new \Qiniu\Http\Client();
39
    $resp = $cli::post('https://acc.qbox.me/user/create_child', $param, $headers);
40
41
    return $resp->body;
42
}
43
44
45
$res3 = getAkSk("1380483031", $res['access_token']);
46
echo '----------------------------get ak sk:\n';
47
var_dump($res3);
0 ignored issues
show
Security Debugging Code introduced by
var_dump($res3); looks like debug code. Are you sure you do not want to remove it? This might expose sensitive data.
Loading history...
48
49
function getAkSk($uid, $aToken) {
50
    $headers = array(
51
        'Authorization' => 'Bearer ' . $aToken
52
    );
53
    $param = '';
54
55
    $cli = new \Qiniu\Http\Client();
56
    $resp = $cli::post('https://acc.qbox.me/user/child_key?uid=' . $uid, $param, $headers);
57
58
    return $resp->body;
59
}
60