FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour API Bancaria (SOLUCIONADO)
Posts: 84
Joined: Wed Oct 24, 2007 12:48 PM
API Bancaria (SOLUCIONADO)
Posted: Mon Apr 12, 2021 08:36 AM
Hola, quiero hacer uso de las APIs Bancarias para acceder a los extractos de cuentas.

He comenzado por analizar la API de BBVA. Con el siguiente c贸digo he conseguido acceder a las cuentas de un usuario de ejemplo que pone BBVA para hacer pruebas :

Code (fw): Select all Collapse
local oHttp, cCadena, cNomObjOLE := "Microsoft.XMLHTTP", 聽cToken := '', ;
聽 聽 聽 cURL聽:= "https://apis.bbva.com/business-accounts-sbx/v1/statements/aeb43"
聽
聽oHttp:Open ( "GET" , cUrl, .f. )
聽oHttp:SetRequestHeader ( "Content-Type", "application/json")
聽oHttp:SetRequestHeader ( "Accept", "application/json")
聽oHttp:SetRequestHeader ( "Authorization", cToken )
聽oHttp:SetRequestHeader ( "Host", "apis.bbva.com" )

聽try
聽 聽 聽 聽 oHttp:Send ()
聽catch
聽 聽 聽 聽 ? 'Error en Send'
聽 聽 聽 聽 return .t.
end
cCadena := oHttp:responseText

En este ejemplo no he incluido cToken y es donde tengo el problema. Para obtener un token de acceso v谩lido el sistema se basa en oAuth (Three Legged Access). La siguiente informaci贸n aparece en la BBVA API_Market para obtener el token de acceso :
GET /token/authorize
This endpoint is invoked by a web browser redirection (it requires user interaction). It redirects to the login page, and then shows the scopes approval page. At the end of this flow, this endpoint returns to the redirect_url configured for the associated application, with an authorization_code attached.
This endpoint issues a web browser redirection to the BBVA Connect login page. If necessary, also shows the scope approval page. Finally, another web browser redirection is made to the application鈥檚 redirect_uri, attaching a query parameter with the Authorization Code.

With that authorization_code and application鈥檚 credentials ( appid + client_secret ), the application must invoke the token endpoint to obtain a valid _SecurityToken.

If there is not any scope specified in the request, the scope of this Security_Token will be the default scope or scopes for each application.

This endpoint returns the access tokens for grant types client_credentials, authorization_code and refresh_token.

Seg煤n indican en la informaci贸n al consumir el servicio con un GET el sistema redirige a una p谩gina para que el usuario se identifique y a continuaci贸n se pasa el control a una uri de mi aplicaci贸n Web. Como estoy intentando acceder desde mi programa de escritorio no s茅 c贸mo acceder a la p谩gina de identificaci贸n y recuperar la respuesta con el token de acceso.

Espero haberme explicado o por lo menos si hay alguien en el foro que haya conseguido acceder a API bancarias y me pudiera echar una mano.
Gracias.
Posts: 728
Joined: Fri Oct 07, 2005 07:38 AM
Re: API Bancaria
Posted: Mon Apr 12, 2021 09:12 AM
Hola, hace un tiempo estuve viendo opciones y quiz谩s te interese esta plataforma.

https://www.afterbanks.com/

No llegu茅 a utilizarla porque mis clientes no me solicitan este tipo de acceso, pero antes de meterte con la API de cada entidad igual te sale a cuenta.
Angel Salom
Visionwin Software - https://www.visionwin.com
------------------------------------------------------------
fwh 19.05 - harbour 3.2 - bcc 7.4
Posts: 84
Joined: Wed Oct 24, 2007 12:48 PM
Re: API Bancaria
Posted: Tue Apr 13, 2021 09:25 AM

Gracias Angel, le echar茅 un vistazo, pero por lo que he visto por encima es una API y para usarla llegar茅 al mismo problema con el que me he encontrado con la de BBVA.

Seguir茅 probando y puede que lo intente con modharbour que me permitir谩 acceder a la p谩gina de identificaci贸n y volver a la p谩gina web de la aplicaci贸n que desarrolle.

Posts: 84
Joined: Wed Oct 24, 2007 12:48 PM
Re: API Bancaria
Posted: Fri Apr 16, 2021 04:22 PM
Hola, he podido avanzar en este tema. He conseguido con el authorization_code que me ha devuelto la p谩gina de identificaci贸n de la banca electr贸nica de BBVA, acceder a un access_token y con 茅l recuperar los movimientos de una cuenta bancaria de prueba. El siguiente c贸digo hace todo el proceso :
Code (fw): Select all Collapse
function BBVA聽 聽()

聽 聽 local oHttp, cCadena, aRespuesta := { => }, cCode, cToken, cFicTok := '.\TOK_BBV.TXT', cFicJSon聽:= '.\EXT_BBV.JSON', ;
聽 聽 聽 聽 聽 cNomObjOLE := "Microsoft.XMLHTTP", ; 
聽聽 聽 聽 聽 聽cRedirect_Uri := "http://localhost", ;
聽 聽 聽 聽 聽 cAppID聽 聽 聽:= "'", 聽cSecretID 聽:= "", ; 聽 聽 聽 聽 聽 聽 聽 聽 聽&& Esta informaci贸n se consigue d谩ndose de alta en https://www.bbvaapimarket.com/es y a帽adiendo una APP
聽 聽 聽 聽 聽 cURL聽 聽:= "https://connect.bbva.com/token"

* 聽 聽Abrir navegador Chrome con la p谩gina d贸nde se solicitan los datos del usuario de la banca electr贸nica de BBVA
聽 聽 shellexecute ( , "open", "chrome.exe", ;
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 "https://connect.bbva.com/sandboxconnect?scope=" + ;
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 "&client_id=" 聽 聽+ cAppID 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽+ ;
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 "&redirect_uri=" + cRedirect_Uri 聽 聽 聽 聽 聽 聽 聽 聽 + ;
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 "&response_type=code" ) 聽 聽
********* 聽 聽Una vez introducidos usuario y contrase帽a, el navegador se redije a cRedirect_Url con un par谩metro que tiene el c贸digo de autorizaci贸n : ?code=xxxxxx
********* 聽 聽cCode := Recuperar de la ventana del navegador la direcci贸n (por ejemplo : http://http://localhost/?code=F16fo8) y sacar code "F16fo8"
* 聽 聽Realizar un POST con el authorization_code para acceder a un access_token v谩lido
聽 聽 try
聽 聽 聽 聽 oHttp := CreateObject (cNomObjOLE)
聽 聽 catch
聽 聽 聽 聽 ? 'Error de creacion oHttp'
聽 聽 聽 聽 return .t.
聽 聽 end

聽 聽 oHttp:Open ( "POST" , cUrl + "?grant_type=authorization_code" + ;
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 "&code=" + ALLTRIM (cCode) 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 + ;
聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 "&redirect_uri=" + cRedirect_Uri, .f. )
聽 聽 oHttp:SetRequestHeader ( "Authorization", "Basic " + cMimeEnc(cAppID + ':' + cSecretID) )

聽 聽 try
聽 聽 聽 聽 oHttp:Send ()
聽 聽 catch
聽 聽 聽 聽 ? 'Error en Send Token'
聽 聽 聽 聽 return .t.
聽 聽 end
聽 聽 cCadena := oHttp:responseText 
聽 聽 HB_MemoWrit ( cFicTok, cCadena, .f. )
聽 聽 aRespuesta := hb_jsonDecode (cCadena)
聽 聽 cToken := aRespuesta ['access_token']

* 聽Realizar un GET con el acces_token y acceder a los movimientos de las cuentas
聽 聽 cUrl聽 聽 聽 聽:= "https://apis.bbva.com/business-accounts-sbx/v1/statements/aeb43"
聽 聽 oHttp:Open ( "GET" , cUrl, .f. )
聽 聽 oHttp:SetRequestHeader ( "Content-Type", "application/json")
聽 聽 oHttp:SetRequestHeader ( "Accept", "application/json")
聽 聽 oHttp:SetRequestHeader ( "Authorization", "jwt " + cToken )
聽 聽 oHttp:SetRequestHeader ( "Host", "apis.bbva.com" )

聽 聽 try
聽 聽 聽 聽 oHttp:Send ()
聽 聽 catch
聽 聽 聽 聽 ? 'Error en Send'
聽 聽 聽 聽 return .t.
聽 聽 end
聽 聽 cCadena := oHttp:responseText 
聽 聽 HB_MemoWrit ( cFicJSon, cCadena, .f. )
聽 聽 oHttp := Nil
return Nil

El problema que tengo ahora es que necesito leer de la ventana de Chrome el authorization_code con que responde la p谩gina de identificaci贸n.

He conseguido con la funci贸n : FindWindow(0, "BBVA Connect Google Chrome") recuperar el hWnd de la ventana, y con GetWindowText(hWnd) el t铆tulo. Pero c贸mo puedo acceder al contenido de la ventana ?
Por ejemplo acceder al objeto html que contiene la ventana de Chrome.

Gracias.
Posts: 838
Joined: Wed Aug 22, 2007 10:09 AM
Re: API Bancaria
Posted: Mon Apr 19, 2021 10:21 AM

Hola:

Probablemente se genere una cookie, que puedas localizar.

Asimismo, quiz谩s sea mejor utilizar un navegador menos intrusivo, como Firefox o Brave, si lo estimas oportuno.

Un saludo

Saludos / Regards,



FWH 20.04, Harbour 3.2.0 dev (r1909261630) y BCC 7.40
Posts: 84
Joined: Wed Oct 24, 2007 12:48 PM
Re: API Bancaria
Posted: Mon Apr 19, 2021 11:45 AM
Gracias Moises, pero no hay ninguna cookie.

He incrustado la ventana del navegador dentro de mi programa, pero no s茅 c贸mo acceder a la direcci贸n que se muestra para leer el code.
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: API Bancaria
Posted: Mon Apr 19, 2021 12:18 PM

Que valor tiene cCadena aqui ?

cCadena := oHttp:responseText

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 84
Joined: Wed Oct 24, 2007 12:48 PM
Re: API Bancaria
Posted: Mon Apr 19, 2021 12:41 PM
cCadena tiene este valor si previamente le he rellenado en el POST un cCode correcto

{"access_token":"eyJ6aXAiOiJERUYiLCJlbmMiOiJBMTI4R0NNIiwiYWxnIjoiUlNBLU9BRVAifQ.XSWOkBMa1fvH5KzfsWVFDQLyJegRTyi-aG4AXh8XiubzfowJlDvtxTnGJTUaKwx_7ASwSfPfMs0VJcQZap6CWvs-HR_MBnHrD6VA3eiy-JvEhNiV2-sYLA-81TmCQj9Zx1oKccRxIRRlXWVAme32CPLTE13JYvocLVeiNIn1zYY2EycyHEEfp9huegwQjU6U19gofXzLCnc8K6GCGLZbm5c2_ZUuzXYk6uIjYzNRHmax2owwPvNRflGz7ZCJRkrP6wBL4oRgfefjTy0-MPfYnW60pbWyHEcu_J1BgAD40WYYxSzUoyCb-Rli8V4xDO8EEAZeHkL7-eJ3LkSXA-uo4A.DGBA9pirTlzwJaNu.788fUGfWZ9sGcL3jPhFC4vO_y5KmZJNdAtAng2ayttCP9ipH2IHFwef2qYfyt8W9-wkC49WxRwGaA0-zytHfWqfBDGA1a1yS419YHxcvFCKEUuyEkd9YXdV96WGKufEimPtd2rJ0hWvvv-6tx7hthbMBV3f6ghFPydYswo3zhzpWuNjZ_AaxQDvB1tNvA9oyJC09_KXP3VcbFOV-C8-sf_2cGoyHV-ejEnvK1lRglmKO2QIJVP5ua8NgeJmnXgTRx1-8Vakhz7NgkA.Nujj611NC6kQ1Nq5D1d5BQ","token_type":"jwt","refresh_token":"eyJ6aXAiOiJERUYiLCJlbmMiOiJBMTI4R0NNIiwiYWxnIjoiUlNBLU9BRVAifQ.jve2r-yYAhdwUFI0ha8jhByskyOlteQuaE8cvEX282TTlIDR29y7OkF3pMLtNEl1A9EfP9vSc1E9fCW3W7UoOqgXZtKrde3VDf2zG6CaFlsyQf8UvaTrXIn1rQY1YgH3q8SGpz64IvfgT2WC53MPpE_337iJvrawAM-KXJbS5dRJG_13J0HDZr2KX2n0j91CbQ9GjYO55oyAly-CNf3JUbe3wll30fabHBE84wiIS9TiILYhxazAHqLhmjJUZQhQSCDMzu8Vuf5j3yDmWTufARl_ctn7AjGLLwkQuocSVCqhVuTOwN2S58AqNcCMEHnhSFxsfFRG2gn4q16h6-ShHQ.5YepOfZxXH8kHaXR.5GFQfnfBVg7KSTKiXTCrb4B4CB-zCIJll2G3kB-vW1ja9uJVuaYSajA-Gs6esal1pqPmA1Jh9V2v3GNfgiDz6Cs0MVqnKxS-3_sdh5NqdmlXUlJ17XXxZ9HhTmA7HBqaxL2fpORW06Gwd2BZNfA1L6pc5fdxIJRnw1IY-YWMaDMR2oH969sM8R_ChLHGXrZHPN0ZkcBufCS4H2dnh6-mbF7fNX5pUwGpyKy2P2fCxOnh4XWuZ5f15wvX7zxDx8-R4bYwWLvElocKqxHlwHwNEJZbAb0kP75dckYIV0hT4g73wfkMsQ5j4CHmAhmQzyqc-WjPM8g36qCMZExZeK-Z-idaUub3NBLEFvGSRrrlvXdvRFg2oqw2JzRFUNg_m2QlhKxuhg.ynbLLTwnfypdGymEmpR2aA","expires_in":2699,"scope":"businessAccountsSbx_aeb43","refresh_expires_in":359999}


El problema lo tengo para conseguir el cCode :
- abierto Chrome con Shellexecute y la p谩gina de identificaci贸n de BBVA Connect
- espero a que el usuario rellene su usuario y contrase帽a
- la p谩gina de BBVA Connect redirije a localhost con el code=
Aparece la pantalla que he puesto antes y en ese momento desde el programa debo leer la direcci贸n en una cadena y sacar lo que haya despu茅s de code=
No s茅 como recuperar la direcci贸n en la que est谩 la ventana de Chrome.
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: API Bancaria
Posted: Mon Apr 19, 2021 06:50 PM

Gabriel,

Usando FindWindow() y una vez tienes el hWnd de la ventana principal, podrias acceder al hWnd del control donde esta la URL si conoces su ID.
Usa Spy++ (te lo instala Visual Studio Community, y es gratuito) para encontrar este valor. Spy++ es muy potente y en unos minutos aprender谩s a usarlo.

En cuanto a usar "Microsoft.XMLHTTP", construye el ejemplo FWH\samles\olebrow.prg y selecciona "Microsoft.XMLHTTP.1.0". Este ejemplo de FWH te muestra "todo" lo que ese objeto OLE puede ofrecerte. Prueba a pedirle otras cosas y a ver si aparece la URL :-)

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 84
Joined: Wed Oct 24, 2007 12:48 PM
Re: API Bancaria
Posted: Tue Apr 20, 2021 09:13 AM
He instalado spyxx y he localizado la ventana de chrome.
驴C贸mo puedo acceder a los controles que contiene ?
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: API Bancaria
Posted: Tue Apr 20, 2021 01:03 PM

Est谩s revisando los "threads", selecciona revisar "Windows" (Ctrl+W) desde la primera opci贸n del men煤

Lo m谩s sencillo es "Find Window" entonces se te muestra un circulo que has de arrastrar con el rat贸n y pasarlo por encima de los controles que quieras revisar

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: API Bancaria
Posted: Tue Apr 20, 2021 01:12 PM

Parece que es una clase propia de Chrome y los controles son simulados.

Intenta por la via del OLE que te he comentado, y si eso tambi茅n falla, yo lo intentar铆a con mod_harbour

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 84
Joined: Wed Oct 24, 2007 12:48 PM
Re: API Bancaria
Posted: Wed Apr 21, 2021 06:47 AM
Muchas gracias, Antonio. He seguido tu consejo y he probado con el objeto OLE "Shell.Explorer.2" y ya he conseguido que funcione.

Al principio lo intent茅 con este ActiveX, pero se activaba IE versi贸n 8 y la p谩gina de ConnectBBVA no se desplegaba bien.
He encontrado en el foro este mensaje d贸nde viene el c贸digo de la funci贸n INTER_APP_WEB_CONFIG, que permite asociar a un ejecutable la versi贸n 11 de IE.

https://forums.fivetechsupport.com/viewtopic.php?f=3&t=36913&hilit=INTER_APP_WEB_CONFIG&sid=67fc2483c0a3c659cdf9f225d2a25661

Ya he conseguido abrir la p谩gina d贸nde se identifica el usuario. Activo un oTimer que cada 3 segundos comprueba que se haya identificado correctamente y el servidor haya redirigido a la Url con el "?code=".

El ActiveX tiene la propiedad "Document" y ese objeto a su vez tiene la propiedad "Url" con la que accedo a la direcci贸n del navegador.
Code (fw): Select all Collapse
oDOM := oActiveX:GetProp( "Document" )
cUrl := oDOM:Url


Voy a depurar el c贸digo y lo publicar茅 aqu铆.
Posts: 84
Joined: Wed Oct 24, 2007 12:48 PM
Re: API Bancaria (SOLUCIONADO)
Posted: Wed Apr 21, 2021 03:37 PM
Buenas tardes, dejo aqu铆 la versi贸n definitiva en forma de clase.
Code (fw): Select all Collapse
#include "Fivewin.ch"

class TApiBBVA

聽 聽 data oWnd 聽 聽聽 聽 聽 聽&& Ventana Padre
聽 聽 data cNomObjOLE 聽 聽 && Nombre del objeto OLE para hacer GET y POST
聽 聽 data cAppID聽 聽 聽 聽 聽&& Informaci垄n APP creada en BBVAMarket
聽 聽 data cSecretID聽 聽 聽 && Informaci垄n C垄digo secreto de BBVAMarket
聽 聽 data cURL聽 聽聽 聽 聽 聽 && URL de BBVA
聽 聽 data cRedirect_Uri聽 && Url a la que se redige la respuesta de ConnectBBVA
聽 聽 data cToken聽聽 聽 聽聽 聽&& Access_Token devuelto por oAuth
聽 聽 data cCode聽 聽 聽 聽 聽聽&& Authorization_Code necesario para solicitar access_token
聽 聽 data cFicTok聽 聽 聽 聽 && Nombre de fichero para almacenar Token
聽 聽 data cFicJSon聽 聽聽 聽 && Nombre de fichero para almacenar respuesta JSon
聽 聽 data oTimer聽聽 聽 聽聽 聽&& Timer para comprobar cada 3 segundos que ha respondido ConnectBBVA

聽 聽 method New (oWnd)
聽 聽 method EXTRACTO ()聽 聽 聽 聽 聽 聽 聽聽 聽聽 && Devuelve JSon con los extractos de las cuentas del cliente BBVA
聽 聽 method PEDIR_CODE ()聽 聽 聽 聽 聽 聽 聽 聽 && Si el usuario a rellenado sus datos correctos en ConnecBBVA, rellena ::cCode
聽 聽 method IniTimer ( oDlg, oActiveX )聽 && Iniciar ::oTimer
聽 聽 method TENGO_CODE ( oActiveX )聽 聽 聽 && Comprueba que la cUrl contiene en ::cCode, lo rellena y devuelve true
聽 聽 method PEDIR_TOKEN ()聽 聽聽 聽 聽 聽 聽 聽 && Petici垄n de access_Token usando ::cCode y si hay respuesta devuelve true
聽 聽 method PEDIR_EXTRACTO ()聽 聽 聽 聽 聽 聽 && Petici垄n de Extracto usando ::cToken, devuelve Json son los datos
endclass

method New (oWnd)聽 聽聽 聽 聽 聽 聽 聽 聽 聽 class TApiBBVA

聽 聽 ::oWnd聽 聽 聽 聽:= oWnd
聽 聽 ::cNomObjOLE := "Microsoft.XMLHTTP" 聽 聽 && "WINHTTP.WINHTTPREQUEST.5.1"
聽 聽 ::cAppID 聽 聽 := '' 聽 聽 聽 聽 聽 && Hay que darse de alta en BBVAMarket
聽 聽 ::cSecretID 聽:= "" 聽 聽 聽 聽
聽 聽 ::cURL聽 聽 聽 聽:= "https://connect.bbva.com/token"
聽 聽 ::cRedirect_Uri := "http://localhost"
聽 聽 ::cToken 聽 聽 := ""
聽 聽 ::cCode 聽 聽 聽:= ""
聽 聽 ::cFicTok 聽 聽:= '.\TOK_BBV.TXT'
聽 聽 ::cFicJSon 聽 := '.\EXT_BBV.JSON'
return Self

method EXTRACTO ()聽 聽 聽 聽 聽 聽 聽 聽 聽 class TApiBBVA

聽 聽 if ::PEDIR_CODE ()
聽 聽 聽 聽 if ::PEDIR_TOKEN ()
聽 聽 聽 聽 聽 聽 ::PEDIR_EXTRACTO ()
聽 聽 聽 聽 endif
聽 聽 endif
return Nil

method PEDIR_CODE ()聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 class TApiBBVA

聽 聽 local oDlg, oActiveX, nPos, oTimer, oApi

聽 聽 oApi := Self
聽 聽 define dialog oDlg from 100, 100 to 950,1000 title "Navegar" pixel ;
聽 聽 聽 聽 聽 聽 聽 of ::oWnd

聽 聽 activate dialog oDlg on init ;
聽 聽 聽 聽 聽 聽( oActiveX := ShowPageWeb( oDlg, ;
聽 聽 聽 聽 聽 聽 聽 聽 "https://connect.bbva.com/sandboxconnect?scope=" + ;
聽 聽 聽 聽 聽 聽 聽 聽 "&client_id=" 聽 聽+ oApi:cAppID 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽+ ;
聽 聽 聽 聽 聽 聽 聽 聽 "&redirect_uri=" + oApi:cRedirect_Uri 聽 聽 聽 聽 聽 聽 聽 + ;
聽 聽 聽 聽 聽 聽 聽 聽 "&response_type=code", 0, 0, 825, 950 ) 聽 聽 聽 聽 聽, ;
聽 聽 聽 聽 聽oApi:IniTimer (oDlg, oActiveX ) )
聽 聽 release ::oTimer

return oDlg:nResult = ID_OK

method IniTimer ( oDlg, oActiveX )聽 聽 聽 聽 聽 class TApiBBVA

聽 聽 define Timer ::oTimer of oDlg interval 3000 ;
聽 聽 聽 聽 action IF ( ::TENGO_CODE (oActiveX), oDlg:End (ID_OK), )
聽 聽 activate Timer ::oTimer
return Nil

method TENGO_CODE ( oActiveX )聽 聽 聽 聽 聽 聽 聽 class TApiBBVA

聽 聽 local oDOM := oActiveX:GetProp( "Document" ), ; // -> Object Document
聽 聽 聽 聽 聽 Retorno := .f., nPos
聽 聽 local cUrl := oDOM:Url

聽 聽 if (nPos := AT ( "?code=", cUrl )) # 0
聽 聽 聽 聽 ::cCode := SUBSTR ( cUrl, nPos + 6 )
聽 聽 聽 聽 Retorno := .t.
聽 聽 endif
return Retorno

Function ShowPageWeb( oParent, cUrl, nT, nL, nH, nW )

聽 聽 local oActiveX, oHttp, oActiveXdo

聽 聽 oActiveX := TActiveX():New( oParent, "Shell.Explorer.2", nT, nL, nW, nH )

聽 聽 oActivex:Silent := .T. // aqui silence... en el script.

聽 聽 oActiveX:Do( "Navigate2", cUrl )

聽 聽 oActivex:SetFocus()

聽 聽 WHILE oActivex:Busy
聽 聽 聽 聽 SysWait(.2)
聽 聽 ENDDO

聽 聽 oActiveXdo := oActiveX:Document()

聽 聽 oHttp := oActiveX:GetProp( "Document" ) // -> Object Document


聽 聽 if Empty( oHttp )
聽 聽 聽 聽 MsgInfo( "Problemas en el Site...", ;
聽 聽 聽 聽 聽 聽 聽"Problemas en el Site..." )
聽 聽 聽 聽 RETURN( .F. )
聽 聽 endif
Return oActiveX

method PEDIR_TOKEN ()聽 聽聽 聽 聽 聽 聽 聽 聽 聽 class TApiBBVA

聽 聽 local oHttp, cCadena, aRespuesta

聽 聽 try
聽 聽 聽 聽 oHttp := CreateObject (::cNomObjOLE)
聽 聽 catch
聽 聽 聽 聽 ? 'Error de creacion oHttp'
聽 聽 聽 聽 return .t.
聽 聽 end

聽 聽 oHttp:Open ( "POST" , ::cUrl + "?grant_type=authorization_code" + ;
聽 聽 聽 聽 聽 聽 聽"&code=" + ALLTRIM (::cCode) 聽 聽 聽 聽 聽 聽 聽 聽 聽 聽 + ;
聽 聽 聽 聽 聽 聽 聽"&redirect_uri=" + ::cRedirect_Uri, .f. )
聽 聽 oHttp:SetRequestHeader ( "Authorization", ;
聽 聽 聽 聽 聽 聽 聽"Basic " + cMimeEnc(::cAppID + ':' + ::cSecretID) )

聽 聽 try
聽 聽 聽 聽 oHttp:Send ()
聽 聽 catch
聽 聽 聽 聽 ? 'Error en Send Token'
聽 聽 聽 聽 return .t.
聽 聽 end
聽 聽 cCadena := oHttp:responseText
*聽 聽HB_MemoWrit ( ::cFicTok, cCadena, .f. )
聽 聽 aRespuesta := hb_jsonDecode (cCadena)

聽 聽 if hb_HHaskey ( aRespuesta, 'access_token' )
聽 聽 聽 聽 ::cToken := aRespuesta ['access_token']
聽 聽 endif
聽 聽 oHttp := Nil
return ! EMPTY ( ::cToken )

method PEDIR_EXTRACTO ()聽 聽 聽 聽 聽 聽 聽 聽 class TApiBBVA

聽 聽 local oHttp, cUrl, cCadena

聽 聽 cURL聽 聽 聽 聽:= "https://apis.bbva.com/business-accounts-sbx/v1/statements/aeb43"
聽 聽 try
聽 聽 聽 聽 oHttp := CreateObject (::cNomObjOLE)
聽 聽 catch
聽 聽 聽 聽 ? 'Error de creacion oHttp'
聽 聽 聽 聽 return .t.
聽 聽 end
聽 聽 oHttp:Open ( "GET" , cUrl, .f. )
聽 聽 oHttp:SetRequestHeader ( "Content-Type", "application/json")
聽 聽 oHttp:SetRequestHeader ( "Accept", "application/json")
聽 聽 oHttp:SetRequestHeader ( "Authorization", "jwt " + ::cToken )
聽 聽 oHttp:SetRequestHeader ( "Host", "apis.bbva.com" )

聽 聽 try
聽 聽 聽 聽 oHttp:Send ()
聽 聽 catch
聽 聽 聽 聽 ? 'Error en Send'
聽 聽 聽 聽 return .t.
聽 聽 end
聽 聽 cCadena := oHttp:responseText
聽 聽 HB_MemoWrit ( ::cFicJSon, cCadena, .f. )
聽 聽 oHttp := Nil
return Nil


La clase se usar铆a as铆 :
Code (fw): Select all Collapse
聽 聽 oApiBBVA := TApiBBVA():new () 聽 聽 聽 聽 聽 聽&& Pasar como par谩metro la ventana padre

聽 聽 oApiBBVA:EXTRACTO ()

La pantalla de identificaci贸n de ConnectBBVA con los datos de usuario de pruebas (contrase帽a:123456)

El resultado final es el fichero EXT_BBV.JSON con el siguiente contenido :
{"result":{"code":200,"info":"OK"},"data":{"AEB43file":"110182241902008000282104202104201000019193174009783CARLOS BANANERO RUIZ \n 2201822419210420210420028972000000000551180000000000ABONO COMP. TRU 30/1/2017 \n 2201822419210420210420021731000000000003500000000000LIQUID.ABONO COM \n 3301822419020080002800010000000025535350001000000002553535100001919317400978 \n 88999999999999999999000035 "}}
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: API Bancaria (SOLUCIONADO)
Posted: Wed Apr 21, 2021 04:03 PM

Excelente!

muchas gracias

regards, saludos

Antonio Linares
www.fivetechsoft.com