From 93384d39ee9ca663b6a2184e5117c55154ea7813 Mon Sep 17 00:00:00 2001 From: faezehzafarbakhsh Date: Sat, 1 Nov 2025 15:39:42 +0330 Subject: [PATCH 1/3] write find code for harim --- .../V3/Dashboard/Harim/PanjareVahedController.php | 12 +++++++++--- .../Harim/PanjareVahed/ReceiveNewRequest.php | 6 ++++-- config/harim_web_services.php | 5 +++++ 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/app/Http/Controllers/V3/Dashboard/Harim/PanjareVahedController.php b/app/Http/Controllers/V3/Dashboard/Harim/PanjareVahedController.php index dbbb9128..9d5c065d 100644 --- a/app/Http/Controllers/V3/Dashboard/Harim/PanjareVahedController.php +++ b/app/Http/Controllers/V3/Dashboard/Harim/PanjareVahedController.php @@ -21,6 +21,13 @@ class PanjareVahedController extends Controller public function receiveNewRequest(ReceiveNewRequest $request): JsonResponse { + $iv = config('harim_web_services.Get_Info.iv'); + $keyString = config('harim_web_services.Get_Info.keyString'); + + $key = hash('sha256',$keyString, true); + + $decrypted = openssl_decrypt($request->data, 'aes-256-cbc', $key, false, $iv); + $wkt = 'POLYGON(('.implode(',', array_map(fn ($c) => "{$c[0]} {$c[1]}", $request->primary_area['coordinates'])).'))'; $result = DB::selectOne('SELECT ST_AsText(ST_PointOnSurface(ST_GeomFromText(?, 4326))) AS point', [$wkt]); preg_match('/POINT\(([^ ]+) ([^ ]+)\)/', $result->point, $matches); @@ -62,12 +69,11 @@ class PanjareVahedController extends Controller 'response_options' => json_encode($request->response_options), 'isic' => $request->isic, 'primary_area' => json_encode($request->primary_area), - 'data' => $request->data['data'], - 'token' => $request->data['token'], + 'data' => $decrypted, + 'token' => $decrypted->token, ]); return response()->json([ - 'request_id' => $request->request_id, 'id' => $harim->id, 'city' => $city->edarateShahri()->first()->name_fa, 'province' => $city->province()->first()->name_fa, diff --git a/app/Http/Requests/V3/Dashboard/Harim/PanjareVahed/ReceiveNewRequest.php b/app/Http/Requests/V3/Dashboard/Harim/PanjareVahed/ReceiveNewRequest.php index d5bc528d..3ddf8d7e 100644 --- a/app/Http/Requests/V3/Dashboard/Harim/PanjareVahed/ReceiveNewRequest.php +++ b/app/Http/Requests/V3/Dashboard/Harim/PanjareVahed/ReceiveNewRequest.php @@ -33,12 +33,14 @@ class ReceiveNewRequest extends FormRequest 'plan_group' => 'required', 'plan_title' => 'required', 'worksheet' => 'required', - 'response_options' => 'required', + 'response_options' => 'required|array', + 'response_options.*.id' => 'required|integer', + 'response_options.*.value' => 'required|string', 'isic' => 'required', 'primary_area' => 'required|array', 'primary_area.type' => 'required|string', 'primary_area.coordinates' => 'required|array', - 'data' => 'required|array', + 'data' => 'required|string', ]; } diff --git a/config/harim_web_services.php b/config/harim_web_services.php index 7104519c..3c8268c6 100644 --- a/config/harim_web_services.php +++ b/config/harim_web_services.php @@ -30,4 +30,9 @@ return [ 'password' => env('HARIM_NEED_GUARANTEE_LETTER_PASSWORD'), 'username' => env('HARIM_NEED_GUARANTEE_LETTER_USERNAME'), ], + + 'Get_Info' => [ + 'key' => env('HARIM_ENCRYPTION_KEY'), + 'iv' => env('HARIM_ENCRYPTION_IV'), + ], ]; From d9d5f39261166aa937a92df93cd4dd6b0598ed7b Mon Sep 17 00:00:00 2001 From: faezehzafarbakhsh Date: Sun, 2 Nov 2025 13:57:26 +0330 Subject: [PATCH 2/3] fix last code for this part --- .../Harim/PanjareVahedController.php | 14 ++++++++----- .../Harim/PanjareVahed/ReceiveNewRequest.php | 20 ++++++++++++++----- config/harim_web_services.php | 2 +- 3 files changed, 25 insertions(+), 11 deletions(-) diff --git a/app/Http/Controllers/V3/Dashboard/Harim/PanjareVahedController.php b/app/Http/Controllers/V3/Dashboard/Harim/PanjareVahedController.php index 9d5c065d..b38127b0 100644 --- a/app/Http/Controllers/V3/Dashboard/Harim/PanjareVahedController.php +++ b/app/Http/Controllers/V3/Dashboard/Harim/PanjareVahedController.php @@ -21,12 +21,16 @@ class PanjareVahedController extends Controller public function receiveNewRequest(ReceiveNewRequest $request): JsonResponse { - $iv = config('harim_web_services.Get_Info.iv'); - $keyString = config('harim_web_services.Get_Info.keyString'); + $iv = config('harim_web_services.Harim_Info.iv'); + $keyString = config('harim_web_services.Harim_Info.keyString'); $key = hash('sha256',$keyString, true); - $decrypted = openssl_decrypt($request->data, 'aes-256-cbc', $key, false, $iv); + $decrypted = openssl_decrypt($request->data,'aes-256-cbc',$key,false, $iv); + + $decodedString = json_decode($decrypted); + $decodedArray = json_decode($decodedString, true); + $wkt = 'POLYGON(('.implode(',', array_map(fn ($c) => "{$c[0]} {$c[1]}", $request->primary_area['coordinates'])).'))'; $result = DB::selectOne('SELECT ST_AsText(ST_PointOnSurface(ST_GeomFromText(?, 4326))) AS point', [$wkt]); @@ -69,8 +73,8 @@ class PanjareVahedController extends Controller 'response_options' => json_encode($request->response_options), 'isic' => $request->isic, 'primary_area' => json_encode($request->primary_area), - 'data' => $decrypted, - 'token' => $decrypted->token, + 'data' => $decodedString, + 'token' => $decodedArray['token'], ]); return response()->json([ diff --git a/app/Http/Requests/V3/Dashboard/Harim/PanjareVahed/ReceiveNewRequest.php b/app/Http/Requests/V3/Dashboard/Harim/PanjareVahed/ReceiveNewRequest.php index 3ddf8d7e..48871f1e 100644 --- a/app/Http/Requests/V3/Dashboard/Harim/PanjareVahed/ReceiveNewRequest.php +++ b/app/Http/Requests/V3/Dashboard/Harim/PanjareVahed/ReceiveNewRequest.php @@ -46,11 +46,21 @@ class ReceiveNewRequest extends FormRequest protected function failedValidation(Validator $validator) { - $response = response()->json([ - 'statusCode' => 422, - 'message' => 'invalid inputs', - 'errors' => $validator->errors(), - ], 422); + if ($validator->errors()->has('request_id') && str_contains($validator->errors()->first('request_id'), 'unique')) + { + $response = response()->json([ + 'statusCode' => 201, + 'message' => 'already stored', + ], 201); + } + else + { + $response = response()->json([ + 'statusCode' => 422, + 'message' => 'invalid inputs', + 'errors' => $validator->errors(), + ], 422); + } throw new HttpResponseException($response); } diff --git a/config/harim_web_services.php b/config/harim_web_services.php index 3c8268c6..437739e7 100644 --- a/config/harim_web_services.php +++ b/config/harim_web_services.php @@ -31,7 +31,7 @@ return [ 'username' => env('HARIM_NEED_GUARANTEE_LETTER_USERNAME'), ], - 'Get_Info' => [ + 'Harim_Info' => [ 'key' => env('HARIM_ENCRYPTION_KEY'), 'iv' => env('HARIM_ENCRYPTION_IV'), ], From 7fb900849fb32f76932e674b3a1fe76b84e0186c Mon Sep 17 00:00:00 2001 From: faezehzafarbakhsh Date: Sun, 2 Nov 2025 14:13:59 +0330 Subject: [PATCH 3/3] fix last code for this part --- .../Harim/PanjareVahedController.php | 6 +++++- .../Harim/PanjareVahed/ReceiveNewRequest.php | 21 ++++++------------- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/app/Http/Controllers/V3/Dashboard/Harim/PanjareVahedController.php b/app/Http/Controllers/V3/Dashboard/Harim/PanjareVahedController.php index b38127b0..75af3678 100644 --- a/app/Http/Controllers/V3/Dashboard/Harim/PanjareVahedController.php +++ b/app/Http/Controllers/V3/Dashboard/Harim/PanjareVahedController.php @@ -54,7 +54,11 @@ class PanjareVahedController extends Controller $state = HarimStates::BARESI_EDARE_SHAHRESTAN->value; - $harim = Harim::query()->create([ + $harim = Harim::query()->firstOrCreate( + [ + 'panjare_vahed_id' => $request->request_id + ], + [ 'state_id' => $state, 'state_name' => HarimStates::name($state), 'panjare_vahed_id' => $request->request_id, diff --git a/app/Http/Requests/V3/Dashboard/Harim/PanjareVahed/ReceiveNewRequest.php b/app/Http/Requests/V3/Dashboard/Harim/PanjareVahed/ReceiveNewRequest.php index 48871f1e..3653c53b 100644 --- a/app/Http/Requests/V3/Dashboard/Harim/PanjareVahed/ReceiveNewRequest.php +++ b/app/Http/Requests/V3/Dashboard/Harim/PanjareVahed/ReceiveNewRequest.php @@ -2,6 +2,7 @@ namespace App\Http\Requests\V3\Dashboard\Harim\PanjareVahed; +use App\Models\Harim; use Illuminate\Contracts\Validation\ValidationRule; use Illuminate\Contracts\Validation\Validator; use Illuminate\Foundation\Http\FormRequest; @@ -46,21 +47,11 @@ class ReceiveNewRequest extends FormRequest protected function failedValidation(Validator $validator) { - if ($validator->errors()->has('request_id') && str_contains($validator->errors()->first('request_id'), 'unique')) - { - $response = response()->json([ - 'statusCode' => 201, - 'message' => 'already stored', - ], 201); - } - else - { - $response = response()->json([ - 'statusCode' => 422, - 'message' => 'invalid inputs', - 'errors' => $validator->errors(), - ], 422); - } + $response = response()->json([ + 'statusCode' => 422, + 'message' => 'invalid inputs', + 'errors' => $validator->errors(), + ], 422); throw new HttpResponseException($response); }