关于Google Play支付校验我之前在网上也找过大量的相关资料,发现大多数都是采用publicKey的方式来校验订单,但是在Google Play提供的官方实例中publicKey其实在客户端也是存在的,所以这种校验想要伪造其实是非常容易的,Google并未像Apple那样提供一个接口来校验订单的信息,但是提供了一个获取订单状态的接口,我们可以通过这个接口在GooglePlay服务器获取某个订单,查看其状态是否合法达到校验目的。

接口地址:https://developers.google.com/android-publisher/api-ref/purchases/products要使用上面的接口获取订单首先是需要登录认证的,这相比其它的平台稍微复杂了一点点,但是Google也提供了完整的库,并不需要我们做过多的开发。

在开发之前我们需要设置一些基本参数(接口地址:https://play.google.com/apps/publish/?dev_acc=08522487669089675329#ApiAccessPlace

1. 首先要在Google Developers Console上创建一个项目(参考图下)

2. 项目创建成功之后需要创建Service Account(参考图下)

---------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------

---------------------------------------------------------------------------------------------------------

3. Service account 授权(参考图下)

4. Service account创建成功之后生成P12 key文件(参考图下)

+++++------------------------------------------------------------------------------------------+++++ 准备工作至此结束

1. 添加Maven项目依赖

<dependency>
<groupId>com.google.apis</groupId>
<artifactId>google-api-services-androidpublisher</artifactId>
<version>v2-rev19-1.20.0</version>
</dependency>

2. 获取订单状态信息完成校验

import com.google.api.client.googleapis.auth.oauth2.GoogleCredential;
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.json.jackson2.JacksonFactory;
import com.google.api.client.util.SecurityUtils;
import com.google.api.services.androidpublisher.AndroidPublisher;
import com.google.api.services.androidpublisher.AndroidPublisherScopes;
import com.google.api.services.androidpublisher.model.ProductPurchase;
import java.io.File;
import java.io.FileInputStream;
import java.security.PrivateKey; /**
* Google Play 支付校验示例.
*
* @author Kevin Zou <kevinz@skfiy.org>
*/
public class GooglePlaySample { public static void main(String[] args) throws Exception { HttpTransport transport = GoogleNetHttpTransport.newTrustedTransport(); PrivateKey privateKey = SecurityUtils.loadPrivateKeyFromKeyStore(
SecurityUtils.getPkcs12KeyStore(),
new FileInputStream(new File("{P12 key file}")), // 生成的P12文件
"notasecret", "privatekey", "notasecret"); GoogleCredential credential = new GoogleCredential.Builder()
.setTransport(transport).setJsonFactory(JacksonFactory.getDefaultInstance())
.setServiceAccountId("{Email address}") // e.g.: 626891557797-frclnjv31rn4ss81ch746g9t6pd3mmej@developer.gserviceaccount.com
.setServiceAccountScopes(AndroidPublisherScopes.all())
.setServiceAccountPrivateKey(privateKey).build(); AndroidPublisher publisher = new AndroidPublisher.Builder(transport,
JacksonFactory.getDefaultInstance(), credential).build(); AndroidPublisher.Purchases.Products products = publisher.purchases().products(); // 参数详细说明: https://developers.google.com/android-publisher/api-ref/purchases/products/get
AndroidPublisher.Purchases.Products.Get product = products.get("{packageName}",
"{productId}", "{token}"); // 获取订单信息
// 返回信息说明: https://developers.google.com/android-publisher/api-ref/purchases/products
// 通过consumptionState, purchaseState可以判断订单的状态
ProductPurchase purchase = product.execute();
}
}

Google Play支付校验的更多相关文章

  1. Google play billing(Google play 内支付) 上篇

    写在前面: 最近Google貌似又被全面封杀了,幸好在此之前,把Google play billing弄完了,现在写篇 博客来做下记录.这篇博客一是自己做个记录,二是帮助其他有需要的人.因为现在基本登 ...

  2. Android支付接入(七):Google In-app-Billing

    前段时间有事请耽搁了,今天跟大家一起看下Google的in-app Billing V3支付.    如果没有Google Play此处附上安装Google Play的一键安装器的链接(需要Root权 ...

  3. Android支付接入(7):Google In-app-Billing

    今天跟大家一起看下Google的in-app Billing V3支付.    如果没有GooglePlay此处附上安装Google Play的一键安装器的链接(需要Root权限):http://ww ...

  4. Android支付接入之Google In-app-Billing

    原文链接:http://www.mobile-open.com/2016/966337.html 因为公司需要接入Google的应用内支付(即Google的in-app Billing V3),接入过 ...

  5. 微信支付开发(7) H5支付

    关键字:微信支付 微信支付v3 H5支付 wap支付 prepay_id 作者:方倍工作室原文: http://www.cnblogs.com/txw1958/p/wxpayv3_h5.html 本文 ...

  6. Google Play笔记之上架

    我最近负责Google Play上架的主要工作 ,现已进入开放测试阶段(随后就可全球首发~~).接入工作已完成,这篇记录一下上架后期的笔记. 开放测试 开放测试是指对所有玩家进行开放式测试,玩家可以通 ...

  7. Google Adsense(Google网站联盟)广告申请指南

    Google AdSense 是一种获取收入的快速简便的方法,适合于各种规模的网站发布商.它可以在网站的内容网页上展示相关性较高的 Google 广告,并且这些广告不会过分夸张醒目.由于所展示的广告同 ...

  8. ***新版微信H5支付技术总结(原创)

    新版微信H5支付官方文档: https://pay.weixin.qq.com/wiki/doc/api/H5.php?chapter=9_20&index=1 H5支付是指商户在微信客户端外 ...

  9. Google Play内购测试

    Google Play内购测试 最近项目做海外版本,接入Google wallet支付后,测试验证比较繁琐,故记录一下. Google wallet支付方式接入完成后,需要按照如下步骤设置,才可以进行 ...

随机推荐

  1. Flexigrid在IE下不显示数据的处理

    文章总结自我的论坛提问: http://bbs.csdn.net/topics/390498434?page=1#post-394918028 解决方法: 网上的答案经我验证都是不靠谱的,以后大家就知 ...

  2. MVC网站发布常见问题

    直接发布的时候生成的bin会漏掉一些文件,从而导致网站无法访问: 解决方法:发布之后,再在本地运行一下网站,然后将运行后生成的bin文件夹下的文件拷贝到发布的文件夹目录下进行覆盖,就可以了

  3. 一、List的扩展

    前言 List的三个扩展方法 1.处理符合in()格式的扩展方法 2.处理符合SelectListItem类型的扩展方法(SelectListItem类型是下拉框要用到的类型) 3.Distinct方 ...

  4. IE9-10 option BUG

    IE 9-10下如果option元素没有定义value而在设置innerText时没有把两边的空白去掉,那么 取el.text,浏览器会进行trim, 并且伪造一个value值,此值会在刚才trim的 ...

  5. linux php安装扩展方法 查找配置文件

    如何在linux中查看nginx.apache.php.mysql配置文件路径了,如果你接收一个别人配置过的环境,但没留下相关文档.这时该怎么判断找到正确的加载文件路径了.可以通过以下来判断 1.判断 ...

  6. 1.4.2 solr字段类型--(1.4.2.6)使用外部文件和程序

    1.4.2 solr字段类型 (1.4.2.1) 字段类型定义和字段类型属性. (1.4.2.2) solr附带的字段类型 (1.4.2.3) 使用货币和汇率 (1.4.2.4) 使用Dates(日期 ...

  7. IOS 从系统图库中获取 图片 并设置为头像

    总会遇到一些应用 要拍照 设置图片之类的的  总结一个方法备用  以后 会 继续拓展到 多图 @interface AddCustomerViewController : UIViewControll ...

  8. FVDI Commander products be replaced SVDI tools,really?

    You may have heard that some FVDI Commander products are being replaced by the new SVDI tools. This ...

  9. SOA与C#

    What is SOA? SOA or Service oriented architecture is an architecture style for building business app ...

  10. [ASP.NET] Session的了解

    ASP.NET Session的使用当中我们会遇到很多的问题,那么这里我们来谈下经常出现的一些常用ASP.NET Session的理解: ASP.NET Session的七点认识之一 对于值类型的变量 ...