v2board/app/Http/Controllers/TutorialController.php

73 lines
2.6 KiB
PHP
Raw Normal View History

2019-11-23 01:41:47 +08:00
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Models\User;
2020-01-02 21:49:04 +08:00
use App\Models\Tutorial;
2019-11-23 01:41:47 +08:00
class TutorialController extends Controller
{
2019-11-23 13:17:33 +08:00
public function getSubscribeUrl (Request $request) {
2019-11-23 01:41:47 +08:00
$user = User::find($request->session()->get('id'));
return response([
2019-11-23 13:27:38 +08:00
'data' => [
2019-11-23 23:32:44 +08:00
'subscribe_url' => config('v2board.subscribe_url', config('v2board.app_url', env('APP_URL'))) . '/api/v1/client/subscribe?token=' . $user['token']
2019-11-23 13:27:38 +08:00
]
2019-11-23 01:41:47 +08:00
]);
}
2019-11-23 13:17:33 +08:00
public function getAppleID (Request $request) {
2019-11-23 01:43:38 +08:00
$user = User::find($request->session()->get('id'));
2019-11-23 15:05:46 +08:00
if ($user->expired_at < time()) {
2019-11-23 01:43:38 +08:00
return response([
2019-11-23 13:31:20 +08:00
'data' => [
]
2019-11-23 01:44:02 +08:00
]);
2019-11-23 01:43:38 +08:00
}
2019-11-23 15:05:02 +08:00
return response([
'data' => [
'apple_id' => config('v2board.apple_id'),
'apple_id_password' => config('v2board.apple_id_password')
]
]);
2019-11-23 01:41:47 +08:00
}
2020-01-02 21:49:04 +08:00
public function fetch (Request $request) {
2020-01-02 22:05:27 +08:00
if ($request->input('id')) {
$tutorial = Tutorial::where('show', 1)
->where('id', $request->input('id'))
->first();
if (!$tutorial) {
abort(500, '教程不存在');
}
return response([
'data' => $tutorial
]);
}
$tutorial = Tutorial::select(['id', 'title', 'description', 'icon'])
->where('show', 1)
->get();
2020-01-02 21:55:50 +08:00
$user = User::find($request->session()->get('id'));
2020-01-02 21:52:20 +08:00
$response = [
'data' => [
'tutorials' => $tutorial,
2020-01-02 23:22:49 +08:00
'safe_area_var' => [
2020-01-02 23:32:31 +08:00
'subscribe_url' => config('v2board.subscribe_url', config('v2board.app_url', env('APP_URL'))) . '/api/v1/client/subscribe?token=' . $user['token'],
2020-01-03 00:24:45 +08:00
'app_name' => config('v2board.app_name', 'V2board'),
'apple_id' => $user->expired_at > time() ? config('v2board.apple_id', '管理员暂无提供AppleID信息') : '账号过期或未订阅',
'apple_id_password' => $user->expired_at > time() ? config('v2board.apple_id_password', '管理员暂无提供AppleID信息') : '账号过期或未订阅'
2020-01-02 23:22:49 +08:00
]
2020-01-02 21:52:20 +08:00
]
];
2020-01-03 00:29:15 +08:00
// fuck support shadowrocket urlsafeb64 subscribe
$response['data']['safe_area_var']['b64_subscribe_url'] = str_replace(
array('+','/','='),array('-','_',''),
base64_encode($response['data']['safe_area_var']['subscribe_url'])
);
// end
2020-01-02 21:52:20 +08:00
return response($response);
2020-01-02 21:49:04 +08:00
}
2019-11-23 01:41:47 +08:00
}