TutorialController.php 3.0 KB

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