Skip to content

Commit

Permalink
fix: json validation
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyber-Root0 committed Jan 17, 2024
1 parent d4685bd commit 5c41029
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 36 deletions.
45 changes: 15 additions & 30 deletions app/classes/FixJson.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
<?php
namespace app\classes;
use JsonMachine\Items;
use JsonMachine\JsonDecoder\DecodingError;
use JsonMachine\JsonDecoder\ErrorWrappingDecoder;
use JsonMachine\JsonDecoder\ExtJsonDecoder;
/*
* @software API for the Siga Student System | Fatec
* @author Bruno Venancio Alves <boteistem@gmail.com>
Expand All @@ -9,37 +13,18 @@

class FixJson{

public static function fix($string){
public static function fix($json){


$curl = curl_init();

curl_setopt_array($curl, [
CURLOPT_URL => "https://jsonformatter.curiousconcept.com/process?=",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_FOLLOWLOCATION => false,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => http_build_query(array(
"jsonfix" => "on",
"jsontemplate" => "1",
"data" => $string,

)),
CURLOPT_HTTPHEADER => [
"Content-Type: application/x-www-form-urlencoded"
],
]);

$response = curl_exec($curl);
//echo $response;
$data = json_decode($response);
return $data->result->data;
$data = [];
$items = Items::fromString($json, ['decoder' => new ErrorWrappingDecoder(new ExtJsonDecoder())]);
foreach ($items as $key => $item) {
if ($key instanceof DecodingError || $item instanceof DecodingError) {
// handle error of this malformed json item
continue;
}
$data[$key] = $item;
}
return json_encode($data);

}
}
6 changes: 3 additions & 3 deletions app/controller/faltas/faltas.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public function __construct(){
$this->crawler = new Crawler;
parent::__construct();
}

public function get(){


Expand All @@ -43,8 +42,9 @@ public function get(){
$XML_HTML = $this->getContent($this->cookie->getCookie());
$this->crawler->addHtmlContent($XML_HTML);
$faltas = $this->crawler->filter('input[name="GXState"]')->attr('value');

$json = $this->fixJson($faltas);

$json = FixJson::fix($faltas);

$output = $this->trataJson(json_decode($json));
$this->response($output);
}else{
Expand Down
1 change: 0 additions & 1 deletion app/sessions/0169519f2519d15512392b5aaba489/browser.json

This file was deleted.

1 change: 0 additions & 1 deletion app/sessions/0169519f2519d15512392b5aaba489/user.json

This file was deleted.

1 change: 1 addition & 0 deletions app/sessions/4b8a0682832e2fb853d0457e465d40/browser.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
["ASP.NET_SessionId","hnmfhc3g2feihcetm1uotj45"]
1 change: 1 addition & 0 deletions app/sessions/4b8a0682832e2fb853d0457e465d40/user.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
KZyWVSOoTmxNBtpeNUI2J08/6iDdqT1SZCQyt0zcnRgCCPcE2erfg9Hykcs56ZKo
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"require": {
"guzzlehttp/guzzle": "*",
"symfony/dom-crawler": "^6.0",
"symfony/css-selector": "^6.0"
"symfony/css-selector": "^6.0",
"halaxa/json-machine": "^1.1"
}
}

0 comments on commit 5c41029

Please sign in to comment.