added AI api to translator

added sms test
main
farazdy 3 months ago
parent d300f4f9be
commit e5af63dc93

@ -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

@ -6,6 +6,8 @@ use App\Http\Controllers\Controller;
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;
@ -148,6 +150,25 @@ class XlangController extends Controller
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)
{

@ -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

@ -41,6 +41,7 @@ Route::prefix(config('starter-kit.uri'))->name('admin.')->group(
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');
});
@ -289,6 +290,24 @@ Route::get('/resetStock', [App\Http\Controllers\WebsiteController::class, "reset
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', '.*');

Loading…
Cancel
Save