laravel fcm推送通知与brozot / Laravel-FCM不在ios上工作,但与android工作正常
即使是ios也可以从fcm控制台获得通知。
控制器function :
public function push(Request $request) { $validator = Validator::make($request->all(), [ 'title' = > 'required', 'body' = > 'required', 'token' = > 'required', 'type' = > 'required', 'id' = > 'required', ]); if ($validator->fails()) { $this->throwValidationException( $request, $validator ); } $title = $request['title']; $body = $request['body']; $type = $request['type']; $id = $request['id']; $dataarray = array( "id" = >$id, "type" = >$type, 'title' = >$title, 'body' = >$body, 'image' = >'321451_v2.jpg', ); $token = $request['token']; return $push = Push::sendpush($title, $body, $dataarray, $token); } push model function : public static function sendpush($title, $body, $dataarray, $token) { $optionBuiler = new OptionsBuilder(); $optionBuiler->setTimeToLive(60 * 20); $notificationBuilder = new PayloadNotificationBuilder($title); $notificationBuilder->setBody($body) ->setSound(''); $dataBuilder = new PayloadDataBuilder(); $dataBuilder->addData($dataarray); $option = $optionBuiler->build(); $notification = $notificationBuilder->build(); $data = $dataBuilder->build(); $token = $token; $downstreamResponse = FCM::sendTo($token, $option, $notification, $data); return new JsonResponse(array('status' = >'1', 'sucess' = >$downstreamResponse->numberSuccess(), 'fail' = > $downstreamResponse->numberFailure(), 'msg' = >$downstreamResponse->tokensWithError()), 200); } Response: { "status": "1", "sucess" : 0, "fail" : 1, "msg" : [] }