From 7c44f09803d517dce2d6170730c7f70a37cf1169 Mon Sep 17 00:00:00 2001 From: hch <16607480311@163.com> Date: Wed, 29 Nov 2023 18:26:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=94=AF=E4=BB=98=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/proguard-rules.pro | 3 + common/build.gradle | 2 +- .../com/yunbao/common/utils/GoogleUtils.java | 33 +++++-- config.gradle | 4 +- gradle.properties | 4 +- .../lib_google/utils/GoogleBillingManage.java | 35 ++++++- .../yunbao/main/activity/GoogleFragment.java | 95 +++++++++++-------- .../yunbao/main/activity/HuaWeiFragment.java | 24 +++-- .../main/activity/MyWalletActivity.java | 8 +- settings.gradle | 2 +- 10 files changed, 137 insertions(+), 73 deletions(-) diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index d17166596..6f4c447c6 100644 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -289,3 +289,6 @@ rx.internal.util.atomic.LinkedQueueNode* consumerNode; -keep class com.huawei.hianalytics.**{*;} -keep class com.huawei.updatesdk.**{*;} -keep class com.huawei.hms.**{*;} + +-keep class com.shayu.lib_google.**{*;} +-keep class com.shayu.lib_huawei.**{*;} diff --git a/common/build.gradle b/common/build.gradle index 971eda0e7..ee2940bd3 100644 --- a/common/build.gradle +++ b/common/build.gradle @@ -211,7 +211,7 @@ dependencies { api 'tech.sud.mgp:SudASR:1.3.3.1158' //华为支付插件包 - api project(':lib_huawei') + //api project(':lib_huawei') //google插件包 api project(':lib_google') diff --git a/common/src/main/java/com/yunbao/common/utils/GoogleUtils.java b/common/src/main/java/com/yunbao/common/utils/GoogleUtils.java index 4f1041a70..d1e89d8a7 100644 --- a/common/src/main/java/com/yunbao/common/utils/GoogleUtils.java +++ b/common/src/main/java/com/yunbao/common/utils/GoogleUtils.java @@ -9,6 +9,7 @@ import com.alibaba.fastjson.JSON; import org.json.JSONObject; +import java.lang.reflect.InvocationTargetException; import java.util.Timer; import java.util.TimerTask; @@ -122,8 +123,21 @@ public class GoogleUtils { } } + Timer timer; + public void setBillingListener(GoogleBillingListener billingListener) { - Timer timer = new Timer(); + if (timer != null) { + timer.cancel(); + timer = null; + } + + try { + googlePay.getClass().getMethod("initResultCode").invoke(googlePay); + } catch (Exception e) { + throw new RuntimeException(e); + } + + timer = new Timer(); TimerTask task = new TimerTask() { @Override public void run() { @@ -133,18 +147,21 @@ public class GoogleUtils { String token = resultCode.getString("resultToken"); String orderId = resultCode.getString("resultOrderId"); if (code == 0) { + timer.cancel(); billingListener.onPaySuccess(token, orderId); + } else if (code == 1) { + timer.cancel(); + billingListener.onPayFailed("支付取消"); + } else if (code == 2) { timer.cancel(); - } else if (code == 1 || code == 2) { billingListener.onPayFailed("支付失败"); - timer.cancel(); } } catch (Exception e) { throw new RuntimeException(e); } } }; - timer.scheduleAtFixedRate(task, 60000, 1000); + timer.schedule(task, 1000, 1000); } public void initializeApp(Context context) { @@ -175,7 +192,7 @@ public class GoogleUtils { } } }; - timer.schedule(task, 10000, 1000); + timer.schedule(task, 1000, 1000); } public void initFireToken(Activity activity) { @@ -198,16 +215,14 @@ public class GoogleUtils { } } - public void setQueryPurchaseListener(Activity activity, QueryPurchasesListener queryPurchasesListener) { Timer timer = new Timer(); TimerTask task = new TimerTask() { @Override public void run() { try { - Class clz = activity.getClassLoader().loadClass("com.shayu.lib_google.utils.GoogleBillingManage"); - googlePay = clz.getConstructor(Activity.class).newInstance(activity); JSONObject object = (JSONObject) googlePay.getClass().getMethod("getQuerySize").invoke(googlePay); + L.e("setQueryPurchaseListenersetQueryPurchaseListener__" + object.getInt("querySize")); if (object.getInt("querySize") != -1) { queryPurchasesListener.onResult(object); timer.cancel(); @@ -217,7 +232,7 @@ public class GoogleUtils { } } }; - timer.schedule(task, 10000, 1000); + timer.schedule(task, 1000, 1000); } diff --git a/config.gradle b/config.gradle index 5b2b25b9c..852408633 100644 --- a/config.gradle +++ b/config.gradle @@ -9,7 +9,7 @@ ext { ] manifestPlaceholders = [ //正式、 -// serverHost : "https://napi.yaoulive.com", + //serverHost : "https://napi.yaoulive.com", // 测试 serverHost : " https://ceshi.yaoulive.com", @@ -20,7 +20,7 @@ ext { baiduAppSecretKey: "nEVSgmuGpU0pjPr6VleEGGAl0hzGW52S", // true表示谷歌支付 false 0 链接包 1 谷歌包 2华为包 - isGooglePlay : 2, + isGooglePlay : 1, //是否上报异常日志 isUploadLog : true, //是否打包成插件包模式 diff --git a/gradle.properties b/gradle.properties index 2ea158c25..c1269158c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -23,6 +23,6 @@ android.enableJetifier=true systemProp.http.proxyHost=127.0.0.1 systemProp.https.proxyHost=127.0.0.1 -systemProp.https.proxyPort=65471 -systemProp.http.proxyPort=65471 +systemProp.https.proxyPort=55219 +systemProp.http.proxyPort=55219 #android.enableR8.fullMode=true \ No newline at end of file diff --git a/lib_google/src/main/java/com/shayu/lib_google/utils/GoogleBillingManage.java b/lib_google/src/main/java/com/shayu/lib_google/utils/GoogleBillingManage.java index 1c1a49e1c..dfd43d032 100644 --- a/lib_google/src/main/java/com/shayu/lib_google/utils/GoogleBillingManage.java +++ b/lib_google/src/main/java/com/shayu/lib_google/utils/GoogleBillingManage.java @@ -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 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 { diff --git a/main/src/main/java/com/yunbao/main/activity/GoogleFragment.java b/main/src/main/java/com/yunbao/main/activity/GoogleFragment.java index c26a864c5..b368c8dad 100644 --- a/main/src/main/java/com/yunbao/main/activity/GoogleFragment.java +++ b/main/src/main/java/com/yunbao/main/activity/GoogleFragment.java @@ -28,6 +28,9 @@ import com.yunbao.main.views.TestWebViewClient; @SuppressLint("ValidFragment") public class GoogleFragment extends Fragment { + private long lastClickTime = 0; + private static final long INTERVAL_TIME = 1500; + private View view; public static String mOrderid, mProductId, MoneyUsds; @@ -99,50 +102,60 @@ public class GoogleFragment extends Fragment { @JavascriptInterface public void androidNewGoToGooglePay(String ProductId, String OrderNumber, String MoneyUsd) { - Log.e(TAG, "ProductId" + ProductId + "OrderNumber" + OrderNumber + "MoneyUsd" + MoneyUsd); - mProductId = ProductId; - mOrderid = OrderNumber; - MoneyUsds = MoneyUsd; + long currentTime = System.currentTimeMillis(); + if (currentTime - lastClickTime > INTERVAL_TIME) { + mProductId = ProductId; + mOrderid = OrderNumber; + MoneyUsds = MoneyUsd; - googleUtils.setBillingListener(new GoogleUtils.GoogleBillingListener() { - @Override - public void onPaySuccess(String token, String orderId) { - payHandler.post(new Runnable() { - @Override - public void run() { - CommonHttpUtil.notifyGoogle(token, orderId, mProductId, mOrderid, adid, new HttpCallback() { - @Override - public void onSuccess(int code, String msg, String[] info) { - if (code == 0) { - Bundle params = new Bundle(); - params.putString("currency", "HKD"); - params.putString("money", MoneyUsds); - Bundle fb_params = new Bundle(); - fb_params.putString(AppEventsConstants.EVENT_PARAM_CURRENCY, "HKD"); - fb_params.putString(AppEventsConstants.EVENT_PARAM_CONTENT_ID, mProductId); - //Google官方充值通知 - Bundle google_params = new Bundle(); - google_params.putString("currency", "HKD"); - google_params.putString("product_id", mProductId); - google_params.putString("transaction_id", mOrderid); - google_params.putString("value", MoneyUsds); - google_params.putString("price", MoneyUsds); - google_params.putString("quantity", "1"); - dis(); - ToastUtil.show("支付成功"); + googleUtils.setBillingListener(new GoogleUtils.GoogleBillingListener() { + @Override + public void onPaySuccess(String token, String orderId) { + payHandler.post(new Runnable() { + @Override + public void run() { + CommonHttpUtil.notifyGoogle(token, orderId, mProductId, mOrderid, adid, new HttpCallback() { + @Override + public void onSuccess(int code, String msg, String[] info) { + if (code == 0) { + Bundle params = new Bundle(); + params.putString("currency", "HKD"); + params.putString("money", MoneyUsds); + Bundle fb_params = new Bundle(); + fb_params.putString(AppEventsConstants.EVENT_PARAM_CURRENCY, "HKD"); + fb_params.putString(AppEventsConstants.EVENT_PARAM_CONTENT_ID, mProductId); + //Google官方充值通知 + Bundle google_params = new Bundle(); + google_params.putString("currency", "HKD"); + google_params.putString("product_id", mProductId); + google_params.putString("transaction_id", mOrderid); + google_params.putString("value", MoneyUsds); + google_params.putString("price", MoneyUsds); + google_params.putString("quantity", "1"); + dis(); + ToastUtil.show("支付成功"); + } } - } - }); - } - }); - } + }); + } + }); + } - @Override - public void onPayFailed(String msg) { - ToastUtil.show(msg); - } - }); - googleUtils.purchase(mProductId); + @Override + public void onPayFailed(String msg) { + payHandler.post(new Runnable() { + @Override + public void run() { + ToastUtil.show(msg); + } + }); + } + }); + googleUtils.purchase(mProductId); + } + lastClickTime = currentTime; + + Log.e(TAG, "ProductId" + ProductId + "OrderNumber" + OrderNumber + "MoneyUsd" + MoneyUsd); } @JavascriptInterface diff --git a/main/src/main/java/com/yunbao/main/activity/HuaWeiFragment.java b/main/src/main/java/com/yunbao/main/activity/HuaWeiFragment.java index 2389daf56..90514ccee 100644 --- a/main/src/main/java/com/yunbao/main/activity/HuaWeiFragment.java +++ b/main/src/main/java/com/yunbao/main/activity/HuaWeiFragment.java @@ -23,7 +23,8 @@ import com.yunbao.main.views.TestWebViewClient; @SuppressLint("ValidFragment") public class HuaWeiFragment extends Fragment { - + private long lastClickTime = 0; + private static final long INTERVAL_TIME = 1500; private View view; public static String mOrderid, mProductId, MoneyUsds; @@ -80,17 +81,22 @@ public class HuaWeiFragment extends Fragment { public void androidNewGoToGooglePay(String ProductId, String OrderNumber, String MoneyUsd) { Log.e(TAG, "ProductId:" + ProductId + " OrderNumber:" + OrderNumber + " MoneyUsd:" + MoneyUsd); - if (ProductId.equals("zs640")) { - ProductId = "zs0640"; + long currentTime = System.currentTimeMillis(); + if (currentTime - lastClickTime > INTERVAL_TIME) { + if (ProductId.equals("zs640")) { + ProductId = "zs0640"; + } + mProductId = ProductId; + mOrderid = OrderNumber; + MoneyUsds = MoneyUsd; + orderId = OrderNumber; + + HwBuilder hwBuilder = new HwBuilder(getActivity()); + hwBuilder.pay(mProductId); } + lastClickTime = currentTime; - mProductId = ProductId; - mOrderid = OrderNumber; - MoneyUsds = MoneyUsd; - orderId = OrderNumber; - HwBuilder hwBuilder = new HwBuilder(getActivity()); - hwBuilder.pay(mProductId); } @JavascriptInterface diff --git a/main/src/main/java/com/yunbao/main/activity/MyWalletActivity.java b/main/src/main/java/com/yunbao/main/activity/MyWalletActivity.java index 9bf8ae7b4..5e63630c0 100644 --- a/main/src/main/java/com/yunbao/main/activity/MyWalletActivity.java +++ b/main/src/main/java/com/yunbao/main/activity/MyWalletActivity.java @@ -93,8 +93,6 @@ public class MyWalletActivity extends AbsActivity { loadingDialog.setShowText(getString(R.string.order_query)); if (CommonAppConfig.IS_GOOGLE_PLAY == 1) { - - googleUtils.queryPurchasesAsync(); googleUtils.setQueryPurchaseListener(mContext, new GoogleUtils.QueryPurchasesListener() { @Override public void onResult(JSONObject obj) { @@ -139,10 +137,14 @@ public class MyWalletActivity extends AbsActivity { } } }); - } else { + googleUtils.queryPurchasesAsync(); + } else if (CommonAppConfig.IS_GOOGLE_PLAY == 2) { hwBuilder.consume(); loadingDialog.setShowText(getString(R.string.order_query_success)); payHandler.postDelayed(() -> loadingDialog.dismiss(), 2000); + } else { + loadingDialog.setShowText(getString(R.string.order_query_success)); + payHandler.postDelayed(() -> loadingDialog.dismiss(), 2000); } }); diff --git a/settings.gradle b/settings.gradle index e5940e07f..686ea5ec5 100644 --- a/settings.gradle +++ b/settings.gradle @@ -4,5 +4,5 @@ include ':FaceUnity' //include ':recognizer'//融云语音转文字模块 include ':Share' include ':pluginsForAnchor' -include ':lib_huawei' +//include ':lib_huawei' include ':lib_google'