|
@@ -8,7 +8,7 @@ use App\Consts\ErrorConst;
|
|
use App\Http\Controllers\QuickApp\BaseController;
|
|
use App\Http\Controllers\QuickApp\BaseController;
|
|
use App\Libs\ApiResponse;
|
|
use App\Libs\ApiResponse;
|
|
use App\Libs\Utils;
|
|
use App\Libs\Utils;
|
|
-use App\Modules\Push\Services\PushService;
|
|
|
|
|
|
+use App\Modules\Push\Services\PushMessageService;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Request;
|
|
use App\Exceptions\ApiException;
|
|
use App\Exceptions\ApiException;
|
|
|
|
|
|
@@ -17,44 +17,31 @@ class PushController extends BaseController
|
|
use ApiResponse;
|
|
use ApiResponse;
|
|
|
|
|
|
/**
|
|
/**
|
|
- * 设置用户推送reg_id
|
|
|
|
* @param Request $request
|
|
* @param Request $request
|
|
* @return mixed
|
|
* @return mixed
|
|
* @throws ApiException
|
|
* @throws ApiException
|
|
|
|
+ * @throws \GuzzleHttp\Exception\GuzzleException
|
|
*/
|
|
*/
|
|
- public function setUserRegId(Request $request)
|
|
|
|
|
|
+ public function pushToUser(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)) {
|
|
|
|
|
|
+ $all = $request->all();
|
|
|
|
+ $uid = (int)getProp($all, 'uid');
|
|
|
|
+ $title = trim(getProp($all, 'title'));
|
|
|
|
+ $content = trim(getProp($all, 'content'));
|
|
|
|
+ $url = trim(getProp($all, 'url'));
|
|
|
|
+ $sign = trim(getProp($all, 'sign'));
|
|
|
|
+ if (empty($uid) || empty($title) || empty($content) || empty($url)) {
|
|
Utils::throwError(ErrorConst::PARAM_ERROR_CODE);
|
|
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);
|
|
|
|
|
|
+ // 签名校验
|
|
|
|
+ if ($sign !== 'dqu7nsNZY&A8AEzwNQ*WpbjHMd6bUt@V') {
|
|
|
|
+ Utils::throwError(ErrorConst::SIGN_NOT_ACCESS);
|
|
}
|
|
}
|
|
|
|
|
|
// 更新用户reg_id
|
|
// 更新用户reg_id
|
|
- $result = PushService::sendMessage($taskId);
|
|
|
|
- if (!$result) {
|
|
|
|
- Utils::throwError(ErrorConst::SYS_EXCEPTION);
|
|
|
|
- }
|
|
|
|
|
|
+ $result = PushMessageService::pushMessageToUser($uid, $title, $content, $url);
|
|
|
|
|
|
- return $this->success();
|
|
|
|
|
|
+ return $this->success($result);
|
|
}
|
|
}
|
|
}
|
|
}
|