android 登录 + 支付 + GA 通了

This commit is contained in:
LYP
2024-08-06 17:54:36 +08:00
parent 638d34a95d
commit 4e608afc37
4 changed files with 91 additions and 49 deletions

View File

@@ -39,6 +39,7 @@ public class SDKTest : MonoBehaviour
private async void OnLogin(EAccoutType accoutType)
{
_messageTxt.text = string.Empty;
Debug.LogError($"[AggSdk::OnLogin] accoutType : {accoutType}");
var info = await TYSdkFacade.Instance.Login(accoutType);
_messageTxt.text = $"Login: {info.isSuccess}";
if(info.isSuccess)

View File

@@ -7,12 +7,12 @@ import android.os.Looper;
import android.text.TextUtils;
import android.util.Log;
//import com.barton.log.GASDKFactory;
//import com.barton.log.builder.GAConfiguration;
//import com.barton.log.builder.ParamsBuilder;
//import com.barton.log.ebarton.BaseUrl;
//import com.barton.log.ebarton.EventType;
//import com.barton.log.logapi.IGASDK;
import com.barton.log.GASDKFactory;
import com.barton.log.builder.GAConfiguration;
import com.barton.log.builder.ParamsBuilder;
import com.barton.log.ebarton.BaseUrl;
import com.barton.log.ebarton.EventType;
import com.barton.log.logapi.IGASDK;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.tuyoo.gamesdk.api.SDKAPI;
@@ -36,7 +36,7 @@ import java.util.Map;
public class SDKManager {
private final static Handler handler = new Handler(Looper.getMainLooper());
// private static IGASDK gasdk;
private static IGASDK gasdk;
private static final String TAG = com.unity3d.player.SDKManager.class.getSimpleName();
private static String curType = TuYooClientID.tyGuest;
public static void InitSDK(Activity activity)
@@ -153,6 +153,18 @@ public class SDKManager {
});
}
public static void UnityLogin(String type) {
curType = type;
Log.e(TAG,"UnityLogin : " + type);
SDKLog.i("UnityLogin : " + type);
handler.post(new Runnable() {
@Override
public void run() {
SDKAPI.getIns().loginByType(type, mLogin);
}
});
}
public static void UnityLoginOut() {
// Log.e(TAG,"UnityLoginOut!!!");
SDKLog.i("UnityLoginOut : ");
@@ -247,55 +259,55 @@ public class SDKManager {
});
}
// private static IGASDK GetGameGa(){
// if(gasdk == null){
// GAConfiguration.Builder builder = new GAConfiguration.Builder()
// .withBaseUrl(BaseUrl.INTERNAL)
// .withContext(SDKWrapper.getInstance().getContext())
// .withClientId(ConfigManager.SDK_CLIENTID)
// .withGameId(ConfigManager.SDK_GAMEID)
// .withProjectId(ConfigManager.SDK_PROJECTID);
// gasdk = GASDKFactory.createGASDK(builder.build());
// }
// return gasdk;
// }
private static IGASDK GetGameGa(){
if(gasdk == null){
GAConfiguration.Builder builder = new GAConfiguration.Builder()
.withBaseUrl(BaseUrl.INTERNAL)
.withContext(SDKWrapper.getInstance().getContext())
.withClientId(ConfigManager.SDK_CLIENTID)
.withGameId(ConfigManager.SDK_GAMEID)
.withProjectId(ConfigManager.SDK_PROJECTID);
gasdk = GASDKFactory.createGASDK(builder.build());
}
return gasdk;
}
public static void SetGaUserInfo(String userId)
{
// Log.e(TAG,"SetGaUserInfo : " + userId);
// SDKLog.i("SetGaUserInfo : " + userId);
// GetGameGa().setUserId(userId);
Log.e(TAG,"SetGaUserInfo : " + userId);
SDKLog.i("SetGaUserInfo : " + userId);
GetGameGa().setUserId(userId);
}
public static void SetGaCommonInfo(String SetGaCommonInfo)
{
// Log.e(TAG,"SetGaCommonInfo : " + SetGaCommonInfo);
// SDKLog.i("SetGaCommonInfo : " + SetGaCommonInfo);
// Gson gson = new Gson();
// Map<String, Object> map = gson.fromJson(SetGaCommonInfo, new TypeToken<Map<String, Object>>(){}.getType());
// for (String key : map.keySet()) {
// System.out.println("Key = " + key + ", Value = " + map.get(key));
// if(!TextUtils.isEmpty(key) && map.get(key) != null){
// GetGameGa().addCommonParameter(key, map.get(key).toString());
// }
// }
Log.e(TAG,"SetGaCommonInfo : " + SetGaCommonInfo);
SDKLog.i("SetGaCommonInfo : " + SetGaCommonInfo);
Gson gson = new Gson();
Map<String, Object> map = gson.fromJson(SetGaCommonInfo, new TypeToken<Map<String, Object>>(){}.getType());
for (String key : map.keySet()) {
System.out.println("Key = " + key + ", Value = " + map.get(key));
if(!TextUtils.isEmpty(key) && map.get(key) != null){
GetGameGa().addCommonParameter(key, map.get(key).toString());
}
}
}
public static void GAReportParams(int type, String eventstr, String paramstr)
{
// Log.e(TAG,"GAReportParams : " + type + " \n" + eventstr + " \n" + paramstr);
//
// SDKLog.i("GAReportParams : " + type + " \n" + eventstr + " \n" + paramstr);
// ParamsBuilder paramsBuilder = ParamsBuilder.newInstance();
// Gson gson = new Gson();
// Map<String, Object> map = gson.fromJson(paramstr, new TypeToken<Map<String, Object>>(){}.getType());
// for (String key : map.keySet()) {
// System.out.println("Key = " + key + ", Value = " + map.get(key));
// if(!TextUtils.isEmpty(key) && map.get(key) != null){
// paramsBuilder.append(key, map.get(key).toString());
// }
// }
// GetGameGa().track(EventType.TRACK, eventstr, paramsBuilder);
Log.e(TAG,"GAReportParams : " + type + " \n" + eventstr + " \n" + paramstr);
SDKLog.i("GAReportParams : " + type + " \n" + eventstr + " \n" + paramstr);
ParamsBuilder paramsBuilder = ParamsBuilder.newInstance();
Gson gson = new Gson();
Map<String, Object> map = gson.fromJson(paramstr, new TypeToken<Map<String, Object>>(){}.getType());
for (String key : map.keySet()) {
System.out.println("Key = " + key + ", Value = " + map.get(key));
if(!TextUtils.isEmpty(key) && map.get(key) != null){
paramsBuilder.append(key, map.get(key).toString());
}
}
GetGameGa().track(EventType.TRACK, eventstr, paramsBuilder);
}
}

View File

@@ -8,6 +8,13 @@ namespace tysdk
hwGuest,
none
}
public class EAccoutTypeName
{
public static string hwGoogle = "hwGoogle";
public static string hwFacebook = "hwFacebook";
public static string hwGuest = "hwGuest";
}
public interface ITYSdkCallback { }
public class LoginInfo : ITYSdkCallback

View File

@@ -1,3 +1,4 @@
using System;
using System.Runtime.InteropServices;
using UnityEngine;
@@ -6,6 +7,7 @@ namespace tysdk
public static class UnityBridgeFunc
{
#if UNITY_EDITOR
//初始化sdk
public static void InitSDK(){}
@@ -51,8 +53,7 @@ namespace tysdk
public static void UnityLoadRvADS(){}
public static void UnityShowRVAD(){}
public static void UnityShowRVAD() { }
#elif UNITY_ANDROID
@@ -89,10 +90,11 @@ namespace tysdk
public static void UnityLogin(EAccoutType accoutType)
{
var typeName = GetLoginTypeName(accoutType);
Debug.LogError("typeName:::" + typeName);
using(var sdkManager = new AndroidJavaClass(SDK_CLASS))
{
sdkManager.CallStatic("UnityLogin", accoutType);
sdkManager.CallStatic("UnityLogin", typeName);
}
}
@@ -194,6 +196,7 @@ namespace tysdk
public static void UnityShowRVAD(){}
#elif UNITY_IOS
//更新登录支付域名
@@ -277,5 +280,24 @@ namespace tysdk
[DllImport("__Internal")]
public static extern int GetATT();
#endif
public static string GetLoginTypeName(EAccoutType accoutType)
{
string str = String.Empty;
switch (accoutType)
{
case EAccoutType.hwGoogle:
str = EAccoutTypeName.hwGoogle;
break;
case EAccoutType.hwFacebook:
str = EAccoutTypeName.hwFacebook;
break;
case EAccoutType.hwGuest:
str = EAccoutTypeName.hwGuest;
break;
}
return str;
}
}
}