23 lines
730 B
PHP
23 lines
730 B
PHP
<?php
|
|
|
|
namespace Tests;
|
|
|
|
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
|
|
|
|
abstract class TestCase extends BaseTestCase
|
|
{
|
|
use CreatesApplication;
|
|
|
|
/**
|
|
* Header `x-access-token` như portal-client gửi (xem ClientAccessTokenCheck).
|
|
*/
|
|
protected function buildClientAccessToken(?int $timestamp = null, ?string $ip = null): string
|
|
{
|
|
$key = hex2bin((string) config('services.client_api.key'));
|
|
$payload = ['s' => (string) config('services.client_api.secret'), 't' => $timestamp ?? time()] + ($ip ? ['ip' => $ip] : []);
|
|
$iv = random_bytes(16);
|
|
|
|
return base64_encode($iv . openssl_encrypt(json_encode($payload), 'aes-256-cbc', $key, OPENSSL_RAW_DATA, $iv));
|
|
}
|
|
}
|