PushController.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace App\Http\Controllers\QuickApp\Push;
  3. use App\Consts\ErrorConst;
  4. use App\Http\Controllers\QuickApp\BaseController;
  5. use App\Libs\ApiResponse;
  6. use App\Libs\Utils;
  7. use App\Modules\Push\Services\PushService;
  8. use Illuminate\Http\Request;
  9. use App\Exceptions\ApiException;
  10. class PushController extends BaseController
  11. {
  12. use ApiResponse;
  13. /**
  14. * 设置用户推送reg_id
  15. * @param Request $request
  16. * @return mixed
  17. * @throws ApiException
  18. */
  19. public function setUserRegId(Request $request)
  20. {
  21. $all = $request->all();
  22. $uid = $this->uid;
  23. $regId = trim(getProp($all, 'reg_id'));
  24. $appId = trim(getProp($all, 'app_id'));
  25. if (empty($regId) || empty($appId)) {
  26. Utils::throwError(ErrorConst::PARAM_ERROR_CODE);
  27. }
  28. // 更新用户reg_id
  29. $result = PushService::setUserRegId($uid, $regId, $appId);
  30. if (!$result) {
  31. Utils::throwError(ErrorConst::SYS_EXCEPTION);
  32. }
  33. return $this->success(compact('uid', 'regId'));
  34. }
  35. public function sendMessage(Request $request)
  36. {
  37. $all = $request->all();
  38. $taskId = (int)getProp($all, 'task_id');
  39. if (empty($taskId)) {
  40. Utils::throwError(ErrorConst::PARAM_ERROR_CODE);
  41. }
  42. // 更新用户reg_id
  43. $result = PushService::sendMessage($taskId);
  44. if (!$result) {
  45. Utils::throwError(ErrorConst::SYS_EXCEPTION);
  46. }
  47. return $this->success();
  48. }
  49. }