谷歌和内地微信支付流程区别在于,微信是异步回调通知,谷歌需要自动请求,前端需要发送消息到服务端服务端发起请求验证该订单是否支付成功

  public boolean verify(Map<String, String> jsonObject,String orderId){
        try {
            List<String> scopes = new ArrayList<>();
            scopes.add(AndroidPublisherScopes.ANDROIDPUBLISHER);
            ResourceLoader resourceLoader = new DefaultResourceLoader();
            Resource resource = resourceLoader.getResource("classpath:resources/pc-api-8727463108932952502-366-8c41220b81b6.json");
            GoogleCredential credential = GoogleCredential.fromStream(resource.getInputStream())
                    .createScoped(scopes);



            HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
            JacksonFactory jsonFactory = new JacksonFactory();
            AndroidPublisher publisher = new AndroidPublisher.Builder(httpTransport, jsonFactory, credential)
                    .setApplicationName("패왕전설").build();
            AndroidPublisher.Purchases purchases = publisher.purchases();
            AndroidPublisher.Purchases.Products.Get request = purchases.products().get(jsonObject.get("packageName"), jsonObject.get("productId"),jsonObject.get("token"));
            System.out.println("==============="+request+"================");
//            Properties systemProperties = System.getProperties();
//            systemProperties.setProperty("http.proxyHost", "127.0.0.1");
//            systemProperties.setProperty("http.proxyPort", "8085");
//            systemProperties.setProperty("https.proxyHost", "127.0.0.1");
//            systemProperties.setProperty("https.proxyPort", "8085");
//            systemProperties.setProperty("socksProxyHost", "127.0.0.1");
//            systemProperties.setProperty("socksProxyPort", "8085");
//            systemProperties.setProperty("http.nonProxyHosts","localhost");
//            systemProperties.setProperty("https.nonProxyHosts","localhost");
//            System.setProperty("sun.net.client.defaultConnectTimeout", String.valueOf(8000));// (单位:毫秒)
//            System.setProperty("https.protocols", "TLSv1,TLSv1.1,TLSv1.2,SSLv3");
            ProductPurchase purchase = request.execute();
            /*获取谷歌订单号*/
            String prd= purchase.getOrderId();

            /*获取状态*/
            Integer state=purchase.getPurchaseState();

            System.out.println(purchase.getDeveloperPayload()+""+purchase.getKind()+prd+""+state);
            System.out.println(purchase.toString());
            if(orderId.equals(prd) && state==0){
                return true;
            }
        }catch (Exception e){
            System.out.println(e);
            return false;
        }

       return false;
       }

上面是谷歌封装好的api调用

需要用到得jar包如下

在这里插入图片描述

注意事项
classpath:resources/pc-api-8727463108932952502-366-8c41220b81b6.json
这个文件是运营在支付后台下载给开发者的

Logo

技术共进,成长同行——讯飞AI开发者社区

更多推荐