C2DM:如何处理第三方php服务器中的注册id


C2DM: What to do with registration id in the 3rd party php server?

我已经为C2DM设置了Android部分,下面是代码的一部分:

private void handleRegistration(Context context, Intent intent) {
 // (...)
    else if (registration != null) {
        Log.d("c2dm", registration);
        Editor editor = context.getSharedPreferences(KEY, Context.MODE_PRIVATE).edit();
        editor.putString(REGISTRATION_KEY, registration);
        editor.commit();
        // Send the registration ID to the 3rd party site that is sending
        // the messages.
        // This should be done in a separate thread.
        // When done, remember that all registration is done.
    }
}

所以它说要将注册ID发送到我的服务器。我应该如何处理它,以及如何在php中发送消息?

代码示例会很棒,因为我对PHP不是很有经验。我看到了这个答案,但它使用会话,而我没有使用会话。

您需要将其保存到MySQL之类的数据库中,以便以后在您想要推送到设备时能够访问它。

然后你会像这个一样发送

include("class.c2dm.php");
$c = new C2DM();
$c->setUsername('appemail@gmail.com');
$c->setPassword('emailpassword');
$c->setSource('com.company.app.package');
$c->setAuthCode($c->getAuthCode());
$regid = "longdeviceid"; //this is the device you want to push to. pull from your database.

$response = $c->send($regid, 'TRACK', array('action' => 'start_tracking'));
echo $response;

在此处获取class.c2dm.php:https://bitbucket.org/Dianoga/php-c2dm/src/0c299de8f10b/class.c2dm.php