GVKun编程网logo

使用php和离子alpha推送通知发送推送通知

8

本文的目的是介绍使用php和离子alpha推送通知发送推送通知的详细情况,我们将通过专业的研究、有关数据的分析等多种方式,同时也不会遗漏关于android–如何阻止新的推送通知被Firebase中的旧

本文的目的是介绍使用php和离子alpha推送通知发送推送通知的详细情况,我们将通过专业的研究、有关数据的分析等多种方式,同时也不会遗漏关于android – 如何阻止新的推送通知被Firebase中的旧推送通知取代?、iOS APNs 推送通知发送成功,但移动端未收到通知、ios – 使用Malcom API发送推送通知、ios – 使用带有自定义参数的Malcom API发送推送通知的知识。

本文目录一览:

使用php和离子alpha推送通知发送推送通知

使用php和离子alpha推送通知发送推送通知

我已经按照所有步骤在 here离子框架中构建简单的应用程序.我使用PHP代码服务器端调用离子 API for push notification.我使用了以下代码,但我没有在我的应用程序中收到通知,请建议解.

<?PHP
    $androidAppId = "e2c77770";
    $data = array(
      "tokens" => "APA91bF2YePDKxE6K6vZYs2KQ27Z4mdehJg-EaZaPy10w-RHN5RUgC_P6Uie24Qu_M28j9bfZcbU6pu8Awofa8h2G5j9jABnebrVIUgKM5JcZPEJHYVW2NINirAm7VnSqGOrqm4YicAoI9Xiw5zkgTx4edqXIANLEhvqsqSCeq-_gAuzZB8wvrQ","notification" => "Hello World!"
    );
    $data_string = json_encode($data);
    $ch = curl_init('https://push.ionic.io/api/v1/push');
    curl_setopt($ch,CURLOPT_CUSTomrEQUEST,"POST");
    curl_setopt($ch,CURLOPT_POSTFIELDS,$data_string);
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
    curl_setopt($ch,CURLOPT_HTTPHEADER,array(
        'Content-Type: application/json','X-Ionic-Application-Id: '.$androidAppId,'Content-Length: ' . strlen($data_string))
    );

    $result = curl_exec($ch);
    ?>

解决方法

我从未处理过离子,但根据 http://docs.ionic.io/v1.0/docs/push-sending-push中给出的python示例,您应该在请求中添加Authorization标头.

private_key = YOUR_PRIVATE_API_KEY
b64 = base64.encodestring('%s:' % private_key).replace('\n','')
#I didn't get why they used colon while encoding the api key??
req.add_header("Authorization","Basic %s" % b64)

那个python片段的PHP实现就是这样的;

<?PHP
$yourApiSecret = "YOUR API SECRET";
$androidAppId = "e2c77770";
$data = array(
  "tokens" => "APA91bF2YePDKxE6K6vZYs2KQ27Z4mdehJg-EaZaPy10w-RHN5RUgC_P6Uie24Qu_M28j9bfZcbU6pu8Awofa8h2G5j9jABnebrVIUgKM5JcZPEJHYVW2NINirAm7VnSqGOrqm4YicAoI9Xiw5zkgTx4edqXIANLEhvqsqSCeq-_gAuzZB8wvrQ","notification" => "Hello World!"
);
$data_string = json_encode($data);
$ch = curl_init('https://push.ionic.io/api/v1/push');
curl_setopt($ch,"POST");
curl_setopt($ch,$data_string);
curl_setopt($ch,true);
curl_setopt($ch,array(
    'Content-Type: application/json','Content-Length: ' . strlen($data_string),'Authorization: Basic '.base64_encode($yourApiSecret)
    )
);

$result = curl_exec($ch);
var_dump($result);

此外,输出结果可能会告诉您很多关于要发送的推送通知的状态.

android – 如何阻止新的推送通知被Firebase中的旧推送通知取代?

android – 如何阻止新的推送通知被Firebase中的旧推送通知取代?

当我触发推送通知时,旧的通知将替换为新通知.但我希望它应该添加到旧通知中.

我的MyFirebaseMessaging类是:

public class MyFirebaseMessaging  extends FirebaseMessagingService {
    String title="";
    String message,type,click_action;
    int no_of_messages;

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        super.onMessageReceived(remoteMessage);

        if(remoteMessage.getData().size()>0) {
            message = remoteMessage.getData().get("body");
            title = remoteMessage.getData().get("title");
            click_action = remoteMessage.getData().get("click_action");
            no_of_messages++;
            ShowNotification(message);
        }
        else
            Log.i("remoteMessage",message);
    }

    private void ShowNotification(String message) {
        Intent intent = new Intent(click_action);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        intent.putExtra("loading_flag","load");
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
        Uri defaultSoundUri = ringtoneManager.getDefaultUri(ringtoneManager.TYPE_NOTIFICATION);
        String NOTIFICATION_CHANNEL_ID = "my_channel_id_01";
        notificationmanager notificationmanager = (notificationmanager) getSystemService(Context.NOTIFICATION_SERVICE);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            @SuppressLint("WrongConstant")
            NotificationChannel notificationChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, "My Notifications", notificationmanager.IMPORTANCE_MAX);

            // Configure the notification channel.
            notificationChannel.setDescription("Channel description");
            notificationChannel.enableLights(true);
            notificationChannel.setLightColor(Color.RED);
            notificationChannel.setVibrationPattern(new long[]{0, 1000, 500, 1000});
            notificationChannel.enableVibration(true);
            notificationmanager.createNotificationChannel(notificationChannel);
        }

        NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this,NOTIFICATION_CHANNEL_ID);
        // if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        //   notificationBuilder.setSmallIcon(R.drawable.vadodaramunicipalcorporation);
        //  notificationBuilder.setColor(getResources().getColor(R.color.backgroundColor));
        //  } else {
        //     setSmallIcon(R.drawable.vadodaramunicipalcorporation)
        //  }
        notificationBuilder.setSmallIcon(R.mipmap.vadodaramunicipalcorporation)
            .setLargeIcon(BitmapFactory.decodeResource(getApplicationContext().getResources(), R.mipmap.vadodaramunicipalcorporation))
            .setContentTitle("You have new "+ title)
            .setDefaults(Notification.DEFAULT_ALL)
            .setWhen(System.currentTimeMillis())
            .setTicker("Hearty365")
            .setContentInfo("Info")
            .setContentText(message+" new Alerts")
            .setNumber(no_of_messages)
            .setAutoCancel(true)
            .setSound(defaultSoundUri)
            .setStyle(new NotificationCompat.BigTextStyle())
            .setContentIntent(pendingIntent)
            .setPriority(Notification.PRIORITY_MAX);
        notificationmanager.notify(0, notificationBuilder.build());
    }
}


{
    "to":"token-key",
    "data" : {
         "body" : "4",
          "title" : "Alert",
          "click_action" : "Activity.DATA_CLICK"
    }
}

解决方法:

new push notification is replaced the old one in firebase push notification in my application,How i will stop this

你需要在notificationmanager.notify()中传递不同的notificationID

示例代码

Date myDate = new Date();
int myNotificationId = Integer.parseInt(new SimpleDateFormat("ddhhmmss",  Locale.US).format(myDate));
notificationmanager.notify(myNotificationId,notificationBuilder.build());

iOS APNs 推送通知发送成功,但移动端未收到通知

iOS APNs 推送通知发送成功,但移动端未收到通知

如何解决iOS APNs 推送通知发送成功,但移动端未收到通知?

自上周五(4 月 23 日)以来一切正常,我收到了沙盒和生产通知。但是当我现在检查时,通知不起作用。我检查了我的 .pem 文件在 2021 年 12 月之前有效,当我运行以下代码时,结果是“消息已成功传递”。我不知道发生了什么。请帮帮我。

<?PHP
    $devicetoken = "a9eb9cd54446b5cad4fa3636dbe822b5d420126fdbb632ef79b4bf07bfd8b6b4";
    $passphrase = ''secret'';

    $message = "Hello World!";

    $ctx = stream_context_create();

    $passphrase = ''secret'';
    $ctx = stream_context_create();
    stream_context_set_option($ctx,''ssl'',''local_cert'',''certi.pem'');
    
    stream_context_set_option($ctx,''passphrase'',$passphrase);
  /* $fp = stream_socket_client(
                               ''ssl://gateway.push.apple.com:2195'',$err,$errstr,60,STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT,$ctx);*/
    $fp = stream_socket_client(''ssl://gateway.sandBox.push.apple.com:2195'',$ctx);
    
    if (!$fp){
        exit("Failed to tess connect: $err $errstr" . PHP_EOL);
    }
    $body = array(''aps'' => array(''alert'' => $message,''sound'' => ''default'',''badge'' => 1),''rewards_badge'' => 1);
    
    $payload = json_encode($body);

    $msg = chr(0) . pack(''n'',32) . pack(''H*'',$devicetoken) . pack(''n'',strlen($payload)) . $payload;
    $result = fwrite($fp,$msg,strlen($msg));
    if (!$result){
        echo ''Message not delivered'' . PHP_EOL;
    }else{
        echo ''Message successfully delivered'' . PHP_EOL;
    }
    fclose($fp);
?>

谢谢

解决方法

我也是。我向 Apple 提交了帮助请求,请他们提供帮助。

我使用相同的测试脚本。我注意到 ssl://gateway.sandbox.push.apple.com:2195 不再有效。 If your Apple devices aren''t getting Apple push notifications

这是新域名? api.sandbox.push.apple.com:443

Sending Notification Requests to APNs

  • 旧端口 2195 和 2196 已弃用,2021 年 3 月后将不再受支持。

我也是。让我们像 Apex Legends 一样一起解决这个问题。

我已向 Apple 提交了 TSI。他们在 2 月 10 日发送了一封电子邮件说:

从 2021 年 3 月 29 日起,与 Apple 推送通知服务的基于令牌和证书的 HTTP/2 连接必须包含新的根证书 (AAACertificateServices 5/12/2020),以取代旧的 GeoTrust Global CA 根证书。为确保无缝过渡并避免推送通知传送失败,请在 3 月 29 日之前验证 HTTP/2 接口的新旧根证书都包含在每个通知服务器的信任存储中。

请注意,Apple 向您颁发的 Apple Push Notification 服务 SSL 提供商证书此时无需更新。

了解有关连接到 APN 的更多信息。

如果您有任何问题,请联系我们。

此致,Apple 开发者关系部

更新 - 5 月 3 日星期一,在向 Apple Dev 提交 TSI 后

  1. 在 Apple 迁移到新的 APNS 提供程序 API(http/2 协议)后,推送通知于 2021 年 3 月 31 日停止为开发者工作。
  2. 要继续使用推送,请参阅此页面:向 APNs 发送通知请求
  3. 在该页面上,我对这 3 项特别感兴趣:

Registering Your App with APNs

Establishing a Token-Based Connection to APNs

Generating a Remote Notification

我学到了什么?

  1. 撤销所有与 APNS 相关的开发者帐号证书
  2. 制作新证书,这次在将它们安装到您的提供服务器时不要制作任何 PEM 文件。此外,请确保在连接到 APNS 时停止使用端口 2195,并使用 443 或 2197。

好消息?新的 APNS 提供程序 API 仍然与 Objective C 兼容!

?

ios – 使用Malcom API发送推送通知

ios – 使用Malcom API发送推送通知

我们通过Malcom API发送APNS.小消息没有问题,但是当我们创建大消息时,没有收到通知.

消息字符串长度是否有限制?

特定密钥的价值是否有限制?

文档目前没有说明长度限制.

提前致谢

解决方法

你是对的.在他们的文档中没有提及它.无论如何,如果您通过malcom.mymalcom.com发送推送到您的应用程序,您可以在键入消息时看到最多的字符.所以,我猜任何通过API的推送请求都应该有相同的限制.

ios – 使用带有自定义参数的Malcom API发送推送通知

ios – 使用带有自定义参数的Malcom API发送推送通知

我正在尝试使用Malcom API在推送通知中发送自定义参数,但我无法从iOS应用程序中读取它们.

示例CURL:

curl -u user:pass -H "Content-Type: application/json" -X POST -d '{ "notification": { "applicationCode": "appUDID","environment": "SANDBox","message": "Message","udids": [ "00c93096526860d932ba1bf116e752b8f2689675" ],"notificationCustomization": { "customfield": [ {"entry": { "key":"new_id","value": "25" }} ],"badge": 5 } } }' http://api.mymalcom.com/v3/notification/push

iOS代码(AppDelegate):

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {

    [MalcomLib didReceiveRemoteNotification:userInfo active:[MalcomLib getAppActive]];

}

userInfo包含以下信息:

{
    aps =     {
        alert = "Message";
        badge = 5;
    };
    notificationId = 521726;
}

你知道我在哪里读这些参数吗?

解决方法

我估计你的JSON不够好.它应该是这样的:

{
"notification":{
  "applicationCode":"yourApplicationCode","environment":"SANDBox","message":"YourMessage","notificationCustomization":{
     "customFields":{
        "entry":[
           {
              "key":"yourkey1","value":"yourvalue1"
           },{
              "key":"yourkey2","value":"yourvalue2"
           },{
              "key":"yourkey3","value":"yourvalue3"
           }
        ]
     }
  }

}
}

希望这可以帮助.

我们今天的关于使用php和离子alpha推送通知发送推送通知的分享就到这里,谢谢您的阅读,如果想了解更多关于android – 如何阻止新的推送通知被Firebase中的旧推送通知取代?、iOS APNs 推送通知发送成功,但移动端未收到通知、ios – 使用Malcom API发送推送通知、ios – 使用带有自定义参数的Malcom API发送推送通知的相关信息,可以在本站进行搜索。

本文标签: