修复支付问题

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

@ -289,3 +289,6 @@ rx.internal.util.atomic.LinkedQueueNode* consumerNode;
-keep class com.huawei.hianalytics.**{*;} -keep class com.huawei.hianalytics.**{*;}
-keep class com.huawei.updatesdk.**{*;} -keep class com.huawei.updatesdk.**{*;}
-keep class com.huawei.hms.**{*;} -keep class com.huawei.hms.**{*;}
-keep class com.shayu.lib_google.**{*;}
-keep class com.shayu.lib_huawei.**{*;}

View File

@ -211,7 +211,7 @@ dependencies {
api 'tech.sud.mgp:SudASR:1.3.3.1158' api 'tech.sud.mgp:SudASR:1.3.3.1158'
// //
api project(':lib_huawei') //api project(':lib_huawei')
//google插件包 //google插件包
api project(':lib_google') api project(':lib_google')

View File

@ -9,6 +9,7 @@ import com.alibaba.fastjson.JSON;
import org.json.JSONObject; import org.json.JSONObject;
import java.lang.reflect.InvocationTargetException;
import java.util.Timer; import java.util.Timer;
import java.util.TimerTask; import java.util.TimerTask;
@ -122,8 +123,21 @@ public class GoogleUtils {
} }
} }
Timer timer;
public void setBillingListener(GoogleBillingListener billingListener) { 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() { TimerTask task = new TimerTask() {
@Override @Override
public void run() { public void run() {
@ -133,18 +147,21 @@ public class GoogleUtils {
String token = resultCode.getString("resultToken"); String token = resultCode.getString("resultToken");
String orderId = resultCode.getString("resultOrderId"); String orderId = resultCode.getString("resultOrderId");
if (code == 0) { if (code == 0) {
timer.cancel();
billingListener.onPaySuccess(token, orderId); billingListener.onPaySuccess(token, orderId);
} else if (code == 1) {
timer.cancel();
billingListener.onPayFailed("支付取消");
} else if (code == 2) {
timer.cancel(); timer.cancel();
} else if (code == 1 || code == 2) {
billingListener.onPayFailed("支付失败"); billingListener.onPayFailed("支付失败");
timer.cancel();
} }
} catch (Exception e) { } catch (Exception e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
}; };
timer.scheduleAtFixedRate(task, 60000, 1000); timer.schedule(task, 1000, 1000);
} }
public void initializeApp(Context context) { 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) { public void initFireToken(Activity activity) {
@ -198,16 +215,14 @@ public class GoogleUtils {
} }
} }
public void setQueryPurchaseListener(Activity activity, QueryPurchasesListener queryPurchasesListener) { public void setQueryPurchaseListener(Activity activity, QueryPurchasesListener queryPurchasesListener) {
Timer timer = new Timer(); Timer timer = new Timer();
TimerTask task = new TimerTask() { TimerTask task = new TimerTask() {
@Override @Override
public void run() { public void run() {
try { 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); JSONObject object = (JSONObject) googlePay.getClass().getMethod("getQuerySize").invoke(googlePay);
L.e("setQueryPurchaseListenersetQueryPurchaseListener__" + object.getInt("querySize"));
if (object.getInt("querySize") != -1) { if (object.getInt("querySize") != -1) {
queryPurchasesListener.onResult(object); queryPurchasesListener.onResult(object);
timer.cancel(); timer.cancel();
@ -217,7 +232,7 @@ public class GoogleUtils {
} }
} }
}; };
timer.schedule(task, 10000, 1000); timer.schedule(task, 1000, 1000);
} }

View File

@ -9,7 +9,7 @@ ext {
] ]
manifestPlaceholders = [ manifestPlaceholders = [
// //
// serverHost : "https://napi.yaoulive.com", //serverHost : "https://napi.yaoulive.com",
// //
serverHost : " https://ceshi.yaoulive.com", serverHost : " https://ceshi.yaoulive.com",
@ -20,7 +20,7 @@ ext {
baiduAppSecretKey: "nEVSgmuGpU0pjPr6VleEGGAl0hzGW52S", baiduAppSecretKey: "nEVSgmuGpU0pjPr6VleEGGAl0hzGW52S",
// true表示谷歌支付 false 0 1 2 // true表示谷歌支付 false 0 1 2
isGooglePlay : 2, isGooglePlay : 1,
// //
isUploadLog : true, isUploadLog : true,
// //

View File

@ -23,6 +23,6 @@ android.enableJetifier=true
systemProp.http.proxyHost=127.0.0.1 systemProp.http.proxyHost=127.0.0.1
systemProp.https.proxyHost=127.0.0.1 systemProp.https.proxyHost=127.0.0.1
systemProp.https.proxyPort=65471 systemProp.https.proxyPort=55219
systemProp.http.proxyPort=65471 systemProp.http.proxyPort=55219
#android.enableR8.fullMode=true #android.enableR8.fullMode=true

View File

@ -1,7 +1,6 @@
package com.shayu.lib_google.utils; package com.shayu.lib_google.utils;
import android.app.Activity; import android.app.Activity;
import android.os.Handler;
import android.util.Log; import android.util.Log;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
@ -145,6 +144,7 @@ public class GoogleBillingManage implements PurchasesUpdatedListener {
queryPurchasesAsync(new PurchasesResponseListener() { queryPurchasesAsync(new PurchasesResponseListener() {
@Override @Override
public void onQueryPurchasesResponse(@NonNull BillingResult billingResult, @NonNull List<Purchase> list) { public void onQueryPurchasesResponse(@NonNull BillingResult billingResult, @NonNull List<Purchase> list) {
Log.e("TAG", "消耗所有商品消耗所有商品消耗所有商品消耗所有商品消耗所有商品消耗所有商品" + list.size());
querySize = list.size(); querySize = list.size();
if (querySize > 0) { if (querySize > 0) {
tradeNo = list.get(0).getProducts().get(0); tradeNo = list.get(0).getProducts().get(0);
@ -162,10 +162,31 @@ public class GoogleBillingManage implements PurchasesUpdatedListener {
* 查询商品订单 * 查询商品订单
*/ */
public void queryPurchasesAsync(PurchasesResponseListener responseListener) { public void queryPurchasesAsync(PurchasesResponseListener responseListener) {
if (billingClient == null) return;
//内购商品交易查询 //内购商品交易查询
QueryPurchasesParams inAppPurchasesQurey = QueryPurchasesParams.newBuilder().setProductType(BillingClient.ProductType.INAPP).build(); if (billingClient == null) {
billingClient.queryPurchasesAsync(inAppPurchasesQurey, responseListener); 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() { public String getAdid() {
@ -180,11 +201,15 @@ public class GoogleBillingManage implements PurchasesUpdatedListener {
} }
} }
int resultCode = -1; int resultCode = -1;
String resultToken = ""; String resultToken = "";
String resultOrderId = ""; String resultOrderId = "";
public void initResultCode() {
resultCode = -1;
}
public JSONObject getPayResult() { public JSONObject getPayResult() {
JSONObject object = new JSONObject(); JSONObject object = new JSONObject();
try { try {

View File

@ -28,6 +28,9 @@ import com.yunbao.main.views.TestWebViewClient;
@SuppressLint("ValidFragment") @SuppressLint("ValidFragment")
public class GoogleFragment extends Fragment { public class GoogleFragment extends Fragment {
private long lastClickTime = 0;
private static final long INTERVAL_TIME = 1500;
private View view; private View view;
public static String mOrderid, mProductId, MoneyUsds; public static String mOrderid, mProductId, MoneyUsds;
@ -99,50 +102,60 @@ public class GoogleFragment extends Fragment {
@JavascriptInterface @JavascriptInterface
public void androidNewGoToGooglePay(String ProductId, String OrderNumber, String MoneyUsd) { public void androidNewGoToGooglePay(String ProductId, String OrderNumber, String MoneyUsd) {
Log.e(TAG, "ProductId" + ProductId + "OrderNumber" + OrderNumber + "MoneyUsd" + MoneyUsd); long currentTime = System.currentTimeMillis();
mProductId = ProductId; if (currentTime - lastClickTime > INTERVAL_TIME) {
mOrderid = OrderNumber; mProductId = ProductId;
MoneyUsds = MoneyUsd; mOrderid = OrderNumber;
MoneyUsds = MoneyUsd;
googleUtils.setBillingListener(new GoogleUtils.GoogleBillingListener() { googleUtils.setBillingListener(new GoogleUtils.GoogleBillingListener() {
@Override @Override
public void onPaySuccess(String token, String orderId) { public void onPaySuccess(String token, String orderId) {
payHandler.post(new Runnable() { payHandler.post(new Runnable() {
@Override @Override
public void run() { public void run() {
CommonHttpUtil.notifyGoogle(token, orderId, mProductId, mOrderid, adid, new HttpCallback() { CommonHttpUtil.notifyGoogle(token, orderId, mProductId, mOrderid, adid, new HttpCallback() {
@Override @Override
public void onSuccess(int code, String msg, String[] info) { public void onSuccess(int code, String msg, String[] info) {
if (code == 0) { if (code == 0) {
Bundle params = new Bundle(); Bundle params = new Bundle();
params.putString("currency", "HKD"); params.putString("currency", "HKD");
params.putString("money", MoneyUsds); params.putString("money", MoneyUsds);
Bundle fb_params = new Bundle(); Bundle fb_params = new Bundle();
fb_params.putString(AppEventsConstants.EVENT_PARAM_CURRENCY, "HKD"); fb_params.putString(AppEventsConstants.EVENT_PARAM_CURRENCY, "HKD");
fb_params.putString(AppEventsConstants.EVENT_PARAM_CONTENT_ID, mProductId); fb_params.putString(AppEventsConstants.EVENT_PARAM_CONTENT_ID, mProductId);
//Google官方充值通知 //Google官方充值通知
Bundle google_params = new Bundle(); Bundle google_params = new Bundle();
google_params.putString("currency", "HKD"); google_params.putString("currency", "HKD");
google_params.putString("product_id", mProductId); google_params.putString("product_id", mProductId);
google_params.putString("transaction_id", mOrderid); google_params.putString("transaction_id", mOrderid);
google_params.putString("value", MoneyUsds); google_params.putString("value", MoneyUsds);
google_params.putString("price", MoneyUsds); google_params.putString("price", MoneyUsds);
google_params.putString("quantity", "1"); google_params.putString("quantity", "1");
dis(); dis();
ToastUtil.show("支付成功"); ToastUtil.show("支付成功");
}
} }
} });
}); }
} });
}); }
}
@Override @Override
public void onPayFailed(String msg) { public void onPayFailed(String msg) {
ToastUtil.show(msg); payHandler.post(new Runnable() {
} @Override
}); public void run() {
googleUtils.purchase(mProductId); ToastUtil.show(msg);
}
});
}
});
googleUtils.purchase(mProductId);
}
lastClickTime = currentTime;
Log.e(TAG, "ProductId" + ProductId + "OrderNumber" + OrderNumber + "MoneyUsd" + MoneyUsd);
} }
@JavascriptInterface @JavascriptInterface

View File

@ -23,7 +23,8 @@ import com.yunbao.main.views.TestWebViewClient;
@SuppressLint("ValidFragment") @SuppressLint("ValidFragment")
public class HuaWeiFragment extends Fragment { public class HuaWeiFragment extends Fragment {
private long lastClickTime = 0;
private static final long INTERVAL_TIME = 1500;
private View view; private View view;
public static String mOrderid, mProductId, MoneyUsds; public static String mOrderid, mProductId, MoneyUsds;
@ -80,17 +81,22 @@ public class HuaWeiFragment extends Fragment {
public void androidNewGoToGooglePay(String ProductId, String OrderNumber, String MoneyUsd) { public void androidNewGoToGooglePay(String ProductId, String OrderNumber, String MoneyUsd) {
Log.e(TAG, "ProductId:" + ProductId + " OrderNumber:" + OrderNumber + " MoneyUsd:" + MoneyUsd); Log.e(TAG, "ProductId:" + ProductId + " OrderNumber:" + OrderNumber + " MoneyUsd:" + MoneyUsd);
if (ProductId.equals("zs640")) { long currentTime = System.currentTimeMillis();
ProductId = "zs0640"; 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 @JavascriptInterface

View File

@ -93,8 +93,6 @@ public class MyWalletActivity extends AbsActivity {
loadingDialog.setShowText(getString(R.string.order_query)); loadingDialog.setShowText(getString(R.string.order_query));
if (CommonAppConfig.IS_GOOGLE_PLAY == 1) { if (CommonAppConfig.IS_GOOGLE_PLAY == 1) {
googleUtils.queryPurchasesAsync();
googleUtils.setQueryPurchaseListener(mContext, new GoogleUtils.QueryPurchasesListener() { googleUtils.setQueryPurchaseListener(mContext, new GoogleUtils.QueryPurchasesListener() {
@Override @Override
public void onResult(JSONObject obj) { 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(); hwBuilder.consume();
loadingDialog.setShowText(getString(R.string.order_query_success)); loadingDialog.setShowText(getString(R.string.order_query_success));
payHandler.postDelayed(() -> loadingDialog.dismiss(), 2000); payHandler.postDelayed(() -> loadingDialog.dismiss(), 2000);
} else {
loadingDialog.setShowText(getString(R.string.order_query_success));
payHandler.postDelayed(() -> loadingDialog.dismiss(), 2000);
} }
}); });

View File

@ -4,5 +4,5 @@ include ':FaceUnity'
//include ':recognizer'// //include ':recognizer'//
include ':Share' include ':Share'
include ':pluginsForAnchor' include ':pluginsForAnchor'
include ':lib_huawei' //include ':lib_huawei'
include ':lib_google' include ':lib_google'