Prepare FUC-XB web support integration
This commit is contained in:
1 parent
2c92a857e8
commit
fa706edeb6
22 files changed
+1164
-2
No files matched your search
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
namespace App\Http\Controllers\V2\Admin;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Services\CustomerService\Settings;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
class CustomerServiceController extends Controller
|
||||
{
|
||||
public function fetch(Settings $settings) { return $this->success($settings->all()); }
|
||||
public function save(Request $request, Settings $settings) {
|
||||
$data=$request->validate([
|
||||
'enabled'=>'required|boolean','base_url'=>'present|nullable|url:http,https|max:255',
|
||||
'website_token'=>'present|nullable|string|max:255', 'working_hours'=>'present|nullable|string|max:200',
|
||||
'offline_title'=>'required|string|max:100','offline_message'=>'required|string|max:500',
|
||||
'ticket_url'=>'required|string|max:500','telegram_enabled'=>'required|boolean',
|
||||
'telegram_bot_code'=>'required|regex:/^[a-z0-9_-]+$/|max:64',
|
||||
'telegram_target_code'=>'required|regex:/^[a-z0-9_-]+$/|max:64',
|
||||
]);
|
||||
$data['base_url']=rtrim($data['base_url']??'', '/');
|
||||
$data['website_token']=$data['website_token']??'';
|
||||
$data['working_hours']=$data['working_hours']??'';
|
||||
if ($data['enabled'] && (!$data['base_url'] || !$data['website_token'])) {
|
||||
throw ValidationException::withMessages(['enabled'=>'启用客服需要服务地址和网站标识']);
|
||||
}
|
||||
$parts=parse_url($data['base_url']);
|
||||
if ($data['base_url'] && (!$parts || isset($parts['user']) || isset($parts['pass']) || isset($parts['query']) || isset($parts['fragment']) || !empty($parts['path']))) {
|
||||
throw ValidationException::withMessages(['base_url'=>'请填写不带路径或认证信息的服务源地址']);
|
||||
}
|
||||
if (!str_starts_with($data['ticket_url'],'/') || str_starts_with($data['ticket_url'],'//') || preg_match('/[\\\\\x00-\x20]/',$data['ticket_url'])) {
|
||||
throw ValidationException::withMessages(['ticket_url'=>'工单入口必须是本站绝对路径']);
|
||||
}
|
||||
admin_setting(['customer_service'=>$data]);
|
||||
return $this->success($settings->all());
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user