Google Play服务端获取订单和核销订单

官方文档地址:https://developers.google.cn/android-publisher/api-ref/rest/v3/purchases.products?hl=zh-cn

java依赖

        <!-- google play -->
        <dependency>
            <groupId>com.google.apis</groupId>
            <artifactId>google-api-services-androidpublisher</artifactId>
            <version>v3-rev20241003-2.0.0</version>
        </dependency>
        <dependency>
            <groupId>com.google.http-client</groupId>
            <artifactId>google-http-client-jackson2</artifactId>
            <version>1.45.0</version>
        </dependency>
        <dependency>
            <groupId>com.google.auth</groupId>
            <artifactId>google-auth-library-oauth2-http</artifactId>
            <version>1.28.0</version>
        </dependency>
        <!-- google play -->

java代码,

credential json文件再谷歌后台配置后获取,支付凭证让前端APP拉取支付后获取后给到服务端。

参考这个文档在Google后台配置服务端验证Google Pay订单的两种方式_谷歌支付验证-CSDN博客

@Test
    void test2() throws Exception {
        // GoogleCredentials credential = GoogleCredentials
        //         .fromStream(FileUtil.getInputStream("/opt/api-project-20840613-43d15092b1b0.json"))
        //         .createScoped(Collections.singletonList(AndroidPublisherScopes.ANDROIDPUBLISHER));
        String token = "json字符串base64编码";
        GoogleCredentials credential = GoogleCredentials
                .fromStream(new ByteArrayInputStream(Base64.decode(token)))
                .createScoped(Collections.singletonList(AndroidPublisherScopes.ANDROIDPUBLISHER));
        HttpRequestInitializer requestInitializer = new HttpCredentialsAdapter(credential);
        AndroidPublisher publisher = new AndroidPublisher.Builder(new NetHttpTransport(), new GsonFactory(), requestInitializer).build();
        AndroidPublisher.Purchases purchases = publisher.purchases();
        //获取凭证对应google订单信息
        final AndroidPublisher.Purchases.Products.Get request = purchases.products()
                .get("com.tangwan.xxx", "test01", "支付凭证token");
        final ProductPurchase purchase = request.execute();
        //凭证核销
        purchases.products()
                .consume("com.tangwan.cn", "test01", "支付凭证token")
                .execute();
        System.out.println(JSONUtil.toJsonStr(purchase));
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值