PHP code example of yiche / sign

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

    

yiche / sign example snippets




$appKey       = '0123456';
$appSecretKey = '4564877211';
$expireTime   = 0;
$signClient   = new \yiche\Sign\Sign($appKey, $appSecretKey, $expireTime);

$data    = [
    'client_time' => time(),
    'name'        => 'Sentiger',
    'age'         => '18'
];

// 生成签名
$signStr = $signClient->createSign($data);

// 检测签名

$checkData         = $data;
$checkData['sign'] = $signStr;
try {
    $signClient->checkSign($checkData);
} catch (\Exception $e) {
    echo $e->getMessage();
}


print_r($signStr);

...

'sassyc' => [
        'app_key'        => '123456',
        'app_secret_key' => '11114fdsfadas',
        'expire_time'    => 0,  //服务端验证签名过期时间0表示不过期
    ]
...


Route::get('sign', function (\yiche\Sign\Sign $signClient) {
    $data = [
        'client_time' => 1543995526,
        'name'        => '张三',
        'age'         => '12'
    ];
    // 生成签名
    $signStr = $signClient->createSign($data);

    // curl传
    $checkData = array_merge($data, [
        'sign' => $signStr
    ]);

    // 检测签名
    $signClient->checkSign($checkData);

    return $signStr;

});