如何在不迁移到firebase的情况下获取google-services.json

时间:2016-09-12 11:35:07

标签: java php android

目前我正在开发一个Android项目。 因此我使用Google Cloud Messaging进行推送通知 我必须向gcm添加另一个应用程序,所以我希望google-services.json文件用于gcm服务,但现在谷歌正在说首先我必须在firebase上注册并迁移它然后我才能获得 google-services.json文件。我不想要firebase基础的原因是我必须根据firebase修改所有webservice。有没有其他方法可以做到这一点?

我有很多像这样的方法。

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);
}  
  }

1 个答案:

答案 0 :(得分:0)

我正在迁移到firebase只是为了下载google-services.json而不更改webservice和android项目上的任何内容,而且它的工作