TutorialController.php 2.6 KB

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