update:更新tysdk:注意直接consume了

This commit is contained in:
2026-05-14 11:49:07 +08:00
parent f9b5413a81
commit 49d80ee008
9 changed files with 61 additions and 12 deletions

View File

@@ -25,4 +25,5 @@ public class ConfigManager {
public static final String PAY_TYPE_CALLBACK_FUNCTION_NAME = "SKUListResult";
public static final String FCM_NOTICE_FUNCTION_NAME = "FCMCallback";
public static final String FCM_REALNAME_CALLBACK_FUNCTION_NAME = "RealNameCallback";
public static final String INIT_CALLBACK_FUNCTION_NAME = "InitResult";
}

View File

@@ -67,6 +67,7 @@ public class FlexionSDKHelper implements SDKManager.ISDKHelper {
} catch (Exception e) {
Log.e(TAG, "TuYoo SDK init failed, skip FLX init: " + e);
TYUnityActivity.setSdkInited();
SDKManager.notifyInitResult(false, "tuyoo_init_failed: " + e.getMessage());
}
if (sdkInitOk) {
@@ -77,10 +78,12 @@ public class FlexionSDKHelper implements SDKManager.ISDKHelper {
Log.i(TAG, "FLX.showFlexionScreens result=" + screenCode);
initBillingService(activity);
TYUnityActivity.setSdkInited();
SDKManager.notifyInitResult(true, "ok");
});
} else {
Log.e(TAG, "FLX.init failed: " + initCode);
TYUnityActivity.setSdkInited();
SDKManager.notifyInitResult(false, "flx_init_failed: " + initCode);
}
});
}
@@ -114,8 +117,41 @@ public class FlexionSDKHelper implements SDKManager.ISDKHelper {
String finalPayload = developerPayload;
activity.runOnUiThread(() -> {
Log.i(TAG, "[PAY-FLOW] launching billing flow for: " + productId + " payload=" + finalPayload);
billingService.launchBillingFlow(activity,
new BillingFlowParams(productId, "inapp", finalPayload));
Log.i(TAG, "[PAY-FLOW] billingService=" + billingService + " billingConnected=" + billingConnected);
try {
BillingResult result = billingService.launchBillingFlow(activity,
new BillingFlowParams(productId, "inapp", finalPayload));
Log.i(TAG, "[PAY-FLOW] launchBillingFlow result: code=" + result.getResponseCode()
+ " debugMsg=" + result.getDebugMessage());
if (result.getResponseCode() == 2001) {
Log.i(TAG, "[PAY-FLOW] service not ready, retry after 3s...");
new android.os.Handler(android.os.Looper.getMainLooper()).postDelayed(() -> {
try {
BillingResult retryResult = billingService.launchBillingFlow(activity,
new BillingFlowParams(productId, "inapp", finalPayload));
Log.i(TAG, "[PAY-FLOW] launchBillingFlow retry result: code=" + retryResult.getResponseCode()
+ " debugMsg=" + retryResult.getDebugMessage());
if (retryResult.getResponseCode() != 2000) {
sendPayCallback(1, "billing_flow_error_" + retryResult.getResponseCode()
+ "_" + retryResult.getDebugMessage(), null, null, null);
}
} catch (Exception ex) {
sendPayCallback(1, "launch_billing_failed: " + ex.getMessage(), null, null, null);
}
}, 3000);
return;
}
if (result.getResponseCode() != 2000) {
Log.e(TAG, "[PAY-FLOW] launchBillingFlow error: code=" + result.getResponseCode()
+ " debugMsg=" + result.getDebugMessage());
sendPayCallback(1, "billing_flow_error_" + result.getResponseCode()
+ "_" + result.getDebugMessage(), null, null, null);
}
} catch (Exception e) {
Log.e(TAG, "[PAY-FLOW] launchBillingFlow exception: " + e.getClass().getName()
+ " msg=" + e.getMessage());
sendPayCallback(1, "launch_billing_failed: " + e.getMessage(), null, null, null);
}
});
}
@@ -184,12 +220,15 @@ public class FlexionSDKHelper implements SDKManager.ISDKHelper {
Log.i(TAG, "[PAY-FLOW] handlePurchase: state=" + purchase.getPurchaseState()
+ " token=" + purchase.getToken());
if (purchase.getPurchaseState() == 0) {
Log.i(TAG, "[PAY-FLOW] purchaseJson=" + purchase.getPurchaseJson());
Log.i(TAG, "[PAY-FLOW] signature=" + purchase.getSignature());
sendPayCallback(0, "success", purchase.getPurchaseJson(), purchase.getSignature(), purchase.getToken());
// 支付成功 → 回传数据给 Unity 做服务端验签,验签通过后由 C# 调 ConsumePurchase
Log.i(TAG, "[PAY-FLOW] purchase success, sending to Unity for verification");
sendPayCallback(0, "success",
purchase.getPurchaseJson(), purchase.getSignature(), purchase.getToken());
// [旧逻辑] 直接消费,跳过验签
// Log.i(TAG, "[PAY-FLOW] auto-consuming pending purchase: " + purchase.getToken());
// consumePurchase(purchase.getToken());
} else if (purchase.getPurchaseState() == 2) {
Log.i(TAG, "[PAY-FLOW] purchase state=2 (pending)");
sendPayCallback(2, "pending", null, null, null);
Log.i(TAG, "[PAY-FLOW] purchase state=2 (pending), skip");
}
}

View File

@@ -25,4 +25,5 @@ public class ConfigManager {
public static final String PAY_TYPE_CALLBACK_FUNCTION_NAME = "SKUListResult";
public static final String FCM_NOTICE_FUNCTION_NAME = "FCMCallback";
public static final String FCM_REALNAME_CALLBACK_FUNCTION_NAME = "RealNameCallback";
public static final String INIT_CALLBACK_FUNCTION_NAME = "InitResult";
}

View File

@@ -25,4 +25,5 @@ public class ConfigManager {
public static final String PAY_TYPE_CALLBACK_FUNCTION_NAME = "SKUListResult";
public static final String FCM_NOTICE_FUNCTION_NAME = "FCMCallback";
public static final String FCM_REALNAME_CALLBACK_FUNCTION_NAME = "RealNameCallback";
public static final String INIT_CALLBACK_FUNCTION_NAME = "InitResult";
}