修复支付问题

This commit is contained in:
hch
2023-11-29 18:26:59 +08:00
parent 0b89ac21e8
commit 7c44f09803
10 changed files with 137 additions and 73 deletions

View File

@@ -1,7 +1,6 @@
package com.shayu.lib_google.utils;
import android.app.Activity;
import android.os.Handler;
import android.util.Log;
import androidx.annotation.NonNull;
@@ -145,6 +144,7 @@ public class GoogleBillingManage implements PurchasesUpdatedListener {
queryPurchasesAsync(new PurchasesResponseListener() {
@Override
public void onQueryPurchasesResponse(@NonNull BillingResult billingResult, @NonNull List<Purchase> list) {
Log.e("TAG", "消耗所有商品消耗所有商品消耗所有商品消耗所有商品消耗所有商品消耗所有商品" + list.size());
querySize = list.size();
if (querySize > 0) {
tradeNo = list.get(0).getProducts().get(0);
@@ -162,10 +162,31 @@ public class GoogleBillingManage implements PurchasesUpdatedListener {
* 查询商品订单
*/
public void queryPurchasesAsync(PurchasesResponseListener responseListener) {
if (billingClient == null) return;
//内购商品交易查询
QueryPurchasesParams inAppPurchasesQurey = QueryPurchasesParams.newBuilder().setProductType(BillingClient.ProductType.INAPP).build();
billingClient.queryPurchasesAsync(inAppPurchasesQurey, responseListener);
if (billingClient == null) {
billingClient = BillingClient.newBuilder(mContext).setListener(this).enablePendingPurchases().build();
//请求连接到GooglePay
billingClient.startConnection(new BillingClientStateListener() {
@Override
public void onBillingSetupFinished(@NonNull BillingResult billingResult) {
int code = billingResult.getResponseCode();
if (code != BillingClient.BillingResponseCode.OK) {
String msg = billingResult.getDebugMessage();
Log.e(TAG, "连接到GooglePay失败 code = " + code + " msg = " + msg);
return;
}
Log.e(TAG, "连接到GooglePay成功");
QueryPurchasesParams inAppPurchasesQurey = QueryPurchasesParams.newBuilder().setProductType(BillingClient.ProductType.INAPP).build();
billingClient.queryPurchasesAsync(inAppPurchasesQurey, responseListener);
}
//连接失败
@Override
public void onBillingServiceDisconnected() {
Log.e(TAG, "连接到GooglePay失败请重试");
}
});
}
}
public String getAdid() {
@@ -180,11 +201,15 @@ public class GoogleBillingManage implements PurchasesUpdatedListener {
}
}
int resultCode = -1;
String resultToken = "";
String resultOrderId = "";
public void initResultCode() {
resultCode = -1;
}
public JSONObject getPayResult() {
JSONObject object = new JSONObject();
try {