123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- <?php
- namespace App\Http\Controllers\QuickApp\Push;
- use App\Consts\ErrorConst;
- use App\Http\Controllers\QuickApp\BaseController;
- use App\Libs\ApiResponse;
- use App\Libs\Utils;
- use App\Modules\Push\Services\PushService;
- use Illuminate\Http\Request;
- use App\Exceptions\ApiException;
- class PushController extends BaseController
- {
- use ApiResponse;
- /**
- * 设置用户推送reg_id
- * @param Request $request
- * @return mixed
- * @throws ApiException
- */
- public function setUserRegId(Request $request)
- {
- $all = $request->all();
- $uid = $this->uid;
- $regId = trim(getProp($all, 'reg_id'));
- $appId = trim(getProp($all, 'app_id'));
- if (empty($regId) || empty($appId)) {
- Utils::throwError(ErrorConst::PARAM_ERROR_CODE);
- }
- // 更新用户reg_id
- $result = PushService::setUserRegId($uid, $regId, $appId);
- if (!$result) {
- Utils::throwError(ErrorConst::SYS_EXCEPTION);
- }
- return $this->success(compact('uid', 'regId'));
- }
- public function sendMessage(Request $request)
- {
- $all = $request->all();
- $taskId = (int)getProp($all, 'task_id');
- if (empty($taskId)) {
- Utils::throwError(ErrorConst::PARAM_ERROR_CODE);
- }
- // 更新用户reg_id
- $result = PushService::sendMessage($taskId);
- if (!$result) {
- Utils::throwError(ErrorConst::SYS_EXCEPTION);
- }
- return $this->success();
- }
- }
|