<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use App\Repository\ModelRepository;
use App\Repository\PriceRepository;
use App\Service\PdfService;
use App\Entity\Payment;
use App\Entity\Client;
class NavigationController extends AbstractController
{
#[Route(path: '/', name: 'index')]
public function index(): Response
{
return $this->render('index.html.twig' );
}
#[Route(path: '/user', name: 'user_page')]
public function userPage( ModelRepository $modelRepository, PriceRepository $priceRepository): Response
{
$models = $modelRepository->findAll();
$price = $priceRepository->findActive();
return $this->render('client/userPage.html.twig' , ["models" => $models, "price" => $price]);
}
#[Route(path: '/readPaymentPdf/{id}', name: 'read_payment_pdf')]
public function readPaymentPdf( PdfService $pdfService , Payment $payment): Response
{
if( ( $this->getUser() != $payment->getClient()->getUser() ) && !$this->isGranted('ROLE_ADMIN') ){
return new Response('', 403);
}
$html = $this->render('pdf/paymentInvoice.html.twig', ['payment' => $payment]);
$pdfService->streamPdf($html);
return new Response('', 200, [
'Content-Type' => 'application/pdf',
]);
}
#[Route(path: '/binanceApi', name: 'binanceApi')]
public function binanceApi(): Response
{
//$connexion = new \PDO("mysql:host=chrisjz9.mysql.db/chrisjz9;dbname=chrisjz9;port=3306", "chrisjz9", "Roinfo91");
$connexion = new \PDO("mysql:host=127.0.0.1;dbname=mmi;port=3306", "root", "");
$requete = "SELECT * FROM CLIENT";
$resultats = $connexion->query($requete);
foreach ($resultats->fetchAll() as $client) {
var_dump( $client['name'] );
}
$url = "https://whattomine.com/coins/162.json?hr=70&p=0.0&fee=0.0&cost=0.1&cost_currency=USD&hcost=0.0&span_br=&span_d=24";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json', 'Content-Type: application/json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
$data = json_decode($response, true);
if($data == null){
return new Response("no response");
}
return new Response( floatval( substr($data['profit'], 1) ) );
}
#[Route(path: '/testApi', name: 'testApi')]
public function testApi(): Response
{
/*
$today = new \DateTime();
$text = "";
$key = "jvIkawn4EeidllU2F14lWz1NJMQJ84CqwFwF5r8eQBrx2EVe3jVoogAfJg84iv81";
$secret = "rdveQW1Vd06Q2LTGL18cluentqNTQkvV0iOAGBajHLrEaalRbDzuMZrphK45okvN";
$ch = curl_init();
$url = "https://api.binance.com/api/v3/depth";
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-MBX-APIKEY:'.$key));
$querystring = "symbol=ETH";
$signature = hash_hmac('SHA256',$querystring ,$secret);
$post = [
'symbol' => 'ETH',
'signature' => $signature,
];
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
$result = curl_exec($ch);
curl_close ($ch);
var_dump($result);
*/
$url = "https://api.binance.com/api/v3/depth?symbol=BNBBTC";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json', 'Content-Type: application/json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
var_dump($response);
return new Response("-----------");
}
}