PHP code example of jeferwang / signature

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

    

jeferwang / signature example snippets


function test()
{
    $appid = '27834yrudfhao7rfouah';
    $appSecret = '0239urq98eurqwfff743q2yf8o7whaeofy3q74rhfoq7fghw';

    $params = [
        'id' => '123',
        'goods_id' => 'abcd123',
        'comment' => '测试Signature',
    ];

    $s = new Signature($appid, $appSecret, $params);
    var_dump($s->generate());
}

test();

$queryData = $request->all();
$appid = array_get($queryData, 'appid');
if (empty($appid)) {
    throw new \Exception("签名校验失败:appid must not empty");
}
$appAuth = ApiAuthModel::where(['appid' => $appid])->first();
if (!$appAuth) {
    throw new \Exception("签名校验失败:appid invalid");
}
$appSecret = $appAuth->app_secret;
$v = new SignatureValidate($queryData, $appSecret);
if (!$v->validate()) {
    throw new \Exception("签名校验失败:signature invalid");
}