服务器收到订阅状态更改通知时如何识别用户

时间:2019-05-14 12:12:32

标签: android google-play

根据Android开发者指南。当用户购买或取消订阅时,我们的服务器将收到发布/订阅通知。

但是似乎我们没有任何信息可以识别用户。如何在服务器中相应地修改用户数据?

以下是我收到的通知

{"version":"1.0","packageName":"com.diamondtech.streammap","eventTimeMillis":"1557833856021","subscriptionNotification":{"version":"1.0","notificationType":2,"purchaseToken":"celgdoceflgifibejhfgafpd.AO-J1OxoputCKFIjQt7QgnF5hSg8jiqDCNEiBM-8kBEOTwXr4oy-33LGr8l6h2Ih1GXX7yjgcptIaatVFN5EHT4_sywD5-qruOhOJZVdwBnGM71-8N-xxxxxxxxxxx","subscriptionId":"premium"}}

以及Google验证API的响应

{  "kind": "androidpublisher#subscriptionPurchase", 
"startTimeMillis": "1557832655139",  "expiryTimeMillis":
"1557834750372",  "autoRenewing": false,  "priceCurrencyCode": "TWD", 
"priceAmountMicros": "160000000",  "countryCode": "TW", 
"developerPayload": "",  "cancelReason": 1,  "orderId":
"GPA.3318-4223-0272-90442..6",  "linkedPurchaseToken":
"cjnnjplpglkmdmdhbhaecobo.AO-J1OzD_JJr1Z8pzSDvJSjujfHVp9EQUsUnBv2kf5JocYsXpT-rX954WIuOSAtmLbMzqJmHudnwvsJll1GnXThj6JoDFSAR2E01fa4eZ7lUIozMOh4a_xxxxxxxxxxxx",
"purchaseType": 0 }

1 个答案:

答案 0 :(得分:0)

答案很晚,但是由于没有答案,这至少可以帮助某人。

仅当客户使用“通过Google订阅”时,您才能获得个人信息:
https://developers.google.com/news/subscribe/

如果您有一个用户在其中购买订阅的应用,则您会从Google获得带有PurchaseToken的收据。并且由于您知道应用程序中的用户,因此将用户信息以及收据(最重要的是purchaseToken)保存在数据库中。

收到通知时,将通知中的purchaseToken与数据库匹配,以确定它属于哪个用户。

请注意,如果用户取消然后重新订阅,他们将获得一个新的purchaseToken,原始的将在Google的收据中的“ linkedPurchaseToken”下:
https://developers.google.com/android-publisher/api-ref/purchases/subscriptions#resource