Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/309.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在java中使用restapi使用Parse从我自己的服务器发送推送通知_Java_Php_Android_Parse Platform - Fatal编程技术网

在java中使用restapi使用Parse从我自己的服务器发送推送通知

在java中使用restapi使用Parse从我自己的服务器发送推送通知,java,php,android,parse-platform,Java,Php,Android,Parse Platform,我需要使用解析推送通知从服务器向android应用程序发送推送通知 我发现你可以通过使用它的object_id向特定设备发送推送通知,object_id是唯一的,并且在每次安装时都分配给应用程序 现在,我正在使用Parse的restapi,按照PHP代码发送推送通知 现在,我不知道把端口443放在哪里,也不知道把appId和restapi键放在PHP代码的头中 <?php $url = 'https://api.parse.com/1/push'; $appId = 'YOUR_A

我需要使用解析推送通知从服务器向android应用程序发送推送通知

我发现你可以通过使用它的object_id向特定设备发送推送通知,object_id是唯一的,并且在每次安装时都分配给应用程序

现在,我正在使用Parse的restapi,按照PHP代码发送推送通知

现在,我不知道把端口443放在哪里,也不知道把appId和restapi键放在PHP代码的头中

<?php

 $url = 'https://api.parse.com/1/push';

 $appId = 'YOUR_APP_ID_HERE';
 $restKey = 'YOUR_REST_API_KEY_HERE';
 $target_device = 'TARGET_INSTALLATION_OBJECT_ID_HERE';  // using object Id of target Installation.
$push_payload = json_encode(array(
                        "where" => array(
                                "objectId" => $target_device,
                        ),
                        "data" => array(
                                "alert" => "This is the alert text."
                        )
                ));

$rest = curl_init();
curl_setopt($rest,CURLOPT_URL,$url);
curl_setopt($rest,CURLOPT_PORT,443);
curl_setopt($rest,CURLOPT_POST,1);
curl_setopt($rest,CURLOPT_POSTFIELDS,$push_payload);
curl_setopt($rest,CURLOPT_HTTPHEADER,
array("X-Parse-Application-Id: " . $appId,
                                "X-Parse-REST-API-Key: " . $restKey,
                                "Content-Type: application/json"));

$response = curl_exec($rest);
echo $response;

?>
 String restApiKey          =   "xxxxxxxxxx";   
String appKey           =   "xxxxxxxxxx";
static String targetDevice      =   "xxxxxxxxxx";   
static String url               =   "https://api.parse.com/1/push";




public static void main(String a[]){

    try {
        HttpClient httpClient   =   new DefaultHttpClient();
        HttpPost  post          =   new HttpPost(url);
        JSONObject json     = new JSONObject();
        json.put("objectId", targetDevice);
        json.put("test", "01234");

        StringEntity s      =   new StringEntity(json.toString());
        s.setContentEncoding("UTF-8");
        s.setContentType("application/json");

        post.setEntity(s);
        httpClient.execute(post);

    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }


}