컬 및 API v1을 사용하여 주제에 Firebase 알림을 보내는 중 오류가 발생했습니다.
P粉127901279
P粉127901279 2023-08-29 17:36:37
0
1
554
<p>在我的 laravel 应用程序中,我使用curl 向订阅某个主题的所有用户发送通知,但是当我发送通知时,我收到此错误:</p> <pre class="brush:php;toolbar:false;">&quot;code&quot;: 400, &quot;message&quot;: &quot;Invalid JSON payload received. Unknown name \&quot;to\&quot;: Cannot find field.&quot;</pre> <p>这是我使用curl发送主题notif的方式:</p> <pre class="brush:php;toolbar:false;">public function sendTopic($topic,$title,$body, $data , $type, $image='') { $client = new Client(); $url = 'https://fcm.googleapis.com/v1/projects/wooloveapp-dda64/messages:send'; $fields = [ 'message' => [ &quot;to&quot; => $topic, &quot;notification&quot; => [ &quot;title&quot; => $title, &quot;body&quot; => $body, ], &quot;data&quot; => [ &quot;data&quot; => json_encode($data) ], &quot;android&quot; => [ &quot;notification&quot; => [ &quot;sound&quot; => &quot;default&quot;, &quot;title&quot; => $title, &quot;body&quot; => $body, 'tag' => $topic, &quot;channel_id&quot; => &quot;500&quot;, ], &quot;priority&quot; => &quot;high&quot;, &quot;ttl&quot; => &quot;86400s&quot; //&quot;badge&quot; => 1 ], &quot;apns&quot; => [ &quot;payload&quot; => [ &quot;aps&quot; => [ &quot;sound&quot; => &quot;default&quot; ] ], &quot;headers&quot; => [ &quot;apns-priority&quot; => &quot;5&quot;, &quot;content_available&quot; => &quot;1&quot; ], ], &quot;webpush&quot;=>[ &quot;headers&quot;=>[ &quot;Urgency&quot;=> &quot;high&quot;, //&quot;image&quot; => &quot;https://wooloveapp.com/img/misc/logo-02.jpg&quot; ] ], ] ]; $headers = [ 'Authorization: Bearer ' .$this->getGoogleAccessToken(), 'Accept:application/json', 'Content-Length:'.strlen(json_encode($fields)), 'Content-Type:application/json', ]; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields)); $result = curl_exec($ch); $result = [ 'result' => $result, //'statusCode' => $statusCode ]; return $result; }</pre></p>
P粉127901279
P粉127901279

모든 응답(1)
P粉304704653

주제로 보내려면 topic 而不是 to를 사용해야 합니다.

최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿