我收到了奇怪的问题,发送推送通知给Android使用FCM。
目标:-发送推送通知 时出错
下面是我向Android发送推送通知的功能
public static function SendMultipleNotificationAndroid($groups) //your api key SERVER API KEY $apiKey = Yii::$app->params['android_api_key']; $url = 'https://fcm.googleapis.com/fcm/send'; $headers = array( 'Authorization:key=' . $apiKey, '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_SSL_VERIFYPEER, false); foreach($groups as $resG){ $users = $resG['users']; $msg = $resG['message']; $type = $resG['notification_type']; $notification_data = $resG['notification_data']; $deviceTokens = []; foreach($users as $resUser){ $deviceTokens[] = $resUser['device_token']; //Add Friend badge count +1 Common::AddRemoveBadgeCount($resUser['user_id']); if(!empty($deviceTokens)){ $fields = array( 'registration_ids' => $deviceTokens, 'priority' => 'high', 'collapse_key' => $resG['notification_type'], 'time_to_live' => 2419200, "click_action" =>"NotificationListingActivity", 'data' => [ "title" => "ProjectName", "body" => $resG['message'], "action_tag" => $resG['notification_type'], "message" => $resG['message'], 'notification_type' => $type, 'notification_data' => $notification_data, 'sound' => 'default', //Print result p($ch,0); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields)); curl_exec($ch);