Get Notification Data
When sending notifications with ReturnMode as RESUME, the response will be a RequestID that you can use to get the notification data.
This service will return information about the number of notifications sent, processed and processing.
POST variables
- HASH: Hash of the company where the template is registered
- ANNAEXEC: The generated IV, which will be used to encrypt the values of other variables
- SentId: The generated ID when sending notifications in ReturnMode = RESUME
Examples
public static string Execute_WebService()
{
string DecKey = "DECRYPTION_KEY";
string EncKey = "ENCRYPTION_KEY";
string Hash = "COMPANY_HASH";
// Generate new IV
TripleDESCryptoServiceProvider auxTdes = new TripleDESCryptoServiceProvider();
auxTdes.GenerateIV();
byte[] IVArray = auxTdes.IV;
string IV = Convert.ToBase64String(IVArray);
string sentId = "NOTIFICATION_ID";
string sentIdEncriptado = Encrypt3DES(sentId, EncKey, IV);
string dadosPost = "HASH=" + Uri.EscapeDataString(Hash);
dadosPost += "&ANNAEXEC=" + Uri.EscapeDataString(IV);
dadosPost += "&sentId=" + Uri.EscapeDataString(sentIdEncriptado);
byte[] dados = Encoding.UTF8.GetBytes(dadosPost);
string url = "https://YOUR_ANNA_URL/aannagetnotificationdata.aspx";
WebRequest requisicaoWeb = WebRequest.Create(url);
requisicaoWeb.Method = "POST";
requisicaoWeb.ContentType = "application/x-www-form-urlencoded";
requisicaoWeb.ContentLength = dados.Length;
Stream dataStream = requisicaoWeb.GetRequestStream();
dataStream.Write(dados, 0, dados.Length);
dataStream.Close();
WebResponse response = requisicaoWeb.GetResponse();
using (dataStream = response.GetResponseStream())
{
StreamReader reader = new StreamReader(dataStream);
string responseFromServer = reader.ReadToEnd();
if (responseFromServer.Contains(IV))
{
string novoIVEncriptado = responseFromServer.Substring(responseFromServer.IndexOf(IV));
novoIVEncriptado = novoIVEncriptado.Replace(IV, "");
string retornoEncriptado = responseFromServer.Substring(0, responseFromServer.IndexOf(IV));
string novoIV = Decrypt3DES(novoIVEncriptado, EncKey, IV);
string retorno = Decrypt3DES(retornoEncriptado, DecKey, novoIV);
response.Close();
return retorno;
}
else
{
response.Close();
return responseFromServer;
}
}
}
try {
String DecKey = "DECRYPTION_KEY";
String EncKey = "ENCRYPTION_KEY";
String Hash = "COMPANY_HASH";
// Generate new IV
byte[] randomBytes = new byte[8];
new Random().nextBytes(randomBytes);
final IvParameterSpec IV = new IvParameterSpec(randomBytes);
String IVString = new String(Base64.getEncoder().encode(randomBytes));
byte[] decKeyDecoded = Base64.getDecoder().decode(DecKey);
byte[] encKeyDecoded = Base64.getDecoder().decode(EncKey);
SecretKey dKey = new SecretKeySpec(decKeyDecoded, "DESede");
SecretKey eKey = new SecretKeySpec(encKeyDecoded, "DESede");
String sentId = "NOTIFICATION_SENT_ID";
String sentIdEncriptado = encrypt(sentId, eKey, IV);
String dadosPost = "HASH=" + URLEncoder.encode(Hash, StandardCharsets.UTF_8);
dadosPost += "&ANNAEXEC=" + URLEncoder.encode(IVString, StandardCharsets.UTF_8);
dadosPost += "&sentId=" + URLEncoder.encode(sentIdEncriptado, StandardCharsets.UTF_8);
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://itda.com.br/AnnA20/aannagetnotificationdata.aspx")) //Caminho onde o AnnA está localizado
.header("Content-Type", "application/x-www-form-urlencoded")
.POST(BodyPublishers.ofString(dadosPost))
.build();
HttpResponse<String> response = client.send(request, BodyHandlers.ofString());
String responseFromServer = response.body();
if (responseFromServer.contains(IVString))
{
String novoIVEncriptado = responseFromServer.substring(responseFromServer.indexOf(IVString));
novoIVEncriptado = novoIVEncriptado.replace(IVString, "");
String retornoEncriptado = responseFromServer.substring(0, responseFromServer.indexOf(IVString));
String novoIVString = decrypt(novoIVEncriptado, eKey, IV);
byte[] ivDecoded = Base64.getDecoder().decode(novoIVString);
IvParameterSpec novoIV = new IvParameterSpec(ivDecoded);
String retorno = decrypt(retornoEncriptado, dKey, novoIV);
return retorno;
}
else
{
return responseFromServer;
}
} catch (NoSuchAlgorithmException | NoSuchPaddingException | InvalidKeyException | InvalidAlgorithmParameterException | IllegalBlockSizeException | BadPaddingException | InterruptedException | IOException ex) {
Logger.getLogger(AnnaTemplateNotification.class.getName()).log(Level.SEVERE, null, ex);
return "Erro";
}
$DecKey = "DECRYPTION_KEY";
$EncKey = "ENCRYPTION_KEY";
$Hash = "COMPANY_HASH";
// Generate new IV
$ivlen = openssl_cipher_iv_length('des-ede3-cbc');
$IV = base64_encode(openssl_random_pseudo_bytes(8));
$sentId = "NOTIFICATION_SENT_ID";
$sentIdEncriptado = encrypt3DES($sentId, $EncKey, $IV);
$dadosPost = array(
'HASH' => $Hash,
'ANNAEXEC' => $IV,
'SentId' => $sentIdEncriptado
);
$url = "https://YOUR_ANNA_URL/aannagetnotificationdata.aspx";
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($dadosPost)
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
if (str_contains($result, $IV)) {
$novoIVEncriptado = substr($result, strpos($result, $IV));
$novoIVEncriptado = str_replace($IV, "", $novoIVEncriptado);
$retornoEncriptado = substr($result, 0, strrpos($result, $IV));
$novoIV = decrypt3DES($novoIVEncriptado, $EncKey, $IV);
$retorno = decrypt3DES($retornoEncriptado, $DecKey, $novoIV);
echo $retorno;
} else {
echo $result;
}
&DecKey = !'DECRYPTION_KEY'
&EncKey = !'ENCRYPTION_KEY'
&Hash = !'COMPANY_HASH'
// Generate new IV
&CryptoEncrypt = new()
&CryptoEncrypt.Algorithm = CryptoEncryptAlgorithm.TripleDES
&Result = &CryptoEncrypt.Encrypt(!'DUMMY')
&IV = &CryptoEncrypt.IV
&CryptoEncrypt.Key = &EncKey
&CryptoEncrypt.IV = &IV
&SentId = !'1'
&SentIdEncriptado = &CryptoEncrypt.Encrypt(&SentId)
&HttpClient.AddVariable(!'HASH', &Hash)
&HttpClient.AddVariable(!'ANNAEXEC', &IV)
&HttpClient.AddVariable(!'SentId', &SentIdEncriptado)
&Url = !'https://YOUR_ANNA_URL/aannagetnotificationdata.aspx'
&HttpClient.AddHeader(!'ContentType', !'application/x-www-form-urlencoded')
&HttpClient.Execute(!'POST', &Url)
&Result = &HttpClient.ToString()
If &Result.Contains(&IV)
&NovoIVEncriptado = &Result.Substring(&Result.IndexOf(&IV))
&NovoIVEncriptado = &NovoIVEncriptado.Replace(&IV, !'')
&RetornoEncriptado = &Result.Substring(1, &Result.IndexOf(&IV) - 1)
&CryptoEncrypt.Key = &EncKey
&CryptoEncrypt.IV = &IV
&NovoIV = &CryptoEncrypt.Decrypt(&NovoIVEncriptado)
&CryptoEncrypt.Key = &DecKey
&CryptoEncrypt.IV = &NovoIV
&Retorno = &CryptoEncrypt.Decrypt(&RetornoEncriptado)
Msg(&Retorno)
Else
Msg(&Result)
Endif
import requests
import json
from Crypto.Cipher import AES, DES3, DES
from Crypto.Util.Padding import pad, unpad
from Crypto.Random import get_random_bytes
from base64 import b64encode, b64decode
# Encryption method
def encrypt(data, enckey, iv):
enckey = b64decode(enckey)
iv = b64decode(iv)
cipher = DES3.new(enckey, DES3.MODE_CBC, iv)
ct_bytes = cipher.encrypt(
pad(bytes(data, encoding='utf-8'), DES3.block_size))
ciphertext = b64encode(ct_bytes).decode('utf-8')
return ciphertext
# Decryption method
def decrypt(data, deckey, iv):
try:
deckey = b64decode(deckey)
iv = b64decode(iv)
data = b64decode(data)
cipher = DES3.new(deckey, DES3.MODE_CBC, iv)
pt = unpad(cipher.decrypt(data), DES3.block_size)
return pt.decode('utf-8')
except (ValueError, KeyError):
return 'Incorrect decryption'
# Creating an IV
key = get_random_bytes(8)
cipher = DES.new(key, DES3.MODE_CBC)
iv = b64encode(cipher.iv).decode('utf-8')
# Integration variables
hash = 'COMPANY_HASH'
enckey = 'ENCRYPTION_KEY'
deckey = 'DECRYPTION_KEY'
url = 'https://YOUR_ANNA_URL/aannagetnotificationdata.aspx'
requestId = 'NOTIFICATION_ID'
# Encrypting data
requestIdEncrypted = encrypt(requestId, enckey, iv)
# Creating the submission structure
request = {
'HASH': hash,
'ANNAEXEC': iv,
'SentId': requestIdEncrypted
}
# Making a post for AnnA
response = requests.post(url, request)
# Retrieving AnnA's response
response = response.text
# Separating the received IV from the AnnA response string
responseEncypted = response.split(iv)
# Decrypting the new IV
newIV = decrypt(responseEncypted[1], enckey, iv)
# Decrypting the content of the reply
responseDecrypt = decrypt(responseEncypted[0], deckey, newIV)
# Log
print('RequestId:', requestId)
print('Retorno:\n', responseDecrypt)