-
Notifications
You must be signed in to change notification settings - Fork 0
/
smart-id_sign.php
64 lines (58 loc) · 2.14 KB
/
smart-id_sign.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
<?php
include './lib.php';
echo "Developers.dokobit.com WS API Smart-ID signing PHP example\n";
$url = 'https://developers.dokobit.com';
$accessToken = ''; //Enter valid developer access token here.
$country = isset($argv[1])?$argv[1]:'lt';
$code = isset($argv[2])?$argv[2]:'30303039914';
$file = isset($argv[3])?$argv[3]:'./test.pdf';
if (empty($accessToken)) {
echo "Access Token is required. Enter at line 5.\n";
exit;
}
echo "Requesting prepare:\n";
$prepared = request($url, $accessToken, 'smartid/sign', [
'type' => 'pdf',
'code' => $code,
'country' => $country,
'language' => 'EN',
'timestamp' => true,
'pdf' => [
'files' => [
[
'name' => substr($file, strrpos($file, "/")+1),
'content' => base64_encode(file_get_contents($file)),
'digest' => hash_file('sha256', $file)
]
],
'reason' => 'Agreement',
'location' => 'Vilnius, Lietuva',
'contact' => 'Seventh Testnumber'
]
]);
echo "Responded: [".$prepared['status']."]\n";
if ($prepared['status'] != 'ok') {
print_r($prepared);
exit;
}
echo "Signing token: [ " . $prepared['token'] . " ]\n";
echo "Your phone will receive Smart-ID signing request with\nVerification code: [ " . $prepared['control_code'] . " ]\n";
echo "Requesting status:\n";
$time = 120;
while ($time > 0) {
$statusResponse = request($url, $accessToken, 'smartid/sign/status/' . $prepared['token'], [], false);
echo "Status: [".$statusResponse['status']."]\n";
if ($statusResponse['status'] == 'ok') {
file_put_contents(
__DIR__ . '/test_signed.pdf',
base64_decode($statusResponse['file']['content'])
);
echo "File signed. Check ./test_signed.pdf\n";
exit;
} elseif ($statusResponse['status'] == 'error') {
var_dump($statusResponse['message']);
exit;
}
sleep(2);
$time -=2;
}