Android:inApp购买收据验证(第2部分) [英] Android : inApp purchase receipt validation (Part 2)

查看:340
本文介绍了Android:inApp购买收据验证(第2部分)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序中实施 inApp ,并将产品添加为管理产品。购买后我想做收据验证。我在开发者控制台中配置如

I am implement inApp purchase in my application and add product as "Manage Product". After purchase I want to do receipt validation.For that I configure in Developer console like

步骤


  1. 开发人员控制台 - >设置 - > API访问

  2. 创建服务器帐户

  3. Google Developer console - >在服务帐户中添加凭据并将其设置为JSON

  1. Developer Console -> Settings -> API access
  2. Create Server account
  3. Google Developer console -> Add a credential in Service account and put it as JSON

添加后我从开发人员那里获得了一个文件它包含的控制台

After adding I got a file from developer console it contains

{
  "type": "service_account",
  "project_id": "api-xxxxx-xxx",
  "private_key_id": "xxxxxxxxxxxxxxxxxxxxxx",
  "private_key": "-----BEGIN PRIVATE KEY-----\ixxxxxxxxxxxxxxxx=\n-----END PRIVATE KEY-----\n",
   "client_email": "test-in-app-receipt-validation@api-xxxxxxx.iam.gserviceaccount.com",
   "client_id": "xxxxxxxxxxxxxxx",
   "auth_uri": "https://accounts.google.com/o/oauth2/auth",
   "token_uri": "https://accounts.google.com/o/oauth2/token",
   "auth_provider_x509_cert_url":   "https://www.googleapis.com/oauth2/v1/certs",
   "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/test-in-app-receipt-validation%40api-9129873511008807687-564452.iam.gserviceaccount.com"
   }


但我不知道如何进行下一步。
如何使用此文件收据验证

But I don't know how to do the next step. How to use this file Receipt validation

购买后我的回复为

{ 
 "orderId":"12999763169054705758.1371079406387615", 
 "packageName":"com.example.app",
 "productId":"exampleSku",
 "purchaseTime":1345678900000,
 "purchaseState":0,
 "developerPayload":"bGoa+V7g/yqDXvKRqq+JTFn4uQZbPiQJo4pf9RzJ",
 "purchaseToken":"rojeslcdyyiapnqcynkjyyjh"
}

任何人都可以帮助我如何处理下一步使用包含JSON值的下载文件的收据验证

Can anyone please help me how to handle the next step for Receipt validation for the make use of downloaded file that contain JSON value

推荐答案

跟进原始问题现在我知道你正在使用Java作为服务器端代码,你会想要使用适用于Java的Google API客户端库。我自己对Java不满意,但文档很容易理解。

Following up on your original question now that I know you're using Java for your server side code, you will want to use the Google API Client Library for Java. I'm not comfortable with Java myself but the documentation is easy to follow.

首先,你需要进行身份验证,看看 Google提供的示例代码。您目前有一个JWT(JSON Web令牌),但您可以通过从Google API仪表板上的相同位置下载 p12 证书文件来保持该示例。

First of, you need to authenticate, take a look at the example code Google provides. You currently have a JWT (JSON Web Token) but you can keep to the example by instead downloading the p12 certificate file from the same place on the Google API Dashboard.

您的身份验证代码应如下所示:

Your authentication code should look something like this:

HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
JsonFactory jsonFactory = JacksonFactory.getDefaultInstance()

GoogleCredential credential = new GoogleCredential.Builder().setTransport(httpTransport)
  .setJsonFactory(jsonFactory)
  .setServiceAccountId(SERVICE_ACCOUNT_EMAIL)
  .setServiceAccountScopes(Collections.singleton(AndroidPublisherScopes.ANDROIDPUBLISHER))
  .setServiceAccountPrivateKeyFromP12File(new File("key.p12"))
  .build();

另外不要忘记设置 SERVICE_ACCOUNT_EMAIL 并将 key.p12 文件存储在服务器可访问的位置。

Also don't forget to set your SERVICE_ACCOUNT_EMAIL and store the key.p12 file somewhere accessible to your server.

如果您有兴趣,这是 docs AndroidPublisherScopes

正如我所提到的,我对Java的了解有限,所以请不要理会我所犯的任何错误。

As I mentioned, my knowledge of Java is limited so please use your disregard any mistakes I have made.

Google已经提供了一些代码示例下载和GitHub回购链接。我建议检查一下。

Google have made some code samples available with downloads and links to GitHub repos. I suggest checking those out.

从这里你可以使用 AndroidPublisher.Purchases.Products.Get 方法来检索购买的详细信息。文档列出了如下签名:

From here you can use the AndroidPublisher.Purchases.Products.Get method to retrieve the details of a purchase. The docs list the signature as following:

AndroidPublisher.Purchases.Products.Get(java.lang.String packageName, java.lang.String productId, java.lang.String token)

对于订阅,使用 AndroidPublisher.Purchases.Subscriptions.Get

如果您需要更多帮助,请考虑使用 java google-提出问题api-java-client 标签。

If you need more help, consider asking a question with the java and google-api-java-client tags.

这篇关于Android:inApp购买收据验证(第2部分)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆