PHP code example of xihrni / yii2-behavior-signature

1. Go to this page and download the library: Download xihrni/yii2-behavior-signature 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/ */

    

xihrni / yii2-behavior-signature example snippets




$c = '1001'; // 客户端ID
$d = time(); // 时间戳(秒)
$s = ceil(substr($d, -6) * 12345.6789); // 计算数值

$url = 'http://xxx.com/index/index?page=1&per-page=10';
$url = explode('?', $url);
$params = trim($url[1] . '&_c=' . $c . '&_d=' . $d . '&_s=' . $s, '&');
$newUrl = $url[0] . '?' . $params;

$t = sha1(md5($newUrl) . $c . $d . $s . 'b8c37e33defde51cf91e1e03e51657da'); // Token

$newUrl .= '&_t=' . $t;
file_put_contents($newUrl);



namespace app\controllers;

use xihrni\yii2\behaviors\SignatureBehavior;

class IndexController extends \yii\web\Controller
{
    public function behaviors()
    {
        return array_merge(parent::behaviors(), [
            'signature' => [
                'class' => SignatureBehavior::className(),
                'switchOn' => true,
                'optional' => ['view'],
                'clientSecrets' => [
                    ['id' => 1001, 'secret' => 'b8c37e33defde51cf91e1e03e51657da'],
                    ['id' => 1002, 'secret' => 'fba9d88164f3e2d9109ee770223212a0'],
                    // ...
                ],
            ],
        ]);
    }

    public function actionIndex()
    {}

    public function actionView($id)
    {}
}
text
http://xxx.com/index/index?page=1&per-page=10&_c=1001&_d=1607475506&_s=5870444392&_t=e9a24fc903d3899b160f15bbb58809b0c901c049