1

나는 안드로이드와 PHP에서 새로운 기능이 있습니다. 푸시 알림 작업 중입니다. 많은 자습서를 읽었지만 모두 Json을위한 일반 텍스트가 아닙니다. json 코드는 여기에 있지만 일반 텍스트 만 보내고 싶습니다. 나는 이것을 읽었다.GCM 일반 텍스트 PHP로 알림 푸시?

https://github.com/mattg888/GCM-PHP-Server-Push-Message/blob/master/GCMPushMessage.php

http://www.androidhive.info/2012/10/android-push-notifications-using-google-cloud-messaging-gcm-php-and-mysql/

나는이 읽었습니다. GCM Error=MissingRegistration sending messages via JSON

내 코드는 어떤 몸에서 나를 도울 수, 여기에 일반 텍스트를 수행하려고 할 경우이 블록

$headers = array(
     'Authorization: key=12dsdsvefdfdfgdfgdfgdfgfgfgfg', 
     'Content-Type: application/x-www-form-urlencoded' 
    ); 

문맥 형을 무시해야

<?php 

$gcm_regid = 'fkjfsdhfsuvgsdhfkfkjshdfuwfsdfh9wfjehf9ufwjfhu9erfjkhf9efiefhwodfh9'; // GCM Registration ID 
$registatoin_ids = array($gcm_regid); 
$message = array("message" => "Hello test"); 


// Set POST variables 
    $url = 'https://android.googleapis.com/gcm/send'; 

    $fields = array(
     'registration_ids' => $gcm_regid, 
     'data' => 'helloword', 
    ); 

    $headers = array(
     'Authorization: key=12dsdsvefdfdfgdfgdfgdfgfgfgfg', 
     'Content-Type: application/x-www-form-urlencoded' 
    ); 
    // Open connection 
    $ch = curl_init(); 

    // Set the url, number of POST vars, POST data 
    curl_setopt($ch, CURLOPT_URL, $url); 

    curl_setopt($ch, CURLOPT_POST, true); 
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 

    // Disabling SSL Certificate support temporarly 
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 

    curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields)); 

    // Execute post 
    $result = curl_exec($ch); 
    if ($result === FALSE) { 
     die('Curl failed: ' . curl_error($ch)); 
    } 

    // Close connection 
    curl_close($ch); 
    echo $result; 

    ?> 

답변

0

이 또한 일반 텍스트로 사용하려면 registration_ids 배열 대신 registration_id이라는 매개 변수에 등록 ID가 전달되어야합니다.