是否有可能在Java服务器添加PHP脚本? [英] Is it possible to add PHP scripts in a Java server?

查看:113
本文介绍了是否有可能在Java服务器添加PHP脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Java服务器与Spring框架运行。现在我不得不开发一个GCM服务,从服务器将数据发送到Android应用程序。

I have a java server running with the spring framework. For now I have to develop a GCM service to send data from the server to an Android app.

我已经看到在互联网上的一些教程和他们都实现了一个PHP脚本此服务。我想知道如果我可以在我的Java服务器弹簧使用它们。

I have been seeing some tutorial on Internet and all of them implements this service in a php script. I'm wondering if I can use them in my java server with spring.

我知道我可以重写code到Java,但我没有那么多的时间,因为它是对大学的工作,所以我不想浪费太多的时间改写了这一切。

I know I can rewrite the code to Java but I don't have so much time as it's a work for University, so I don't wanna waste much time rewriting all of this..

所以我想知道是否可以添加这些PHP脚本,如果是这样,我该怎么办呢?

So I'd like to know if it is possible to add these php scripts and if so, how can I do it?

推荐答案

即使接口的Java服务器与一些PHP code发送GCM消息,您仍然需要注册ID和通知的有效载荷传递给$ C $℃。不会简单地使用 GCM-的server.jar 由谷歌提供的是更容易?

Even if you interface your Java server with some PHP code that sends GCM messages, you would still have to pass registration IDs and notification payload to that code. Wouldn't it be easier to simply use the gcm-server.jar supplied by Google?

使用 GCM-的server.jar 中,code,你需要发送一个GCM的消息是这样简单:

Using gcm-server.jar, the code you need to send a GCM message is as simple as this :

Sender sender = new Sender(apiKey);
Message message = new Message.Builder()
    .delayWhileIdle(true)
    .addData("key1", "value1")
    .addData("key2", "value2")
    .build();
Result result = sender.send(message, registrationId, numOfRetries);

如果您想处理的错误响应,你应该检查结果情况,看是否由GCM服务器已成功收到消息,如果没有,发生了什么错误。

If you wish to handle error responses, you should check the result instance to see if the message was successfully received by the GCM server, and if not, what error occurred.

你必须要实现的唯一的另一件事是一定的servlet,从你的Andr​​oid应用程序接受注册ID和将它们存储在你的数据库。也许你可以使用现有的PHP code那部分(你不会需要PHP code和Java code之间的接口)。

The only other thing you'll have to implement is some servlet that accepts registration IDs from your Android app and stores them in your DB. Perhaps you can use existing PHP code for that part (you won't need any interface between the PHP code and Java code).

这篇关于是否有可能在Java服务器添加PHP脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆