2016-09-12 6 views
0

現在、私はアンドロイドプロジェクトに取り組んでいます。 プッシュ通知のためにGoogle Cloud Messagingを使用しています。gcmに別のアプリを追加する必要があります。google-services.json gcmサービス用のファイルが必要ですが、現在Googleではと言っています。まずfirebaseに登録してからマイグレーションしてください。google-services.jsonファイル。私がfirebaseベースを望んでいない理由は、firebaseに従ってすべてのwebserviceをmodする必要があるということです。これを行うための他の方法はありますか?firebaseに移行せずにgoogle-services.jsonを取得する方法

私はこれほど多くの方法を持っています。

public function send_message($gcm_id,$details){ 

$reg_token = array($gcm_id); 

$msg =array("message"=>$details); 

//Creating a new array fileds and adding the msg array and registration token array here 
$fields = array 
(
    'registration_ids' => $reg_token, 
    'data'   => $msg 
); 

//Adding the api key in one more array header 
$headers = array 
(
    'Authorization: key= MY_API_KEY', 
    'Content-Type: application/json' 
); 

//Using curl to perform http request 
$ch = curl_init(); 
curl_setopt($ch,CURLOPT_URL, 'https://android.googleapis.com/gcm/send'); 
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)); 


//Getting the result 
$result = curl_exec($ch); 
curl_close($ch); 

//Decoding json from result 
$res = json_decode($result); 


//Getting value from success 
$flag = $res->success; 

//if success is 1 means message is sent \ 
$response = array("error" => FALSE); 
if($flag == 1){ 
    //Redirecting back to our form with a request success 
    $response["error"] = false; 
    $response["error_msg"] = "Message SuccessFully Sent Check Your Device"; 
    echo json_encode($response); 

}else{ 
    //Redirecting back to our form with a request failure 
    $response["error"] = TRUE; 
    $response["error_msg"] = "Eror Occured"; 

    echo json_encode($response); 
} 
    } 

答えて

0

私はWebサービスとAndroidプロジェクトには何も変更せずにGoogleの-services.jsonをダウンロードするfirebaseへの移行だ、とそれはまだGCMを使用して

+0

AndroidとWebサービスを動作しています – g03r03

関連する問題