From 8adbf52324fb2ffd24e07e6f9883cab7c0a87263 Mon Sep 17 00:00:00 2001 From: "CHIEFSOFT\\ameye" Date: Mon, 16 Sep 2024 16:49:17 -0400 Subject: [PATCH] promo data --- app/Controllers/BaseController.php | 47 ++++++++++++++++++++++++++++++ app/Controllers/Home.php | 8 +++-- app/Views/welcome_message.php | 10 +++++-- 3 files changed, 61 insertions(+), 4 deletions(-) diff --git a/app/Controllers/BaseController.php b/app/Controllers/BaseController.php index 8b435da..7c3213d 100644 --- a/app/Controllers/BaseController.php +++ b/app/Controllers/BaseController.php @@ -55,4 +55,51 @@ abstract class BaseController extends Controller // E.g.: $this->session = \Config\Services::session(); } + + public function APIcall($method, $url, $data) { + // $curl = curl_init(); + $curl = curl_init($url); + switch ($method) { + case "GET": + $params2 = ''; + foreach($data as $key2=>$value2) + $params2 .= $key2.'='.$value2.'&'; + + $params2 = trim($params2, '&'); + $url = $url.'?'.$params2;// add param to URL + log_message('critical', "API URL FINAL =>".$url ); + //curl_setopt($curl, CURLOPT_FRESH_CONNECT, true); + //curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); + //curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data)); + break; + case "POST": + curl_setopt($curl, CURLOPT_POST, 1); + if ($data) + // curl_setopt($curl, CURLOPT_POSTFIELDS, $data); + curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data)); + // curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data)); + break; + case "PUT": + curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "PUT"); + if ($data) + curl_setopt($curl, CURLOPT_POSTFIELDS, $data); + break; + } + + curl_setopt($curl, CURLOPT_URL, $url); + curl_setopt($curl, CURLOPT_HTTPHEADER, array( + 'APIKEY: RegisteredAPIkey', + 'Content-Type: application/json', + )); + + curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); + curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); + $result = curl_exec($curl); + + if(!$result) { + echo("Connection failure!"); + } + curl_close($curl); + return json_decode($result, true); + } } diff --git a/app/Controllers/Home.php b/app/Controllers/Home.php index 2e4aaf6..585db2f 100644 --- a/app/Controllers/Home.php +++ b/app/Controllers/Home.php @@ -12,9 +12,13 @@ class Home extends BaseController public function promoIndex($promo,$promoOwner=''):string{ // echo $promo; // echo $promoOwner; + //http://10.204.5.100:9083/en/promo/api/v1/start + + $in["promo"] = $promo; $in["promo_owner"] = $promoOwner; - - return view('welcome_message'); + $out = $this->APIcall('POST','http://10.204.5.100:9083/en/promo/api/v1/start',[]); +var_dump($out); + return view('welcome_message', $out); } } diff --git a/app/Views/welcome_message.php b/app/Views/welcome_message.php index 349e26f..1bc0f60 100644 --- a/app/Views/welcome_message.php +++ b/app/Views/welcome_message.php @@ -47,7 +47,7 @@ - {{site_trade_name}} + @@ -67,7 +67,13 @@ -    Welcome to {{site_name}}; please follow the link below to learn about our opportunities. +    + + + + + +