/
home
/
henzagold
/
server
/
app
/
Models
/
File Upload :
llllll
Current File: //home/henzagold/server/app/Models/WebServiceGold.php
<?php namespace App\Models; use http\Exception; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Http\JsonResponse; use Illuminate\Support\Facades\Http; use Illuminate\Support\Facades\Log; use Morilog\Jalali\Jalalian; class WebServiceGold extends Model { use HasFactory; public static function getPriceGold18Ayar() { $data=ConfigStatic::where('key','gold_price')->first(); $data=json_decode($data->val,true); $price=$data["geram18"]["p"]; $price=str_replace(',','',$price); $price=intval($price); return $price/10; } public static function getAllPrice(){ $data=ConfigStatic::where('key','gold_price')->first(); $data=json_decode($data->val,true); return $data; } public static function getAllPriceFromWebService(){ //old method /*try { //$response = Http::get('https://api.tgju.online/v1/widget'); $response = Http::get('https://api.accessban.com/v1/widget'); $body=$response->body(); $start=strpos($body,'tgju_data'); $end=strpos($body,';'); $filter=substr($body,$start+12,$end-16); $data=json_decode($filter,true); return $data; }catch (Exception $e) { return 0; }*/ //method 2 //$token='eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczpcL1wvZ2F0ZXdheS5hY2Nlc3NiYW4uY29tXC9wdWJsaWMiLCJzdWIiOiJjZjUxYWNiMi1hOTUzLTVmN2EtOTc3NS01NWFhMDU3NTYzODciLCJpYXQiOjE2MjM4NTgwOTEsImV4cCI6MTc4MTYyNDQ5MSwibmFtZSI6Ilx1MDYyN1x1MDY0NVx1MDZjY1x1MDYzMSBcdTA2NDVcdTA2MmRcdTA2NDVcdTA2MmYgXHUwNjJkXHUwNjI3XHUwNjJjXHUwNmNjIFx1MDYyN1x1MDYyOFx1MDY0OFx1MDYyN1x1MDY0NFx1MDY0MVx1MDYyYVx1MDYyZC0xMTE0NiJ9.a3p-bmbW6evlvnl7vueHeXxnuAMyb-ElpzE9tsGxS7c'; // $token='eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiJodHRwczpcL1wvZ2F0ZXdheS5hY2Nlc3NiYW4uY29tXC9wdWJsaWMiLCJzdWIiOiJjZjUxYWNiMi1hOTUzLTVmN2EtOTc3NS01NWFhMDU3NTYzODciLCJpYXQiOjE2MzIwMjc3ODUsImV4cCI6MTc4OTc5NDE4NSwibmFtZSI6Ilx1MDYyN1x1MDY0NVx1MDZjY1x1MDYzMSBcdTA2NDVcdTA2MmRcdTA2NDVcdTA2MmYgXHUwNjJkXHUwNjI3XHUwNjJjXHUwNmNjIFx1MDYyN1x1MDYyOFx1MDY0OFx1MDYyN1x1MDY0NFx1MDY0MVx1MDYyYVx1MDYyZC0xMTE0NiJ9.c8aTAf7kewR0J_N8q8WCcXBgagLFb1PRYOWqZVBAH9A'; // //timeout(3)-> // $response = Http::withHeaders([ // 'Accept' => 'application/json', // 'Authorization' => 'Bearer '.$token, // ])->get('http://gateway.accessban.com/public/web-service/list/common?format=json&limit=30&page=1'); // $body=$response->json(); // if($response->status()==401) // { // Log::info('Web service Gold is Expired'); // return; // } // //Log::info('this is body'); // //Log::info($body); // if($body==null || ($body!=null && !isset($body['data']))) // { // //Log::info('Web service Gold body is null'); // return ; // } // /* conver data Format */ // $body=$body['data']; // $temp=[]; // foreach ($body as $value) { // $temp[$value['slug']]= $value; // $temp[$value['slug']]['uaj']=Utility::convertDate($temp[$value['slug']]['updated_at']); // } //save data to data base // $service = Http::get('https://api.ratebox.ir/apijson.php?token=41e58ccc0d6faa6adbd1e5122d38c3b6') $service = Http::get('https://api.ratebox.ir/apijson.php?token='.env('WEBSERVICE_TOKEN')) ->json(); $b1 =$b2=$b3=false; if(!is_null($service)){ if (isset($service["4"])){ $array['mesghal'] = $service["4"]; $array['mesghal']['slug'] = 'mesghal'; $array['mesghal']['uaj'] = Jalalian::forge($array['mesghal']['updated_at'])->format('Y/m/d - h:i'); $b1 = true; } if (isset($service["5"])){ $array['geram18'] = $service["5"]; $array['geram18']['slug'] = "geram18"; $array['geram18']['uaj'] = Jalalian::forge($array['geram18']['updated_at'])->format('Y/m/d - h:i'); $b2 = true; } if (isset($service["6"])){ $array['geram24'] = $service["6"]; $array['geram24']['slug'] = "geram24"; $array['geram24']['uaj'] = Jalalian::forge($array['geram24']['updated_at'])->format('Y/m/d - h:i'); $b3 = true; } if ($b1 && $b2 && $b3){ $price=ConfigStatic::where('key','gold_price'); $price->update(['val' => $array]); } } return $array; } }
Copyright ©2k19 -
Hexid
|
Tex7ure