mishannn/tinkoff-api

非官方Tinkoff API库

安装: 36

依赖项: 0

建议者: 0

安全: 0

星标: 2

关注者: 3

分支: 1

开放问题: 0

类型:package

1.0.5 2018-10-07 13:47 UTC

This package is auto-updated.

Last update: 2024-09-08 08:08:58 UTC


README

要求

  • PHP >= 5.5.0
  • GuzzleHttp

安装

composer require mishannn/tinkoff-api

使用示例

require_once __DIR__ . '/vendor/autoload.php';

use mishannn\Tinkoff\TinkoffAPI;
use mishannn\Tinkoff\WaitingConfirmationException;

try {
	$params = [];

    $post = filter_input_array(INPUT_POST);
    if (!empty($post)) {
        if (is_string($post['wuid'])) {
            $params['webUserId'] = $post['wuid'];
        }

        if (is_string($post['session'])) {
            $params['sessionId'] = $post['session'];
        }
    }

    $tinkoffApi = new TinkoffAPI($params);

    if (!empty($post) && $post['sms'] === 'true') {
        $tinkoffApi->confirmBySms($post['method'], $post['ticket'], $post['code']);
        $tinkoffApi->levelUp();

        $sessionId = $tinkoffApi->getLocalSessionId();
        $webUserId = $tinkoffApi->getLocalWebUserId();

        echo "<b>SESSION:</b> {$sessionId}<br><b>WUID:</b> {$webUserId}";
    } else {
        $tinkoffApi->signUp(LOGIN, PASSWORD);
        $tinkoffApi->levelUp();

        $sessionId = $tinkoffApi->getLocalSessionId();
        $webUserId = $tinkoffApi->getLocalWebUserId();

        echo "<b>SESSION:</b> {$sessionId}<br><b>WUID:</b> {$webUserId}";
    }
} catch (WaitingConfirmationException $exception) {
    $data = $exception->getData();

    $html = '<form method="post">'
        . '<input type="hidden" name="sms" value="true">'
        . '<input type="hidden" name="wuid" value="' . $exception->getWebUserId() . '">'
        . '<input type="hidden" name="session" value="' . $exception->getSessionId() . '">'
        . '<input type="hidden" name="method" value="' . $data->initialOperation . '">'
        . '<input type="hidden" name="ticket" value="' . $data->operationTicket . '">'
        . '<input type="text" name="code">'
        . '<button type="submit">Confirm</button>'
        . '</form>';

    echo $html;
} catch (Exception $exception) {
    echo $exception->getMessage();
} catch (Throwable $exception) {
    echo $exception->getMessage();
}