-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdemo-ts.php
More file actions
69 lines (57 loc) · 2.29 KB
/
Copy pathdemo-ts.php
File metadata and controls
69 lines (57 loc) · 2.29 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
<?php
/* This demo shows you how to add a document level timestamp signature to a PDF document
* through the Swisscom All-in Signing Service.
*/
use GuzzleHttp\Client as GuzzleClient;
use GuzzleHttp\Handler\CurlHandler;
use Http\Factory\Guzzle\RequestFactory;
use Http\Factory\Guzzle\StreamFactory;
use Mjelamanov\GuzzlePsr18\Client as Psr18Wrapper;
use setasign\SetaPDF\Signer\Module\SwisscomAIS\SignException;
use setasign\SetaPDF\Signer\Module\SwisscomAIS\TimestampModule;
date_default_timezone_set('Europe/Berlin');
error_reporting(E_ALL | E_STRICT);
ini_set('display_errors', 1);
// require the autoload class from Composer
require_once('../vendor/autoload.php');
if (!file_exists(__DIR__ . '/settings/settings-ts.php')) {
throw new RuntimeException('Missing settings/settings-ts.php!');
}
$settings = require(__DIR__ . '/settings/settings-ts.php');
$guzzleOptions = [
'handler' => new CurlHandler(),
'http_errors' => false,
'verify' => __DIR__ . '/ais-ca-ssl.crt',
'cert' => $settings['cert'],
'ssl_key' => $settings['privateKey']
];
$httpClient = new GuzzleClient($guzzleOptions);
// only required if you are using guzzle < 7
$httpClient = new Psr18Wrapper($httpClient);
// create an HTTP writer
$writer = new SetaPDF_Core_Writer_Http('Swisscom.pdf');
// let's get the document
$document = SetaPDF_Core_Document::loadByFilename('files/tektown/Laboratory-Report.pdf', $writer);
// now let's create a signer instance
$signer = new SetaPDF_Signer($document);
$signer->setAllowSignatureContentLengthChange(false);
$signer->setSignatureContentLength(17500);
// set some signature properties
$signer->setLocation($_SERVER['SERVER_NAME']);
$signer->setContactInfo('+01 2345 67890123');
$signer->setReason('testing...');
// create a Swisscom AIS module instance
$module = new TimestampModule($settings['customerId'], $httpClient, new RequestFactory(), new StreamFactory());
// pass the timestamp module to the signer instance
$signer->setTimestampModule($module);
try {
// create the document timestamp
$signer->timestamp();
} catch (SignException $e) {
echo 'Error in SwisscomAIS: ' . $e->getMessage() . ' with code ' . $e->getCode() . '<br />';
/* Get the AIS Error details */
echo "<pre>";
var_dump($e->getResultMajor());
var_dump($e->getResultMinor());
echo "</pre>";
}