TutorialController.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Http\Request;
  4. use App\Http\Controllers\Controller;
  5. use App\Models\User;
  6. use App\Models\Tutorial;
  7. class TutorialController extends Controller
  8. {
  9. public function getSubscribeUrl(Request $request)
  10. {
  11. $user = User::find($request->session()->get('id'));
  12. return response([
  13. 'data' => [
  14. 'subscribe_url' => config('v2board.subscribe_url', config('v2board.app_url', env('APP_URL'))) . '/api/v1/client/subscribe?token=' . $user['token']
  15. ]
  16. ]);
  17. }
  18. public function getAppleID(Request $request)
  19. {
  20. $user = User::find($request->session()->get('id'));
  21. if ($user->expired_at < time()) {
  22. return response([
  23. 'data' => [
  24. ]
  25. ]);
  26. }
  27. return response([
  28. 'data' => [
  29. 'apple_id' => config('v2board.apple_id'),
  30. 'apple_id_password' => config('v2board.apple_id_password')
  31. ]
  32. ]);
  33. }
  34. public function fetch(Request $request)
  35. {
  36. if ($request->input('id')) {
  37. $tutorial = Tutorial::where('show', 1)
  38. ->where('id', $request->input('id'))
  39. ->first();
  40. if (!$tutorial) {
  41. abort(500, '教程不存在');
  42. }
  43. return response([
  44. 'data' => $tutorial
  45. ]);
  46. }
  47. $tutorial = Tutorial::select(['id', 'title', 'description', 'icon'])
  48. ->where('show', 1)
  49. ->get();
  50. $user = User::find($request->session()->get('id'));
  51. $response = [
  52. 'data' => [
  53. 'tutorials' => $tutorial,
  54. 'safe_area_var' => [
  55. 'subscribe_url' => config('v2board.subscribe_url', config('v2board.app_url', env('APP_URL'))) . '/api/v1/client/subscribe?token=' . $user['token'],
  56. 'app_name' => config('v2board.app_name', 'V2board'),
  57. 'apple_id' => $user->expired_at > time() ? config('v2board.apple_id', '管理员暂无提供AppleID信息') : '账号过期或未订阅',
  58. 'apple_id_password' => $user->expired_at > time() ? config('v2board.apple_id_password', '管理员暂无提供AppleID信息') : '账号过期或未订阅'
  59. ]
  60. ]
  61. ];
  62. // fuck support shadowrocket urlsafeb64 subscribe
  63. $response['data']['safe_area_var']['b64_subscribe_url'] = str_replace(
  64. array('+', '/', '='),
  65. array('-', '_', ''),
  66. base64_encode($response['data']['safe_area_var']['subscribe_url'])
  67. );
  68. // end
  69. return response($response);
  70. }
  71. }