Rumah  >  Soal Jawab  >  teks badan

Terhadap ralat semasa menghantar pemberitahuan firebase ke topik menggunakan curl dan api v1

<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粉127901279P粉127901279389 hari yang lalu489

membalas semua(1)saya akan balas

  • P粉304704653

    P粉3047046532023-08-30 10:26:37

    Anda mesti menggunakan topic 而不是 to jika anda ingin menghantar ke topik.

    balas
    0
  • Batalbalas