API C/C++
HSM Dinamo
Carregando...
Procurando...
Nenhuma entrada encontrado
post_put_get_delete_pix.c

Exemplo requisição POST, PUT, GET e DELETE padrão PIX definido no SPI(Sistema de Pagamentos Instantâneos).

Veja Nota sobre os exemplos.
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <dinamo.h> /* header do Dinamo */
#define HOST_ADDR "127.0.0.1"
#define USER_ID "master"
#define USER_PWD "12345678"
int main()
{
int nRet = 0;
struct AUTH_PWD authPwd;
HSESSIONCTX hSession = NULL;
const char *pszHeaderList[] = { "Content-Type: application/xml; charset=utf-8" };
DWORD dwHeaderListCount = 1; //Número de linhas em pszHeaderList
BYTE pbTestData[] = "<?xml version=\"1.0\" encoding=\"UTF - 8\" standalone=\"no\"?><xml>sdfsdf</xml>";
const char szKeyId[] = "key";
const char szKeyCert[] = "key_cert";
const char szPIXChain[] = "pix_chain";
BYTE *pbResponseHeader = NULL;
DWORD dwResponseHeaderLen = 0;
BYTE *pbResponseBody = NULL;
DWORD dwResponseBodyLen = 0;
const char szUrl[] = "https://127.0.0.1:8000";
//Inicializa as bibliotecas do Dinamo
nRet = DInitialize(0);
if (nRet) {
printf("Falha na funcao: DInitialize \nCodigo de erro: %d\n", nRet);
goto clean;
}
printf("Bibliotecas inicializadas.\n");
//Inicializa a estrutura para conexão com o HSM
strncpy(authPwd.szAddr, HOST_ADDR, sizeof(authPwd.szAddr));
authPwd.nPort = DEFAULT_PORT;
strncpy(authPwd.szUserId, USER_ID, sizeof(authPwd.szUserId));
strncpy(authPwd.szPassword, USER_PWD, sizeof(authPwd.szPassword));
nRet = DOpenSession(&hSession, SS_USER_PWD, (BYTE *)&authPwd, sizeof(authPwd), ENCRYPTED_CONN);
if (nRet) {
printf("Falha na funcao: DOpenSession \nCodigo de erro: %d\n", nRet);
goto clean;
}
printf("Sessao com o Dinamo estabelecida.\n");
nRet = DPIXPost(hSession,
szKeyId,
szKeyCert,
szPIXChain,
szUrl,
dwHeaderListCount,
pszHeaderList,
sizeof(pbTestData) - 1,
pbTestData,
0,
&dwResponseHeaderLen,
&pbResponseHeader,
&dwResponseBodyLen,
&pbResponseBody,
0);
if (nRet) {
printf("Falha na funcao: DPIXPost \nCodigo de erro: %d\n", nRet);
goto clean;
}
DFree(pbResponseHeader);
DFree(pbResponseBody);
printf("PIX post executado com sucesso\n");
nRet = DPIXPut(hSession,
szKeyId,
szKeyCert,
szPIXChain,
szUrl,
dwHeaderListCount,
pszHeaderList,
sizeof(pbTestData) - 1,
pbTestData,
0,
&dwResponseHeaderLen,
&pbResponseHeader,
&dwResponseBodyLen,
&pbResponseBody,
0);
if (nRet) {
printf("Falha na funcao: DPIXPut \nCodigo de erro: %d\n", nRet);
goto clean;
}
DFree(pbResponseHeader);
DFree(pbResponseBody);
printf("PIX put executado com sucesso\n");
nRet = DPIXGet(hSession,
szKeyId,
szKeyCert,
szPIXChain,
szUrl,
0,
NULL,
0,
&dwResponseHeaderLen,
&pbResponseHeader,
&dwResponseBodyLen,
&pbResponseBody,
0);
if (nRet) {
printf("Falha na funcao: DPIXGet \nCodigo de erro: %d\n", nRet);
goto clean;
}
DFree(pbResponseHeader);
DFree(pbResponseBody);
printf("PIX get executado com sucesso\n");
nRet = DPIXDelete(hSession,
szKeyId,
szKeyCert,
szPIXChain,
szUrl,
0,
NULL,
0,
&dwResponseHeaderLen,
&pbResponseHeader,
&dwResponseBodyLen,
&pbResponseBody,
0);
if (nRet) {
printf("Falha na funcao: DPIXDelete \nCodigo de erro: %d\n", nRet);
goto clean;
}
DFree(pbResponseHeader);
DFree(pbResponseBody);
printf("PIX delete executado com sucesso\n");
clean:
if (hSession) {
DCloseSession(&hSession, 0);
printf("Sessao encerrada.\n");
}
printf("Bibliotecas finalizada.\n");
return nRet;
}
Application Programming Interface (API) do HSM Dinamo.
void * HSESSIONCTX
Definição dinamo.h:68
#define DEFAULT_PORT
Definição dinamo.h:1949
unsigned char BYTE
Definição dinamo.h:45
unsigned int DWORD
Definição dinamo.h:46
#define ENCRYPTED_CONN
Definição dinamo.h:585
#define SS_USER_PWD
Definição dinamo.h:576
void AAP_API DFree(void *p)
int AAP_API DPIXDelete(HSESSIONCTX hSession, const char *szKeyId, const char *szCertId, const char *szPIXCertChainId, const char *szURL, DWORD dwCountRequestHeaderList, const char *pszRequestHeaderList[], DWORD dwTimeOut, DWORD *pdwSizeResponseHeaders, BYTE **ppbResponseHeaders, DWORD *pdwSizeResponseBody, BYTE **ppbResponseBody, DWORD dwParam)
int AAP_API DPIXPost(HSESSIONCTX hSession, const char *szKeyId, const char *szCertId, const char *szPIXCertChainId, const char *szURL, DWORD dwCountRequestHeaderList, const char *pszRequestHeaderList[], DWORD dwSizeRequestData, BYTE *pbRequestData, DWORD dwTimeOut, DWORD *pdwSizeResponseHeaders, BYTE **ppbResponseHeaders, DWORD *pdwSizeResponseBody, BYTE **ppbResponseBody, DWORD dwParam)
int AAP_API DPIXGet(HSESSIONCTX hSession, const char *szKeyId, const char *szCertId, const char *szPIXCertChainId, const char *szURL, DWORD dwCountRequestHeaderList, const char *pszRequestHeaderList[], DWORD dwTimeOut, DWORD *pdwSizeResponseHeaders, BYTE **ppbResponseHeaders, DWORD *pdwSizeResponseBody, BYTE **ppbResponseBody, DWORD dwParam)
int AAP_API DPIXPut(HSESSIONCTX hSession, const char *szKeyId, const char *szCertId, const char *szPIXCertChainId, const char *szURL, DWORD dwCountRequestHeaderList, const char *pszRequestHeaderList[], DWORD dwSizeRequestData, BYTE *pbRequestData, DWORD dwTimeOut, DWORD *pdwSizeResponseHeaders, BYTE **ppbResponseHeaders, DWORD *pdwSizeResponseBody, BYTE **ppbResponseBody, DWORD dwParam)
int AAP_API DOpenSession(HSESSIONCTX *phSession, DWORD dwParam, BYTE *pbData, DWORD dwDataLen, DWORD dwFlags)
int AAP_API DCloseSession(HSESSIONCTX *phSession, DWORD dwFlags)
int AAP_API DInitialize(DWORD dwReserved)
int AAP_API DFinalize()
Definição dinamo.h:3090
int nPort
Definição dinamo.h:3092
char szUserId[MAX_USR_LEN]
Definição dinamo.h:3093
char szAddr[MAX_ADDR_LEN]
Definição dinamo.h:3091
char szPassword[MAX_USR_PWD]
Definição dinamo.h:3094