Esta documentação descreve como acessar e autenticar a API de Integração Rein Sistemas de forma segura.
<?php
function getToken($secretKey, $endpoint, $database, $timestamp) {
$dataToSign = "$endpoint.$database.$timestamp";
$signature = hash_hmac('sha256', $dataToSign, $secretKey);
return $signature;
}
$endpoint = "/api/v1/produto";
$apiUrl = "https://api.rein.net.br$endpoint";
$secretKey = 'secret_key';
$clientId = '0000-0000-0000-0000';
$expireAt = 300;
$timestamp = time() + $expireAt;
$database = 'test';
$token = getToken($secretKey, $endpoint, $database, $timestamp);
$headers = [
'Token: ' . $token,
'Database: ' . $database,
'Timestamp: ' . $timestamp,
'ClientId: ' . $clientId,
];
$ch = curl_init($apiUrl);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
echo($response);
?>
const crypto = require('crypto');
const https = require('https');
const secretKey = 'secret_key';
const clientId = '0000-0000-0000-0000';
const database = 'test';
const endpoint = '/api/v1/produto';
const expireAt = 300;
const timestamp = Math.floor(Date.now() / 1000) + expireAt;
const dataToSign = `${endpoint}.${database}.${timestamp}`;
const token = crypto.createHmac('sha256', secretKey)
.update(dataToSign)
.digest('hex');
const options = {
hostname: 'api.rein.net.br',
path: endpoint,
method: 'GET',
headers: {
'Token': token,
'Database': database,
'Timestamp': timestamp,
'ClientId': clientId
}
};
const req = https.request(options, res => {
let data = '';
res.on('data', chunk => data += chunk);
res.on('end', () => console.log(data));
});
req.on('error', error => console.error(error));
req.end();
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Base64;
import java.util.Scanner;
public class TokenExample {
public static void main(String[] args) throws Exception {
String secretKey = "secret_key";
String clientId = "0000-0000-0000-0000";
String database = "test";
String endpoint = "/api/v1/produto";
long expireAt = 300;
long timestamp = System.currentTimeMillis() / 1000 + expireAt;
String dataToSign = endpoint + "." + database + "." + timestamp;
Mac hmacSha256 = Mac.getInstance("HmacSHA256");
SecretKeySpec keySpec = new SecretKeySpec(secretKey.getBytes(), "HmacSHA256");
hmacSha256.init(keySpec);
byte[] hash = hmacSha256.doFinal(dataToSign.getBytes());
String token = bytesToHex(hash);
URL url = new URL("https://api.rein.net.br" + endpoint);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Token", token);
conn.setRequestProperty("Database", database);
conn.setRequestProperty("Timestamp", String.valueOf(timestamp));
conn.setRequestProperty("ClientId", clientId);
Scanner scanner = new Scanner(conn.getInputStream());
while (scanner.hasNext()) {
System.out.println(scanner.nextLine());
}
scanner.close();
}
private static String bytesToHex(byte[] bytes) {
StringBuilder hex = new StringBuilder();
for (byte b : bytes)
hex.append(String.format("%02x", b));
return hex.toString();
}
}
Em caso de dúvidas ou problemas com a integração, entre em contato com o time técnico da Rein através de:
📧 https://ajuda.reinsistemas.com.br/contato
📞 (41) 3077-5497