2019-11-23 01:41:47 +08:00
|
|
|
<?php
|
|
|
|
|
2020-01-29 16:08:50 +08:00
|
|
|
namespace App\Http\Controllers\User;
|
2019-11-23 01:41:47 +08:00
|
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
2020-01-29 16:08:50 +08:00
|
|
|
use Illuminate\Http\Request;
|
2019-11-23 01:41:47 +08:00
|
|
|
use App\Models\User;
|
2020-01-02 21:49:04 +08:00
|
|
|
use App\Models\Tutorial;
|
2020-04-16 23:01:18 +08:00
|
|
|
use Illuminate\Support\Facades\DB;
|
2019-11-23 01:41:47 +08:00
|
|
|
|
|
|
|
class TutorialController extends Controller
|
|
|
|
{
|
2020-01-11 13:36:52 +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
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2020-01-11 13:36:52 +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
|
|
|
|
2020-01-11 13:36:52 +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
|
|
|
|
]);
|
|
|
|
}
|
2020-03-06 01:19:51 +08:00
|
|
|
$tutorial = Tutorial::select(['id', 'category_id', 'title'])
|
2020-01-02 22:05:27 +08:00
|
|
|
->where('show', 1)
|
2020-04-20 16:07:06 +08:00
|
|
|
->orderBy('sort', 'ASC')
|
2020-02-19 14:31:02 +08:00
|
|
|
->get()
|
2020-02-19 14:33:35 +08:00
|
|
|
->groupBy('category_id');
|
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'),
|
2020-03-05 02:03:50 +08:00
|
|
|
'apple_id' => $user->expired_at > time() || $user->expired_at === NULL ? config('v2board.apple_id', '本站暂无提供AppleID信息') : '账号过期或未订阅',
|
|
|
|
'apple_id_password' => $user->expired_at > time() || $user->expired_at === NULL ? 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(
|
2020-01-11 13:36:52 +08:00
|
|
|
array('+', '/', '='),
|
|
|
|
array('-', '_', ''),
|
2020-01-03 00:29:15 +08:00
|
|
|
base64_encode($response['data']['safe_area_var']['subscribe_url'])
|
|
|
|
);
|
2020-05-26 09:08:45 +08:00
|
|
|
// end
|
|
|
|
// fuck support surge urlencode subscribe
|
|
|
|
$response['data']['safe_area_var']['ue_subscribe_url'] = urlencode($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
|
|
|
}
|