PHP code example of seffeng / afs
1. Go to this page and download the library: Download seffeng/afs 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/ */
seffeng / afs example snippets
/**
* SiteController
*/
use Seffeng\Afs\AfsClient;
class SiteController extends Controller
{
public function index()
{
try {
$accessKeyId = ''; // 阿里云 AccessKeyId
$accessSecret = ''; // 阿里云 AccessKeySecret
$appKey = ''; // 阿里云验证码 appkey
$ip = '192.168.1.100'; // 客户端IP
$scene = 'ic_login'; // 使用场景标识,必填参数,可从前端获取 [ic_login, nc_activity_h5, ...]
$token = '1627557...'; // 请求唯一标识,必填参数,从前端获取
$sig = '05XqrtZ0Ea...'; // 签名串,必填参数,从前端获取
$sessionId = '01sWbn...'; // 会话ID,必填参数,从前端获取
$afs = new AfsClient($accessKeyId, $accessSecret, $appKey);
$afs->setScene($scene);
$afs->setToken($token);
$afs->setSig($sig);
$afs->setSessionId($sessionId);
$afs->setRemoteIp($ip);
var_dump($afs->verify());
} catch (AfsException $e) {
echo $e->getMessage();
} catch (\Exception $e) {
echo $e->getMessage();
}
}
}
├─src
│ │ AfsClient.php
│ ├─Exceptions
│ │ AfsException.php
└─tests
AfsTest.php