feat(channel): 同步渠道构建配置
This commit is contained in:
@@ -43,7 +43,7 @@ import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Unified SDKManager for all channels (GooglePlay / Flexion / RuStore / EnjoyPay).
|
||||
* Unified SDKManager for all channels (GooglePlay / Flexion / RuStore).
|
||||
* C# passes the channel string via InitSDK(activity, channel); Java dispatches
|
||||
* internally via switch. All login/link/GA/share logic is shared.
|
||||
* Channel-specific behaviour is limited to: Init, Pay, thirdExtend, Review.
|
||||
@@ -59,7 +59,17 @@ public class SDKManager {
|
||||
|
||||
// Channel SDK adapter
|
||||
public interface IChannelSDKAdapter {
|
||||
void init(Activity activity);
|
||||
default IChannelSDKAdapter loadConfig() {
|
||||
return this;
|
||||
}
|
||||
|
||||
String getChannel();
|
||||
|
||||
void init();
|
||||
|
||||
default String normalizeSkuList(String msg) {
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
|
||||
public interface IPaymentAdapter {
|
||||
@@ -82,9 +92,19 @@ public class SDKManager {
|
||||
void refreshBilling();
|
||||
}
|
||||
|
||||
public interface IChannelInfoAdapter {
|
||||
String getStorePageUri(Activity activity);
|
||||
}
|
||||
|
||||
public interface IReviewAdapter {
|
||||
void review(Activity activity);
|
||||
}
|
||||
|
||||
private static IChannelSDKAdapter sdkAdapter;
|
||||
|
||||
public static void queryProductsByIDs(String productIds) {
|
||||
Log.i(TAG, "[FLEXION-SKU-PRICE] queryProductsByIDs productIds=" + productIds
|
||||
+ " adapter=" + (sdkAdapter != null ? sdkAdapter.getClass().getName() : "null"));
|
||||
if (sdkAdapter instanceof IProductQueryAdapter) {
|
||||
((IProductQueryAdapter) sdkAdapter).queryProducts(productIds);
|
||||
return;
|
||||
@@ -125,7 +145,17 @@ public class SDKManager {
|
||||
|
||||
public static void CancelBillingFlow() {
|
||||
Log.w(TAG, "CancelBillingFlow");
|
||||
// FlexionSDKAdapter.cancelPurchase();
|
||||
}
|
||||
|
||||
public static String GetStorePageUri() {
|
||||
if (sdkAdapter instanceof IChannelInfoAdapter) {
|
||||
try {
|
||||
return ((IChannelInfoAdapter) sdkAdapter).getStorePageUri(UnityPlayer.currentActivity);
|
||||
} catch (Throwable e) {
|
||||
Log.w(TAG, "GetStorePageUri exception: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
public static boolean IsGooglePlayServicesAvailable() {
|
||||
@@ -147,29 +177,26 @@ public class SDKManager {
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Init — with channel helper support
|
||||
// Init with channel helper support
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
public static void InitSDK(Activity activity, String ch) {
|
||||
channel = ChannelEntry.CHANNEL;
|
||||
sdkAdapter = ChannelEntry.createSDKAdapter();
|
||||
sdkAdapter = ChannelAdapterManager.createSdkAdapter(activity);
|
||||
sdkAdapter.loadConfig();
|
||||
|
||||
// Log.i(TAG, "[CHANNEL-VERIFY] Java InitSDK channel=" + channel
|
||||
// + " fromCSharp=" + ch
|
||||
// + " adapter=" + (sdkAdapter != null ? sdkAdapter.getClass().getSimpleName() : "default"));
|
||||
channel = sdkAdapter.getChannel();
|
||||
|
||||
Log.i(TAG, "[CHANNEL-VERIFY] Java InitSDK channel=" + channel
|
||||
+ " fromCSharp=" + ch
|
||||
+ " adapter=" + sdkAdapter.getClass().getName());
|
||||
|
||||
// Sync channel to C# ChannelConfig
|
||||
UnityPlayer.UnitySendMessage(ConfigManager.UNITY_FACADE_NAME,
|
||||
"SetChannelFromNative", channel);
|
||||
|
||||
if (sdkAdapter != null) {
|
||||
sdkAdapter.init(activity);
|
||||
} else {
|
||||
initDefault(activity);
|
||||
}
|
||||
sdkAdapter.init();
|
||||
}
|
||||
|
||||
private static void initDefault(Activity activity) {
|
||||
static void initDefault(Activity activity) {
|
||||
activity.runOnUiThread(() -> {
|
||||
SDKAPI.getIns().lightModeEnable();
|
||||
try {
|
||||
@@ -258,6 +285,7 @@ public class SDKManager {
|
||||
|
||||
public static void UnityResetServerUrl(String url) {
|
||||
SDKLog.i("UnityResetServerUrl : " + url);
|
||||
SetDNSIPsEnable(false);
|
||||
SDKAPI.getIns().updateServer(url);
|
||||
}
|
||||
|
||||
@@ -446,7 +474,7 @@ public class SDKManager {
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Payment — channel dispatch
|
||||
// Payment channel dispatch
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
public static void UnityKnow(String productId, String productName, String productCount,
|
||||
@@ -461,7 +489,9 @@ public class SDKManager {
|
||||
public static void UnityKnowNew(String productId, String productPrice, String productName,
|
||||
String productCount, String prodorderId, String appInfo,
|
||||
String ptype) {
|
||||
SDKLog.i("[SDKManager.UnityKnowNew] channel=" + channel
|
||||
String currentChannel = getCurrentChannelForLog();
|
||||
SDKLog.i("[SDKManager.UnityKnowNew] channel=" + currentChannel
|
||||
+ ", adapter=" + (sdkAdapter != null ? sdkAdapter.getClass().getName() : "null")
|
||||
+ ", ptype=" + ptype
|
||||
+ ", productId=" + productId
|
||||
+ ", productPrice=" + productPrice
|
||||
@@ -489,8 +519,19 @@ public class SDKManager {
|
||||
SDKAPI.getIns().payNew(payData, payType, mPay);
|
||||
}
|
||||
|
||||
private static String getCurrentChannelForLog() {
|
||||
try {
|
||||
if (sdkAdapter != null && !TextUtils.isEmpty(sdkAdapter.getChannel())) {
|
||||
return sdkAdapter.getChannel();
|
||||
}
|
||||
} catch (Throwable ignored) {
|
||||
}
|
||||
|
||||
return TextUtils.isEmpty(channel) ? "GooglePlay" : channel;
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// thirdExtend — with channel helper support
|
||||
// thirdExtend with channel helper support
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
public static void thirdExtend() {
|
||||
@@ -518,7 +559,7 @@ public class SDKManager {
|
||||
JSONObject result = new JSONObject();
|
||||
result.put("code", code);
|
||||
if (code == SDKCallBack.Extend.EXTEND_CODE_SUCCESS) {
|
||||
result.put("respObj", ChannelEntry.normalizeSkuList(msg));
|
||||
result.put("respObj", ChannelAdapterManager.normalizeSkuList(msg));
|
||||
} else {
|
||||
Log.e(TAG, "thirdExtend failed: " + msg);
|
||||
result.put("thirdExtend_errStr", msg);
|
||||
@@ -594,12 +635,19 @@ public class SDKManager {
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Review — channel dispatch
|
||||
// Review channel dispatch
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
public static void Review() {
|
||||
Log.w(TAG, "[ReviewDebug] Review called channel=" + channel);
|
||||
if ("Rustore".equals(channel)) {
|
||||
RuStoreReview();
|
||||
} else if ("Flexion".equals(channel)) {
|
||||
if (sdkAdapter instanceof IReviewAdapter) {
|
||||
((IReviewAdapter) sdkAdapter).review(UnityPlayer.currentActivity);
|
||||
} else {
|
||||
Log.w(TAG, "Review skipped: no Flexion review adapter");
|
||||
}
|
||||
} else {
|
||||
GooglePlayReview();
|
||||
}
|
||||
@@ -693,4 +741,34 @@ public class SDKManager {
|
||||
Log.e(TAG, "Messenger ShareDialog can not show");
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetDNSIPsEnable(boolean enable) {
|
||||
if ("Flexion".equals(channel)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if(enable) {
|
||||
SetDNSIPs(true, new String[]{
|
||||
"34.111.1.231",
|
||||
"2600:1901:0:c31b::"
|
||||
});
|
||||
}
|
||||
else{
|
||||
SetDNSIPs(false, new String[0]);
|
||||
}
|
||||
}
|
||||
|
||||
private static void SetDNSIPs(boolean enable, String[] ips) {
|
||||
InvokeSDKAPIStaticMethod("enableDoh", new Class[]{boolean.class}, new Object[]{enable});
|
||||
InvokeSDKAPIStaticMethod("setHttpDnsIps", new Class[]{String[].class}, new Object[]{ips});
|
||||
}
|
||||
|
||||
private static void InvokeSDKAPIStaticMethod(String methodName, Class<?>[] parameterTypes, Object[] args) {
|
||||
try {
|
||||
SDKAPI.class.getMethod(methodName, parameterTypes).invoke(null, args);
|
||||
} catch (NoSuchMethodException ignored) {
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user