-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.php
74 lines (58 loc) · 2.12 KB
/
example.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
<?php
function base64url_encode($str) {
return rtrim(strtr(base64_encode($str), '+/', '-_'), '=');
}
function uuid() {
$data = random_bytes(16);
$data[6] = chr(ord($data[6]) & 0x0f | 0x40);
$data[8] = chr(ord($data[8]) & 0x3f | 0x80);
return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4));
}
/**
* cURL extension is required to be enabled for this function
*/
function httpPost($url, $data, $certPath, $privKeyPath, $headers) {
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data, JSON_UNESCAPED_SLASHES));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_SSLKEY, $privKeyPath);
curl_setopt($curl, CURLOPT_SSLCERT, $certPath);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($curl);
curl_close($curl);
return $response;
}
$certPath = '../qseal.cer';
$privKeyPath = '../qseal.key';
$clientCertUrl = '<public_link_to_your_cert>';
$cert = file_get_contents($certPath);
$privKey = file_get_contents($privKeyPath);
$thumbprint = base64url_encode(openssl_x509_fingerprint($cert, 'sha256', true));
$signHeaders = [
'kid' => $thumbprint,
'x5u' => $clientCertUrl,
'x5t#S256' => $thumbprint,
'alg' => 'RS256',
'crit' => ['iat'],
'iat' => time(),
];
$signHeadersBase64 = base64url_encode(json_encode($signHeaders, JSON_UNESCAPED_SLASHES));
$payload = [
'submitId' => uuid(),
'validityPeriod' => 'MONTHS_6',
'redirectUrl' => 'https://www.domain.com/callback',
'scopes' => ['AccountBalance', 'AccountBasicData', 'AccountTransactions', 'FX', 'PaymentGate', 'TransferInitiation'],
];
openssl_sign(
$signHeadersBase64 . '.' . base64url_encode(json_encode($payload, JSON_UNESCAPED_SLASHES)),
$signature,
$privKey,
OPENSSL_ALGO_SHA256
);
$headers = [
'Content-Type: application/json',
'X-JWS-SIGNATURE: ' . $signHeadersBase64 . '..' . base64url_encode($signature),
];
$response = httpPost('https://tpp.walutomat.dev/api/v3/consent/create', $payload, $certPath, $privKeyPath, $headers);
var_dump($response);