几周前,在一个项目中,出现了将CRM与Tinkoff Bank API集成的问题。 特别是有关获取银行帐户对帐单的信息。
该资产具有:
- openapi.tinkoff.ru
- 电话支持服务(由于技术支持部门很忙-挽救溺水者的工作,溺水者的手工)
- Google文档: 24386_policy.pdf (里面带有俄语字母,带有令人愉悦的表情,巫术转向,虽然不合适,但仍然是一件事情……)
在google框的过程中,还发现有评论认为设置Tinkoff Bank API非常有趣且不容易(请参阅banki.ru上的文章
“ Tinkoff API-我们对此太愚蠢” )。
是的,我不得不稍作修改,因此,为节省研讨会中其他同志的时间,本文是写的。
我注意到,Tinkoff Bank API使用Oauth 2.0进行授权。
为什么我们需要openapi.tinkoff.ru?
- 测试(见下文);
- 为了猜测什么是什么以及如何 没有直接的夹板; 我们以直觉的水平工作!...
让我们开始吧。 在“ SSO授权”部分中,单击“如何/隐藏”,然后单击/安全/令牌#refresh-token(“通过刷新令牌发行令牌”),选择Grant_type作为参数,然后在refresh_token字段中(可以在用户帐户)。 点击按钮“尝试一下!” 这些操作的结果是获得了诸如
access_token这样
的重要信息 (即openapi.tinkoff.ru
演示了接收它
的可能性)。
接下来,查看“帐户和付款”部分,单击/合伙人/公司/ {INN} /摘录(“声明收据”)。 我们研究了获取参数所需的参数:授权,INN,accountNumber,从头到尾。
授权-我们猜想授权只不过是我们在“ SSO授权”部分中收到的access_token;
INN-我们为其配置API的组织的INN;
从-哪一天开始(放电时间);
直到-哪一天(放电时间)。
因此(我们看一下Oauth 2.0资料),
获取语句数据的过程分为两个阶段-首先获得access_token,然后手边具有access_token,我们获得该语句的数据 。 太好了 算法很清楚,我们编写了代码(出于明显的原因,下面的代码中的$ user,$ pass,$ refresh_token,$ inn,$ accountNumber的代码值中的访问参数已更改)。
创建以下文件:
- 第一个设置文件是StartSettings.php
- 第二个启动文件是Start.php
- 用于向API发布数据或从API解析数据的第三个文件是TinkoffInsertData.php ; 我们使用CURL(php)。
- 空的数据库转储,可以在其中上载语句的数据: bank.sql ; MySQL数据库(我们通过PDO将数据发送到数据库)。
因此,请看一下代码并对其进行注释!
设置文件-StartSettings.php:
$host = '127.0.0.1'; $db = 'bank'; $user = 'root'; $pass = ''; $charset = 'utf8'; $dsn = "mysql:host=$host;dbname=$db;charset=$charset"; $opt = [ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, PDO::ATTR_EMULATE_PREPARES => false, ]; $pdo = new PDO($dsn, $user, $pass, $opt); $user="IKu0jn98kllkI90kklii";
起始文件-Start.php:
session_start(); error_reporting(E_ALL); include 'StartSettings.php'; include 'TinkoffInsertData.php'; TinkoffInsertData($user,$pass,$refresh_token, $inn, $accountNumber, $from_year, $from_month, $from_day, $till_year, $till_month, $till_day, $pdo); $stmt = $pdo->prepare("INSERT INTO `bank`.`dateofwork` (dateofwork) VALUES (NOW())"); $stmt->execute();
用于向API发布数据或从API解析数据的文件-TinkoffInsertData.php:
function TinkoffInsertData($user,$pass,$refresh_token, $inn, $accountNumber, $from_year, $from_month, $from_day, $till_year, $till_month, $till_day, $pdo){
读者:我希望本文能帮助您通过网络服务和客户服务获利。 愿力量与您同在!
Tinkoff Bank技术支持人员:希望本文能减轻您的负担! 祝你好运