PHP code example of simplon / signr

1. Go to this page and download the library: Download simplon/signr 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/ */

    

simplon / signr example snippets


use Simplon\Signr\Signr;

$secretKeySignedRequest = '123456';

$data = [
  'secret' => [
    'user'         => [
      'gameUid'      => 'xxx',
      'email'        => 'xxx',
      'gameServerId' => 'xxx',
    ],
    'order'        => [
      'checkoutUid'    => 'xxx',
      'inGameCurrency' => 'xxx',
      'realCurrency'   => 'xxx',
      'currencyCode'   => 'xxx',
      'provider'       => 'xxx',
      'created'        => 'xxx',
    ],
    'partnerToken' => 'xxx',
  ],
];

// create signed request
$signedRequest = (new Signr())
    ->setData($data)
    ->setSecretKey($secretKeySignedRequest)
    ->create()
    ->getSignedRequest();

use Simplon\Signr\Signr;

$signedRequest = 'xxxzzzyyy';
$secretKeySignedRequest = '123456';

// read data should result the following array...
$data = (new Signr())
    ->setSignedRequest($signedRequest)
    ->setSecretKey($secretKeySignedRequest)
    ->read()
    ->getData();

/*
$data = [
  'secret' => [
    'user'         => [
      'gameUid'      => 'xxx',
      'email'        => 'xxx',
      'gameServerId' => 'xxx',
    ],
    'order'        => [
      'checkoutUid'    => 'xxx',
      'inGameCurrency' => 'xxx',
      'realCurrency'   => 'xxx',
      'currencyCode'   => 'xxx',
      'provider'       => 'xxx',
      'created'        => 'xxx',
    ],
    'partnerToken' => 'xxx',
  ],
];
*/

use Simplon\Signr\Signr;

$signedRequest = 'xxxzzzyyy';
$secretKeySignedRequest = '123456';

// lets hold the instance
$signr = new Signr()
    ->setSignedRequest($signedRequest)
    ->setSecretKey($secretKeySignedRequest)
    ->read();

// is expired?
$isExpired = $signr
    ->setExpireTimeMinutes(120) // time to run against the expiration
    ->isExpired();

if($isExpired === TRUE)
{
  echo "SignedRequest is expired!";
}