ova777 / tsoauth
Tronsalt OAuth库
v1.0.3
2016-08-31 10:28 UTC
Requires
- php: >=5.3
- ext-curl: *
- ext-json: *
This package is not auto-updated.
Last update: 2024-09-14 19:31:15 UTC
README
Tronsalt OAuth库
用法
创建TSOauth对象
use ova777\TSOAuth; $tsoauth = TSOAuth\Core::create(array( 'auto_refresh_token' => true, 'id' => 'OAUTH_CLIENT_ID', 'secret' => 'OAUTH_CLIENT_SECRET', 'host' => 'https://tronsalt.ru', 'access_token' => '', //If exists 'refresh_token' => '', //If exists 'scope' => array('user.data'), //Required permissions ));
重定向到用户认证
$tsoauth->goAuthorizationCode();
如果用户点击"取消"(拒绝访问)
将重定向到您的REDIRECT_URI,并带有GET参数"error"和"error_description"
if(isset($_GET['error'])) { ?> <b><?= $_GET['error'] ?></b><br/> <?= $_GET['error_description'] ?> <?php }
如果用户被授予访问权限
将重定向到您的REDIRECT_URI,并带有GET参数"code"
您需要通过"code"获取"access_token"和"refresh_token"
try { $tsoauth->getAccessTokenByCode($_GET['code']); //Save $tsoauth->access_token and $tsoauth->refresh_token for this User } catch (TSOAuth\Except $error) { echo $error->asString(); }
如果您有"access_token"和"refresh_token",您可以进行交易
try { $transaction = $tsoauth->makeTransaction('500'); //Sum if(isset($transaction['actions'])) { $commit = $tsoauth->endTransaction($transaction['actions']['commit']); //print_r($commit); } } catch (TSOAuth\Except $error) { echo $error->asString(); }