简体   繁体   English

Java中的Android GCM推送通知服务器端

[英]Android GCM Push Notification server side in java

I have a couple of questions regarding GCM. 关于GCM,我有几个问题。

  1. On the official page for GCM , under Getting Started, it says Decide which Google-provided GCM connection server you want to use— HTTP or XMPP (CCS). GCM的官方页面 “入门”下,显示“ Decide which Google-provided GCM connection server you want to use— HTTP or XMPP (CCS). Now I understand the difference between the two of these in practice, but when he says DECIDE which one to choose, I am not sure what is he expecting of me? 现在我了解了实践中这两者之间的区别,但是当他说决定选择哪一个时,我不确定他对我有什么期望? Is there something I need to do differently for the two of these. 我需要为这两个做不同的事情吗?
  2. I have the android app ready for GCM. 我已经为GCM准备好了android应用。 For the server part of things, I am not sure what am I supposed to do. 对于服务器而言,我不确定该怎么做。 Can I just do a POST request to https://android.googleapis.com/gcm/send nd pass parameters along? 我可以向https://android.googleapis.com/gcm/send nd传递参数发出POST请求吗? I can use HTTPClient for this one, right? 我可以为此使用HTTPClient,对吗? Is there something special? 有什么特别的吗?
  3. Also, the server that I have to do in step 2. It need not be a server right? 另外,我在步骤2中必须要做的服务器。它不一定是服务器吗? It can be any standalone java code and I can just run it, to make a POST to gcm? 它可以是任何独立的Java代码,我也可以运行它以对gcm进行POST? Only for testing purposes. 仅用于测试目的。

2 - that's basically it, here' my server code, it's a PHP file in my server 2-基本上就是这样,这是我的服务器代码,这是我服务器中的PHP文件

public function send_push(){
    $message = "your message";

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

    $fields = array(
                    'registration_ids'  => array("GCM_REGISTRATION"),
                    'data'              => array( "message" => $message ),
                    );

    $headers = array( 
                        'Authorization: key=YOUR_API_KEY',
                        'Content-Type: application/json'
                    );

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

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

    // Execute post
    $result = curl_exec($ch);

    // Close connection
    curl_close($ch);

    echo $result;
}

GCM_REGISTRATION is the hash you get after you run your app for the first time to register in GCM. GCM_REGISTRATION是您首次运行应用以在GCM中注册后所获得的哈希值。 if everything is ok, You can see this in logcat 如果一切正常,您可以在logcat中看到

api_key is the hash you get when you create your app( you have probably seen it on the documentation) api_key是创建应用程序时获得的哈希(您可能已经在文档中看到了)

3 - I believe it doesn't need to be a server because it's actually going to send the message to Google servers which is going to deliver it to your app 3-我认为它不必是服务器,因为它实际上是将消息发送到Google服务器,然后再将其传递到您的应用程序中

  1. Yes, there's a big difference between http and ccs severs. 是的,http和ccs服务器之间有很大的区别。 The former involves simple http requests. 前者涉及简单的http请求。 The latter requires xmpp protocol implementation. 后者需要xmpp协议实现。

  2. Yes, any code that submits http requests should work if you are taking the gcm http approach. 是的,如果您采用的是gcm http方法,则任何提交http请求的代码都应该起作用。

  3. For testing purposes you don't need a server. 出于测试目的,您不需要服务器。 Any code submitting http requests would do. 任何提交http请求的代码都可以。 However, you'll have to pass the device registration id to your server code in order to send a GCM message. 但是,您必须将设备注册ID传递到服务器代码,才能发送GCM消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何通过java服务器使用GCM向Android设备发送推送通知? - how to send push notification to the android device using GCM by java server? Android GCM Java Server - 无消息数据的推送通知 - Android GCM Java Server - Push Notification without message data 没有服务器的Android GCM推送通知,或者使用Microsoft SQL(非Mysql)和WCF服务(非PHP)的GCM推送通知 - Android GCM push notification without server OR GCM push notification using Microsoft SQL(Not Mysql) and WCF service(Not PHP) 如何触发gcm向Android设备发送推送通知(使用Java服务器) - how to trigger a gcm to send a push notification to android device(using java server) Android GCM推送通知当机 - android GCM Push notification crashing Android通知使用GCM和带有JSON消息的Java推送为空 - Android notification push empty using GCM and java with json message 如何使用GCM从Java服务器向Android应用程序发送通知? - How to send notification to Android app from Java server using GCM? 配置Openfire服务器以支持GCM推送通知 - Configure Openfire server to support GCM push notification 如何使用GCM在Android上进行推送通知? - How to make push notification with GCM work on android? 如何使用Java GCM API在Android设备上获取失败推送通知的注册ID - How to get registration id of failure push notification on android device using Java GCM API
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM