php–Android GCM中的通知生成问题

php–Android GCM中的通知生成问题,第1张

概述我遇到以下两个问题:第一个问题:我必须注册两个使用相同设备的客户,因此他们具有相同的注册ID.当我从服务器端向这两个客户发送报价时,显示的通知应取决于登录的客户.例如(见图):在我的申请表中,我有一个客户登录表单.在这种形式下,如果用户gnanavel登录,则应用程序必须单独接收

我遇到以下两个问题:

第一个问题:

我必须注册两个使用相同设备的客户,因此他们具有相同的注册ID.

当我从服务器端向这两个客户发送报价时,显示的通知应取决于登录的客户.

例如(见图):

在我的申请表中,我有一个客户登录表单.在这种形式下,如果用户gnanavel登录,则应用程序必须单独接收其优惠,而不是其他优惠.

同样,如果用户jeya登录,该应用程序必须单独接收她的优惠,而不是其他的优惠.

目前该应用程序正在接收这两个优惠

编辑:

我已经在我的数据库中创建了登录状态字段.如果我的客户登录设备意味着收到了他的报价单独的通知.我没有得到其他的报价.工作得很好.

我点击了优惠按钮检查了条件:

 $getregID = MysqLi_query($con,"select * from pim_customers where customer_ID='$customer_ID' and gcm_regID='$regID' and loginstatus='Y'");

我写这些条件意味着我的第一个问题得到了解决.但提出了另一个问题.

另一个问题是.,

当管理员输入某些要约时,客户只有在登录客户时才必须在设备上接收通知.否则,不应收到通知.这部分运作良好.

问题是,当我的客户长时间注销时,管理员会在此期间输入更多优惠.

如果客户在2天后登录应用程序,他应该收到所有待处理的消息.如何获取待处理的消息?

管理员端输入提供的时间客户注销意味着loginstatus在数据库中是’N’.那么如何执行这些条件并接收通知.

 $getregID = MysqLi_query($con,"select * from pim_customers where customer_ID='$customer_ID' and gcm_regID='$regID' and loginstatus='Y'");

这是单击商品按钮时执行的服务器端代码:

if (isset($_GET["regID"]) && isset($_GET["customer_ID"]) && isset($_GET["message"])) {  $regID = $_GET["regID"];  $message = $_GET["message"];  $customer_ID = $_GET["customer_ID"];  include_once './GCM.PHP';  $getregID = MysqLi_query($con,"select * from pim_customers where customer_ID='$customer_ID' and gcm_regID='$regID' and loginstatus='Y'");  $count1=MysqLi_num_rows($getregID);  while($row = MysqLi_fetch_array($getregID))  {    $ID=$row['customer_ID'];  }  if (MysqLi_num_rows($getregID) > 0) {    $query = MysqLi_query($con,"select count(offer) as count from pim_productdeal where customer_ID='$ID' and offer!=''");    $count = MysqLi_fetch_array($query);    $msg = $count['count'];    $gcm = new GCM();    $registatoin_IDs = array($regID);    $message = array("price" => $msg." "."The offers received");    $result = $gcm->send_notification($registatoin_IDs, $customer_ID, $message);    echo $result;  }}

这是我的AndroID端代码:

public class GCMIntentService extends GCMBaseIntentService {  private static final String TAG = "GCMIntentService";  String regID;  public GCMIntentService() {    super(SENDER_ID);  }  @OverrIDe  protected voID onRegistered(Context context, String registrationID) {    ServerUtilitIEs.register(context, Registeractivity.first_name, Registeractivity.last_name, Registeractivity.email, Registeractivity.password, registrationID);  }  @OverrIDe  protected voID onUnregistered(Context context, String registrationID) {    Log.i(TAG, "Device unregistered");    displayMessage(context, getString(R.string.gcm_unregistered));    ServerUtilitIEs.unregister(context, registrationID);  }  @OverrIDe  protected voID onMessage(Context context, Intent intent) {    Log.i(TAG, "Received message");    GCMRegistrar.checkDevice(this);    GCMRegistrar.checkManifest(this);    regID = GCMRegistrar.getRegistrationID(this);    String message = intent.getExtras().getString("price");    displayMessage(context, message);    if(Constants.response != null) {      generateNotification(context,message);    }  }  @OverrIDe  protected voID onDeletedMessages(Context context, int total) {    Log.i(TAG, "Received deleted messages notification");    String message = getString(R.string.gcm_deleted, total);    displayMessage(context, message);    // notifIEs user    generateNotification(context,message);  }  @OverrIDe  public voID one rror(Context context, String errorID) {    Log.i(TAG, "Received error: " + errorID);    displayMessage(context, getString(R.string.gcm_error, errorID));  }  @OverrIDe  protected boolean onRecoverableError(Context context, String errorID) {    // log message    Log.i(TAG, "Received recoverable error: " + errorID);    displayMessage(context, getString(R.string.gcm_recoverable_error,            errorID));    return super.onRecoverableError(context, errorID);  }  private static voID generateNotification(Context context,String message) {    int icon = R.drawable.icon;    long when = System.currentTimeMillis();    notificationmanager notificationmanager = (notificationmanager)            context.getSystemService(Context.NOTIFICATION_SERVICE);    Notification notification = new Notification(icon, message, when);    String Title = context.getString(R.string.app_name);    Intent notificationIntent = new Intent(context, MyDealProducts.class);    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_top |            Intent.FLAG_ACTIVITY_SINGLE_top);    PendingIntent intent =            PendingIntent.getActivity(context, 0, notificationIntent, 0);    notification.setLatestEventInfo(context, Title, message, intent);    notification.flags |= Notification.FLAG_auto_CANCEL;    notification.defaults |= Notification.DEFAulT_SOUND;    notification.defaults |= Notification.DEFAulT_VIBRATE;    notificationmanager.notify(0, notification);        }}

解决方法:

我编辑了您的问题,以便更容易理解.我希望我没有改变你的意思.如果我这样做,我道歉并请你纠正我.

现在我的回答:

>您的服务器应该知道哪个用户当前登录到哪个设备.您应该在服务器中维护一个已登录用户的表,并且对于每个登录用户,它将保存他/她登录的设备的标识符.为此,您必须向服务器发送请求每次用户登录或注销时.请求应包含用户标识和设备标识.对于设备ID,您可以使用注册ID或使用服务器生成的其他ID(最好在服务器中生成一个比注册ID短的ID,因此使用效率更高.你会必须维护一个将注册ID映射到设备ID的表.
>当管理员创建新要约并将其分配给用户时,只有在用户登录时才会向应用程序发送GCM通知.因此,在您使用同一设备的两个用户的示例中,如果其中一个是登录后,您将仅为登录用户向该设备发送一个通知.如果他们都没有登录,您将不会发送任何通知.您将在数据库中存储新商品,并等待其中一个商家登录.
>当GCM消息到达设备时,您应该将其发送给当前登录的用户,因为一个用户可能在消息发送后注销但另一个用户在到达设备之前登录.为此,您的GCM消息应包含用户标识符作为附加字段.如果消息到达设备的用户ID与当前登录的用户不匹配,则会丢弃该消息并且不显示通知.
>当用户登录时,服务器将收到请求(请参阅#1).在此请求的响应中,服务器应将用户在服务器的DB中提供的所有商品返回给设备.
>对于在设备长时间处于非活动状态时发送的消息 – 当设备再次变为活动状态时,可能会从GCM向其发送旧消息(如果它们尚未被GCM丢弃).如果这些消息不属于当前登录用户,则将其丢弃(请参阅#3).如果它们属于当前登录用户,则应显示它们.
>我不了解PHP,但是由于我对您的服务器代码的了解有限,似乎您向设备发送了一条GCM消息,其中包含用户拥有的优惠数量.您应该对发送的所有邮件使用相同的collapse_key.这样,如果服务器在设备脱机时发送了多条消息,则当它再次变为活动状态时,其中只有一条将被发送到设备.如果所有消息都包含可用商品的数量,则无需获取所有待处理消息.

总结

以上是内存溢出为你收集整理的php – Android GCM中的通知生成问题全部内容,希望文章能够帮你解决php – Android GCM中的通知生成问题所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1106874.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-28
下一篇2022-05-28

发表评论

登录后才能评论

评论列表(0条)

    保存