在java中使用restapi使用Parse从我自己的服务器发送推送通知
我需要使用解析推送通知从服务器向android应用程序发送推送通知 我发现你可以通过使用它的object_id向特定设备发送推送通知,object_id是唯一的,并且在每次安装时都分配给应用程序 现在,我正在使用Parse的restapi,按照PHP代码发送推送通知 现在,我不知道把端口443放在哪里,也不知道把appId和restapi键放在PHP代码的头中在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
<?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();
}
}