106 lines
2.9 KiB
PHP
106 lines
2.9 KiB
PHP
<?php
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\System;
|
|
use Illuminate\Http\Request;
|
|
|
|
class OutController extends Controller{
|
|
|
|
public function getConfig(Request $request){
|
|
$msg = '';
|
|
try {
|
|
$ts = $request->get('ts');
|
|
$sign = $this->getSign('get_config',$ts );
|
|
if ($sign != $request->get('sign')) {
|
|
$this->returnJson([], 400, "签名不对");
|
|
exit;
|
|
}
|
|
$data = System::find(1);
|
|
$arr = [
|
|
'app_address' => $this->decry_data($data->app_address) ?: "",
|
|
'app_key' => $this->decry_data($data->app_key) ?: "",
|
|
'gui_address' => $this->decry_data($data->gui_address) ?: "",
|
|
];
|
|
$this->returnJson($arr);
|
|
exit;
|
|
} catch (\Exception $e) {
|
|
$msg = $e->getMessage();
|
|
}
|
|
$this->returnJson([], 400, $msg);
|
|
exit;
|
|
}
|
|
|
|
public function updateConfig(Request $request){
|
|
try {
|
|
|
|
$ts = $request->get('ts');
|
|
|
|
$app_address = $request->post('app_address');
|
|
$app_key = $request->post('app_key');
|
|
$gui_address = $request->post('gui_address');
|
|
|
|
$arr = [
|
|
'app_address' => $app_address,
|
|
'app_key' => $app_key,
|
|
'gui_address' => $gui_address,
|
|
];
|
|
|
|
$sign = $this->getSign('edit_config', $ts, $arr);
|
|
if ($sign != $request->get('sign')) {
|
|
$this->returnJson([], 400, "签名不对");
|
|
exit;
|
|
}
|
|
|
|
System::where(['id'=>1])->update(
|
|
[
|
|
'app_address' => $this->encry_data($app_address),
|
|
'app_key' => $this->encry_data($app_key),
|
|
'gui_address' => $this->encry_data($gui_address),
|
|
]
|
|
);
|
|
|
|
|
|
$this->returnJson($arr);
|
|
exit;
|
|
} catch (\Exception $e) {
|
|
$msg = $e->getMessage();
|
|
}
|
|
$this->returnJson([], 400, $msg);
|
|
}
|
|
|
|
private function getSign($api,$ts,$arr=[]): string
|
|
{
|
|
$sinArr = [
|
|
'secret' => config('secret.sign_key'),
|
|
'ts' => $ts,
|
|
'api' => $api,
|
|
];
|
|
$sinArr = array_merge($sinArr, $arr);
|
|
$str = implode("|", $sinArr);
|
|
return md5($str);
|
|
}
|
|
|
|
private function returnJson($data,$code=200,$msg=""){
|
|
$data = [
|
|
'code' => $code,
|
|
'msg' => $msg,
|
|
'data' => (object)$data,
|
|
];
|
|
echo json_encode($data, 256);
|
|
exit;
|
|
}
|
|
|
|
|
|
private function encry_data($data){
|
|
return $data;
|
|
// $key = config('secret.encry_key');
|
|
// return openssl_encrypt($data, 'AES-256-ECB', $key);
|
|
}
|
|
|
|
private function decry_data($endata){
|
|
return $endata;
|
|
// $key = config('secret.encry_key');
|
|
// return openssl_decrypt($endata, 'AES-256-ECB', $key);
|
|
}
|
|
}
|