dsfdfd1211 2013-07-03 19:34
浏览 37
已采纳

是否可以在Java服务器中添加PHP脚本?

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.

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.

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..

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

  • 写回答

3条回答 默认 最新

  • dongzhan0624 2013-07-03 20:07
    关注

    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?

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

    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.

    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).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历