Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 当GCM服务器向收件人发送邮件时,我如何知道是哪个用户发送了邮件_Java_Php_Android_Google Cloud Messaging_Google Play Services - Fatal编程技术网

Java 当GCM服务器向收件人发送邮件时,我如何知道是哪个用户发送了邮件

Java 当GCM服务器向收件人发送邮件时,我如何知道是哪个用户发送了邮件,java,php,android,google-cloud-messaging,google-play-services,Java,Php,Android,Google Cloud Messaging,Google Play Services,我已经成功地实现了GCM服务器,并且在接收方收到消息和通知。但是我如何知道是哪个客户端发送了该消息。这是因为在从服务器向GCM发送消息时,我们从不包含发送消息的客户端的密钥 有没有办法让我知道寄件人的钥匙 我实际上是这样做的: 1.将消息从客户端应用程序发送到第三方服务器。 2.将消息存储在第三方服务器中。 3.从服务器向GCM发送消息 这就是我实现服务器端代码向GCM发送消息的方式 $url = 'https://android.googleapis.com/gcm/send'; $recei

我已经成功地实现了GCM服务器,并且在接收方收到消息和通知。但是我如何知道是哪个客户端发送了该消息。这是因为在从服务器向GCM发送消息时,我们从不包含发送消息的客户端的密钥

有没有办法让我知道寄件人的钥匙

我实际上是这样做的: 1.将消息从客户端应用程序发送到第三方服务器。 2.将消息存储在第三方服务器中。 3.从服务器向GCM发送消息

这就是我实现服务器端代码向GCM发送消息的方式

$url = 'https://android.googleapis.com/gcm/send';
$receive_id=$_POST['receiver_key'];
$message=$_POST['message'];

$registrationIDs = array( $receive_id);


    $fields = array(
        'registration_ids' => $registrationIDs,
        'data' => array( "message" => $message ),
    );
    $headers = array(
        'Authorization: key=' . $api_key,
        'Content-Type: application/json'
    );

$ch=curl_init();

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_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt( $ch, CURLOPT_POSTFIELDS, json_encode($fields) );

 $curl_result = curl_exec( $ch );
我在客户端使用了HTTPPOST请求来发送收件人密钥和消息

下面是我用来接收消息的IntentService。 此IntentService从广播接收器启动

  import android.app.IntentService;
import android.app.Notification;
import android.app.Notification.Builder;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.NotificationCompat;
import android.util.Log;

import com.google.android.gms.gcm.GoogleCloudMessaging;

public class GCMIntentService extends IntentService{

    public GCMIntentService(String Iservice) {
        super(Iservice);
        // TODO Auto-generated constructor stub
    }

    public GCMIntentService()
    {
        super("MyIntentService");

    }
    @Override
    protected void onHandleIntent(Intent intent) {
        // TODO Auto-generated method stub
        Bundle b=intent.getExtras();
        GoogleCloudMessaging gcm=GoogleCloudMessaging.getInstance(this);
        String mType=gcm.getMessageType(intent);   //Message received here.
        NotificationCompat.Builder mBuilder =
                new NotificationCompat.Builder(this);

        String msg = intent.getStringExtra("message");
        Log.e("Message recieved",msg+" ");          


        NotificationManager mNotificationManager =
                (NotificationManager) getSystemService(NOTIFICATION_SERVICE);   //using notification manager to send notification
        Intent i = new Intent(this, Chats.class);
        i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);                               

        PendingIntent pIntent = PendingIntent.getActivity(this, 0, i, 0);              
        Builder builder  = new Notification.Builder(this);
        builder.setContentTitle("New Message Arrived!");
        builder.setContentText(msg+"");
        builder.setSmallIcon(R.drawable.ic_launcher);                       
        builder.setContentIntent(pIntent);
        mNotificationManager.notify(0, builder.build());                   

    }

}

receipent正在接收消息,但我如何知道是哪个用户发送了该消息。

我认为您可以将数据与gcm请求一起传递到您的服务器,服务器ping google服务器以将相关数据传递给收件人应用程序,这反过来又使用通过gcm接收的数据处理和解析这些信息可以在接收方获得发送方的信息。这是一个很好的解决方案…实际上我想这样做,但后来我想知道,GCM提供了如此出色的功能,那么为什么他们不在收件人端提供发件人的信息,也不在向GCM发送请求时接受发件人的任何信息呢?对不起,我说的是“将数据与GCM请求一起传递到您的服务器”!实际上,客户端应用程序与第三方应用程序服务器通信,客户端应用程序本身不会触发gcm请求,第三方服务器会触发gcm请求,它会告诉谷歌要点击哪个“注册Id”(客户端应用程序在谷歌服务器上注册,第三方服务器将其保存以备将来通信)和“注册Id”用于标识收件人。顺便说一句,发件人将始终是相同的,即第三方服务器我同意,发件人始终是第三方服务器。但我的问题是“在GCM服务器将邮件发送给收件人之后…”“收件人”如何知道是哪个用户发送了该邮件。“”。这是我实际的问题。因此,在该数组“array”(“message”=>$message)”中,我认为您也可以输入发送方的详细信息,尝试输入,然后查看gcm通知到达时广播接收方端的响应。