mirror of
https://github.com/v2board/v2board.git
synced 2025-06-16 22:57:47 +08:00
@ -118,6 +118,8 @@ class CheckCommission extends Command
|
||||
return false;
|
||||
}
|
||||
$inviteUserId = $inviter->invite_user_id;
|
||||
// update order actual commission balance
|
||||
$order->actual_commission_balance = $order->actual_commission_balance + $commissionBalance;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -2,25 +2,24 @@
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\Ticket;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Models\ServerLog;
|
||||
|
||||
class ResetServerLog extends Command
|
||||
class CheckTicket extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'reset:serverLog';
|
||||
protected $signature = 'check:ticket';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = '节点服务器日志重置';
|
||||
protected $description = '工单检查任务';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
@ -39,6 +38,14 @@ class ResetServerLog extends Command
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
ServerLog::truncate();
|
||||
ini_set('memory_limit', -1);
|
||||
$tickets = Ticket::where('status', 0)
|
||||
->where('updated_at', '<=', time() - 24 * 3600)
|
||||
->get();
|
||||
foreach ($tickets as $ticket) {
|
||||
if ($ticket->user_id === $ticket->last_reply_user_id) continue;
|
||||
$ticket->status = 1;
|
||||
$ticket->save();
|
||||
}
|
||||
}
|
||||
}
|
@ -44,18 +44,27 @@ class ResetTraffic extends Command
|
||||
public function handle()
|
||||
{
|
||||
ini_set('memory_limit', -1);
|
||||
foreach (Plan::get() as $plan) {
|
||||
switch ($plan->reset_traffic_method) {
|
||||
case null: {
|
||||
$resetMethods = Plan::select(
|
||||
DB::raw("GROUP_CONCAT(`id`) as plan_ids"),
|
||||
DB::raw("reset_traffic_method as method")
|
||||
)
|
||||
->groupBy('reset_traffic_method')
|
||||
->get()
|
||||
->toArray();
|
||||
foreach ($resetMethods as $resetMethod) {
|
||||
$planIds = explode(',', $resetMethod['plan_ids']);
|
||||
switch (true) {
|
||||
case ($resetMethod['method'] === NULL): {
|
||||
$resetTrafficMethod = config('v2board.reset_traffic_method', 0);
|
||||
$builder = with(clone($this->builder))->whereIn('plan_id', $planIds);
|
||||
switch ((int)$resetTrafficMethod) {
|
||||
// month first day
|
||||
case 0:
|
||||
$this->resetByMonthFirstDay($this->builder);
|
||||
$this->resetByMonthFirstDay($builder);
|
||||
break;
|
||||
// expire day
|
||||
case 1:
|
||||
$this->resetByExpireDay($this->builder);
|
||||
$this->resetByExpireDay($builder);
|
||||
break;
|
||||
// no action
|
||||
case 2:
|
||||
@ -63,17 +72,17 @@ class ResetTraffic extends Command
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 0: {
|
||||
$builder = with(clone($this->builder))->where('plan_id', $plan->id);
|
||||
case ($resetMethod['method'] === 0): {
|
||||
$builder = with(clone($this->builder))->whereIn('plan_id', $planIds);
|
||||
$this->resetByMonthFirstDay($builder);
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
$builder = with(clone($this->builder))->where('plan_id', $plan->id);
|
||||
case ($resetMethod['method'] === 1): {
|
||||
$builder = with(clone($this->builder))->whereIn('plan_id', $planIds);
|
||||
$this->resetByExpireDay($builder);
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
case ($resetMethod['method'] === 2): {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -42,8 +42,8 @@ class V2boardStatistics extends Command
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
ini_set('memory_limit', -1);
|
||||
$this->statOrder();
|
||||
$this->statServer();
|
||||
}
|
||||
|
||||
private function statOrder()
|
||||
@ -55,9 +55,9 @@ class V2boardStatistics extends Command
|
||||
->whereNotIn('status', [0, 2]);
|
||||
$orderCount = $builder->count();
|
||||
$orderAmount = $builder->sum('total_amount');
|
||||
$builder = $builder->where('commission_balance', '!=', 0);
|
||||
$builder = $builder->whereNotNull('actual_commission_balance');
|
||||
$commissionCount = $builder->count();
|
||||
$commissionAmount = $builder->sum('commission_balance');
|
||||
$commissionAmount = $builder->sum('actual_commission_balance');
|
||||
$data = [
|
||||
'order_count' => $orderCount,
|
||||
'order_amount' => $orderAmount,
|
||||
@ -75,26 +75,4 @@ class V2boardStatistics extends Command
|
||||
}
|
||||
StatOrder::create($data);
|
||||
}
|
||||
|
||||
private function statServer()
|
||||
{
|
||||
$endAt = strtotime(date('Y-m-d'));
|
||||
$startAt = strtotime('-1 day', $endAt);
|
||||
$statistics = ServerLog::select([
|
||||
'server_id',
|
||||
'method as server_type',
|
||||
DB::raw("sum(u) as u"),
|
||||
DB::raw("sum(d) as d"),
|
||||
])
|
||||
->where('log_at', '>=', $startAt)
|
||||
->where('log_at', '<', $endAt)
|
||||
->groupBy('server_id', 'method')
|
||||
->get()
|
||||
->toArray();
|
||||
foreach ($statistics as $statistic) {
|
||||
$statistic['record_type'] = 'd';
|
||||
$statistic['record_at'] = $startAt;
|
||||
StatServerJob::dispatch($statistic);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,8 +2,10 @@
|
||||
|
||||
namespace App\Console;
|
||||
|
||||
use App\Utils\CacheKey;
|
||||
use Illuminate\Console\Scheduling\Schedule;
|
||||
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class Kernel extends ConsoleKernel
|
||||
{
|
||||
@ -24,14 +26,15 @@ class Kernel extends ConsoleKernel
|
||||
*/
|
||||
protected function schedule(Schedule $schedule)
|
||||
{
|
||||
Cache::put(CacheKey::get('SCHEDULE_LAST_CHECK_AT', null), time());
|
||||
// v2board
|
||||
$schedule->command('v2board:statistics')->dailyAt('0:10');
|
||||
// check
|
||||
$schedule->command('check:order')->everyMinute();
|
||||
$schedule->command('check:commission')->everyMinute();
|
||||
$schedule->command('check:ticket')->everyMinute();
|
||||
// reset
|
||||
$schedule->command('reset:traffic')->daily();
|
||||
$schedule->command('reset:serverLog')->quarterly()->at('0:15');
|
||||
// send
|
||||
$schedule->command('send:remindMail')->dailyAt('11:30');
|
||||
// horizon metrics
|
||||
|
@ -30,6 +30,25 @@ class CouponController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
public function show(Request $request)
|
||||
{
|
||||
if (empty($request->input('id'))) {
|
||||
abort(500, '参数有误');
|
||||
}
|
||||
$coupon = Coupon::find($request->input('id'));
|
||||
if (!$coupon) {
|
||||
abort(500, '优惠券不存在');
|
||||
}
|
||||
$coupon->show = $coupon->show ? 0 : 1;
|
||||
if (!$coupon->save()) {
|
||||
abort(500, '保存失败');
|
||||
}
|
||||
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
public function generate(CouponGenerate $request)
|
||||
{
|
||||
if ($request->input('generate_count')) {
|
||||
@ -63,8 +82,6 @@ class CouponController extends Controller
|
||||
$coupons = [];
|
||||
$coupon = $request->validated();
|
||||
$coupon['created_at'] = $coupon['updated_at'] = time();
|
||||
$coupon['limit_plan_ids'] = json_encode($coupon['limit_plan_ids']);
|
||||
$coupon['limit_period'] = json_encode($coupon['limit_period']);
|
||||
unset($coupon['generate_count']);
|
||||
for ($i = 0;$i < $request->input('generate_count');$i++) {
|
||||
$coupon['code'] = Helper::randomChar(8);
|
||||
@ -84,7 +101,7 @@ class CouponController extends Controller
|
||||
$endTime = date('Y-m-d H:i:s', $coupon['ended_at']);
|
||||
$limitUse = $coupon['limit_use'] ?? '不限制';
|
||||
$createTime = date('Y-m-d H:i:s', $coupon['created_at']);
|
||||
$limitPlanIds = implode("/", json_decode($coupon['limit_plan_ids'], true)) ?? '不限制';
|
||||
$limitPlanIds = isset($coupon['limit_plan_ids']) ? implode("/", $coupon['limit_plan_ids']) : '不限制';
|
||||
$data .= "{$coupon['name']},{$type},{$value},{$startTime},{$endTime},{$limitUse},{$limitPlanIds},{$coupon['code']},{$createTime}\r\n";
|
||||
}
|
||||
echo $data;
|
||||
|
@ -40,6 +40,27 @@ class NoticeController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function show(Request $request)
|
||||
{
|
||||
if (empty($request->input('id'))) {
|
||||
abort(500, '参数有误');
|
||||
}
|
||||
$notice = Notice::find($request->input('id'));
|
||||
if (!$notice) {
|
||||
abort(500, '公告不存在');
|
||||
}
|
||||
$notice->show = $notice->show ? 0 : 1;
|
||||
if (!$notice->save()) {
|
||||
abort(500, '保存失败');
|
||||
}
|
||||
|
||||
return response([
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
|
||||
public function drop(Request $request)
|
||||
{
|
||||
if (empty($request->input('id'))) {
|
||||
|
@ -5,6 +5,7 @@ namespace App\Http\Controllers\Admin;
|
||||
use App\Http\Requests\Admin\OrderAssign;
|
||||
use App\Http\Requests\Admin\OrderUpdate;
|
||||
use App\Http\Requests\Admin\OrderFetch;
|
||||
use App\Models\CommissionLog;
|
||||
use App\Services\OrderService;
|
||||
use App\Services\UserService;
|
||||
use App\Utils\Helper;
|
||||
@ -36,6 +37,19 @@ class OrderController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
public function detail(Request $request)
|
||||
{
|
||||
$order = Order::find($request->input('id'));
|
||||
if (!$order) abort(500, '订单不存在');
|
||||
$order['commission_log'] = CommissionLog::where('trade_no', $order->trade_no)->get();
|
||||
if ($order->surplus_order_ids) {
|
||||
$order['surplus_orders'] = Order::whereIn('id', $order->surplus_order_ids)->get();
|
||||
}
|
||||
return response([
|
||||
'data' => $order
|
||||
]);
|
||||
}
|
||||
|
||||
public function fetch(OrderFetch $request)
|
||||
{
|
||||
$current = $request->input('current') ? $request->input('current') : 1;
|
||||
|
@ -26,7 +26,12 @@ class PaymentController extends Controller
|
||||
{
|
||||
$payments = Payment::all();
|
||||
foreach ($payments as $k => $v) {
|
||||
$payments[$k]['notify_url'] = url("/api/v1/guest/payment/notify/{$v->payment}/{$v->uuid}");
|
||||
$notifyUrl = url("/api/v1/guest/payment/notify/{$v->payment}/{$v->uuid}");
|
||||
if ($v->notify_domain) {
|
||||
$parseUrl = parse_url($notifyUrl);
|
||||
$notifyUrl = $v->notify_domain . $parseUrl['path'];
|
||||
}
|
||||
$payments[$k]['notify_url'] = $notifyUrl;
|
||||
}
|
||||
return response([
|
||||
'data' => $payments
|
||||
@ -58,22 +63,20 @@ class PaymentController extends Controller
|
||||
'data' => true
|
||||
]);
|
||||
}
|
||||
$request->validate([
|
||||
$params = $request->validate([
|
||||
'name' => 'required',
|
||||
'icon' => 'nullable',
|
||||
'payment' => 'required',
|
||||
'config' => 'required'
|
||||
'config' => 'required',
|
||||
'notify_domain' => 'nullable|url'
|
||||
], [
|
||||
'name.required' => '显示名称不能为空',
|
||||
'payment.required' => '网关参数不能为空',
|
||||
'config.required' => '配置参数不能为空'
|
||||
'config.required' => '配置参数不能为空',
|
||||
'notify_domain.url' => '自定义通知域名格式有误'
|
||||
]);
|
||||
if (!Payment::create([
|
||||
'name' => $request->input('name'),
|
||||
'icon' => $request->input('icon'),
|
||||
'payment' => $request->input('payment'),
|
||||
'config' => $request->input('config'),
|
||||
'uuid' => Helper::randomChar(8)
|
||||
])) {
|
||||
$params['uuid'] = Helper::randomChar(8);
|
||||
if (!Payment::create($params)) {
|
||||
abort(500, '保存失败');
|
||||
}
|
||||
return response([
|
||||
|
@ -31,9 +31,9 @@ class StatController extends Controller
|
||||
'month_register_total' => User::where('created_at', '>=', strtotime(date('Y-m-1')))
|
||||
->where('created_at', '<', time())
|
||||
->count(),
|
||||
'ticket_pendding_total' => Ticket::where('status', 0)
|
||||
'ticket_pending_total' => Ticket::where('status', 0)
|
||||
->count(),
|
||||
'commission_pendding_total' => Order::where('commission_status', 0)
|
||||
'commission_pending_total' => Order::where('commission_status', 0)
|
||||
->where('invite_user_id', '!=', NULL)
|
||||
->whereNotIn('status', [0, 2])
|
||||
->where('commission_balance', '>', 0)
|
||||
|
52
app/Http/Controllers/Admin/SystemController.php
Normal file
52
app/Http/Controllers/Admin/SystemController.php
Normal file
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Models\ServerShadowsocks;
|
||||
use App\Models\ServerTrojan;
|
||||
use App\Services\ServerService;
|
||||
use App\Utils\CacheKey;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\ServerGroup;
|
||||
use App\Models\ServerV2ray;
|
||||
use App\Models\Plan;
|
||||
use App\Models\User;
|
||||
use App\Models\Ticket;
|
||||
use App\Models\Order;
|
||||
use App\Models\StatOrder;
|
||||
use App\Models\StatServer;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Laravel\Horizon\Contracts\MasterSupervisorRepository;
|
||||
|
||||
class SystemController extends Controller
|
||||
{
|
||||
public function getStatus()
|
||||
{
|
||||
return response([
|
||||
'data' => [
|
||||
'schedule' => $this->getScheduleStatus(),
|
||||
'horizon' => $this->getHorizonStatus()
|
||||
]
|
||||
]);
|
||||
}
|
||||
|
||||
protected function getScheduleStatus():bool
|
||||
{
|
||||
return (time() - 120) < Cache::get(CacheKey::get('SCHEDULE_LAST_CHECK_AT', null));
|
||||
}
|
||||
|
||||
protected function getHorizonStatus():bool
|
||||
{
|
||||
if (! $masters = app(MasterSupervisorRepository::class)->all()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return collect($masters)->contains(function ($master) {
|
||||
return $master->status === 'paused';
|
||||
}) ? false : true;
|
||||
}
|
||||
}
|
||||
|
@ -58,7 +58,11 @@ class UserController extends Controller
|
||||
$pageSize = $request->input('pageSize') >= 10 ? $request->input('pageSize') : 10;
|
||||
$sortType = in_array($request->input('sort_type'), ['ASC', 'DESC']) ? $request->input('sort_type') : 'DESC';
|
||||
$sort = $request->input('sort') ? $request->input('sort') : 'created_at';
|
||||
$userModel = User::orderBy($sort, $sortType);
|
||||
$userModel = User::select(
|
||||
DB::raw('*'),
|
||||
DB::raw('(u+d) as total_used')
|
||||
)
|
||||
->orderBy($sort, $sortType);
|
||||
$this->filter($request, $userModel);
|
||||
$total = $userModel->count();
|
||||
$res = $userModel->forPage($current, $pageSize)
|
||||
|
@ -13,10 +13,6 @@ use Symfony\Component\Yaml\Yaml;
|
||||
|
||||
class AppController extends Controller
|
||||
{
|
||||
CONST CLIENT_CONFIG = '{"policy":{"levels":{"0":{"uplinkOnly":0}}},"dns":{"servers":["114.114.114.114","8.8.8.8"]},"outboundDetour":[{"protocol":"freedom","tag":"direct","settings":{}}],"inbound":{"listen":"0.0.0.0","port":31211,"protocol":"socks","settings":{"auth":"noauth","udp":true,"ip":"127.0.0.1"}},"inboundDetour":[{"listen":"0.0.0.0","allocate":{"strategy":"always","refresh":5,"concurrency":3},"port":31210,"protocol":"http","tag":"httpDetour","domainOverride":["http","tls"],"streamSettings":{},"settings":{"timeout":0}}],"routing":{"strategy":"rules","settings":{"domainStrategy":"IPIfNonMatch","rules":[{"type":"field","ip":["geoip:cn"],"outboundTag":"direct"},{"type":"field","ip":["0.0.0.0/8","10.0.0.0/8","100.64.0.0/10","127.0.0.0/8","169.254.0.0/16","172.16.0.0/12","192.0.0.0/24","192.0.2.0/24","192.168.0.0/16","198.18.0.0/15","198.51.100.0/24","203.0.113.0/24","::1/128","fc00::/7","fe80::/10"],"outboundTag":"direct"}]}},"outbound":{"tag":"proxy","sendThrough":"0.0.0.0","mux":{"enabled":false,"concurrency":8},"protocol":"vmess","settings":{"vnext":[{"address":"server","port":443,"users":[{"id":"uuid","alterId":2,"security":"auto","level":0}],"remark":"remark"}]},"streamSettings":{"network":"tcp","tcpSettings":{"header":{"type":"none"}},"security":"none","tlsSettings":{"allowInsecure":true,"allowInsecureCiphers":true},"kcpSettings":{"header":{"type":"none"},"mtu":1350,"congestion":false,"tti":20,"uplinkCapacity":5,"writeBufferSize":1,"readBufferSize":1,"downlinkCapacity":20},"wsSettings":{"path":"","headers":{"Host":"server.cc"}}}}}';
|
||||
CONST SOCKS_PORT = 10010;
|
||||
CONST HTTP_PORT = 10011;
|
||||
|
||||
public function getConfig(Request $request)
|
||||
{
|
||||
$servers = [];
|
||||
|
@ -23,7 +23,7 @@ class Clash
|
||||
$appName = config('v2board.app_name', 'V2Board');
|
||||
header("subscription-userinfo: upload={$user['u']}; download={$user['d']}; total={$user['transfer_enable']}; expire={$user['expired_at']}");
|
||||
header('profile-update-interval: 24');
|
||||
header("content-disposition: filename={$appName}");
|
||||
header("content-disposition:attachment;filename={$appName}");
|
||||
$defaultConfig = base_path() . '/resources/rules/default.clash.yaml';
|
||||
$customConfig = base_path() . '/resources/rules/custom.clash.yaml';
|
||||
if (\File::exists($customConfig)) {
|
||||
@ -51,20 +51,21 @@ class Clash
|
||||
|
||||
$config['proxies'] = array_merge($config['proxies'] ? $config['proxies'] : [], $proxy);
|
||||
foreach ($config['proxy-groups'] as $k => $v) {
|
||||
if (!is_array($config['proxy-groups'][$k]['proxies'])) continue;
|
||||
if (!is_array($config['proxy-groups'][$k]['proxies'])) $config['proxy-groups'][$k]['proxies'] = [];
|
||||
$isFilter = false;
|
||||
foreach ($config['proxy-groups'][$k]['proxies'] as $src) {
|
||||
foreach ($proxies as $dst) {
|
||||
if (!$this->isRegex($src)) continue;
|
||||
$isFilter = true;
|
||||
$config['proxy-groups'][$k]['proxies'] = array_values(array_diff($config['proxy-groups'][$k]['proxies'], [$src]));
|
||||
if ($this->isMatch($src, $dst)) {
|
||||
$isFilter = true;
|
||||
$config['proxy-groups'][$k]['proxies'] = array_diff($config['proxy-groups'][$k]['proxies'], [$src]);
|
||||
array_push($config['proxy-groups'][$k]['proxies'], $dst);
|
||||
}
|
||||
}
|
||||
if ($isFilter) continue;
|
||||
}
|
||||
if (!$isFilter) {
|
||||
$config['proxy-groups'][$k]['proxies'] = array_merge($config['proxy-groups'][$k]['proxies'], $proxies);
|
||||
}
|
||||
if ($isFilter) continue;
|
||||
$config['proxy-groups'][$k]['proxies'] = array_merge($config['proxy-groups'][$k]['proxies'], $proxies);
|
||||
}
|
||||
// Force the current subscription domain to be a direct rule
|
||||
$subsDomain = $_SERVER['SERVER_NAME'];
|
||||
@ -97,7 +98,7 @@ class Clash
|
||||
$array['server'] = $server['host'];
|
||||
$array['port'] = $server['port'];
|
||||
$array['uuid'] = $uuid;
|
||||
$array['alterId'] = $server['alter_id'];
|
||||
$array['alterId'] = 0;
|
||||
$array['cipher'] = 'auto';
|
||||
$array['udp'] = true;
|
||||
|
||||
@ -115,6 +116,12 @@ class Clash
|
||||
$array['network'] = 'ws';
|
||||
if ($server['networkSettings']) {
|
||||
$wsSettings = $server['networkSettings'];
|
||||
$array['ws-opts'] = [];
|
||||
if (isset($wsSettings['path']) && !empty($wsSettings['path']))
|
||||
$array['ws-opts']['path'] = $wsSettings['path'];
|
||||
if (isset($wsSettings['headers']['Host']) && !empty($wsSettings['headers']['Host']))
|
||||
$array['ws-opts']['headers'] = ['Host' => $wsSettings['headers']['Host']];
|
||||
// TODO: 2022.06.01 remove it
|
||||
if (isset($wsSettings['path']) && !empty($wsSettings['path']))
|
||||
$array['ws-path'] = $wsSettings['path'];
|
||||
if (isset($wsSettings['headers']['Host']) && !empty($wsSettings['headers']['Host']))
|
||||
@ -124,9 +131,9 @@ class Clash
|
||||
if ($server['network'] === 'grpc') {
|
||||
$array['network'] = 'grpc';
|
||||
if ($server['networkSettings']) {
|
||||
$grpcObject = $server['networkSettings'];
|
||||
$grpcSettings = $server['networkSettings'];
|
||||
$array['grpc-opts'] = [];
|
||||
$array['grpc-opts']['grpc-service-name'] = $grpcObject['serviceName'];
|
||||
$array['grpc-opts']['grpc-service-name'] = $grpcSettings['serviceName'];
|
||||
}
|
||||
}
|
||||
|
||||
@ -149,10 +156,11 @@ class Clash
|
||||
|
||||
private function isMatch($exp, $str)
|
||||
{
|
||||
try {
|
||||
return preg_match($exp, $str);
|
||||
} catch (\Exception $e) {
|
||||
return false;
|
||||
}
|
||||
return @preg_match($exp, $str);
|
||||
}
|
||||
|
||||
private function isRegex($exp)
|
||||
{
|
||||
return @preg_match($exp, null) !== false;
|
||||
}
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ class Passwall
|
||||
"add" => $server['host'],
|
||||
"port" => (string)$server['port'],
|
||||
"id" => $uuid,
|
||||
"aid" => (string)$server['alter_id'],
|
||||
"aid" => '0',
|
||||
"net" => $server['network'],
|
||||
"type" => "none",
|
||||
"host" => "",
|
||||
|
@ -54,7 +54,7 @@ class SSRPlus
|
||||
"add" => $server['host'],
|
||||
"port" => (string)$server['port'],
|
||||
"id" => $uuid,
|
||||
"aid" => (string)$server['alter_id'],
|
||||
"aid" => '0',
|
||||
"net" => $server['network'],
|
||||
"type" => "none",
|
||||
"host" => "",
|
||||
|
@ -58,7 +58,7 @@ class Shadowrocket
|
||||
$config = [
|
||||
'tfo' => 1,
|
||||
'remark' => $server['name'],
|
||||
'alterId' => $server['alter_id']
|
||||
'alterId' => 0
|
||||
];
|
||||
if ($server['tls']) {
|
||||
$config['tls'] = 1;
|
||||
|
@ -56,16 +56,17 @@ class Stash
|
||||
$isFilter = false;
|
||||
foreach ($config['proxy-groups'][$k]['proxies'] as $src) {
|
||||
foreach ($proxies as $dst) {
|
||||
if (!$this->isRegex($src)) continue;
|
||||
$isFilter = true;
|
||||
$config['proxy-groups'][$k]['proxies'] = array_values(array_diff($config['proxy-groups'][$k]['proxies'], [$src]));
|
||||
if ($this->isMatch($src, $dst)) {
|
||||
$isFilter = true;
|
||||
$config['proxy-groups'][$k]['proxies'] = array_diff($config['proxy-groups'][$k]['proxies'], [$src]);
|
||||
array_push($config['proxy-groups'][$k]['proxies'], $dst);
|
||||
}
|
||||
}
|
||||
if ($isFilter) continue;
|
||||
}
|
||||
if (!$isFilter) {
|
||||
$config['proxy-groups'][$k]['proxies'] = array_merge($config['proxy-groups'][$k]['proxies'], $proxies);
|
||||
}
|
||||
if ($isFilter) continue;
|
||||
$config['proxy-groups'][$k]['proxies'] = array_merge($config['proxy-groups'][$k]['proxies'], $proxies);
|
||||
}
|
||||
// Force the current subscription domain to be a direct rule
|
||||
$subsDomain = $_SERVER['SERVER_NAME'];
|
||||
@ -98,7 +99,7 @@ class Stash
|
||||
$array['server'] = $server['host'];
|
||||
$array['port'] = $server['port'];
|
||||
$array['uuid'] = $uuid;
|
||||
$array['alterId'] = $server['alter_id'];
|
||||
$array['alterId'] = 0;
|
||||
$array['cipher'] = 'auto';
|
||||
$array['udp'] = true;
|
||||
|
||||
@ -116,6 +117,12 @@ class Stash
|
||||
$array['network'] = 'ws';
|
||||
if ($server['networkSettings']) {
|
||||
$wsSettings = $server['networkSettings'];
|
||||
$array['ws-opts'] = [];
|
||||
if (isset($wsSettings['path']) && !empty($wsSettings['path']))
|
||||
$array['ws-opts']['path'] = $wsSettings['path'];
|
||||
if (isset($wsSettings['headers']['Host']) && !empty($wsSettings['headers']['Host']))
|
||||
$array['ws-opts']['headers'] = ['Host' => $wsSettings['headers']['Host']];
|
||||
// TODO: 2022.06.01 remove it
|
||||
if (isset($wsSettings['path']) && !empty($wsSettings['path']))
|
||||
$array['ws-path'] = $wsSettings['path'];
|
||||
if (isset($wsSettings['headers']['Host']) && !empty($wsSettings['headers']['Host']))
|
||||
@ -125,9 +132,9 @@ class Stash
|
||||
if ($server['network'] === 'grpc') {
|
||||
$array['network'] = 'grpc';
|
||||
if ($server['networkSettings']) {
|
||||
$grpcObject = $server['networkSettings'];
|
||||
$grpcSettings = $server['networkSettings'];
|
||||
$array['grpc-opts'] = [];
|
||||
$array['grpc-opts']['grpc-service-name'] = $grpcObject['serviceName'];
|
||||
$array['grpc-opts']['grpc-service-name'] = $grpcSettings['serviceName'];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -88,6 +88,7 @@ class Surfboard
|
||||
"{$server['host']}",
|
||||
"{$server['port']}",
|
||||
"username={$uuid}",
|
||||
"vmess-aead=true",
|
||||
'tfo=true',
|
||||
'udp-relay=true'
|
||||
];
|
||||
|
@ -87,6 +87,7 @@ class Surge
|
||||
"{$server['host']}",
|
||||
"{$server['port']}",
|
||||
"username={$uuid}",
|
||||
"vmess-aead=true",
|
||||
'tfo=true',
|
||||
'udp-relay=true'
|
||||
];
|
||||
|
@ -54,7 +54,7 @@ class V2rayN
|
||||
"add" => $server['host'],
|
||||
"port" => (string)$server['port'],
|
||||
"id" => $uuid,
|
||||
"aid" => (string)$server['alter_id'],
|
||||
"aid" => '0',
|
||||
"net" => $server['network'],
|
||||
"type" => "none",
|
||||
"host" => "",
|
||||
|
@ -54,7 +54,7 @@ class V2rayNG
|
||||
"add" => $server['host'],
|
||||
"port" => (string)$server['port'],
|
||||
"id" => $uuid,
|
||||
"aid" => (string)$server['alter_id'],
|
||||
"aid" => '0',
|
||||
"net" => $server['network'],
|
||||
"type" => "none",
|
||||
"host" => "",
|
||||
|
@ -4,6 +4,7 @@ namespace App\Http\Controllers\Guest;
|
||||
|
||||
use App\Utils\Dict;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
|
||||
class CommController extends Controller
|
||||
{
|
||||
@ -33,4 +34,11 @@ class CommController extends Controller
|
||||
}
|
||||
return $suffix;
|
||||
}
|
||||
|
||||
public function getHitokoto()
|
||||
{
|
||||
return response([
|
||||
'data' => Http::get('https://v1.hitokoto.cn/')->json()
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ class PaymentController extends Controller
|
||||
if (!$this->handle($verify['trade_no'], $verify['callback_no'])) {
|
||||
abort(500, 'handle error');
|
||||
}
|
||||
die(isset($paymentService->customResult) ? $paymentService->customResult : 'success');
|
||||
die(isset($verify['custom_result']) ? $verify['custom_result'] : 'success');
|
||||
} catch (\Exception $e) {
|
||||
abort(500, 'fail');
|
||||
}
|
||||
|
@ -5,18 +5,16 @@ namespace App\Http\Controllers\Guest;
|
||||
use App\Services\TelegramService;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\User;
|
||||
use App\Utils\Helper;
|
||||
use App\Services\TicketService;
|
||||
|
||||
class TelegramController extends Controller
|
||||
{
|
||||
protected $msg;
|
||||
protected $commands = [];
|
||||
|
||||
public function __construct(Request $request)
|
||||
{
|
||||
if ($request->input('access_token') !== md5(config('v2board.telegram_bot_token'))) {
|
||||
abort(500, 'authentication failed');
|
||||
abort(401);
|
||||
}
|
||||
}
|
||||
|
||||
@ -24,41 +22,34 @@ class TelegramController extends Controller
|
||||
{
|
||||
$this->msg = $this->getMessage($request->input());
|
||||
if (!$this->msg) return;
|
||||
$this->handle();
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$msg = $this->msg;
|
||||
try {
|
||||
switch($this->msg->message_type) {
|
||||
case 'send':
|
||||
$this->fromSend();
|
||||
break;
|
||||
case 'reply':
|
||||
$this->fromReply();
|
||||
break;
|
||||
foreach (glob(base_path('app//Plugins//Telegram//Commands') . '/*.php') as $file) {
|
||||
$command = basename($file, '.php');
|
||||
$class = '\\App\\Plugins\\Telegram\\Commands\\' . $command;
|
||||
if (!class_exists($class)) continue;
|
||||
$instance = new $class();
|
||||
if ($msg->message_type === 'message') {
|
||||
if (!isset($instance->command)) continue;
|
||||
if ($msg->command !== $instance->command) continue;
|
||||
$instance->handle($msg);
|
||||
return;
|
||||
}
|
||||
if ($msg->message_type === 'reply_message') {
|
||||
if (!isset($instance->regex)) continue;
|
||||
if (!preg_match($instance->regex, $msg->reply_text, $match)) continue;
|
||||
$instance->handle($msg, $match);
|
||||
return;
|
||||
}
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$telegramService = new TelegramService();
|
||||
$telegramService->sendMessage($this->msg->chat_id, $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private function fromSend()
|
||||
{
|
||||
switch($this->msg->command) {
|
||||
case '/bind': $this->bind();
|
||||
break;
|
||||
case '/traffic': $this->traffic();
|
||||
break;
|
||||
case '/getlatesturl': $this->getLatestUrl();
|
||||
break;
|
||||
case '/unbind': $this->unbind();
|
||||
break;
|
||||
default: $this->help();
|
||||
}
|
||||
}
|
||||
|
||||
private function fromReply()
|
||||
{
|
||||
// ticket
|
||||
if (preg_match("/[#](.*)/", $this->msg->reply_text, $match)) {
|
||||
$this->replayTicket($match[1]);
|
||||
$telegramService->sendMessage($msg->chat_id, $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@ -66,135 +57,18 @@ class TelegramController extends Controller
|
||||
{
|
||||
if (!isset($data['message'])) return false;
|
||||
$obj = new \StdClass();
|
||||
$obj->is_private = $data['message']['chat']['type'] === 'private' ? true : false;
|
||||
if (!isset($data['message']['text'])) return false;
|
||||
$text = explode(' ', $data['message']['text']);
|
||||
$obj->command = $text[0];
|
||||
$obj->args = array_slice($text, 1);
|
||||
$obj->chat_id = $data['message']['chat']['id'];
|
||||
$obj->message_id = $data['message']['message_id'];
|
||||
$obj->message_type = !isset($data['message']['reply_to_message']['text']) ? 'send' : 'reply';
|
||||
$obj->message_type = !isset($data['message']['reply_to_message']['text']) ? 'message' : 'reply_message';
|
||||
$obj->text = $data['message']['text'];
|
||||
if ($obj->message_type === 'reply') {
|
||||
$obj->is_private = $data['message']['chat']['type'] === 'private';
|
||||
if ($obj->message_type === 'reply_message') {
|
||||
$obj->reply_text = $data['message']['reply_to_message']['text'];
|
||||
}
|
||||
return $obj;
|
||||
}
|
||||
|
||||
private function bind()
|
||||
{
|
||||
$msg = $this->msg;
|
||||
if (!$msg->is_private) return;
|
||||
if (!isset($msg->args[0])) {
|
||||
abort(500, '参数有误,请携带订阅地址发送');
|
||||
}
|
||||
$subscribeUrl = $msg->args[0];
|
||||
$subscribeUrl = parse_url($subscribeUrl);
|
||||
parse_str($subscribeUrl['query'], $query);
|
||||
$token = $query['token'];
|
||||
if (!$token) {
|
||||
abort(500, '订阅地址无效');
|
||||
}
|
||||
$user = User::where('token', $token)->first();
|
||||
if (!$user) {
|
||||
abort(500, '用户不存在');
|
||||
}
|
||||
if ($user->telegram_id) {
|
||||
abort(500, '该账号已经绑定了Telegram账号');
|
||||
}
|
||||
$user->telegram_id = $msg->chat_id;
|
||||
if (!$user->save()) {
|
||||
abort(500, '设置失败');
|
||||
}
|
||||
$telegramService = new TelegramService();
|
||||
$telegramService->sendMessage($msg->chat_id, '绑定成功');
|
||||
}
|
||||
|
||||
private function unbind()
|
||||
{
|
||||
$msg = $this->msg;
|
||||
if (!$msg->is_private) return;
|
||||
$user = User::where('telegram_id', $msg->chat_id)->first();
|
||||
$telegramService = new TelegramService();
|
||||
if (!$user) {
|
||||
$this->help();
|
||||
$telegramService->sendMessage($msg->chat_id, '没有查询到您的用户信息,请先绑定账号', 'markdown');
|
||||
return;
|
||||
}
|
||||
$user->telegram_id = NULL;
|
||||
if (!$user->save()) {
|
||||
abort(500, '解绑失败');
|
||||
}
|
||||
$telegramService->sendMessage($msg->chat_id, '解绑成功', 'markdown');
|
||||
}
|
||||
|
||||
private function help()
|
||||
{
|
||||
$msg = $this->msg;
|
||||
if (!$msg->is_private) return;
|
||||
$telegramService = new TelegramService();
|
||||
$commands = [
|
||||
'/bind 订阅地址 - 绑定你的' . config('v2board.app_name', 'V2Board') . '账号',
|
||||
'/traffic - 查询流量信息',
|
||||
'/getlatesturl - 获取最新的' . config('v2board.app_name', 'V2Board') . '网址',
|
||||
'/unbind - 解除绑定'
|
||||
];
|
||||
$text = implode(PHP_EOL, $commands);
|
||||
$telegramService->sendMessage($msg->chat_id, "你可以使用以下命令进行操作:\n\n$text", 'markdown');
|
||||
}
|
||||
|
||||
private function traffic()
|
||||
{
|
||||
$msg = $this->msg;
|
||||
if (!$msg->is_private) return;
|
||||
$user = User::where('telegram_id', $msg->chat_id)->first();
|
||||
$telegramService = new TelegramService();
|
||||
if (!$user) {
|
||||
$this->help();
|
||||
$telegramService->sendMessage($msg->chat_id, '没有查询到您的用户信息,请先绑定账号', 'markdown');
|
||||
return;
|
||||
}
|
||||
$transferEnable = Helper::trafficConvert($user->transfer_enable);
|
||||
$up = Helper::trafficConvert($user->u);
|
||||
$down = Helper::trafficConvert($user->d);
|
||||
$remaining = Helper::trafficConvert($user->transfer_enable - ($user->u + $user->d));
|
||||
$text = "🚥流量查询\n———————————————\n计划流量:`{$transferEnable}`\n已用上行:`{$up}`\n已用下行:`{$down}`\n剩余流量:`{$remaining}`";
|
||||
$telegramService->sendMessage($msg->chat_id, $text, 'markdown');
|
||||
}
|
||||
|
||||
private function getLatestUrl()
|
||||
{
|
||||
$msg = $this->msg;
|
||||
$user = User::where('telegram_id', $msg->chat_id)->first();
|
||||
$telegramService = new TelegramService();
|
||||
$text = sprintf(
|
||||
"%s的最新网址是:%s",
|
||||
config('v2board.app_name', 'V2Board'),
|
||||
config('v2board.app_url')
|
||||
);
|
||||
$telegramService->sendMessage($msg->chat_id, $text, 'markdown');
|
||||
}
|
||||
|
||||
private function replayTicket($ticketId)
|
||||
{
|
||||
$msg = $this->msg;
|
||||
if (!$msg->is_private) return;
|
||||
$user = User::where('telegram_id', $msg->chat_id)->first();
|
||||
if (!$user) {
|
||||
abort(500, '用户不存在');
|
||||
}
|
||||
$ticketService = new TicketService();
|
||||
if ($user->is_admin || $user->is_staff) {
|
||||
$ticketService->replyByAdmin(
|
||||
$ticketId,
|
||||
$msg->text,
|
||||
$user->id
|
||||
);
|
||||
}
|
||||
$telegramService = new TelegramService();
|
||||
$telegramService->sendMessage($msg->chat_id, "#`{$ticketId}` 的工单已回复成功", 'markdown');
|
||||
$telegramService->sendMessageWithAdmin("#`{$ticketId}` 的工单已由 {$user->email} 进行回复", true);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -34,6 +34,7 @@ class DeepbworkController extends Controller
|
||||
// 后端获取用户
|
||||
public function user(Request $request)
|
||||
{
|
||||
ini_set('memory_limit', -1);
|
||||
$nodeId = $request->input('node_id');
|
||||
$server = ServerV2ray::find($nodeId);
|
||||
if (!$server) {
|
||||
@ -47,7 +48,7 @@ class DeepbworkController extends Controller
|
||||
$user->v2ray_user = [
|
||||
"uuid" => $user->uuid,
|
||||
"email" => sprintf("%s@v2board.user", $user->uuid),
|
||||
"alter_id" => $server->alter_id,
|
||||
"alter_id" => 0,
|
||||
"level" => 0,
|
||||
];
|
||||
unset($user['uuid']);
|
||||
|
@ -30,6 +30,7 @@ class ShadowsocksTidalabController extends Controller
|
||||
// 后端获取用户
|
||||
public function user(Request $request)
|
||||
{
|
||||
ini_set('memory_limit', -1);
|
||||
$nodeId = $request->input('node_id');
|
||||
$server = ServerShadowsocks::find($nodeId);
|
||||
if (!$server) {
|
||||
|
@ -34,6 +34,7 @@ class TrojanTidalabController extends Controller
|
||||
// 后端获取用户
|
||||
public function user(Request $request)
|
||||
{
|
||||
ini_set('memory_limit', -1);
|
||||
$nodeId = $request->input('node_id');
|
||||
$server = ServerTrojan::find($nodeId);
|
||||
if (!$server) {
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace App\Http\Controllers\User;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\CommissionLog;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\User;
|
||||
use App\Models\Order;
|
||||
@ -27,15 +28,13 @@ class InviteController extends Controller
|
||||
public function details(Request $request)
|
||||
{
|
||||
return response([
|
||||
'data' => Order::where('invite_user_id', $request->session()->get('id'))
|
||||
->where('commission_balance', '>', 0)
|
||||
->whereIn('status', [3, 4])
|
||||
'data' => CommissionLog::where('invite_user_id', $request->session()->get('id'))
|
||||
->select([
|
||||
'id',
|
||||
'commission_status',
|
||||
'commission_balance',
|
||||
'created_at',
|
||||
'updated_at'
|
||||
'trade_no',
|
||||
'order_amount',
|
||||
'get_amount',
|
||||
'created_at'
|
||||
])
|
||||
->get()
|
||||
]);
|
||||
|
@ -13,7 +13,8 @@ class NoticeController extends Controller
|
||||
{
|
||||
$current = $request->input('current') ? $request->input('current') : 1;
|
||||
$pageSize = 5;
|
||||
$model = Notice::orderBy('created_at', 'DESC');
|
||||
$model = Notice::orderBy('created_at', 'DESC')
|
||||
->where('show', 1);
|
||||
$total = $model->count();
|
||||
$res = $model->forPage($current, $pageSize)
|
||||
->get();
|
||||
|
@ -4,6 +4,7 @@ namespace App\Http\Controllers\User;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\User\OrderSave;
|
||||
use App\Models\CommissionLog;
|
||||
use App\Models\Payment;
|
||||
use App\Services\CouponService;
|
||||
use App\Services\OrderService;
|
||||
@ -46,7 +47,7 @@ class OrderController extends Controller
|
||||
]);
|
||||
}
|
||||
|
||||
public function details(Request $request)
|
||||
public function detail(Request $request)
|
||||
{
|
||||
$order = Order::where('user_id', $request->session()->get('id'))
|
||||
->where('trade_no', $request->input('trade_no'))
|
||||
@ -59,6 +60,9 @@ class OrderController extends Controller
|
||||
if (!$order['plan']) {
|
||||
abort(500, __('Subscription plan does not exist'));
|
||||
}
|
||||
if ($order->surplus_order_ids) {
|
||||
$order['surplus_orders'] = Order::whereIn('id', $order->surplus_order_ids)->get();
|
||||
}
|
||||
return response([
|
||||
'data' => $order
|
||||
]);
|
||||
|
@ -13,6 +13,7 @@ use App\Models\ServerLog;
|
||||
use App\Models\User;
|
||||
|
||||
use App\Utils\Helper;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class ServerController extends Controller
|
||||
{
|
||||
@ -29,30 +30,4 @@ class ServerController extends Controller
|
||||
'data' => $servers
|
||||
]);
|
||||
}
|
||||
|
||||
public function logFetch(Request $request)
|
||||
{
|
||||
$type = $request->input('type') ? $request->input('type') : 0;
|
||||
$current = $request->input('current') ? $request->input('current') : 1;
|
||||
$pageSize = $request->input('pageSize') >= 10 ? $request->input('pageSize') : 10;
|
||||
$serverLogModel = ServerLog::where('user_id', $request->session()->get('id'))
|
||||
->orderBy('log_at', 'DESC');
|
||||
switch ($type) {
|
||||
case 0:
|
||||
$serverLogModel->where('log_at', '>=', strtotime(date('Y-m-d')));
|
||||
break;
|
||||
case 1:
|
||||
$serverLogModel->where('log_at', '>=', strtotime(date('Y-m-d')) - 604800);
|
||||
break;
|
||||
case 2:
|
||||
$serverLogModel->where('log_at', '>=', strtotime(date('Y-m-1')));
|
||||
}
|
||||
$total = $serverLogModel->count();
|
||||
$res = $serverLogModel->forPage($current, $pageSize)
|
||||
->get();
|
||||
return response([
|
||||
'data' => $res,
|
||||
'total' => $total
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
29
app/Http/Controllers/User/StatController.php
Normal file
29
app/Http/Controllers/User/StatController.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\User;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\StatUser;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class StatController extends Controller
|
||||
{
|
||||
public function getTrafficLog(Request $request)
|
||||
{
|
||||
$builder = StatUser::select([
|
||||
DB::raw('sum(u) as u'),
|
||||
DB::raw('sum(d) as d'),
|
||||
'record_at',
|
||||
'user_id',
|
||||
'server_rate'
|
||||
])
|
||||
->where('user_id', $request->session()->get('id'))
|
||||
->where('record_at', '>=', strtotime(date('Y-m-1')))
|
||||
->groupBy('record_at', 'user_id', 'server_rate')
|
||||
->orderBy('record_at', 'DESC');
|
||||
return response([
|
||||
'data' => $builder->get()
|
||||
]);
|
||||
}
|
||||
}
|
@ -10,11 +10,9 @@ use App\Utils\CacheKey;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\User;
|
||||
use App\Models\Plan;
|
||||
use App\Models\ServerV2ray;
|
||||
use App\Models\Ticket;
|
||||
use App\Utils\Helper;
|
||||
use App\Models\Order;
|
||||
use App\Models\ServerLog;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class UserController extends Controller
|
||||
@ -195,10 +193,14 @@ class UserController extends Controller
|
||||
$today = date('d');
|
||||
$lastDay = date('d', strtotime('last day of +0 months'));
|
||||
|
||||
if ((int)config('v2board.reset_traffic_method') === 0) {
|
||||
if ((int)config('v2board.reset_traffic_method') === 0 ||
|
||||
(isset($user->plan->reset_traffic_method) && $user->plan->reset_traffic_method === 0))
|
||||
{
|
||||
return $lastDay - $today;
|
||||
}
|
||||
if ((int)config('v2board.reset_traffic_method') === 1) {
|
||||
if ((int)config('v2board.reset_traffic_method') === 1 ||
|
||||
(isset($user->plan->reset_traffic_method) && $user->plan->reset_traffic_method === 1))
|
||||
{
|
||||
if ((int)$day >= (int)$today && (int)$day >= (int)$lastDay) {
|
||||
return $lastDay - $today;
|
||||
}
|
||||
|
@ -24,7 +24,6 @@ class ServerV2raySave extends FormRequest
|
||||
'tls' => 'required',
|
||||
'tags' => 'nullable|array',
|
||||
'rate' => 'required|numeric',
|
||||
'alter_id' => 'required|integer',
|
||||
'network' => 'required|in:tcp,kcp,ws,http,domainsocket,quic,grpc',
|
||||
'networkSettings' => 'nullable|array',
|
||||
'ruleSettings' => 'nullable|array',
|
||||
|
@ -68,6 +68,7 @@ class AdminRoute
|
||||
$router->post('/order/assign', 'Admin\\OrderController@assign');
|
||||
$router->post('/order/paid', 'Admin\\OrderController@paid');
|
||||
$router->post('/order/cancel', 'Admin\\OrderController@cancel');
|
||||
$router->post('/order/detail', 'Admin\\OrderController@detail');
|
||||
// User
|
||||
$router->get ('/user/fetch', 'Admin\\UserController@fetch');
|
||||
$router->post('/user/update', 'Admin\\UserController@update');
|
||||
@ -87,6 +88,7 @@ class AdminRoute
|
||||
$router->post('/notice/save', 'Admin\\NoticeController@save');
|
||||
$router->post('/notice/update', 'Admin\\NoticeController@update');
|
||||
$router->post('/notice/drop', 'Admin\\NoticeController@drop');
|
||||
$router->post('/notice/show', 'Admin\\NoticeController@show');
|
||||
// Ticket
|
||||
$router->get ('/ticket/fetch', 'Admin\\TicketController@fetch');
|
||||
$router->post('/ticket/reply', 'Admin\\TicketController@reply');
|
||||
@ -95,6 +97,7 @@ class AdminRoute
|
||||
$router->get ('/coupon/fetch', 'Admin\\CouponController@fetch');
|
||||
$router->post('/coupon/generate', 'Admin\\CouponController@generate');
|
||||
$router->post('/coupon/drop', 'Admin\\CouponController@drop');
|
||||
$router->post('/coupon/show', 'Admin\\CouponController@show');
|
||||
// Knowledge
|
||||
$router->get ('/knowledge/fetch', 'Admin\\KnowledgeController@fetch');
|
||||
$router->get ('/knowledge/getCategory', 'Admin\\KnowledgeController@getCategory');
|
||||
@ -108,6 +111,8 @@ class AdminRoute
|
||||
$router->post('/payment/getPaymentForm', 'Admin\\PaymentController@getPaymentForm');
|
||||
$router->post('/payment/save', 'Admin\\PaymentController@save');
|
||||
$router->post('/payment/drop', 'Admin\\PaymentController@drop');
|
||||
// System
|
||||
$router->get ('/system/getStatus', 'Admin\\SystemController@getStatus');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ class GuestRoute
|
||||
$router->match(['get', 'post'], '/payment/notify/{method}/{uuid}', 'Guest\\PaymentController@notify');
|
||||
// Comm
|
||||
$router->get ('/comm/config', 'Guest\\CommController@config');
|
||||
$router->get ('/comm/getHitokoto', 'Guest\\CommController@getHitokoto');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,10 @@ class UserRoute
|
||||
$router->post('/order/save', 'User\\OrderController@save');
|
||||
$router->post('/order/checkout', 'User\\OrderController@checkout');
|
||||
$router->get ('/order/check', 'User\\OrderController@check');
|
||||
$router->get ('/order/details', 'User\\OrderController@details');
|
||||
// TODO: 1.5.6 remove
|
||||
$router->get ('/order/details', 'User\\OrderController@detail');
|
||||
// TODO: 1.5.6 remove
|
||||
$router->get ('/order/detail', 'User\\OrderController@detail');
|
||||
$router->get ('/order/fetch', 'User\\OrderController@fetch');
|
||||
$router->get ('/order/getPaymentMethod', 'User\\OrderController@getPaymentMethod');
|
||||
$router->post('/order/cancel', 'User\\OrderController@cancel');
|
||||
@ -45,7 +48,6 @@ class UserRoute
|
||||
$router->post('/ticket/withdraw', 'User\\TicketController@withdraw');
|
||||
// Server
|
||||
$router->get ('/server/fetch', 'User\\ServerController@fetch');
|
||||
$router->get ('/server/log/fetch', 'User\\ServerController@logFetch');
|
||||
// Coupon
|
||||
$router->post('/coupon/check', 'User\\CouponController@check');
|
||||
// Telegram
|
||||
@ -56,6 +58,8 @@ class UserRoute
|
||||
// Knowledge
|
||||
$router->get ('/knowledge/fetch', 'User\\KnowledgeController@fetch');
|
||||
$router->get ('/knowledge/getCategory', 'User\\KnowledgeController@getCategory');
|
||||
// Stat
|
||||
$router->get ('/stat/getTrafficLog', 'User\\StatController@getTrafficLog');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -1,58 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Services\ServerService;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class ServerLogJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
protected $u;
|
||||
protected $d;
|
||||
protected $userId;
|
||||
protected $server;
|
||||
protected $protocol;
|
||||
|
||||
public $tries = 3;
|
||||
public $timeout = 3;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($u, $d, $userId, $server, $protocol)
|
||||
{
|
||||
$this->onQueue('server_log');
|
||||
$this->u = $u;
|
||||
$this->d = $d;
|
||||
$this->userId = $userId;
|
||||
$this->server = $server;
|
||||
$this->protocol = $protocol;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$serverService = new ServerService();
|
||||
if (!$serverService->log(
|
||||
$this->userId,
|
||||
$this->server->id,
|
||||
$this->u,
|
||||
$this->d,
|
||||
$this->server->rate,
|
||||
$this->protocol
|
||||
)) {
|
||||
throw new \Exception('日志记录失败');
|
||||
}
|
||||
}
|
||||
}
|
@ -12,20 +12,28 @@ use Illuminate\Queue\SerializesModels;
|
||||
class StatServerJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
protected $statistic;
|
||||
protected $u;
|
||||
protected $d;
|
||||
protected $server;
|
||||
protected $protocol;
|
||||
protected $recordType;
|
||||
|
||||
public $tries = 3;
|
||||
public $timeout = 5;
|
||||
public $timeout = 60;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $statistic)
|
||||
public function __construct($u, $d, $server, $protocol, $recordType = 'd')
|
||||
{
|
||||
$this->onQueue('stat_server');
|
||||
$this->statistic = $statistic;
|
||||
$this->onQueue('stat');
|
||||
$this->u = $u;
|
||||
$this->d = $d;
|
||||
$this->server = $server;
|
||||
$this->protocol = $protocol;
|
||||
$this->recordType = $recordType;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -35,18 +43,33 @@ class StatServerJob implements ShouldQueue
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$statistic = $this->statistic;
|
||||
$data = StatServer::where('record_at', $statistic['record_at'])
|
||||
->where('server_id', $statistic['server_id'])
|
||||
$recordAt = strtotime(date('Y-m-d'));
|
||||
if ($this->recordType === 'm') {
|
||||
//
|
||||
}
|
||||
|
||||
$data = StatServer::where('record_at', $recordAt)
|
||||
->where('server_id', $this->server->id)
|
||||
->lockForUpdate()
|
||||
->first();
|
||||
if ($data) {
|
||||
try {
|
||||
$data->update($statistic);
|
||||
$data->update([
|
||||
'u' => $data['u'] + $this->u,
|
||||
'd' => $data['d'] + $this->d
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
abort(500, '节点统计数据更新失败');
|
||||
}
|
||||
} else {
|
||||
if (!StatServer::create($statistic)) {
|
||||
if (!StatServer::create([
|
||||
'server_id' => $this->server->id,
|
||||
'server_type' => $this->protocol,
|
||||
'u' => $this->u,
|
||||
'd' => $this->d,
|
||||
'record_type' => $this->recordType,
|
||||
'record_at' => $recordAt
|
||||
])) {
|
||||
abort(500, '节点统计数据创建失败');
|
||||
}
|
||||
}
|
||||
|
82
app/Jobs/StatUserJob.php
Normal file
82
app/Jobs/StatUserJob.php
Normal file
@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs;
|
||||
|
||||
use App\Models\StatServer;
|
||||
use App\Models\StatUser;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class StatUserJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
protected $u;
|
||||
protected $d;
|
||||
protected $userId;
|
||||
protected $server;
|
||||
protected $protocol;
|
||||
protected $recordType;
|
||||
|
||||
public $tries = 3;
|
||||
public $timeout = 60;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($u, $d, $userId, $server, $protocol, $recordType = 'd')
|
||||
{
|
||||
$this->onQueue('stat');
|
||||
$this->u = $u;
|
||||
$this->d = $d;
|
||||
$this->userId = $userId;
|
||||
$this->server = $server;
|
||||
$this->protocol = $protocol;
|
||||
$this->recordType = $recordType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$recordAt = strtotime(date('Y-m-d'));
|
||||
if ($this->recordType === 'm') {
|
||||
//
|
||||
}
|
||||
|
||||
$data = StatUser::where('record_at', $recordAt)
|
||||
->where('server_id', $this->server->id)
|
||||
->where('user_id', $this->userId)
|
||||
->first();
|
||||
if ($data) {
|
||||
try {
|
||||
$data->update([
|
||||
'u' => $data['u'] + $this->u,
|
||||
'd' => $data['d'] + $this->d
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
abort(500, '用户统计数据更新失败');
|
||||
}
|
||||
} else {
|
||||
if (!StatUser::create([
|
||||
'user_id' => $this->userId,
|
||||
'server_id' => $this->server->id,
|
||||
'server_type' => $this->protocol,
|
||||
'server_rate' => $this->server->rate,
|
||||
'u' => $this->u,
|
||||
'd' => $this->d,
|
||||
'record_type' => $this->recordType,
|
||||
'record_at' => $recordAt
|
||||
])) {
|
||||
abort(500, '用户统计数据创建失败');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
16
app/Models/StatUser.php
Normal file
16
app/Models/StatUser.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class StatUser extends Model
|
||||
{
|
||||
protected $table = 'v2_stat_user';
|
||||
protected $dateFormat = 'U';
|
||||
protected $guarded = ['id'];
|
||||
protected $casts = [
|
||||
'created_at' => 'timestamp',
|
||||
'updated_at' => 'timestamp'
|
||||
];
|
||||
}
|
@ -5,8 +5,6 @@
|
||||
*/
|
||||
namespace App\Payments;
|
||||
|
||||
use Omnipay\Omnipay;
|
||||
|
||||
class AlipayF2F {
|
||||
public function __construct($config)
|
||||
{
|
||||
@ -36,43 +34,36 @@ class AlipayF2F {
|
||||
|
||||
public function pay($order)
|
||||
{
|
||||
$gateway = Omnipay::create('Alipay_AopF2F');
|
||||
$gateway->setSignType('RSA2'); //RSA/RSA2
|
||||
$gateway->setAppId($this->config['app_id']);
|
||||
$gateway->setPrivateKey($this->config['private_key']); // 可以是路径,也可以是密钥内容
|
||||
$gateway->setAlipayPublicKey($this->config['public_key']); // 可以是路径,也可以是密钥内容
|
||||
$gateway->setNotifyUrl($order['notify_url']);
|
||||
$request = $gateway->purchase();
|
||||
$request->setBizContent([
|
||||
'subject' => config('v2board.app_name', 'V2Board') . ' - 订阅',
|
||||
'out_trade_no' => $order['trade_no'],
|
||||
'total_amount' => $order['total_amount'] / 100
|
||||
]);
|
||||
/** @var \Omnipay\Alipay\Responses\AopTradePreCreateResponse $response */
|
||||
$response = $request->send();
|
||||
$result = $response->getAlipayResponse();
|
||||
if ($result['code'] !== '10000') {
|
||||
abort(500, $result['sub_msg']);
|
||||
try {
|
||||
$gateway = new \Library\AlipayF2F();
|
||||
$gateway->setMethod('alipay.trade.precreate');
|
||||
$gateway->setAppId($this->config['app_id']);
|
||||
$gateway->setPrivateKey($this->config['private_key']); // 可以是路径,也可以是密钥内容
|
||||
$gateway->setAlipayPublicKey($this->config['public_key']); // 可以是路径,也可以是密钥内容
|
||||
$gateway->setNotifyUrl($order['notify_url']);
|
||||
$gateway->setBizContent([
|
||||
'subject' => config('v2board.app_name', 'V2Board') . ' - 订阅',
|
||||
'out_trade_no' => $order['trade_no'],
|
||||
'total_amount' => $order['total_amount'] / 100
|
||||
]);
|
||||
$gateway->send();
|
||||
return [
|
||||
'type' => 0, // 0:qrcode 1:url
|
||||
'data' => $gateway->getQrCodeUrl()
|
||||
];
|
||||
} catch (\Exception $e) {
|
||||
abort(500, $e->getMessage());
|
||||
}
|
||||
return [
|
||||
'type' => 0, // 0:qrcode 1:url
|
||||
'data' => $response->getQrCode()
|
||||
];
|
||||
}
|
||||
|
||||
public function notify($params)
|
||||
{
|
||||
$gateway = Omnipay::create('Alipay_AopF2F');
|
||||
$gateway->setSignType('RSA2'); //RSA/RSA2
|
||||
$gateway = new \Library\AlipayF2F();
|
||||
$gateway->setAppId($this->config['app_id']);
|
||||
$gateway->setPrivateKey($this->config['private_key']); // 可以是路径,也可以是密钥内容
|
||||
$gateway->setAlipayPublicKey($this->config['public_key']); // 可以是路径,也可以是密钥内容
|
||||
$request = $gateway->completePurchase();
|
||||
$request->setParams($_POST); //Optional
|
||||
try {
|
||||
/** @var \Omnipay\Alipay\Responses\AopCompletePurchaseResponse $response */
|
||||
$response = $request->send();
|
||||
if ($response->isPaid()) {
|
||||
if ($gateway->verify($params)) {
|
||||
/**
|
||||
* Payment is successful
|
||||
*/
|
||||
|
148
app/Payments/BTCPay.php
Normal file
148
app/Payments/BTCPay.php
Normal file
@ -0,0 +1,148 @@
|
||||
<?php
|
||||
|
||||
namespace App\Payments;
|
||||
|
||||
|
||||
class BTCPay {
|
||||
public function __construct($config) {
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
public function form()
|
||||
{
|
||||
return [
|
||||
'btcpay_url' => [
|
||||
'label' => 'API接口所在网址(包含最后的斜杠)',
|
||||
'description' => '',
|
||||
'type' => 'input',
|
||||
],
|
||||
'btcpay_storeId' => [
|
||||
'label' => 'storeId',
|
||||
'description' => '',
|
||||
'type' => 'input',
|
||||
],
|
||||
'btcpay_api_key' => [
|
||||
'label' => 'API KEY',
|
||||
'description' => '个人设置中的API KEY(非商店设置中的)',
|
||||
'type' => 'input',
|
||||
],
|
||||
'btcpay_webhook_key' => [
|
||||
'label' => 'WEBHOOK KEY',
|
||||
'description' => '',
|
||||
'type' => 'input',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function pay($order) {
|
||||
|
||||
$params = [
|
||||
'jsonResponse' => true,
|
||||
'amount' => sprintf('%.2f', $order['total_amount'] / 100),
|
||||
'currency' => 'CNY',
|
||||
'metadata' => [
|
||||
'orderId' => $order['trade_no']
|
||||
]
|
||||
];
|
||||
|
||||
$params_string = @json_encode($params);
|
||||
|
||||
$ret_raw = self::_curlPost($this->config['btcpay_url'] . 'api/v1/stores/' . $this->config['btcpay_storeId'] . '/invoices', $params_string);
|
||||
|
||||
$ret = @json_decode($ret_raw, true);
|
||||
|
||||
if(empty($ret['checkoutLink'])) {
|
||||
abort(500, "error!");
|
||||
}
|
||||
return [
|
||||
'type' => 1, // Redirect to url
|
||||
'data' => $ret['checkoutLink'],
|
||||
];
|
||||
}
|
||||
|
||||
public function notify($params) {
|
||||
$payload = trim(file_get_contents('php://input'));
|
||||
|
||||
$headers = getallheaders();
|
||||
|
||||
//IS Btcpay-Sig
|
||||
//NOT BTCPay-Sig
|
||||
//API doc is WRONG!
|
||||
$headerName = 'Btcpay-Sig';
|
||||
$signraturHeader = isset($headers[$headerName]) ? $headers[$headerName] : '';
|
||||
$json_param = json_decode($payload, true);
|
||||
|
||||
$computedSignature = "sha256=" . \hash_hmac('sha256', $payload, $this->config['btcpay_webhook_key']);
|
||||
|
||||
if (!self::hashEqual($signraturHeader, $computedSignature)) {
|
||||
abort(400, 'HMAC signature does not match');
|
||||
return false;
|
||||
}
|
||||
|
||||
//get order id store in metadata
|
||||
$context = stream_context_create(array(
|
||||
'http' => array(
|
||||
'method' => 'GET',
|
||||
'header' => "Authorization:" . "token " . $this->config['btcpay_api_key'] . "\r\n"
|
||||
)
|
||||
));
|
||||
|
||||
$invoiceDetail = file_get_contents($this->config['btcpay_url'] . 'api/v1/stores/' . $this->config['btcpay_storeId'] . '/invoices/' . $json_param['invoiceId'], false, $context);
|
||||
$invoiceDetail = json_decode($invoiceDetail, true);
|
||||
|
||||
|
||||
$out_trade_no = $invoiceDetail['metadata']["orderId"];
|
||||
$pay_trade_no=$json_param['invoiceId'];
|
||||
return [
|
||||
'trade_no' => $out_trade_no,
|
||||
'callback_no' => $pay_trade_no
|
||||
];
|
||||
http_response_code(200);
|
||||
die('success');
|
||||
}
|
||||
|
||||
|
||||
private function _curlPost($url,$params=false){
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_HEADER, 0);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 300);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
|
||||
curl_setopt(
|
||||
$ch, CURLOPT_HTTPHEADER, array('Authorization:' .'token '.$this->config['btcpay_api_key'], 'Content-Type: application/json')
|
||||
);
|
||||
$result = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $str1
|
||||
* @param string $str2
|
||||
* @return bool
|
||||
*/
|
||||
private function hashEqual($str1, $str2)
|
||||
{
|
||||
|
||||
if (function_exists('hash_equals')) {
|
||||
return \hash_equals($str1, $str2);
|
||||
}
|
||||
|
||||
if (strlen($str1) != strlen($str2)) {
|
||||
return false;
|
||||
} else {
|
||||
$res = $str1 ^ $str2;
|
||||
$ret = 0;
|
||||
|
||||
for ($i = strlen($res) - 1; $i >= 0; $i--) {
|
||||
$ret |= ord($res[$i]);
|
||||
}
|
||||
return !$ret;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
107
app/Payments/CoinPayments.php
Normal file
107
app/Payments/CoinPayments.php
Normal file
@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
namespace App\Payments;
|
||||
|
||||
class CoinPayments {
|
||||
public function __construct($config) {
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
public function form()
|
||||
{
|
||||
return [
|
||||
'coinpayments_merchant_id' => [
|
||||
'label' => 'Merchant ID',
|
||||
'description' => '商户 ID,填写您在 Account Settings 中得到的 ID',
|
||||
'type' => 'input',
|
||||
],
|
||||
'coinpayments_ipn_secret' => [
|
||||
'label' => 'IPN Secret',
|
||||
'description' => '通知密钥,填写您在 Merchant Settings 中自行设置的值',
|
||||
'type' => 'input',
|
||||
],
|
||||
'coinpayments_currency' => [
|
||||
'label' => '货币代码',
|
||||
'description' => '填写您的货币代码(大写),建议与 Merchant Settings 中的值相同',
|
||||
'type' => 'input',
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
public function pay($order) {
|
||||
|
||||
// IPN notifications are slow, when the transaction is successful, we should return to the user center to avoid user confusion
|
||||
$parseUrl = parse_url($order['return_url']);
|
||||
$port = isset($parseUrl['port']) ? ":{$parseUrl['port']}" : '';
|
||||
$successUrl = "{$parseUrl['scheme']}://{$parseUrl['host']}{$port}";
|
||||
|
||||
$params = [
|
||||
'cmd' => '_pay_simple',
|
||||
'reset' => 1,
|
||||
'merchant' => $this->config['coinpayments_merchant_id'],
|
||||
'item_name' => $order['trade_no'],
|
||||
'item_number' => $order['trade_no'],
|
||||
'want_shipping' => 0,
|
||||
'currency' => $this->config['coinpayments_currency'],
|
||||
'amountf' => sprintf('%.2f', $order['total_amount'] / 100),
|
||||
'success_url' => $successUrl,
|
||||
'cancel_url' => $order['return_url'],
|
||||
'ipn_url' => $order['notify_url']
|
||||
];
|
||||
|
||||
$params_string = http_build_query($params);
|
||||
|
||||
return [
|
||||
'type' => 1, // Redirect to url
|
||||
'data' => 'https://www.coinpayments.net/index.php?' . $params_string,
|
||||
'custom_result' => 'IPN OK'
|
||||
];
|
||||
}
|
||||
|
||||
public function notify($params) {
|
||||
|
||||
if (!isset($params['merchant']) || $params['merchant'] != trim($this->config['coinpayments_merchant_id'])) {
|
||||
abort(500, 'No or incorrect Merchant ID passed');
|
||||
}
|
||||
|
||||
$headers = getallheaders();
|
||||
|
||||
ksort($params);
|
||||
reset($params);
|
||||
$request = stripslashes(http_build_query($params));
|
||||
|
||||
$headerName = 'Hmac';
|
||||
$signHeader = isset($headers[$headerName]) ? $headers[$headerName] : '';
|
||||
|
||||
$hmac = hash_hmac("sha512", $request, trim($this->config['coinpayments_ipn_secret']));
|
||||
|
||||
// if (!hash_equals($hmac, $signHeader)) {
|
||||
// if ($hmac != $_SERVER['HTTP_HMAC']) { <-- Use this if you are running a version of PHP below 5.6.0 without the hash_equals function
|
||||
// $this->dieSendMessage(400, 'HMAC signature does not match');
|
||||
// }
|
||||
|
||||
if ($hmac != $signHeader) {
|
||||
abort(400, 'HMAC signature does not match');
|
||||
}
|
||||
|
||||
// HMAC Signature verified at this point, load some variables.
|
||||
|
||||
$status = $params['status'];
|
||||
|
||||
if ($status >= 100 || $status == 2) {
|
||||
// payment is complete or queued for nightly payout, success
|
||||
return [
|
||||
'trade_no' => $params['item_number'],
|
||||
'callback_no' => $params['txn_id']
|
||||
];
|
||||
} else if ($status < 0) {
|
||||
//payment error, this is usually final but payments will sometimes be reopened if there was no exchange rate conversion or with seller consent
|
||||
abort(500, 'Payment Timed Out or Error');
|
||||
} else {
|
||||
//payment is pending, you can optionally add a note to the order page
|
||||
die('IPN OK: pending');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
129
app/Payments/Coinbase.php
Normal file
129
app/Payments/Coinbase.php
Normal file
@ -0,0 +1,129 @@
|
||||
<?php
|
||||
|
||||
namespace App\Payments;
|
||||
|
||||
class Coinbase {
|
||||
public function __construct($config) {
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
public function form()
|
||||
{
|
||||
return [
|
||||
'coinbase_url' => [
|
||||
'label' => '接口地址',
|
||||
'description' => '',
|
||||
'type' => 'input',
|
||||
],
|
||||
'coinbase_api_key' => [
|
||||
'label' => 'API KEY',
|
||||
'description' => '',
|
||||
'type' => 'input',
|
||||
],
|
||||
'coinbase_webhook_key' => [
|
||||
'label' => 'WEBHOOK KEY',
|
||||
'description' => '',
|
||||
'type' => 'input',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function pay($order) {
|
||||
|
||||
$params = [
|
||||
'name' => '订阅套餐',
|
||||
'description' => '订单号 ' . $order['trade_no'],
|
||||
'pricing_type' => 'fixed_price',
|
||||
'local_price' => [
|
||||
'amount' => sprintf('%.2f', $order['total_amount'] / 100),
|
||||
'currency' => 'CNY'
|
||||
],
|
||||
'metadata' => [
|
||||
"outTradeNo" => $order['trade_no'],
|
||||
],
|
||||
];
|
||||
|
||||
$params_string = http_build_query($params);
|
||||
|
||||
$ret_raw = self::_curlPost($this->config['coinbase_url'], $params_string);
|
||||
|
||||
$ret = @json_decode($ret_raw, true);
|
||||
|
||||
if(empty($ret['data']['hosted_url'])) {
|
||||
abort(500, "error!");
|
||||
}
|
||||
return [
|
||||
'type' => 1,
|
||||
'data' => $ret['data']['hosted_url'],
|
||||
];
|
||||
}
|
||||
|
||||
public function notify($params) {
|
||||
|
||||
$payload = trim(file_get_contents('php://input'));
|
||||
$json_param = json_decode($payload, true);
|
||||
|
||||
|
||||
$headerName = 'X-Cc-Webhook-Signature';
|
||||
$headers = getallheaders();
|
||||
$signatureHeader = isset($headers[$headerName]) ? $headers[$headerName] : '';
|
||||
$computedSignature = \hash_hmac('sha256', $payload, $this->config['coinbase_webhook_key']);
|
||||
|
||||
if (!self::hashEqual($signatureHeader, $computedSignature)) {
|
||||
abort(400, 'HMAC signature does not match');
|
||||
}
|
||||
|
||||
$out_trade_no = $json_param['event']['data']['metadata']['outTradeNo'];
|
||||
$pay_trade_no=$json_param['event']['id'];
|
||||
return [
|
||||
'trade_no' => $out_trade_no,
|
||||
'callback_no' => $pay_trade_no
|
||||
];
|
||||
http_response_code(200);
|
||||
die('success');
|
||||
}
|
||||
|
||||
|
||||
private function _curlPost($url,$params=false){
|
||||
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_HEADER, 0);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
||||
curl_setopt($ch, CURLOPT_TIMEOUT, 300);
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
|
||||
curl_setopt(
|
||||
$ch, CURLOPT_HTTPHEADER, array('X-CC-Api-Key:' .$this->config['coinbase_api_key'], 'X-CC-Version: 2018-03-22')
|
||||
);
|
||||
$result = curl_exec($ch);
|
||||
curl_close($ch);
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $str1
|
||||
* @param string $str2
|
||||
* @return bool
|
||||
*/
|
||||
public function hashEqual($str1, $str2)
|
||||
{
|
||||
if (function_exists('hash_equals')) {
|
||||
return \hash_equals($str1, $str2);
|
||||
}
|
||||
|
||||
if (strlen($str1) != strlen($str2)) {
|
||||
return false;
|
||||
} else {
|
||||
$res = $str1 ^ $str2;
|
||||
$ret = 0;
|
||||
|
||||
for ($i = strlen($res) - 1; $i >= 0; $i--) {
|
||||
$ret |= ord($res[$i]);
|
||||
}
|
||||
return !$ret;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -50,6 +50,7 @@ class MGate {
|
||||
$params['sign'] = md5($str);
|
||||
$curl = new Curl();
|
||||
$curl->setUserAgent('MGate');
|
||||
$curl->setOpt(CURLOPT_SSL_VERIFYPEER, 0);
|
||||
$curl->post($this->config['mgate_url'] . '/v1/gateway/fetch', http_build_query($params));
|
||||
$result = $curl->response;
|
||||
if (!$result) {
|
||||
|
@ -40,7 +40,7 @@ class StripeAlipay {
|
||||
$currency = $this->config['currency'];
|
||||
$exchange = $this->exchange('CNY', strtoupper($currency));
|
||||
if (!$exchange) {
|
||||
abort(500, __('user.order.stripeAlipay.currency_convert_timeout'));
|
||||
abort(500, __('Currency conversion has timed out, please try again later'));
|
||||
}
|
||||
Stripe::setApiKey($this->config['stripe_sk_live']);
|
||||
$source = Source::create([
|
||||
@ -58,7 +58,7 @@ class StripeAlipay {
|
||||
]
|
||||
]);
|
||||
if (!$source['redirect']['url']) {
|
||||
abort(500, __('user.order.stripeAlipay.gateway_request_failed'));
|
||||
abort(500, __('Payment gateway request failed'));
|
||||
}
|
||||
return [
|
||||
'type' => 1,
|
||||
|
@ -46,7 +46,7 @@ class StripeCredit {
|
||||
$currency = $this->config['currency'];
|
||||
$exchange = $this->exchange('CNY', strtoupper($currency));
|
||||
if (!$exchange) {
|
||||
abort(500, __('user.order.stripeCard.currency_convert_timeout'));
|
||||
abort(500, __('Currency conversion has timed out, please try again later'));
|
||||
}
|
||||
Stripe::setApiKey($this->config['stripe_sk_live']);
|
||||
try {
|
||||
@ -62,10 +62,10 @@ class StripeCredit {
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
info($e);
|
||||
abort(500, __('user.order.stripeCard.was_problem'));
|
||||
abort(500, __('Payment failed. Please check your credit card information'));
|
||||
}
|
||||
if (!$charge->paid) {
|
||||
abort(500, __('user.order.stripeCard.deduction_failed'));
|
||||
abort(500, __('Payment failed. Please check your credit card information'));
|
||||
}
|
||||
return [
|
||||
'type' => 2,
|
||||
|
@ -40,7 +40,7 @@ class StripeWepay {
|
||||
$currency = $this->config['currency'];
|
||||
$exchange = $this->exchange('CNY', strtoupper($currency));
|
||||
if (!$exchange) {
|
||||
abort(500, __('user.order.stripeAlipay.currency_convert_timeout'));
|
||||
abort(500, __('Currency conversion has timed out, please try again later'));
|
||||
}
|
||||
Stripe::setApiKey($this->config['stripe_sk_live']);
|
||||
$source = Source::create([
|
||||
@ -58,7 +58,7 @@ class StripeWepay {
|
||||
]
|
||||
]);
|
||||
if (!$source['wechat']['qr_code_url']) {
|
||||
abort(500, __('user.order.stripeWepay.gateway_request_failed'));
|
||||
abort(500, __('Payment gateway request failed'));
|
||||
}
|
||||
return [
|
||||
'type' => 0,
|
||||
|
@ -9,7 +9,6 @@ class WechatPayNative {
|
||||
public function __construct($config)
|
||||
{
|
||||
$this->config = $config;
|
||||
$this->customResult = '<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>';
|
||||
}
|
||||
|
||||
public function form()
|
||||
@ -57,7 +56,8 @@ class WechatPayNative {
|
||||
}
|
||||
return [
|
||||
'type' => 0,
|
||||
'data' => $response['code_url']
|
||||
'data' => $response['code_url'],
|
||||
'custom_result' => '<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>'
|
||||
];
|
||||
}
|
||||
|
||||
|
38
app/Plugins/Telegram/Commands/Bind.php
Normal file
38
app/Plugins/Telegram/Commands/Bind.php
Normal file
@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Plugins\Telegram\Commands;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Plugins\Telegram\Telegram;
|
||||
|
||||
class Bind extends Telegram {
|
||||
public $command = '/bind';
|
||||
public $description = '将Telegram账号绑定到网站';
|
||||
|
||||
public function handle($message, $match = []) {
|
||||
if (!$message->is_private) return;
|
||||
if (!isset($message->args[0])) {
|
||||
abort(500, '参数有误,请携带订阅地址发送');
|
||||
}
|
||||
$subscribeUrl = $message->args[0];
|
||||
$subscribeUrl = parse_url($subscribeUrl);
|
||||
parse_str($subscribeUrl['query'], $query);
|
||||
$token = $query['token'];
|
||||
if (!$token) {
|
||||
abort(500, '订阅地址无效');
|
||||
}
|
||||
$user = User::where('token', $token)->first();
|
||||
if (!$user) {
|
||||
abort(500, '用户不存在');
|
||||
}
|
||||
if ($user->telegram_id) {
|
||||
abort(500, '该账号已经绑定了Telegram账号');
|
||||
}
|
||||
$user->telegram_id = $message->chat_id;
|
||||
if (!$user->save()) {
|
||||
abort(500, '设置失败');
|
||||
}
|
||||
$telegramService = $this->telegramService;
|
||||
$telegramService->sendMessage($message->chat_id, '绑定成功');
|
||||
}
|
||||
}
|
21
app/Plugins/Telegram/Commands/GetLatestUrl.php
Normal file
21
app/Plugins/Telegram/Commands/GetLatestUrl.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Plugins\Telegram\Commands;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Plugins\Telegram\Telegram;
|
||||
|
||||
class GetLatestUrl extends Telegram {
|
||||
public $command = '/getlatesturl';
|
||||
public $description = '将Telegram账号绑定到网站';
|
||||
|
||||
public function handle($message, $match = []) {
|
||||
$telegramService = $this->telegramService;
|
||||
$text = sprintf(
|
||||
"%s的最新网址是:%s",
|
||||
config('v2board.app_name', 'V2Board'),
|
||||
config('v2board.app_url')
|
||||
);
|
||||
$telegramService->sendMessage($message->chat_id, $text, 'markdown');
|
||||
}
|
||||
}
|
37
app/Plugins/Telegram/Commands/ReplyTicket.php
Normal file
37
app/Plugins/Telegram/Commands/ReplyTicket.php
Normal file
@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace App\Plugins\Telegram\Commands;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Plugins\Telegram\Telegram;
|
||||
use App\Services\TicketService;
|
||||
|
||||
class ReplyTicket extends Telegram {
|
||||
public $regex = '/[#](.*)/';
|
||||
public $description = '快速工单回复';
|
||||
|
||||
public function handle($message, $match = []) {
|
||||
if (!$message->is_private) return;
|
||||
$this->replayTicket($message, $match[1]);
|
||||
}
|
||||
|
||||
|
||||
private function replayTicket($msg, $ticketId)
|
||||
{
|
||||
$user = User::where('telegram_id', $msg->chat_id)->first();
|
||||
if (!$user) {
|
||||
abort(500, '用户不存在');
|
||||
}
|
||||
if (!$msg->text) return;
|
||||
if (!($user->is_admin || $user->is_staff)) return;
|
||||
$ticketService = new TicketService();
|
||||
$ticketService->replyByAdmin(
|
||||
$ticketId,
|
||||
$msg->text,
|
||||
$user->id
|
||||
);
|
||||
$telegramService = $this->telegramService;
|
||||
$telegramService->sendMessage($msg->chat_id, "#`{$ticketId}` 的工单已回复成功", 'markdown');
|
||||
$telegramService->sendMessageWithAdmin("#`{$ticketId}` 的工单已由 {$user->email} 进行回复", true);
|
||||
}
|
||||
}
|
28
app/Plugins/Telegram/Commands/Traffic.php
Normal file
28
app/Plugins/Telegram/Commands/Traffic.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Plugins\Telegram\Commands;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Plugins\Telegram\Telegram;
|
||||
use App\Utils\Helper;
|
||||
|
||||
class Traffic extends Telegram {
|
||||
public $command = '/traffic';
|
||||
public $description = '查询流量信息';
|
||||
|
||||
public function handle($message, $match = []) {
|
||||
$telegramService = $this->telegramService;
|
||||
if (!$message->is_private) return;
|
||||
$user = User::where('telegram_id', $message->chat_id)->first();
|
||||
if (!$user) {
|
||||
$telegramService->sendMessage($message->chat_id, '没有查询到您的用户信息,请先绑定账号', 'markdown');
|
||||
return;
|
||||
}
|
||||
$transferEnable = Helper::trafficConvert($user->transfer_enable);
|
||||
$up = Helper::trafficConvert($user->u);
|
||||
$down = Helper::trafficConvert($user->d);
|
||||
$remaining = Helper::trafficConvert($user->transfer_enable - ($user->u + $user->d));
|
||||
$text = "🚥流量查询\n———————————————\n计划流量:`{$transferEnable}`\n已用上行:`{$up}`\n已用下行:`{$down}`\n剩余流量:`{$remaining}`";
|
||||
$telegramService->sendMessage($message->chat_id, $text, 'markdown');
|
||||
}
|
||||
}
|
26
app/Plugins/Telegram/Commands/UnBind.php
Normal file
26
app/Plugins/Telegram/Commands/UnBind.php
Normal file
@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Plugins\Telegram\Commands;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Plugins\Telegram\Telegram;
|
||||
|
||||
class UnBind extends Telegram {
|
||||
public $command = '/unbind';
|
||||
public $description = '将Telegram账号从网站解绑';
|
||||
|
||||
public function handle($message, $match = []) {
|
||||
if (!$message->is_private) return;
|
||||
$user = User::where('telegram_id', $message->chat_id)->first();
|
||||
$telegramService = $this->telegramService;
|
||||
if (!$user) {
|
||||
$telegramService->sendMessage($message->chat_id, '没有查询到您的用户信息,请先绑定账号', 'markdown');
|
||||
return;
|
||||
}
|
||||
$user->telegram_id = NULL;
|
||||
if (!$user->save()) {
|
||||
abort(500, '解绑失败');
|
||||
}
|
||||
$telegramService->sendMessage($message->chat_id, '解绑成功', 'markdown');
|
||||
}
|
||||
}
|
15
app/Plugins/Telegram/Telegram.php
Normal file
15
app/Plugins/Telegram/Telegram.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Plugins\Telegram;
|
||||
|
||||
use App\Services\TelegramService;
|
||||
|
||||
abstract class Telegram {
|
||||
abstract protected function handle($message, $match);
|
||||
public $telegramService;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->telegramService = new TelegramService();
|
||||
}
|
||||
}
|
@ -81,7 +81,7 @@ class CouponService
|
||||
|
||||
public function check()
|
||||
{
|
||||
if (!$this->coupon) {
|
||||
if (!$this->coupon || !$this->coupon->show) {
|
||||
abort(500, __('Invalid coupon'));
|
||||
}
|
||||
if ($this->coupon->limit_use <= 0 && $this->coupon->limit_use !== NULL) {
|
||||
|
@ -117,30 +117,29 @@ class OrderService
|
||||
public function setInvite(User $user):void
|
||||
{
|
||||
$order = $this->order;
|
||||
if ($user->invite_user_id && $order->total_amount > 0) {
|
||||
$order->invite_user_id = $user->invite_user_id;
|
||||
$isCommission = false;
|
||||
switch ((int)$user->commission_type) {
|
||||
case 0:
|
||||
$commissionFirstTime = (int)config('v2board.commission_first_time_enable', 1);
|
||||
$isCommission = (!$commissionFirstTime || ($commissionFirstTime && !$this->haveValidOrder($user)));
|
||||
break;
|
||||
case 1:
|
||||
$isCommission = true;
|
||||
break;
|
||||
case 2:
|
||||
$isCommission = !$this->haveValidOrder($user);
|
||||
break;
|
||||
}
|
||||
if ($user->invite_user_id && ($order->total_amount <= 0)) return;
|
||||
$order->invite_user_id = $user->invite_user_id;
|
||||
$inviter = User::find($user->invite_user_id);
|
||||
if (!$inviter) return;
|
||||
$isCommission = false;
|
||||
switch ((int)$inviter->commission_type) {
|
||||
case 0:
|
||||
$commissionFirstTime = (int)config('v2board.commission_first_time_enable', 1);
|
||||
$isCommission = (!$commissionFirstTime || ($commissionFirstTime && !$this->haveValidOrder($user)));
|
||||
break;
|
||||
case 1:
|
||||
$isCommission = true;
|
||||
break;
|
||||
case 2:
|
||||
$isCommission = !$this->haveValidOrder($user);
|
||||
break;
|
||||
}
|
||||
|
||||
if ($isCommission) {
|
||||
$inviter = User::find($user->invite_user_id);
|
||||
if ($inviter && $inviter->commission_rate) {
|
||||
$order->commission_balance = $order->total_amount * ($inviter->commission_rate / 100);
|
||||
} else {
|
||||
$order->commission_balance = $order->total_amount * (config('v2board.invite_commission', 10) / 100);
|
||||
}
|
||||
}
|
||||
if (!$isCommission) return;
|
||||
if ($inviter && $inviter->commission_rate) {
|
||||
$order->commission_balance = $order->total_amount * ($inviter->commission_rate / 100);
|
||||
} else {
|
||||
$order->commission_balance = $order->total_amount * (config('v2board.invite_commission', 10) / 100);
|
||||
}
|
||||
}
|
||||
|
||||
@ -163,7 +162,14 @@ class OrderService
|
||||
|
||||
private function getSurplusValueByOneTime(User $user, Order $order)
|
||||
{
|
||||
$plan = Plan::find($user->plan_id);
|
||||
$lastOneTimeOrder = Order::where('user_id', $user->id)
|
||||
->where('period', 'onetime')
|
||||
->where('status', 3)
|
||||
->orderBy('id', 'DESC')
|
||||
->first();
|
||||
if (!$lastOneTimeOrder) return;
|
||||
$plan = Plan::find($lastOneTimeOrder->plan_id);
|
||||
if (!$plan) return;
|
||||
$trafficUnitPrice = $plan->onetime_price / $plan->transfer_enable;
|
||||
if ($user->discount && $trafficUnitPrice) {
|
||||
$trafficUnitPrice = $trafficUnitPrice - ($trafficUnitPrice * $user->discount / 100);
|
||||
|
@ -8,7 +8,6 @@ use App\Models\Payment;
|
||||
class PaymentService
|
||||
{
|
||||
public $method;
|
||||
public $customResult;
|
||||
protected $class;
|
||||
protected $config;
|
||||
protected $payment;
|
||||
@ -26,9 +25,9 @@ class PaymentService
|
||||
$this->config['enable'] = $payment['enable'];
|
||||
$this->config['id'] = $payment['id'];
|
||||
$this->config['uuid'] = $payment['uuid'];
|
||||
$this->config['notify_domain'] = $payment['notify_domain'];
|
||||
};
|
||||
$this->payment = new $this->class($this->config);
|
||||
if (isset($this->payment->customResult)) $this->customResult = $this->payment->customResult;
|
||||
}
|
||||
|
||||
public function notify($params)
|
||||
@ -39,8 +38,15 @@ class PaymentService
|
||||
|
||||
public function pay($order)
|
||||
{
|
||||
// custom notify domain name
|
||||
$notifyUrl = url("/api/v1/guest/payment/notify/{$this->method}/{$this->config['uuid']}");
|
||||
if ($this->config['notify_domain']) {
|
||||
$parseUrl = parse_url($notifyUrl);
|
||||
$notifyUrl = $this->config['notify_domain'] . $parseUrl['path'];
|
||||
}
|
||||
|
||||
return $this->payment->pay([
|
||||
'notify_url' => url("/api/v1/guest/payment/notify/{$this->method}/{$this->config['uuid']}"),
|
||||
'notify_url' => $notifyUrl,
|
||||
'return_url' => config('v2board.app_url', env('APP_URL')) . '/#/order/' . $order['trade_no'],
|
||||
'trade_no' => $order['trade_no'],
|
||||
'total_amount' => $order['total_amount'],
|
||||
|
@ -8,12 +8,13 @@ use App\Models\User;
|
||||
use App\Models\ServerV2ray;
|
||||
use App\Models\ServerTrojan;
|
||||
use App\Utils\CacheKey;
|
||||
use App\Utils\Helper;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
|
||||
class ServerService
|
||||
{
|
||||
|
||||
CONST V2RAY_CONFIG = '{"api":{"services":["HandlerService","StatsService"],"tag":"api"},"dns":{},"stats":{},"inbound":{"port":443,"protocol":"vmess","settings":{"clients":[]},"sniffing":{"enabled":true,"destOverride":["http","tls"]},"streamSettings":{"network":"tcp"},"tag":"proxy"},"inboundDetour":[{"listen":"127.0.0.1","port":23333,"protocol":"dokodemo-door","settings":{"address":"0.0.0.0"},"tag":"api"}],"log":{"loglevel":"debug","access":"access.log","error":"error.log"},"outbound":{"protocol":"freedom","settings":{}},"outboundDetour":[{"protocol":"blackhole","settings":{},"tag":"block"}],"routing":{"rules":[{"inboundTag":"api","outboundTag":"api","type":"field"}]},"policy":{"levels":{"0":{"handshake":4,"connIdle":300,"uplinkOnly":5,"downlinkOnly":30,"statsUserUplink":true,"statsUserDownlink":true}}}}';
|
||||
CONST V2RAY_CONFIG = '{"log":{"loglevel":"debug","access":"access.log","error":"error.log"},"api":{"services":["HandlerService","StatsService"],"tag":"api"},"dns":{},"stats":{},"inbounds":[{"port":443,"protocol":"vmess","settings":{"clients":[]},"sniffing":{"enabled":true,"destOverride":["http","tls"]},"streamSettings":{"network":"tcp"},"tag":"proxy"},{"listen":"127.0.0.1","port":23333,"protocol":"dokodemo-door","settings":{"address":"0.0.0.0"},"tag":"api"}],"outbounds":[{"protocol":"freedom","settings":{}},{"protocol":"blackhole","settings":{},"tag":"block"}],"routing":{"rules":[{"type":"field","inboundTag":"api","outboundTag":"api"}]},"policy":{"levels":{"0":{"handshake":4,"connIdle":300,"uplinkOnly":5,"downlinkOnly":30,"statsUserUplink":true,"statsUserDownlink":true}}}}';
|
||||
CONST TROJAN_CONFIG = '{"run_type":"server","local_addr":"0.0.0.0","local_port":443,"remote_addr":"www.taobao.com","remote_port":80,"password":[],"ssl":{"cert":"server.crt","key":"server.key","sni":"domain.com"},"api":{"enabled":true,"api_addr":"127.0.0.1","api_port":10000}}';
|
||||
public function getV2ray(User $user, $all = false):array
|
||||
{
|
||||
@ -26,14 +27,16 @@ class ServerService
|
||||
for ($i = 0; $i < count($v2ray); $i++) {
|
||||
$v2ray[$i]['type'] = 'v2ray';
|
||||
$groupId = $v2ray[$i]['group_id'];
|
||||
if (in_array($user->group_id, $groupId)) {
|
||||
if ($v2ray[$i]['parent_id']) {
|
||||
$v2ray[$i]['last_check_at'] = Cache::get(CacheKey::get('SERVER_V2RAY_LAST_CHECK_AT', $v2ray[$i]['parent_id']));
|
||||
} else {
|
||||
$v2ray[$i]['last_check_at'] = Cache::get(CacheKey::get('SERVER_V2RAY_LAST_CHECK_AT', $v2ray[$i]['id']));
|
||||
}
|
||||
array_push($servers, $v2ray[$i]->toArray());
|
||||
if (!in_array($user->group_id, $groupId)) continue;
|
||||
if (strpos($v2ray[$i]['port'], '-') !== false) {
|
||||
$v2ray[$i]['port'] = Helper::randomPort($v2ray[$i]['port']);
|
||||
}
|
||||
if ($v2ray[$i]['parent_id']) {
|
||||
$v2ray[$i]['last_check_at'] = Cache::get(CacheKey::get('SERVER_V2RAY_LAST_CHECK_AT', $v2ray[$i]['parent_id']));
|
||||
} else {
|
||||
$v2ray[$i]['last_check_at'] = Cache::get(CacheKey::get('SERVER_V2RAY_LAST_CHECK_AT', $v2ray[$i]['id']));
|
||||
}
|
||||
array_push($servers, $v2ray[$i]->toArray());
|
||||
}
|
||||
|
||||
|
||||
@ -51,14 +54,16 @@ class ServerService
|
||||
for ($i = 0; $i < count($trojan); $i++) {
|
||||
$trojan[$i]['type'] = 'trojan';
|
||||
$groupId = $trojan[$i]['group_id'];
|
||||
if (in_array($user->group_id, $groupId)) {
|
||||
if ($trojan[$i]['parent_id']) {
|
||||
$trojan[$i]['last_check_at'] = Cache::get(CacheKey::get('SERVER_TROJAN_LAST_CHECK_AT', $trojan[$i]['parent_id']));
|
||||
} else {
|
||||
$trojan[$i]['last_check_at'] = Cache::get(CacheKey::get('SERVER_TROJAN_LAST_CHECK_AT', $trojan[$i]['id']));
|
||||
}
|
||||
array_push($servers, $trojan[$i]->toArray());
|
||||
if (!in_array($user->group_id, $groupId)) continue;
|
||||
if (strpos($trojan[$i]['port'], '-') !== false) {
|
||||
$trojan[$i]['port'] = Helper::randomPort($trojan[$i]['port']);
|
||||
}
|
||||
if ($trojan[$i]['parent_id']) {
|
||||
$trojan[$i]['last_check_at'] = Cache::get(CacheKey::get('SERVER_TROJAN_LAST_CHECK_AT', $trojan[$i]['parent_id']));
|
||||
} else {
|
||||
$trojan[$i]['last_check_at'] = Cache::get(CacheKey::get('SERVER_TROJAN_LAST_CHECK_AT', $trojan[$i]['id']));
|
||||
}
|
||||
array_push($servers, $trojan[$i]->toArray());
|
||||
}
|
||||
return $servers;
|
||||
}
|
||||
@ -74,15 +79,16 @@ class ServerService
|
||||
for ($i = 0; $i < count($shadowsocks); $i++) {
|
||||
$shadowsocks[$i]['type'] = 'shadowsocks';
|
||||
$groupId = $shadowsocks[$i]['group_id'];
|
||||
if (in_array($user->group_id, $groupId)) {
|
||||
if ($shadowsocks[$i]['parent_id']) {
|
||||
$shadowsocks[$i]['last_check_at'] = Cache::get(CacheKey::get('SERVER_SHADOWSOCKS_LAST_CHECK_AT', $shadowsocks[$i]['parent_id']));
|
||||
} else {
|
||||
$shadowsocks[$i]['last_check_at'] = Cache::get(CacheKey::get('SERVER_SHADOWSOCKS_LAST_CHECK_AT', $shadowsocks[$i]['id']));
|
||||
}
|
||||
array_push($servers, $shadowsocks[$i]->toArray());
|
||||
if (!in_array($user->group_id, $groupId)) continue;
|
||||
if (strpos($shadowsocks[$i]['port'], '-') !== false) {
|
||||
$shadowsocks[$i]['port'] = Helper::randomPort($shadowsocks[$i]['port']);
|
||||
}
|
||||
|
||||
if ($shadowsocks[$i]['parent_id']) {
|
||||
$shadowsocks[$i]['last_check_at'] = Cache::get(CacheKey::get('SERVER_SHADOWSOCKS_LAST_CHECK_AT', $shadowsocks[$i]['parent_id']));
|
||||
} else {
|
||||
$shadowsocks[$i]['last_check_at'] = Cache::get(CacheKey::get('SERVER_SHADOWSOCKS_LAST_CHECK_AT', $shadowsocks[$i]['id']));
|
||||
}
|
||||
array_push($servers, $shadowsocks[$i]->toArray());
|
||||
}
|
||||
return $servers;
|
||||
}
|
||||
@ -129,9 +135,9 @@ class ServerService
|
||||
}
|
||||
$json = json_decode(self::V2RAY_CONFIG);
|
||||
$json->log->loglevel = (int)config('v2board.server_log_enable') ? 'debug' : 'none';
|
||||
$json->inboundDetour[0]->port = (int)$localPort;
|
||||
$json->inbound->port = (int)$server->server_port;
|
||||
$json->inbound->streamSettings->network = $server->network;
|
||||
$json->inbounds[1]->port = (int)$localPort;
|
||||
$json->inbounds[0]->port = (int)$server->server_port;
|
||||
$json->inbounds[0]->streamSettings->network = $server->network;
|
||||
$this->setDns($server, $json);
|
||||
$this->setNetwork($server, $json);
|
||||
$this->setRule($server, $json);
|
||||
@ -165,7 +171,7 @@ class ServerService
|
||||
array_push($dns->servers, 'localhost');
|
||||
}
|
||||
$json->dns = $dns;
|
||||
$json->outbound->settings->domainStrategy = 'UseIP';
|
||||
$json->outbounds[0]->settings->domainStrategy = 'UseIP';
|
||||
}
|
||||
}
|
||||
|
||||
@ -174,25 +180,25 @@ class ServerService
|
||||
if ($server->networkSettings) {
|
||||
switch ($server->network) {
|
||||
case 'tcp':
|
||||
$json->inbound->streamSettings->tcpSettings = $server->networkSettings;
|
||||
$json->inbounds[0]->streamSettings->tcpSettings = $server->networkSettings;
|
||||
break;
|
||||
case 'kcp':
|
||||
$json->inbound->streamSettings->kcpSettings = $server->networkSettings;
|
||||
$json->inbounds[0]->streamSettings->kcpSettings = $server->networkSettings;
|
||||
break;
|
||||
case 'ws':
|
||||
$json->inbound->streamSettings->wsSettings = $server->networkSettings;
|
||||
$json->inbounds[0]->streamSettings->wsSettings = $server->networkSettings;
|
||||
break;
|
||||
case 'http':
|
||||
$json->inbound->streamSettings->httpSettings = $server->networkSettings;
|
||||
$json->inbounds[0]->streamSettings->httpSettings = $server->networkSettings;
|
||||
break;
|
||||
case 'domainsocket':
|
||||
$json->inbound->streamSettings->dsSettings = $server->networkSettings;
|
||||
$json->inbounds[0]->streamSettings->dsSettings = $server->networkSettings;
|
||||
break;
|
||||
case 'quic':
|
||||
$json->inbound->streamSettings->quicSettings = $server->networkSettings;
|
||||
$json->inbounds[0]->streamSettings->quicSettings = $server->networkSettings;
|
||||
break;
|
||||
case 'grpc':
|
||||
$json->inbound->streamSettings->grpcSettings = $server->networkSettings;
|
||||
$json->inbounds[0]->streamSettings->grpcSettings = $server->networkSettings;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -234,7 +240,7 @@ class ServerService
|
||||
array_push($json->routing->rules, $protocolObj);
|
||||
}
|
||||
if (empty($domainRules) && empty($protocolRules)) {
|
||||
$json->inbound->sniffing->enabled = false;
|
||||
$json->inbounds[0]->sniffing->enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
@ -242,19 +248,19 @@ class ServerService
|
||||
{
|
||||
if ((int)$server->tls) {
|
||||
$tlsSettings = $server->tlsSettings;
|
||||
$json->inbound->streamSettings->security = 'tls';
|
||||
$json->inbounds[0]->streamSettings->security = 'tls';
|
||||
$tls = (object)[
|
||||
'certificateFile' => '/root/.cert/server.crt',
|
||||
'keyFile' => '/root/.cert/server.key'
|
||||
];
|
||||
$json->inbound->streamSettings->tlsSettings = new \StdClass();
|
||||
$json->inbounds[0]->streamSettings->tlsSettings = new \StdClass();
|
||||
if (isset($tlsSettings->serverName)) {
|
||||
$json->inbound->streamSettings->tlsSettings->serverName = (string)$tlsSettings->serverName;
|
||||
$json->inbounds[0]->streamSettings->tlsSettings->serverName = (string)$tlsSettings->serverName;
|
||||
}
|
||||
if (isset($tlsSettings->allowInsecure)) {
|
||||
$json->inbound->streamSettings->tlsSettings->allowInsecure = (int)$tlsSettings->allowInsecure ? true : false;
|
||||
$json->inbounds[0]->streamSettings->tlsSettings->allowInsecure = (int)$tlsSettings->allowInsecure ? true : false;
|
||||
}
|
||||
$json->inbound->streamSettings->tlsSettings->certificates[0] = $tls;
|
||||
$json->inbounds[0]->streamSettings->tlsSettings->certificates[0] = $tls;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -12,15 +12,12 @@ use Illuminate\Support\Facades\DB;
|
||||
class TicketService {
|
||||
public function replyByAdmin($ticketId, $message, $userId):void
|
||||
{
|
||||
if ($message)
|
||||
$ticket = Ticket::where('id', $ticketId)
|
||||
->first();
|
||||
if (!$ticket) {
|
||||
abort(500, '工单不存在');
|
||||
}
|
||||
if ($ticket->status) {
|
||||
abort(500, '工单已关闭,无法回复');
|
||||
}
|
||||
$ticket->status = 0;
|
||||
DB::beginTransaction();
|
||||
$ticketMessage = TicketMessage::create([
|
||||
'user_id' => $userId,
|
||||
|
@ -3,6 +3,8 @@
|
||||
namespace App\Services;
|
||||
|
||||
use App\Jobs\ServerLogJob;
|
||||
use App\Jobs\StatServerJob;
|
||||
use App\Jobs\StatUserJob;
|
||||
use App\Jobs\TrafficFetchJob;
|
||||
use App\Models\InviteCode;
|
||||
use App\Models\Order;
|
||||
@ -85,6 +87,7 @@ class UserService
|
||||
public function trafficFetch(int $u, int $d, int $userId, object $server, string $protocol)
|
||||
{
|
||||
TrafficFetchJob::dispatch($u, $d, $userId, $server, $protocol);
|
||||
ServerLogJob::dispatch($u, $d, $userId, $server, $protocol);
|
||||
StatServerJob::dispatch($u, $d, $server, $protocol, 'd');
|
||||
StatUserJob::dispatch($u, $d, $userId, $server, $protocol, 'd');
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,8 @@ class CacheKey
|
||||
'SERVER_SHADOWSOCKS_LAST_CHECK_AT' => 'ss节点最后检查时间',
|
||||
'SERVER_SHADOWSOCKS_LAST_PUSH_AT' => 'ss节点最后推送时间',
|
||||
'TEMP_TOKEN' => '临时令牌',
|
||||
'LAST_SEND_EMAIL_REMIND_TRAFFIC' => '最后发送流量邮件提醒'
|
||||
'LAST_SEND_EMAIL_REMIND_TRAFFIC' => '最后发送流量邮件提醒',
|
||||
'SCHEDULE_LAST_CHECK_AT' => '计划任务最后检查时间'
|
||||
];
|
||||
|
||||
public static function get(string $key, $uniqueValue)
|
||||
|
@ -112,4 +112,9 @@ class Helper
|
||||
}
|
||||
return $subscribeUrl;
|
||||
}
|
||||
|
||||
public static function randomPort($range) {
|
||||
$portRange = explode('-', $range);
|
||||
return rand($portRange[0], $portRange[1]);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user