420 lines
		
	
	
		
			12 KiB
		
	
	
	
		
			C#
		
	
	
		
			Executable File
		
	
	
			
		
		
	
	
			420 lines
		
	
	
		
			12 KiB
		
	
	
	
		
			C#
		
	
	
		
			Executable File
		
	
	
| using System;
 | ||
| using System.Collections.Generic;
 | ||
| using System.Security.Cryptography;
 | ||
| using System.Text;
 | ||
| using UnityEngine;
 | ||
| 
 | ||
| namespace EFSDK
 | ||
| {
 | ||
|     /// <summary>
 | ||
|     /// TKG Native SDK Android platform interface call
 | ||
|     /// </summary>
 | ||
|     public class EFSdk
 | ||
|     {
 | ||
|         private static EFSdk _mEfSdk;
 | ||
| 
 | ||
|         // 保持变量名不变
 | ||
|         private static string mappingInfo = "";
 | ||
| 
 | ||
|         public static EFSdk get()
 | ||
|         {
 | ||
|             if (_mEfSdk == null)
 | ||
|             {
 | ||
|                 _mEfSdk = new EFSdk();
 | ||
|             }
 | ||
| 
 | ||
|             return _mEfSdk;
 | ||
|         }
 | ||
| 
 | ||
| 
 | ||
|         private AndroidJavaObject jo;
 | ||
| 
 | ||
|         public EFSdk()
 | ||
|         {
 | ||
|             Debug.Log($"GetNewSDKClass():{GetNewSDKClass()}");
 | ||
|             
 | ||
|             // java interface class
 | ||
|             using (AndroidJavaClass jc = new AndroidJavaClass(GetNewSDKClass()))
 | ||
|             {
 | ||
|                 jo = jc.GetStatic<AndroidJavaObject>("INSTANCE");
 | ||
|             }
 | ||
|         }
 | ||
| 
 | ||
|         private static string oriSDKPName = "com.earn.push";
 | ||
|         private static string oriSDK = "_SDK";
 | ||
| 
 | ||
|         private static string GetNewSDKClass()
 | ||
|         {
 | ||
|             return GetSDKPackage()  + GenerateAndroidName(oriSDK);
 | ||
|         }
 | ||
| 
 | ||
|         private static string GetSDKPackage()
 | ||
|         {
 | ||
|             string[] parts = oriSDKPName.Split('.');
 | ||
|             string[] parts2 = new string[parts.Length];
 | ||
|             for (int i = 0; i < parts.Length; i++)
 | ||
|             {
 | ||
|                 parts2[i] = GenerateAndroidName(parts[i]);
 | ||
|             }
 | ||
| 
 | ||
|             string newPName = "";
 | ||
|             for (int i = 0; i < parts2.Length; i++)
 | ||
|             {
 | ||
|                 newPName+=parts2[i]+".";
 | ||
|             }
 | ||
|             return newPName;
 | ||
|         }
 | ||
| 
 | ||
|         private static string GenerateAndroidName(string oriString)
 | ||
|         {
 | ||
|             string md5Str = GetFirstEightWithUnderscore(GetMD5Hash(Application.identifier + oriString));
 | ||
|             return md5Str;
 | ||
|         }
 | ||
| 
 | ||
|         public static string GetMD5Hash(string input)
 | ||
|         {
 | ||
|             using (var md5 = MD5.Create())
 | ||
|             {
 | ||
|                 var inputBytes = Encoding.ASCII.GetBytes(input);
 | ||
|                 var hashBytes = md5.ComputeHash(inputBytes);
 | ||
| 
 | ||
|                 var builder = new StringBuilder();
 | ||
|                 foreach (var t in hashBytes)
 | ||
|                 {
 | ||
|                     builder.Append(t.ToString("x2")); // Convert byte to hexadecimal string
 | ||
|                 }
 | ||
| 
 | ||
|                 return builder.ToString();
 | ||
|             }
 | ||
|         }
 | ||
| 
 | ||
|         static string GetFirstEightWithUnderscore(string str)
 | ||
|         {
 | ||
|             if (string.IsNullOrEmpty(str)) return str;
 | ||
|             string sub = str.Length <= 8 ? str : str.Substring(0, 8);
 | ||
|             if (char.IsDigit(sub[0]))
 | ||
|             {
 | ||
|                 sub = "a" + sub;
 | ||
|             }
 | ||
|             return sub;
 | ||
|         }
 | ||
| 
 | ||
|         private T SDKCall<T>(string _method, params object[] _param)
 | ||
|         {
 | ||
|             try
 | ||
|             {
 | ||
|                 string newMethod = GenerateAndroidName(_method);
 | ||
|                 Debug.Log($"SDKCall<T> newMethod:{newMethod}");
 | ||
|                 return jo.Call<T>(newMethod, _param);
 | ||
|             }
 | ||
|             catch (Exception e)
 | ||
|             {
 | ||
|                 Debug.LogError(e);
 | ||
|             }
 | ||
| 
 | ||
|             return default(T);
 | ||
|         }
 | ||
| 
 | ||
|         private void SDKCall(string _method, params object[] _param)
 | ||
|         {
 | ||
|             try
 | ||
|             {
 | ||
|                 string newMethod = GenerateAndroidName(_method);
 | ||
|                 Debug.Log($"SDKCall newMethod:{newMethod}");
 | ||
|                 jo.Call(newMethod, _param);
 | ||
|             }
 | ||
|             catch (Exception e)
 | ||
|             {
 | ||
|                 Debug.LogError(e);
 | ||
|             }
 | ||
|         }
 | ||
| 
 | ||
|         public enum ActionType
 | ||
|         {
 | ||
|             SDK_INIT_Succ, //GAM页面加载成功
 | ||
|             H5_Load_Succ, //H5页面加载成功
 | ||
|             ON_RESUME, //游戏可见时回调,
 | ||
|             // CAN_GOBACK, //游戏可见时回调,
 | ||
|         }
 | ||
| 
 | ||
|         public Action<ActionType, string> ActionCallback;
 | ||
|         public Action<string, Dictionary<string, string>> ActionSDKEventCallback;
 | ||
|         public Action<string> HdH5ImpressionAction;
 | ||
|         public Action<bool> mCanGobackAction;
 | ||
|         public Action<bool> mReqNotifyPermissionAction;
 | ||
| 
 | ||
|         /// <summary>
 | ||
|         /// 在Init方法之后调用这个方法,设置SDK上报事件回调,  将SDK传过来的事件上报到Firebase,数数等
 | ||
|         /// </summary>
 | ||
|         /// <param name="actionCallbvack">
 | ||
|         ///     事件ID,事件属性
 | ||
|         /// </param>
 | ||
|         public void SetSDKEventCallback(Action<string, Dictionary<string, string>> eventKeyDict)
 | ||
|         {
 | ||
|             ActionSDKEventCallback = eventKeyDict;
 | ||
|         }
 | ||
| 
 | ||
|         /// <summary>
 | ||
|         /// 互动广告展示回调,此时可以计算上报互动广告展示次数和收益
 | ||
|         /// </summary>
 | ||
|         /// <param name="callback">string 是互动广告的url</param>
 | ||
|         public void SetHdH5ImpressionCallback(Action<string> callback)
 | ||
|         {
 | ||
|             HdH5ImpressionAction = callback;
 | ||
|         }
 | ||
| 
 | ||
| 
 | ||
|         /// <summary>
 | ||
|         ///  初始化
 | ||
|         /// </summary>
 | ||
|         /// <param name="actionCallbvack">ActionType 回调类型 ;  string msg </param>
 | ||
|         public void Init(Action<ActionType, string> actionCallbvack)
 | ||
|         {
 | ||
|             ActionCallback = actionCallbvack;
 | ||
|             SDKInit();
 | ||
|         }
 | ||
| 
 | ||
|         private void SDKInit()
 | ||
|         {
 | ||
|             SDKCall("initSDK", mappingInfo);
 | ||
|             ActionCallback?.Invoke(ActionType.SDK_INIT_Succ, string.Empty);
 | ||
|         }
 | ||
| 
 | ||
|         /// <summary>
 | ||
|         /// 展示WebView
 | ||
|         /// </summary>
 | ||
|         /// <param name="id">标签id</param>
 | ||
|         /// <param name="url">网址</param>
 | ||
|         /// <param name="pRect"></param>
 | ||
|         /// <param name="pCam"></param>
 | ||
|         public void ShowWebView(int id, string url, RectTransform pRect, Camera pCam = null)
 | ||
|         {
 | ||
|             Vector3[] tWorldCorners = new Vector3[4];
 | ||
|             pRect.GetWorldCorners(tWorldCorners);
 | ||
|             Vector2 tTopLeft = RectTransformUtility.WorldToScreenPoint(pCam, tWorldCorners[1]);
 | ||
|             Vector2 tBottomRight = RectTransformUtility.WorldToScreenPoint(pCam, tWorldCorners[3]);
 | ||
|             int tWidth = (int)Mathf.Abs(tBottomRight.x - tTopLeft.x);
 | ||
|             int tHeight = (int)Mathf.Abs(tBottomRight.y - tTopLeft.y);
 | ||
|             SDKCall("showWebViewToActivity", id, url, (int)tTopLeft.x, (int)(Screen.height - tTopLeft.y), tWidth,
 | ||
|                 tHeight);
 | ||
|         }
 | ||
| 
 | ||
|         /// <summary>
 | ||
|         /// 移除所有原生View, 回到游戏时调用
 | ||
|         /// </summary>
 | ||
|         /// <returns></returns>
 | ||
|         public void RemoveAll()
 | ||
|         {
 | ||
|             SDKCall("removeAll");
 | ||
|         }
 | ||
| 
 | ||
|         /// <summary>
 | ||
|         /// 刷新当前页面
 | ||
|         /// </summary>
 | ||
|         /// <returns></returns>
 | ||
|         public void Refresh()
 | ||
|         {
 | ||
|             SDKCall("refresh");
 | ||
|         }
 | ||
| 
 | ||
|         /// <summary>
 | ||
|         /// 回上一页
 | ||
|         /// </summary>
 | ||
|         /// <returns></returns>
 | ||
|         public void GoBack()
 | ||
|         {
 | ||
|             SDKCall("goBack");
 | ||
|         }
 | ||
| 
 | ||
|         /// <summary>
 | ||
|         /// 回首页
 | ||
|         /// </summary>
 | ||
|         /// <returns></returns>
 | ||
|         public void GoHome()
 | ||
|         {
 | ||
|             SDKCall("goHome");
 | ||
|         }
 | ||
| 
 | ||
| 
 | ||
|         /// <summary>
 | ||
|         /// 
 | ||
|         /// </summary>
 | ||
|         /// <param name="message"></param>
 | ||
|         public void ShowToast(string message)
 | ||
|         {
 | ||
|             SDKCall("showToast", message);
 | ||
|         }
 | ||
| 
 | ||
|         /// <summary>
 | ||
|         /// 判断当前网页是否还能返回上一页,  true:可以返回,此时页面不在首页   false: 不能返回了,当前页面就在首页
 | ||
|         /// </summary>
 | ||
|         public void CanGoback(Action<bool> canGobackAction)
 | ||
|         {
 | ||
|             mCanGobackAction = canGobackAction;
 | ||
|             SDKCall("canGoback");
 | ||
|         }
 | ||
| 
 | ||
|         #region 推送通知
 | ||
| 
 | ||
|         /// <summary>
 | ||
|         /// 满足条件:未领取 R$0.1 的 买量用户, 调用这个方法
 | ||
|         /// </summary>
 | ||
|         public void SubscribeUnclaimed01()
 | ||
|         {
 | ||
|             SDKCall("subscribeUnclaimed01");
 | ||
|         }
 | ||
| 
 | ||
|         /// <summary>
 | ||
|         ///  不满足条件:未领取 R$0.1 的 买量用户, 调用这个方法
 | ||
|         /// </summary>
 | ||
|         public void UnSubscribeUnclaimed01()
 | ||
|         {
 | ||
|             SDKCall("unSubscribeUnclaimed01");
 | ||
|         }
 | ||
| 
 | ||
|         /// <summary>
 | ||
|         //  满足条件: 在排队中 且 当日R$1 未领取 的买量用户, 调用这个方法
 | ||
|         /// </summary>
 | ||
|         public void SubscribePending1()
 | ||
|         {
 | ||
|             SDKCall("subscribePending1");
 | ||
|         }
 | ||
| 
 | ||
|         /// <summary>
 | ||
|         /// 不满足条件: 在排队中 且 当日R$1 未领取 的买量用户, 调用这个方法
 | ||
|         /// </summary>
 | ||
|         public void UnSubscribePending1()
 | ||
|         {
 | ||
|             SDKCall("unSubscribePending1");
 | ||
|         }
 | ||
| 
 | ||
|         /// <summary>
 | ||
|         /// 订阅Firebase推送主题
 | ||
|         /// </summary>
 | ||
|         /// <param name="topic">主题名称</param>
 | ||
|         public void SubscribeToTopic(string topic)
 | ||
|         {
 | ||
|             SDKCall("subscribeToTopic", topic);
 | ||
|         }
 | ||
| 
 | ||
|         /// <summary>
 | ||
|         ///  取消订阅Firebase推送主题
 | ||
|         /// </summary>
 | ||
|         /// <param name="topic">主题名称</param>
 | ||
|         public void UnSubscribeToTopic(string topic)
 | ||
|         {
 | ||
|             SDKCall("UnSubscribeToTopic", topic);
 | ||
|         }
 | ||
| 
 | ||
| 
 | ||
|         /// <summary>
 | ||
|         /// 向SDK上报当前金币总数,每次金币变化都要调用一次
 | ||
|         /// </summary>
 | ||
|         /// <param name="totalGold"></param>
 | ||
|         public void SendTotalGold2SDK(int totalGold)
 | ||
|         {
 | ||
|             SDKCall("setGoldNum", totalGold.ToString());
 | ||
|         }
 | ||
| 
 | ||
|         /// <summary>
 | ||
|         /// 向SDK上报当前要提现的现金额,每次变化都要调用一次
 | ||
|         /// </summary>
 | ||
|         /// <param name="cashNum"></param>
 | ||
|         public void SendCashNum2SDK(double cashNum)
 | ||
|         {
 | ||
|             SDKCall("setCashNum", cashNum.ToString("0.00"));
 | ||
|         }
 | ||
| 
 | ||
|         /// <summary>
 | ||
|         /// 向SDK上报 游戏名字(当前语言的),每次语言变化都上报
 | ||
|         /// </summary>
 | ||
|         /// <param name="gameName"></param>
 | ||
|         public void SetGameName(string gameName)
 | ||
|         {
 | ||
|             SDKCall("setGameName", gameName);
 | ||
|         }
 | ||
| 
 | ||
| 
 | ||
|         /// <summary>
 | ||
|         /// 设置当前游戏语言是否是 西班牙语
 | ||
|         /// 
 | ||
|         /// </summary>
 | ||
|         /// <param name="isEs">西班牙语传 true, 其他的都传 false </param>
 | ||
|         public void SetCurrLang(bool isEs)
 | ||
|         {
 | ||
|             SDKCall("setCurrLang", isEs);
 | ||
|         }
 | ||
| 
 | ||
|         /// <summary>
 | ||
|         /// 获取当前是否有通知权限
 | ||
|         /// </summary>
 | ||
|         public bool HasNotifyPermission()
 | ||
|         {
 | ||
|             return SDKCall<bool>("hasNotifyPermission");
 | ||
|         }
 | ||
| 
 | ||
|         /// <summary>
 | ||
|         /// 请求获取通知权限
 | ||
|         /// </summary>
 | ||
|         public void ReqNotifyPermission()
 | ||
|         {
 | ||
|             SDKCall("reqNotifyPermission");
 | ||
|         }
 | ||
| 
 | ||
|         /// <summary>
 | ||
|         /// 请求获取通知权限
 | ||
|         /// <param name="action">授权弹窗关闭回调  bool:表示用户是否允许了权限  true:有权限  false:无权限</param>
 | ||
|         /// </summary>
 | ||
|         public void ReqNotifyPermission(Action<bool> action)
 | ||
|         {
 | ||
|             mReqNotifyPermissionAction = action;
 | ||
|             SDKCall("reqNotifyPermission");
 | ||
|         }
 | ||
| 
 | ||
|         /// <summary>
 | ||
|         /// 设置推送开关, SDK默认关闭通知
 | ||
|         /// </summary>
 | ||
|         /// <param name="isOpen"></param>
 | ||
|         public void SetPushSwitch(bool isOpen)
 | ||
|         {
 | ||
|             SDKCall("pushSwitch", isOpen);
 | ||
|         }
 | ||
| 
 | ||
|         /// <summary>
 | ||
|         /// 消息类通知弹出间隔设置为60秒(在线参数控制)-Key: messagenotif  Value:60
 | ||
|         /// </summary>
 | ||
|         /// <param name="timeSeconds"></param>
 | ||
|         public void SetPushMessagenotif(int timeSeconds)
 | ||
|         {
 | ||
|             SDKCall("setPushMessagenotif", timeSeconds);
 | ||
|         }
 | ||
| 
 | ||
|         /// <summary>
 | ||
|         /// 持续性通知在进入游戏时弹出的时间间隔设置为300秒(在线参数控制 )-Key:persistentnotif Value:300
 | ||
|         /// </summary>
 | ||
|         /// <param name="timeSeconds"></param>
 | ||
|         public void SetPushPersistentnotif(int timeSeconds)
 | ||
|         {
 | ||
|             SDKCall("setPushPersistentnotif", timeSeconds);
 | ||
|         }
 | ||
| 
 | ||
| 
 | ||
|         /// <summary>
 | ||
|         /// 每次回调游戏的onResume的时候都调用一次,获取游戏要跳转的页面
 | ||
|         /// </summary>
 | ||
|         /// <returns>
 | ||
|         /// 0 不需要进行任何跳转
 | ||
|         /// 1 进行游戏主页
 | ||
|         /// 2 进入游戏的金币提现界面
 | ||
|         /// 3 进入对应小游戏1界面
 | ||
|         /// 4 进入对应小游戏2界面
 | ||
|         /// </returns>
 | ||
|         public int GetJumpPage()
 | ||
|         {
 | ||
|             return SDKCall<int>("getJumpPage");
 | ||
|         }
 | ||
| 
 | ||
|         #endregion
 | ||
|     }
 | ||
| }
 |