PHP code example of ylly / certsign

1. Go to this page and download the library: Download ylly/certsign library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ylly / certsign example snippets


$signator = SignatorFactory::createFromYamlFile('/path/to/config.yml');

$signator = SignatorFactory::createFromArray($configArray);

$signature = Signature::create()->setImage('/path/to/sign.png', false);
//$signature = Signature::create()->setImage('BASE64');
//$signature = Signature::create()->setImage(new Image(...));

$request = Request::create()
    ->setHolder('Firstname', 'Lastname', '[email protected]', '0601020304')
    ->addDocument('Document-1', '/path/to/doc.pdf', $signature, false)
    ->addDocument('Document-2', 'BASE64', $signature);

$request->setOTP('0601020304'); // Will send a SMS
//$request->setOTP('[email protected]'); // Will send an Email

// Generate the order, returns the order ID
$orderId = $signator->createOrder($request);

// Send the OTP, can be reused to generate a new OTP
$signator->validate($orderId);

// Create the signature request with the documents and signature image
$signator->createRequest($request, $orderId);

// Enter OTP given by SMS or Email, will return false if the code is invalid
// Returns the signed documents
$documents = $signator->sign($orderId, 'MyOTP');

// Generate the order, returns the order ID
$orderId = $signator->createOrder($request);

// Create the signature request with the documents and signature image
$signator->createRequest($request, $orderId);

// Returns the signed documents
$documents = $signator->sign($orderId);

class Listener implement LogListenerInterface
{
    public function recieve($level, $message)
    {
        // do something
    }
}

$signator->addListener(new Listener());

$image = new Image(100, 50, new Color(255, 255, 255));
$image->setStyle(new TextStyle(0, 0, 12, 2, new Color(0, 0, 0));
$image->addText('SignText');