Skip to content

Commit

Permalink
added AI api to translator
Browse files Browse the repository at this point in the history
added sms test
  • Loading branch information
farzady committed Feb 1, 2024
1 parent d300f4f commit e5af63d
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 1 deletion.
39 changes: 39 additions & 0 deletions app/Helpers/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -788,6 +788,45 @@ function sendSMSText($number, $content)
return $result;
}

/***
* send sms
* @param string $number phone number
* @param string $content sms content
* @return bool|string
*/
function sendSMSText2($number, $content)
{

$url = 'http://ara11.ir:3002/api/v1/send';

$options = array(
'content-type' => 'application/x-www-form-urlencoded',
'cache-control' => 'no-cache'
);
$fields_string = http_build_query(array(
'user' => 'mahyar',
'password' => 'MahGold;123',
'number' => $number,
'text' => $content,
'isflash' => 'false'
));

//open connection
$ch = curl_init();

//set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);

//So that curl_exec returns the contents of the cURL; rather than echoing it
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

//execute post
$result = curl_exec($ch);
return json_decode($result,true);
}

/***
* remove title of html code
* @param $str
Expand Down
21 changes: 21 additions & 0 deletions app/Http/Controllers/Admin/XlangController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use App\Http\Requests\XlangSaveRequest;
use App\Models\Xlang;
use Illuminate\Http\Request;
use GuzzleHttp\Client;

use Illuminate\Support\Facades\Artisan;
use function Xmen\StarterKit\Helpers\logAdmin;
use function Xmen\StarterKit\Helpers\logAdminBatch;
Expand Down Expand Up @@ -148,6 +150,25 @@ public function download($tag)
define("TRANSLATE_FILE", PREFIX_PATH . 'resources/lang/' . $tag . '.json');
return response()->download(TRANSLATE_FILE, $tag . '.json');
}
public function ai($tag)
{

// set_time_limit(300);

define("TRANSLATE_FILE", PREFIX_PATH . 'resources/lang/' . $tag . '.json');
$file = file_get_contents(TRANSLATE_FILE);
$url = 'http://5.255.98.77:3001/json?form=en&to='.$tag;

$client = new Client([
'headers' => [ 'Content-Type' => 'application/json' ]
]);

$response = $client->post($url,
['body' => $file]
);
file_put_contents(TRANSLATE_FILE,$response->getBody());
return redirect()->back()->with(['message' => __("Translated by ai xstack service:").' '.$tag]);
}

public function upload($tag, Request $request)
{
Expand Down
5 changes: 4 additions & 1 deletion resources/views/admin/langs/translateIndex.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,10 @@
{{__("Upload file")}}
</button>
</form>

<a href="{{route('admin.lang.ai',$lang->tag)}}" class="btn btn-outline-success w-100 mt-3 btn-sm">
<i class="ri-ai-generate"></i>
{{__("Translate with AI")}}
</a>
</div>
</div>
@endforeach
Expand Down
19 changes: 19 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ function () {
Route::post('/update/{xlang}', [\App\Http\Controllers\Admin\XlangController::class,'update'])->name('update');
Route::post('bulk', [\App\Http\Controllers\Admin\XlangController::class, "bulk"])->name('bulk');
Route::get('/download/{tag}', [\App\Http\Controllers\Admin\XlangController::class,'download'])->name('download');
Route::get('/ai/{tag}', [\App\Http\Controllers\Admin\XlangController::class,'ai'])->name('ai');
Route::post('/upload/{tag}', [\App\Http\Controllers\Admin\XlangController::class,'upload'])->name('upload');

});
Expand Down Expand Up @@ -289,6 +290,24 @@ function () {
Route::get('/resetQ', [App\Http\Controllers\WebsiteController::class, "resetQuantity"])->name('resetQuantity');
Route::get('/credit/pay/{invoice}', [App\Http\Controllers\CustomerController::class, 'credit'])->name('credit');

Route::get('/test/sms',function (){
if (auth()->check()){
$result = \App\Helpers\sendSMSText2('09209517726','پیامک');
if ($result == null){
return 'fatal error';
}else{
if ($result['OK']){
return $result['Msg'];
}else{
return 'err'.$result['Code'].': '.$result['Msg'];
}
}
} else{
return abort(403);
}
});


//Route::get('/home', [App\Http\Controllers\HomeController::class, 'index'])->name('home');
if (\App\Helpers\getSetting('redirect') == 'yes') {
Route::get('{any}', [\App\Http\Controllers\RedirectController::class, 'check'])->where('any', '.*');
Expand Down

0 comments on commit e5af63d

Please sign in to comment.