java接入google pay连接超时和连接被拒绝问题

总结一下自己接入google pay内支付遇到的问题
流程是app使用支付完成,返回数据,java服务端验证订单信息,并进行处理
HttpTransport transport = GoogleNetHttpTransport.newTrustedTransport(); PrivateKey privateKey = SecurityUtils.loadPrivateKeyFromKeyStore(SecurityUtils.getPkcs12KeyStore(), GoogleSignInterceptor.class.getResourceAsStream(P12_Key), "notasecret", "privatekey", "notasecret"); GoogleCredential credential = new GoogleCredential.Builder().setTransport(transport) .setJsonFactory(JacksonFactory.getDefaultInstance()).setServiceAccountId(SERVICE_ACCOUNT_EMAIL) .setServiceAccountScopes(Collections.singleton(AndroidPublisherScopes.ANDROIDPUBLISHER)) .setServiceAccountPrivateKey(privateKey).build(); AndroidPublisher publisher = new AndroidPublisher.Builder(transport, JacksonFactory.getDefaultInstance(), setHttpTimeout(credential)).setApplicationName("emeetapptest").build(); AndroidPublisher.Purchases.Products products = publisher.purchases().products(); AndroidPublisher.Purchases.Products.Get product = products.get(packageName, productId, purchaseToken); ProductPurchase purchase = product.execute(); if (purchase.getPurchaseState() != 0) { logger.error("订单未支付!"); }在这里插入代码片
在product.execute()时出现socket连接超时和服务被拒绝问题
解决办法:
1.开启,使用全局代理模式
2.连接前加入:Properties systemProperties = System.getProperties();
systemProperties.setProperty(“http.proxyHost”, “127.0.0.1”);
systemProperties.setProperty(“http.proxyPort”, “8080”);
systemProperties.setProperty(“https.proxyHost”, “127.0.0.1”);
systemProperties.setProperty(“https.proxyPort”, “8080”);
systemProperties.setProperty(“socksProxyHost”, “127.0.0.1”);
systemProperties.setProperty(“socksProxyPort”, “8080”);
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”);
上面的8080端口使用代理的端口,tomcat使用的8081
3.使用jdk1.8.因为1.7只支持TLS1
4.本地vm参数中设置catalina.sh 中-Djavax.net.debug=all
测试可以查询订单结果

你可能感兴趣的:(google内支付)