-
Notifications
You must be signed in to change notification settings - Fork 0
/
calculaVF.php
68 lines (50 loc) · 1.92 KB
/
calculaVF.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
require 'include/headers_api_php.php';
require 'include/std_messages_api_php.php';
# Get JSON as a string
$json_str = file_get_contents('php://input');
# Get as an object
$json_obj = json_decode($json_str, true);
if(count($json_obj) < 2) {
$json_output = $JSONStandard[3];
} else {
if(!isset($json_obj["authKey"]) || !isset($json_obj["param"])) {
//Bad request
$json_output = $JSONStandard[3];
} else {
if(isset($json_obj["authKey"])) {
//Verifica a permissao de uso
//Como eh publica, todos podem usar
if(true) {
//Executa o codigo da API
//Parametros esperados
//VP = valor presente
//n = numero de periodos
//i = taxa de juros
if(count($json_obj["param"]) != 3) {
//Bad request
$json_output = str_replace('__RESULT__', '"Parametros invalidos. Utilizar: Valor Presente, Tx. Juros, Periodos"', $JSONStandard[4]);
} else {
$vp = $json_obj["param"][0];
$i = $json_obj["param"][1];
$n = $json_obj["param"][2];
$strResult = ($vp)*pow((1+($i/100)),$n);
$json_output = str_replace('__RESULT__', $strResult, $JSONStandard[0]);
unset($strResult, $vp, $i, $n);
}
} else {
//Forbidden
$json_output = $JSONStandard[2];
}
} else {
//Forbidden
$json_output = $JSONStandard[2];
}
}
}
if(isset($JSONStandard)){ unset($JSONStandard);}
if(isset($json_str)){ unset($json_str);}
if(isset($json_obj)){ unset($json_obj);}
if(isset($result)){ unset($result);}
echo $json_output;
?>