/
smart-id_sign_adoc.php
74 lines (69 loc) · 2.57 KB
/
smart-id_sign_adoc.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
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';
/**
* Smart-ID test data can be found at https://support.dokobit.com/article/667-mobile-id-and-smart-id-test-data
*/
$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' => 'adoc.ggedoc',
'code' => $code,
'country' => $country,
'adoc' => [
'title' => 'Demo document',
'files' => [
[
'name' => substr($file, strrpos($file, "/")+1),
'content' => base64_encode(file_get_contents($file)),
'digest' => hash_file('sha256', $file),
'type' => 'main',
]
],
'authors' => [
[
'name' => 'Vardenis Pavardenis',
'code' => $code,
'address' => 'Vilnius',
'individual' => true,
]
],
'signing_purpose' => 'signature',
'signer_individual_name' => 'Vardenis Pavardenis',
'signer_position_name' => 'CEO',
]
]);
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.adoc',
base64_decode($statusResponse['file']['content'])
);
echo "File signed. Check ./test_signed.adoc\n";
exit;
} elseif ($statusResponse['status'] == 'error') {
var_dump($statusResponse['message']);
exit;
}
sleep(2);
$time -=2;
}