Google Play 开发者通知

发布于 2025-01-20 00:51:47 字数 238 浏览 3 评论 0 原文

我在设置端点以通过 ac# 控制器中的 Pub/Sub 接收 Google Play 开发者通知时遇到困难。我已经针对应用程序设置了所有内容以发布到某个主题,并且我已在 Google Pub/Sub 中成功设置了订阅...并且测试通知正在 Google Pub/Sub 上通过...问题是我遇到了在我的服务器端 C# 控制器端点上接收推送通知时遇到问题...我不确定如何设置以及是否有正确的 json 签名。我找不到与此相关的任何示例或文档。任何帮助将不胜感激!

I'm having difficulty setting up an end-point to receive Google Play Developer Notifications via Pub/Sub in a c# controller. I've set everything up against the app to publish to a topic and I have successfully setup a subscription in Google Pub/Sub...and the test notification is coming through on Google Pub/Sub...the problem is I am having trouble receiving the push notification on my server side c# controller end-point...I'm not sure how to set that up and if I have the correct json signature. I can't find any examples or documentation around this. Any help would be appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

九公里浅绿 2025-01-27 00:51:47

这是我对Pub/sub的第一个“测试”,该样本对我有用。

请参阅此处的所有样本:

这些步骤需要完成:

  1. 在此处创建一个主题:
  2. ​“ IAP”,添加 [email  procearted] AS Pub/sub Publisher。这将允许Google Play在此主题上发布。
  3. 在订阅下 [email  protected] ,它运行良好。检查您的环境变量“ Google_application_credentials”,并将此用户提取为“ IAP-SUB”权限的Pub/Sub Subscriber。
  4. Play商店需要在“货币化设置”下配置。字符串为例:项目/yourproject/topics/iap
  5. 按测试消息(您还可以在云控制台中看到它)

测试消息可能看起来像这样:

20:16:07:收到消息6108129433484522 20:16:07:
{“版本”:“ 1.0”,“ packagename”:“ com.yourproject”,“ eventTimeMillis”:“ 166666642564858”,“ testnotification”:{“ version”:{“ version”:“ 1.0”}}}

class class class class in the Backvers in Buckdent in Background note等待。
如果您只想在控制台中尝试,请使用 Console.Readline()

public class GCloudPubSub : IDisposable
{
    public String projectId { get; set; }
    public String subscriptionId { get; set; }

    private SubscriberClient _client;
    
    public FirebasePubSub() {
        projectId = "yourproject";
        subscriptionId = "iap-sub";
    }

    public async void Start() 
    {
        SubscriptionName subscriptionName = SubscriptionName.FromProjectSubscription(projectId, subscriptionId);
        _client = await SubscriberClient.CreateAsync(subscriptionName);
        await _client.StartAsync(HandleMessage);
    }

    public async void Stop()
    {
        await _client.StopAsync(CancellationToken.None);
    }

    public void Dispose()
    {
        Stop();
    }

    static Task<SubscriberClient.Reply> HandleMessage(PubsubMessage message, CancellationToken token)
    {
        Log($"Received message {message.MessageId}");

        string text = System.Text.Encoding.UTF8.GetString(message.Data.ToArray());

        Log(text);

        return Task.FromResult(SubscriberClient.Reply.Ack);
    }

    static void Log(string text) => Console.WriteLine($"{DateTime.UtcNow:HH:mm:ss}: {text}");
}

希望这会引导您以正确的方式:)

This is my first "test" of Pub/Sub and this sample worked for me.

See all samples here: https://github.com/GoogleCloudPlatform/dotnet-docs-samples/tree/main/pubsub/api/Pubsub.Samples

These steps needs to be done:

  1. Create a topic here: https://console.cloud.google.com/cloudpubsub/topic/ , in the example we call it "iap"
  2. Under permission for "iap", add [email protected] as Pub/Sub publisher. This will allow Google Play to publish on this topic.
  3. Under subscriptions https://console.cloud.google.com/cloudpubsub/subscription add your service account/personal gmail or what ever that is linked to your c# server later on. I tested [email protected] and it worked fine. Check your environment variable "GOOGLE_APPLICATION_CREDENTIALS" and extract this user as Pub/Sub subscriber in permissions for "iap-sub".
  4. Play store needs to be configured under "Monetization setup". String are for instance: projects/yourproject/topics/iap
  5. Press a test message (you can also see it in the Cloud console)

Test message could look something like this:

20:16:07: Received message 6108129433484522 20:16:07:
{"version":"1.0","packageName":"com.yourproject","eventTimeMillis":"1666642564858","testNotification":{"version":"1.0"}}

Class below runs the client in the background without waiting.
If you just wanna try in a console, use the Console.ReadLine()

public class GCloudPubSub : IDisposable
{
    public String projectId { get; set; }
    public String subscriptionId { get; set; }

    private SubscriberClient _client;
    
    public FirebasePubSub() {
        projectId = "yourproject";
        subscriptionId = "iap-sub";
    }

    public async void Start() 
    {
        SubscriptionName subscriptionName = SubscriptionName.FromProjectSubscription(projectId, subscriptionId);
        _client = await SubscriberClient.CreateAsync(subscriptionName);
        await _client.StartAsync(HandleMessage);
    }

    public async void Stop()
    {
        await _client.StopAsync(CancellationToken.None);
    }

    public void Dispose()
    {
        Stop();
    }

    static Task<SubscriberClient.Reply> HandleMessage(PubsubMessage message, CancellationToken token)
    {
        Log(
quot;Received message {message.MessageId}");

        string text = System.Text.Encoding.UTF8.GetString(message.Data.ToArray());

        Log(text);

        return Task.FromResult(SubscriberClient.Reply.Ack);
    }

    static void Log(string text) => Console.WriteLine(
quot;{DateTime.UtcNow:HH:mm:ss}: {text}");
}

Hopefully this will lead you on the right way :)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文