refactor the web services

This commit is contained in:
2025-03-08 14:48:03 +03:30
parent 03e2bcfdf9
commit 5f2cbf5f12
5 changed files with 99 additions and 48 deletions

View File

@@ -5,29 +5,42 @@ namespace App\Services;
use App\Models\RoadObserved;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Log;
use SoapClient;
use SoapFault;
class NikarayanService
{
/**
* @throws SoapFault
*/
public function updateRoadObservedInfoByNikarayan(Request $request, RoadObserved $roadObserved, $files)
{
if (App::isProduction())
{
$url = "https://riws.rmto.ir/WebServices/NRPTrafficStatus.asmx?wsdl";
try {
$url = "https://riws.rmto.ir/WebServices/NRPTrafficStatus.asmx?wsdl";
$array = array('strUserName' => 'vaytelrop',
'strPassword' => 'VaYtelROP*2024',
'strAutoID' => $roadObserved->fk_RegisteredEventMessage,
'strStateID' => ($request->input('rms-status') == 1) ? '2' : '3',
'strDescription' => $request->input('rms-description') ?? $roadObserved->rms_description,
'strPreviousImageLink' => "https://rms.rmto.ir/".$files,
'strNextImageLink' => "https://rms.rmto.ir/".$files,
'strRMSDateAndTime' => $roadObserved->updated_at
);
$array = array('strUserName' => 'vaytelrop',
'strPassword' => 'VaYtelROP*2024',
'strAutoID' => $roadObserved->fk_RegisteredEventMessage,
'strStateID' => ($request->input('rms-status') == 1) ? '2' : '3',
'strDescription' => $request->input('rms-description') ?? $roadObserved->rms_description,
'strPreviousImageLink' => "https://rms.rmto.ir/".$files,
'strNextImageLink' => "https://rms.rmto.ir/".$files,
'strRMSDateAndTime' => $roadObserved->updated_at
);
$soapClient = new SoapClient($url);
$soapClient = new SoapClient($url);
$result = $soapClient->UpdateInfo_RoadObservedProblems($array);
Log::channel('nikarayan')->info($result);
return $soapClient->UpdateInfo_RoadObservedProblems($array);
return $result;
}
catch (\Exception $e) {
Log::channel('nikarayan')->error($e->getMessage());
throw $e;
}
}
return 0;

View File

@@ -2,62 +2,82 @@
namespace App\Services;
use Exception;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Log;
class NominatimService
{
/**
* @throws Exception
*/
public function get_way_id_from_nominatim($lat = null, $lng = null)
{
if (App::isProduction())
{
$url = "https://testmap.141.ir/nominatim/reverse?format=jsonv2&lat=".$lat."&lon=".$lng."&zoom=16&addressdetails=16";
$arrContextOptions=array(
"ssl"=>array(
"verify_peer"=>false,
"verify_peer_name"=>false,
),
);
try {
$url = "https://testmap.141.ir/nominatim/reverse?format=jsonv2&lat=".$lat."&lon=".$lng."&zoom=16&addressdetails=16";
$arrContextOptions=array(
"ssl"=>array(
"verify_peer"=>false,
"verify_peer_name"=>false,
),
);
$result = file_get_contents($url, false, stream_context_create($arrContextOptions));
$result = json_decode($result);
if (isset($result->osm_type)) {
if ($result->osm_type == 'way') {
return $result->osm_id;
$result = file_get_contents($url, false, stream_context_create($arrContextOptions));
$result = json_decode($result);
if (isset($result->osm_type)) {
if ($result->osm_type == 'way') {
return $result->osm_id;
}
}
return 0;
}
catch (Exception $e) {
Log::channel('nominatim')->error($e->getMessage());
throw $e;
}
return 0;
}
return 0;
}
/**
* @throws Exception
*/
function getIDFromNominatim($s_lng, $s_lat, $d_lng, $d_lat)
{
if (App::isProduction())
{
$url = "https://testmap.141.ir/route/v1/driving/" . $s_lng . "," . $s_lat . ";" . $d_lng . "," . $d_lat . "?overview=full&alternatives=true&steps=true";
$arrContextOptions = array(
"ssl" => array(
"verify_peer" => false,
"verify_peer_name" => false,
),
);
$result = file_get_contents($url, false, stream_context_create($arrContextOptions));
$result = json_decode($result);
if (count($result->routes) > 1 && $result->routes[1]->distance < $result->routes[0]->distance) {
// if(){
$ways = $result->routes[1]->legs[0]->steps;
// }
} else
$ways = $result->routes[0]->legs[0]->steps;
$ids = array();
foreach ($ways as $key => $value) {
if (!in_array($value->name, $ids)) {
$ids[] = $value->name;
try {
$url = "https://testmap.141.ir/route/v1/driving/" . $s_lng . "," . $s_lat . ";" . $d_lng . "," . $d_lat . "?overview=full&alternatives=true&steps=true";
$arrContextOptions = array(
"ssl" => array(
"verify_peer" => false,
"verify_peer_name" => false,
),
);
$result = file_get_contents($url, false, stream_context_create($arrContextOptions));
$result = json_decode($result);
if (count($result->routes) > 1 && $result->routes[1]->distance < $result->routes[0]->distance) {
// if(){
$ways = $result->routes[1]->legs[0]->steps;
// }
} else
$ways = $result->routes[0]->legs[0]->steps;
$ids = array();
foreach ($ways as $key => $value) {
if (!in_array($value->name, $ids)) {
$ids[] = $value->name;
}
}
}
return $ids;
return $ids;
}
catch (Exception $e) {
Log::channel('nominatim')->error($e->getMessage());
throw $e;
}
}
return [1, 2, 3];