| | |
| | | using UnityEngine; |
| | | using LitJson; |
| | | using UnityEngine.Events; |
| | | using System.Collections.Generic; |
| | | using System.Runtime.InteropServices; |
| | | using System.Collections; |
| | | |
| | | public class SDKUtility : SingletonMonobehaviour<SDKUtility> |
| | | { |
| | | public static bool assetCopyFinish = false; |
| | | |
| | | public static float ElectricQuantity = 1f; |
| | | public static string UniqueID = ""; |
| | | public static string AND_UserAgent = ""; |
| | | public static string AND_MacAddress = ""; |
| | | public static string AND_IMEI = ""; |
| | | public static string AND_AndroidID = ""; |
| | | public static string AND_IP = ""; |
| | | public UnityAction<string> onUniqueIDChanged; |
| | | public static int wifiSignal = 3; |
| | | |
| | | public NetworkReachability NetWorkState = NetworkReachability.NotReachable; |
| | | |
| | | public UnityAction onAssetsCopyFinish; |
| | | public UnityAction<int, int> onBatteryChanged; |
| | | // 0 "未开启监视电池状态", 1 "电池未充电状态", 2 "电池充电状态", 3 "电池充电完成" |
| | | public int BatteryState { get; private set; } |
| | | public UnityAction<int> onBatteryStateChanged; |
| | | /// <summary> |
| | | /// 网络状态改变: 0: 无网络 1: wifi网络 2: 手机网络( >= 2为手机网络, 依次为2G,3G,4G) |
| | | /// </summary> |
| | | public UnityAction<int> onNetStatusChanged; |
| | | public UnityAction<int> onPhoneSignalChanged; |
| | | public UnityAction<int> onWifiSignalChanged; |
| | | public string GeTuiClientID { get; private set; } |
| | | |
| | | public string channelId = "1000"; |
| | | public string platfromId = "1000"; |
| | | |
| | | private const int CODE_SDK_COPY_ASSETS_OVER = 2001; |
| | | private const int CODE_SDK_BATTERY_CHANGED = 2002; |
| | | private const int CODE_SDK_NETSTATE_CHANGED = 2003; |
| | | private const int CODE_SDK_GETUI_CLIENT_ID = 2004; |
| | | private const int CODE_SDK_GETUI_MESSAGE = 2005; |
| | | private const int CODE_SDK_PHONESIGNAL_LEVEL = 2006; |
| | | private const int CODE_SDK_WIFISIGNAL_LEVEL = 2007; |
| | | private const int CODE_SDK_EXTERNALSTORAGEDIRECTORY = 2008; |
| | | private const int CODE_SDK_MAKEKEYANDVISIBLE = 2010; |
| | | private const int CODE_SDK_IOS_OPENURL = 2011; |
| | | private const int CODE_SDK_BATTERY_STATE_CHANGE = 2012; |
| | | private const int CODE_SDK_UNIQUE_ID_CHANGE = 2013; |
| | | private const int CODE_SDK_AD_TOKEN = 4000; |
| | | private const int CODE_SDK_USERAGENT = 4100; |
| | | |
| | | public static bool hasGetAndroidInfo = false; |
| | | |
| | | public string Account { get; private set; } |
| | | |
| | | public string AD_Token |
| | | { |
| | | get; private set; |
| | | } |
| | | |
| | | [DllImport("__Internal")] |
| | | private static extern void IOSMessageHandle(string json); |
| | | |
| | | /// <summary> |
| | | /// Android的内部存储根目录 |
| | | /// </summary> |
| | | public string externalStorageDirectory = null; |
| | | |
| | | public void Initialize() |
| | | { |
| | | GeTuiClientID = string.Empty; |
| | | |
| | | if (VersionConfig.Get().versionAuthority == VersionAuthority.Release) |
| | | { |
| | | SendClientPackage(); |
| | | } |
| | | |
| | | #if !UNITY_EDITOR |
| | | |
| | | |
| | | #if UNITY_IOS |
| | | var assetsCopyFinishVersion = LocalSave.GetString("AssetCopyCompleted_IOS"); |
| | | if (string.IsNullOrEmpty(assetsCopyFinishVersion)) |
| | | { |
| | | assetCopyFinish = false; |
| | | } |
| | | else |
| | | { |
| | | assetCopyFinish = VersionConfig.Get().version == assetsCopyFinishVersion; |
| | | } |
| | | |
| | | FreePlatformInit(); |
| | | #endif |
| | | StartCoroutine("GetWifiState"); |
| | | #endif |
| | | |
| | | } |
| | | |
| | | private IEnumerator GetWifiState() |
| | | { |
| | | while (true) |
| | | { |
| | | yield return WaitingForSecondConst.WaitMS1000; |
| | | |
| | | if (Application.internetReachability != NetWorkState) |
| | | { |
| | | NetWorkState = Application.internetReachability; |
| | | |
| | | if (onNetStatusChanged != null) |
| | | { |
| | | onNetStatusChanged((int)NetWorkState); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | public void TestBattery() |
| | | { |
| | | int level = Random.Range(1, 100); |
| | | int total = 100; |
| | | ElectricQuantity = (float)level / total; |
| | | |
| | | //Debug.LogFormat("收到电量通知 => 当前: {0}, 总量: {1}, 百分比:{2}", level, total, ElectricQuantity); |
| | | |
| | | if (onBatteryChanged != null) |
| | | { |
| | | onBatteryChanged(level, total); |
| | | } |
| | | } |
| | | |
| | | public void TestWifi() |
| | | { |
| | | NetworkReachability _state = (NetworkReachability)Random.Range(0, 2); |
| | | if (NetWorkState != _state) |
| | | { |
| | | NetWorkState = _state; |
| | | if (onNetStatusChanged != null) |
| | | { |
| | | onNetStatusChanged((int)NetWorkState); |
| | | } |
| | | //Debug.LogFormat("网络状态变更: {0}", NetWorkState); |
| | | } |
| | | |
| | | } |
| | | |
| | | public void Recv_SDK_Callback(string msg) |
| | | { |
| | | JsonData _jsonData = JsonMapper.ToObject(msg); |
| | | switch ((int)_jsonData["code"]) |
| | | { |
| | | case CODE_SDK_FREEPLATFORM_INIT_OK:// 初始化成功 |
| | | if (onFreePlatformInitOk != null) |
| | | { |
| | | onFreePlatformInitOk(); |
| | | } |
| | | break; |
| | | case CODE_SDK_FREEPLATFORM_INIT_FAIL:// 初始化失败 |
| | | if (onFreePlatformInitFail != null) |
| | | { |
| | | onFreePlatformInitFail(); |
| | | } |
| | | break; |
| | | case CODE_SDK_FREEPLATFORM_LOGIN_OK:// 登陆成功 |
| | | |
| | | #if UNITY_ANDROID |
| | | HandleFreePlatformLoginOk(_jsonData["info"]); |
| | | #elif UNITY_IOS |
| | | HandleFreePlatformLoginOk(_jsonData); |
| | | #endif |
| | | |
| | | OperationLogCollect.Instance.RecordEvent(6); |
| | | |
| | | break; |
| | | case CODE_SDK_FREEPLATFORM_LOGIN_FAIL:// 登陆成功 |
| | | if (onFreePlatformLoginFail != null) |
| | | { |
| | | onFreePlatformLoginFail(); |
| | | } |
| | | break; |
| | | case CODE_SDK_FREEPLATFORM_LOGOUT_OK:// 登出成功 |
| | | if (onFreePlatformLogoutOk != null) |
| | | { |
| | | onFreePlatformLogoutOk(); |
| | | } |
| | | break; |
| | | case CODE_SDK_FREEPLATFORM_LOGOUT_FAIL:// 登出失败 |
| | | if (onFreePlatformLogoutFail != null) |
| | | { |
| | | onFreePlatformLogoutFail(); |
| | | } |
| | | break; |
| | | case CODE_SDK_FREEPLATFORM_PAY_OK:// 支付成功 |
| | | if (onFreePlatformPayOk != null) |
| | | { |
| | | onFreePlatformPayOk(); |
| | | } |
| | | break; |
| | | case CODE_SDK_FREEPLATFORM_PAY_FAIL:// 支付失败 |
| | | if (onFreePlatformPayFail != null) |
| | | { |
| | | onFreePlatformPayFail(); |
| | | } |
| | | break; |
| | | case CODE_SDK_FREEPLATFORM_PAY_CANCEL:// 支付退出 |
| | | if (onFreePlatformPayCancel != null) |
| | | { |
| | | onFreePlatformPayCancel(); |
| | | } |
| | | break; |
| | | case CODE_SDK_FREEPLATFORM_BIND_OK: |
| | | if (onFreePlatformBindOk != null) |
| | | { |
| | | onFreePlatformBindOk(); |
| | | } |
| | | break; |
| | | case CODE_SDK_FREEPLATFORM_BIND_FAIL: |
| | | if (onFreePlatformBindFail != null) |
| | | { |
| | | onFreePlatformBindFail(); |
| | | } |
| | | break; |
| | | case CODE_SDK_AD_TOKEN: |
| | | AD_Token = _jsonData["token"].ToString(); |
| | | //Debug.LogFormat("获取广告sdk的Token: {0}", AD_Token); |
| | | break; |
| | | case CODE_SDK_FREEPLATFORM_REG_OK: |
| | | Account = _jsonData["account"].ToString(); |
| | | OperationLogCollect.Instance.RecordEvent(5); |
| | | SendTouTiaoADEvent(1); |
| | | break; |
| | | case CODE_SDK_BATTERY_CHANGED:// 电量改变 |
| | | #if UNITY_ANDROID |
| | | HandleBatteryChanged(_jsonData["info"]); |
| | | #elif UNITY_IOS |
| | | HandleBatteryChanged(_jsonData); |
| | | #endif |
| | | break; |
| | | case CODE_SDK_BATTERY_STATE_CHANGE: |
| | | BatteryState = (int)_jsonData["status"]; |
| | | //Debug.LogFormat("收到充电状态: {0}", BatteryState); |
| | | if (onBatteryStateChanged != null) |
| | | { |
| | | onBatteryStateChanged(BatteryState); |
| | | } |
| | | break; |
| | | case CODE_SDK_COPY_ASSETS_OVER:// 资源拷贝完毕 |
| | | assetCopyFinish = true; |
| | | if (onAssetsCopyFinish != null) |
| | | { |
| | | onAssetsCopyFinish(); |
| | | } |
| | | break; |
| | | case CODE_SDK_GETUI_CLIENT_ID:// 个推客户端ID |
| | | HandleGT_ClientID(_jsonData); |
| | | break; |
| | | case CODE_SDK_GETUI_MESSAGE:// 个推透传信息 |
| | | HandleGT_TouChuanMSG(_jsonData["info"]); |
| | | break; |
| | | case CODE_SDK_EXTERNALSTORAGEDIRECTORY: |
| | | externalStorageDirectory = _jsonData["info"].ToString(); |
| | | break; |
| | | case CODE_SDK_UNIQUE_ID_CHANGE: |
| | | //WriteDebug(msg); |
| | | UniqueID = _jsonData["uniqueID"].ToString(); |
| | | //WriteDebug("获取的唯一识别码为: " + UniqueID); |
| | | if (onUniqueIDChanged != null) |
| | | { |
| | | onUniqueIDChanged(UniqueID); |
| | | } |
| | | break; |
| | | case CODE_SDK_USERAGENT: |
| | | //WriteDebug(msg); |
| | | #if UNITY_ANDROID |
| | | AND_MacAddress = _jsonData["mac"].ToString(); |
| | | AND_AndroidID = _jsonData["android_id"].ToString(); |
| | | AND_IMEI = _jsonData["imei"].ToString(); |
| | | #endif |
| | | AND_UserAgent = _jsonData["userAgent"].ToString(); |
| | | AND_IP = _jsonData["ip"].ToString(); |
| | | hasGetAndroidInfo = true; |
| | | //WriteDebug("是否完成设备信息获取: " + hasGetAndroidInfo); |
| | | break; |
| | | } |
| | | } |
| | | |
| | | public void StartCopyAsset() |
| | | { |
| | | AndroidJavaClass _jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); |
| | | AndroidJavaObject _jo = _jc.GetStatic<AndroidJavaObject>("currentActivity"); |
| | | _jo.Call("copyAsset"); |
| | | } |
| | | |
| | | public int GetDeviceMemInfo() |
| | | { |
| | | AndroidJavaClass _jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); |
| | | AndroidJavaObject _jo = _jc.GetStatic<AndroidJavaObject>("currentActivity"); |
| | | return _jo.Call<int>("getMemInfo"); |
| | | } |
| | | |
| | | public void RestartApp() |
| | | { |
| | | AndroidJavaClass _jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); |
| | | AndroidJavaObject _jo = _jc.GetStatic<AndroidJavaObject>("currentActivity"); |
| | | _jo.Call("RestartApp"); |
| | | } |
| | | |
| | | public void CopyTextToClipboard(string content) |
| | | { |
| | | AndroidJavaClass _jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); |
| | | AndroidJavaObject _jo = _jc.GetStatic<AndroidJavaObject>("currentActivity"); |
| | | _jo.Call("CopyTextToClipboard", content); |
| | | } |
| | | |
| | | public void OpenUrl(string url) |
| | | { |
| | | #if UNITY_ANDROID |
| | | AndroidJavaClass _jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); |
| | | AndroidJavaObject _jo = _jc.GetStatic<AndroidJavaObject>("currentActivity"); |
| | | _jo.Call("OpenUrl", url); |
| | | #elif UNITY_IOS |
| | | string _content = "{\"code\":2011,\"url\":\"" + url + "\"}"; |
| | | IOSMessageHandle(_content); |
| | | #endif |
| | | } |
| | | |
| | | public void SendClientPackage() |
| | | { |
| | | #if UNITY_ANDROID && !UNITY_EDITOR |
| | | AndroidJavaClass _jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); |
| | | AndroidJavaObject _jo = _jc.GetStatic<AndroidJavaObject>("currentActivity"); |
| | | _jo.Call("setClientPackageID", VersionConfig.Get().clientPackageFlag); |
| | | #endif |
| | | } |
| | | |
| | | public void InstallAPK(string path) |
| | | { |
| | | AndroidJavaClass _jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); |
| | | AndroidJavaObject _jo = _jc.GetStatic<AndroidJavaObject>("currentActivity"); |
| | | _jo.Call("InstallAPK", path); |
| | | } |
| | | |
| | | public void MakeKeyAndVisible() |
| | | { |
| | | #if UNITY_IOS |
| | | string _content = "{\"code\":2010}"; |
| | | IOSMessageHandle(_content); |
| | | #endif |
| | | } |
| | | |
| | | public string GetAndroidRoot() |
| | | { |
| | | return externalStorageDirectory; |
| | | } |
| | | |
| | | private void HandleBatteryChanged(JsonData data) |
| | | { |
| | | int _level = (int)data["level"]; |
| | | int _scale = (int)data["scale"]; |
| | | |
| | | ElectricQuantity = (float)_level / _scale; |
| | | |
| | | //Debug.LogFormat("收到电量通知 => 当前: {0}, 总量: {1}, 百分比:{2}", _level, _scale, ElectricQuantity); |
| | | |
| | | if (onBatteryChanged != null) |
| | | { |
| | | onBatteryChanged(_level, _scale); |
| | | } |
| | | } |
| | | |
| | | private void HandleGT_ClientID(JsonData data) |
| | | { |
| | | GeTuiClientID = data["clientID"].ToString(); |
| | | //DesignDebug.Log("收到个推 => ClientID: " + GeTuiClientID); |
| | | } |
| | | |
| | | private void HandleGT_TouChuanMSG(JsonData data) |
| | | { |
| | | string _getuiMSG = data["msg"].ToString(); |
| | | //DesignDebug.Log("收到个推透传信息 => msg: " + _getuiMSG); |
| | | } |
| | | |
| | | #region 自由SDK相关 |
| | | |
| | | public struct FP_LoginOk |
| | | { |
| | | public string account; |
| | | public string token; |
| | | public string tokenExpire; |
| | | public int phone; |
| | | public int accountID; |
| | | } |
| | | |
| | | public struct FP_CheckIDAuthentication |
| | | { |
| | | public string errorcode; |
| | | public string errordesc; |
| | | public string type; |
| | | public string card_id; |
| | | } |
| | | |
| | | public struct FP_DoIDAuthentication |
| | | { |
| | | public string errorcode; |
| | | public string errordesc; |
| | | public string card_id; |
| | | } |
| | | |
| | | public string AppID |
| | | { |
| | | get |
| | | { |
| | | return VersionConfig.Get().appId; |
| | | } |
| | | } |
| | | |
| | | private const int CODE_SDK_FREEPLATFORM_INIT_OK = 3000; |
| | | private const int CODE_SDK_FREEPLATFORM_INIT_FAIL = 3001; |
| | | private const int CODE_SDK_FREEPLATFORM_LOGIN_OK = 3002; |
| | | private const int CODE_SDK_FREEPLATFORM_LOGIN_FAIL = 3003; |
| | | private const int CODE_SDK_FREEPLATFORM_LOGOUT_OK = 3004; |
| | | private const int CODE_SDK_FREEPLATFORM_LOGOUT_FAIL = 3005; |
| | | private const int CODE_SDK_FREEPLATFORM_PAY_OK = 3006; |
| | | private const int CODE_SDK_FREEPLATFORM_PAY_FAIL = 3007; |
| | | private const int CODE_SDK_FREEPLATFORM_PAY_CANCEL = 3008; |
| | | private const int CODE_SDK_FREEPLATFORM_BIND_OK = 3009; |
| | | private const int CODE_SDK_FREEPLATFORM_BIND_FAIL = 3010; |
| | | private const int CODE_SDK_FREEPLATFORM_REG_OK = 3011; |
| | | |
| | | public UnityAction onFreePlatformInitOk; |
| | | public UnityAction onFreePlatformInitFail; |
| | | public UnityAction<FP_LoginOk> onFreePlatformLoginOk; |
| | | public UnityAction onFreePlatformLoginFail; |
| | | public UnityAction onFreePlatformLogoutOk; |
| | | public UnityAction onFreePlatformLogoutFail; |
| | | public UnityAction onFreePlatformPayOk; |
| | | public UnityAction onFreePlatformPayFail; |
| | | public UnityAction onFreePlatformPayCancel; |
| | | public UnityAction onFreePlatformBindOk; |
| | | public UnityAction onFreePlatformBindFail; |
| | | public UnityAction<FP_CheckIDAuthentication> onFreePlatfromCheckIDOK; |
| | | public UnityAction<FP_DoIDAuthentication> onFreePlatfromDoIDAuthenticationOk; |
| | | |
| | | public void FreePlatformInit() |
| | | { |
| | | #if UNITY_IOS |
| | | IOSMessageHandle("{\"code\":3100}"); |
| | | #endif |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 自由SDK登陆 |
| | | /// </summary> |
| | | public void FreePlatformLogin() |
| | | { |
| | | #if UNITY_ANDROID |
| | | AndroidJavaClass _jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); |
| | | AndroidJavaObject _jo = _jc.GetStatic<AndroidJavaObject>("currentActivity"); |
| | | _jo.Call("FreePlatformLogin"); |
| | | #elif UNITY_IOS |
| | | IOSMessageHandle("{\"code\":3101}"); |
| | | #endif |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 自由SDK退出 |
| | | /// </summary> |
| | | public void FreePlatformLoginout() |
| | | { |
| | | #if UNITY_ANDROID |
| | | AndroidJavaClass _jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); |
| | | AndroidJavaObject _jo = _jc.GetStatic<AndroidJavaObject>("currentActivity"); |
| | | _jo.Call("FreePlatformLogout"); |
| | | #elif UNITY_IOS |
| | | IOSMessageHandle("{\"code\":3102}"); |
| | | #endif |
| | | } |
| | | |
| | | public void FreePlatformBindPhone() |
| | | { |
| | | #if UNITY_ANDROID |
| | | AndroidJavaClass _jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); |
| | | AndroidJavaObject _jo = _jc.GetStatic<AndroidJavaObject>("currentActivity"); |
| | | _jo.Call("BindPhone"); |
| | | #endif |
| | | } |
| | | |
| | | public void FreePlatformSwitchAccount() |
| | | { |
| | | #if UNITY_ANDROID |
| | | AndroidJavaClass _jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); |
| | | AndroidJavaObject _jo = _jc.GetStatic<AndroidJavaObject>("currentActivity"); |
| | | _jo.Call("SwitchAccount"); |
| | | #endif |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 自由SDK显示游戏中悬浮 |
| | | /// </summary> |
| | | public void FreePlatformShowGameFloat() |
| | | { |
| | | #if UNITY_ANDROID |
| | | AndroidJavaClass _jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); |
| | | AndroidJavaObject _jo = _jc.GetStatic<AndroidJavaObject>("currentActivity"); |
| | | _jo.Call("ShowGameFloat"); |
| | | #endif |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 自由SDK隐藏游戏中悬浮 |
| | | /// </summary> |
| | | public void FreePlatformHideGameFloat() |
| | | { |
| | | #if UNITY_ANDROID |
| | | AndroidJavaClass _jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); |
| | | AndroidJavaObject _jo = _jc.GetStatic<AndroidJavaObject>("currentActivity"); |
| | | _jo.Call("HideGameFloat"); |
| | | #endif |
| | | } |
| | | |
| | | private Dictionary<string, string> m_PaymentTable = new Dictionary<string, string>(); |
| | | private string m_EncodeKey = "03sujm7gerywdvyd5vkkk772rs4by230"; |
| | | |
| | | /// <summary> |
| | | /// 自由SDK支付 fixed sdk 支付逻辑修改 |
| | | /// </summary> |
| | | public void FreePlatformPay(string title, float money, string cpInfo) |
| | | { |
| | | m_PaymentTable["ProductID"] = "snxxz"; |
| | | m_PaymentTable["OperatorID"] = VersionConfig.Get().appId; |
| | | m_PaymentTable["RegionName"] = "s" + ServerListCenter.Instance.currentServer.region_flag; |
| | | m_PaymentTable["TimeStamp"] = ((long)(System.DateTime.Now - System.TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1))).TotalSeconds).ToString(); |
| | | m_PaymentTable["Time"] = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); |
| | | m_PaymentTable["EventID"] = "12001"; |
| | | m_PaymentTable["IP"] = DeviceUtility.GetIp(); |
| | | m_PaymentTable["AccountID"] = Snxxz.UI.ModelCenter.Instance.GetModel<Snxxz.UI.LoginModel>().sdkLoginResult.account; |
| | | m_PaymentTable["SessionID"] = "11"; |
| | | m_PaymentTable["Level"] = PlayerDatas.Instance.baseData.LV.ToString(); |
| | | m_PaymentTable["VIPLevel"] = PlayerDatas.Instance.baseData.VIPLv.ToString(); |
| | | m_PaymentTable["CurrencyAmount"] = money.ToString(); |
| | | m_PaymentTable["OrderTitle"] = title; |
| | | m_PaymentTable["OrderInfo"] = cpInfo; |
| | | m_PaymentTable["AppID"] = VersionConfig.Get().appId; |
| | | |
| | | var _stringBuilder = new System.Text.StringBuilder(); |
| | | var _md5Body = _stringBuilder.Append(m_PaymentTable["AppID"]). |
| | | Append(m_PaymentTable["AccountID"]). |
| | | Append(m_PaymentTable["TimeStamp"]). |
| | | Append(m_PaymentTable["CurrencyAmount"]). |
| | | Append(m_EncodeKey); |
| | | |
| | | var _md5Encode = System.Security.Cryptography.MD5.Create(); |
| | | var _encodeResult = _md5Encode.ComputeHash(System.Text.Encoding.UTF8.GetBytes(_md5Body.ToString())); |
| | | |
| | | _stringBuilder.Remove(0, _stringBuilder.Length); |
| | | for (int i = 0; i < _encodeResult.Length; ++i) |
| | | { |
| | | _stringBuilder.Append(_encodeResult[i].ToString("x2")); |
| | | } |
| | | |
| | | m_PaymentTable["Sign"] = _stringBuilder.ToString(); |
| | | m_PaymentTable["RoleID"] = PlayerDatas.Instance.baseData.PlayerName; |
| | | |
| | | _stringBuilder.Remove(0, _stringBuilder.Length); |
| | | |
| | | HttpRequest.Instance.RequestHttpGet(_stringBuilder.Append("http://recharge.game.173on.com:11000/api?"). |
| | | Append(HttpRequest.HashtablaToString(m_PaymentTable)).ToString(), |
| | | HttpRequest.defaultHttpContentType, 1, (bool result, string message) => |
| | | { |
| | | if (result) |
| | | { |
| | | JsonData _json = JsonMapper.ToObject(message); |
| | | |
| | | int _callbackResult = (int)_json["result"]; |
| | | |
| | | if (_callbackResult == 1) |
| | | { |
| | | #if !UNITY_EDITOR |
| | | |
| | | #if UNITY_ANDROID |
| | | AndroidJavaClass _jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); |
| | | AndroidJavaObject _jo = _jc.GetStatic<AndroidJavaObject>("currentActivity"); |
| | | _jo.Call("Pay", title, _json["orderid"].ToString(), money, cpInfo); |
| | | |
| | | #elif UNITY_IOS |
| | | JsonData _params = new JsonData(); |
| | | _params["code"] = 3103; |
| | | _params["identifier"] = VersionConfig.Get().bundleIdentifier; |
| | | _params["cpOrderId"] = _json["orderid"].ToString(); |
| | | _params["total"] = money; |
| | | _params["cpInfo"] = cpInfo; |
| | | _params["title"] = title; |
| | | IOSMessageHandle(_params.ToJson()); |
| | | #endif |
| | | m_Order = _json["orderid"].ToString(); |
| | | m_Money = money; |
| | | #endif |
| | | } |
| | | else |
| | | { |
| | | Debug.Log(_json["msg"].ToString()); |
| | | if (onFreePlatformPayFail != null) |
| | | { |
| | | onFreePlatformPayFail(); |
| | | } |
| | | } |
| | | } |
| | | else |
| | | { |
| | | if (onFreePlatformPayFail != null) |
| | | { |
| | | onFreePlatformPayFail(); |
| | | } |
| | | } |
| | | }); |
| | | } |
| | | |
| | | string authenticationCardId = ""; |
| | | public void FreePlatformDoIDAuthentication(string _account, string _userName, string _idNumber) |
| | | { |
| | | authenticationCardId = _idNumber; |
| | | |
| | | var tables = new Dictionary<string, string>(); |
| | | tables["app_id"] = VersionConfig.Get().appId; |
| | | tables["account"] = _account; |
| | | tables["card_id"] = _idNumber; |
| | | tables["mac"] = DeviceUtility.GetMac(); |
| | | tables["rolename"] = _userName; |
| | | tables["channelid"] = channelId; |
| | | |
| | | var url = "http://zysdk.xileyougame.com/api.php/Service/anti_mystery?"; |
| | | HttpRequest.Instance.RequestHttpGet(StringUtility.Contact(url, HttpRequest.HashtablaToString(tables)), HttpRequest.defaultHttpContentType, 1, HandleIDAuthenticationResult); |
| | | } |
| | | |
| | | public void FreePlatformCheckIDAuthentication(string _account) |
| | | { |
| | | var url = "http://zysdk.xileyougame.com/api.php/Service/check_mystery?"; |
| | | var tables = new Dictionary<string, string>(); |
| | | tables["app_id"] = VersionConfig.Get().appId; |
| | | tables["channelid"] = channelId; |
| | | tables["account"] = _account; |
| | | tables["platfrom_id"] = platfromId; |
| | | |
| | | HttpRequest.Instance.RequestHttpGet(StringUtility.Contact(url, HttpRequest.HashtablaToString(tables)), HttpRequest.defaultHttpContentType, 1, HandleCheckIDAuthenticationResult); |
| | | } |
| | | |
| | | private void HandleIDAuthenticationResult(bool _ok, string _result) |
| | | { |
| | | if (_ok) |
| | | { |
| | | if (onFreePlatfromDoIDAuthenticationOk != null) |
| | | { |
| | | var result = JsonMapper.ToObject<FP_DoIDAuthentication>(_result); |
| | | result.card_id = authenticationCardId; |
| | | onFreePlatfromDoIDAuthenticationOk(result); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | |
| | | } |
| | | } |
| | | |
| | | private void HandleCheckIDAuthenticationResult(bool _ok, string _result) |
| | | { |
| | | if (_ok) |
| | | { |
| | | if (onFreePlatfromCheckIDOK != null) |
| | | { |
| | | var result = JsonMapper.ToObject<FP_CheckIDAuthentication>(_result); |
| | | onFreePlatfromCheckIDOK(result); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | |
| | | } |
| | | } |
| | | |
| | | private void HandleFreePlatformLoginOk(JsonData data) |
| | | { |
| | | FP_LoginOk _loginOK = new FP_LoginOk |
| | | { |
| | | token = data["token"].ToString(), |
| | | tokenExpire = data["token_expire"].ToString(), |
| | | account = data["account"].ToString(), |
| | | accountID = int.Parse(data["account_id"].ToString()), |
| | | phone = 0 |
| | | }; |
| | | |
| | | Account = _loginOK.account; |
| | | |
| | | if (onFreePlatformLoginOk != null) |
| | | { |
| | | onFreePlatformLoginOk(_loginOK); |
| | | } |
| | | |
| | | // string _cachePath = Application.persistentDataPath + "/record_sdk_login_content.txt"; |
| | | // |
| | | // if (!File.Exists(_cachePath)) |
| | | // { |
| | | // File.Create(_cachePath); |
| | | // } |
| | | // |
| | | // string _content = string.Format("[{0}] sdk登陆完成, 获得信息 (token=\"{1}\", tokenExpire=\"{2}\", account=\"{3}\", accountID=\"{4}\", phone=\"{5}\")", |
| | | // System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"), |
| | | // _loginOK.token, |
| | | // _loginOK.tokenExpire, |
| | | // _loginOK.account, |
| | | // _loginOK.accountID, |
| | | // _loginOK.phone); |
| | | // |
| | | // FileStream _fs = new FileStream(_cachePath, FileMode.Append); |
| | | // StreamWriter _sw = new StreamWriter(_fs); |
| | | // _sw.WriteLine(_content); |
| | | // _sw.Close(); |
| | | // _fs.Close(); |
| | | } |
| | | |
| | | public void OnServerChargeOk(string orderID, uint coin) |
| | | { |
| | | OperationLogCollect.Instance.RecordEvent(9, coin); |
| | | SendTouTiaoADEvent(2); |
| | | #if (UNITY_IOS || UNITY_ANDROID) && !UNITY_EDITOR |
| | | |
| | | Dictionary<string, string> dict = new Dictionary<string, string>(); |
| | | dict.Add("token", AD_Token); |
| | | dict.Add("amount", coin.ToString()); |
| | | HttpRequest.Instance.RequestHttpPost("http://tako.lingleigame.com/api/pay?", |
| | | dict, |
| | | "application/x-www-form-urlencoded", |
| | | 1, (result, msg) => |
| | | { |
| | | Debug.LogFormat("广告充值埋点回调结果: {0}, 信息: {1}", result, msg); |
| | | }); |
| | | #endif |
| | | if (onFreePlatformPayOk != null) |
| | | { |
| | | onFreePlatformPayOk(); |
| | | } |
| | | |
| | | AndroidJavaClass _jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); |
| | | AndroidJavaObject _jo = _jc.GetStatic<AndroidJavaObject>("currentActivity"); |
| | | _jo.Call("PayFinished", orderID, "_default_", "CNY", (float)coin / 100); |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region 热云SDK相关 |
| | | |
| | | private string m_Order; |
| | | private float m_Money; |
| | | |
| | | public void TrackRegister(string account) |
| | | { |
| | | AndroidJavaClass _jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); |
| | | AndroidJavaObject _jo = _jc.GetStatic<AndroidJavaObject>("currentActivity"); |
| | | _jo.Call("TrackRegister", account); |
| | | } |
| | | |
| | | public void TrackLogin(string account) |
| | | { |
| | | AndroidJavaClass _jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); |
| | | AndroidJavaObject _jo = _jc.GetStatic<AndroidJavaObject>("currentActivity"); |
| | | _jo.Call("TrackLogin", account); |
| | | } |
| | | |
| | | public void TrackPaymentStart(string transactionId, string paymentType, string currencyType, float currencyAmount) |
| | | { |
| | | AndroidJavaClass _jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); |
| | | AndroidJavaObject _jo = _jc.GetStatic<AndroidJavaObject>("currentActivity"); |
| | | _jo.Call("TrackPaymentStart", transactionId, paymentType, currencyType, currencyAmount); |
| | | } |
| | | |
| | | public void TrackPaymentFinish(string transactionId, string paymentType, string currencyType, float currencyAmount) |
| | | { |
| | | AndroidJavaClass _jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); |
| | | AndroidJavaObject _jo = _jc.GetStatic<AndroidJavaObject>("currentActivity"); |
| | | _jo.Call("TrackPaymentFinish", transactionId, paymentType, currencyType, currencyAmount); |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region 极光推送相关 |
| | | public void GeTui_SendLocalMessage(JsonData jsonData) |
| | | { |
| | | // ------ 举例 ------ |
| | | // JsonData _params = new JsonData (); |
| | | // _params ["code"] = 2005; |
| | | // _params ["id"] = 5;// id 重要, 标示每个通知的更新或者移除 |
| | | // _params ["title"] = "the title";// 推送标题 |
| | | // _params ["subtitle"] = "the subtitle";// 副标题 |
| | | // _params ["content"] = "the content";// 具体内容 |
| | | // _params ["badge"] = -1;// 角标 |
| | | // |
| | | // // 以下为决定应该多久后弹出此通知 |
| | | // System.TimeSpan ts = System.DateTime.UtcNow - new System.DateTime (1970, 1, 1, 0, 0, 0, 0); |
| | | // long ret = System.Convert.ToInt64 (ts.TotalSeconds) + 3;// 表示3秒后 |
| | | // _params ["fireTime"] = ret; |
| | | |
| | | #if UNITY_IOS && !UNITY_EDITOR |
| | | IOSMessageHandle(jsonData.ToJson()); |
| | | #elif UNITY_ANDROID && !UNITY_EDITOR |
| | | |
| | | jsonData["fireTime"] = (long)jsonData["fireTime"] * 1000; |
| | | |
| | | AndroidJavaClass _jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); |
| | | AndroidJavaObject _jo = _jc.GetStatic<AndroidJavaObject>("currentActivity"); |
| | | _jo.Call("addLocalNotification", jsonData.ToJson()); |
| | | #endif |
| | | } |
| | | |
| | | public void GeTui_RemoveLocalMessage(string id) |
| | | { |
| | | JsonData _params = new JsonData(); |
| | | _params["code"] = 2006; |
| | | _params["id"] = id;// id 重要, 标示每个通知的更新或者移除 |
| | | |
| | | #if UNITY_IOS && !UNITY_EDITOR |
| | | IOSMessageHandle(_params.ToJson()); |
| | | #elif UNITY_ANDROID && !UNITY_EDITOR |
| | | AndroidJavaClass _jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); |
| | | AndroidJavaObject _jo = _jc.GetStatic<AndroidJavaObject>("currentActivity"); |
| | | _jo.Call("removeNotification", id); |
| | | #endif |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | public void SendTouTiaoADEvent(int eventType) |
| | | { |
| | | #if !UNITY_EDITOR |
| | | string _url = "http://center.secondworld.net.cn:53004/ad/eventtype/" + VersionConfig.Get().clientPackageFlag + "?"; |
| | | |
| | | var tables = new Dictionary<string, string>(); |
| | | tables["MAC1"] = AND_MacAddress; |
| | | tables["UA"] = WWW.EscapeURL(AND_UserAgent); |
| | | tables["ANDROIDID1"] = AND_AndroidID; |
| | | tables["IP"] = AND_IP; |
| | | tables["IMEI"] = AND_IMEI; |
| | | tables["event_type"] = eventType.ToString(); |
| | | |
| | | string _content = StringUtility.Contact(_url, HttpRequest.HashtablaToString(tables)); |
| | | |
| | | Debug.Log("TouTiaoAD: " + _content); |
| | | |
| | | HttpRequest.Instance.RequestHttpGet(_content, HttpRequest.defaultHttpContentType, 1, (result, message) => |
| | | { |
| | | if (!result) |
| | | { |
| | | Debug.Log(message); |
| | | } |
| | | }); |
| | | #endif |
| | | } |
| | | |
| | | //public void WriteDebug(string content) |
| | | //{ |
| | | // string _url = Application.persistentDataPath + "/debug_log.txt"; |
| | | // System.IO.FileInfo _fileInfo = new System.IO.FileInfo(_url); |
| | | // System.IO.StreamWriter _sw = null; |
| | | // if (_fileInfo.Exists) |
| | | // { |
| | | // _sw = _fileInfo.AppendText(); |
| | | // } |
| | | // else |
| | | // { |
| | | // _sw = _fileInfo.CreateText(); |
| | | // } |
| | | // _sw.WriteLine(content); |
| | | // _sw.Close(); |
| | | // _sw.Dispose(); |
| | | //} |
| | | } |
| | | using UnityEngine;
|
| | | using LitJson;
|
| | | using UnityEngine.Events;
|
| | | using System.Collections;
|
| | | using System.Collections.Generic;
|
| | |
|
| | | public class SDKUtility : SingletonMonobehaviour<SDKUtility>
|
| | | {
|
| | | [System.Runtime.InteropServices.DllImport("__Internal")]
|
| | | private static extern void IOSMessageHandle(string json);
|
| | |
|
| | | public enum E_ChargingType
|
| | | {
|
| | | NoCharging = 1,
|
| | | Charging = 2,
|
| | | ChargingFull = 3,
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// sdk初始化是否完成标识
|
| | | /// 客户端一般需要等待这个值为true才继续逻辑
|
| | | /// </summary>
|
| | | public bool InitFinished { get; private set; }
|
| | |
|
| | | #region 基础定义与回调
|
| | |
|
| | | /// <summary>
|
| | | /// 当前设备电量值
|
| | | /// </summary>
|
| | | public int BatteryLevel { get; private set; }
|
| | | /// <summary>
|
| | | /// 设备电量值改变回调
|
| | | /// </summary>
|
| | | public UnityAction<int> OnBatteryLevelChanged;
|
| | |
|
| | | /// <summary>
|
| | | /// 当前充电状态
|
| | | /// </summary>
|
| | | public E_ChargingType ChargingType { get; private set; }
|
| | | /// <summary>
|
| | | /// 当前充电状态改变回调
|
| | | /// </summary>
|
| | | public UnityAction<E_ChargingType> OnChargingTypeChanged;
|
| | |
|
| | | /// <summary>
|
| | | /// 设备信息
|
| | | /// </summary>
|
| | | public DeviceInfo Device { get; private set; }
|
| | | /// <summary>
|
| | | /// 设备信息改变回调
|
| | | /// </summary>
|
| | | public UnityAction<DeviceInfo> OnDeviceInfoChanged;
|
| | |
|
| | | /// <summary>
|
| | | /// 当前网络状态
|
| | | /// </summary>
|
| | | public NetworkReachability NetworkType { get; private set; }
|
| | | /// <summary>
|
| | | /// 当前网络状态改变回调
|
| | | /// </summary>
|
| | | public UnityAction<NetworkReachability> OnNetworkStatusChanged;
|
| | |
|
| | | /// <summary>
|
| | | /// 是否已经将StreamingAsset拷贝至目标路径
|
| | | /// </summary>
|
| | | public bool AssetCopyFinished { get; private set; }
|
| | |
|
| | | /// <summary>
|
| | | /// 安卓设备根目录
|
| | | /// </summary>
|
| | | public string DeviceRootPath { get; private set; }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region 极光推送
|
| | | public string RegistrationID { get; private set; }
|
| | | #endregion
|
| | |
|
| | | #region 自由sdk
|
| | | public FP_LoginOk FreePlatformInfo { get; private set; }
|
| | | #endregion
|
| | |
|
| | | private JsonData m_Json = new JsonData();
|
| | |
|
| | | public void Init()
|
| | | {
|
| | | RegistrationID = string.Empty;
|
| | | AssetCopyFinished = false;
|
| | | #if !UNITY_EDITOR
|
| | | if (InitFinished)
|
| | | {
|
| | | return;
|
| | | }
|
| | |
|
| | | #if UNITY_IOS
|
| | |
|
| | | var assetsCopyFinishVersion = LocalSave.GetString("AssetCopyCompleted_IOS");
|
| | | if (string.IsNullOrEmpty(assetsCopyFinishVersion))
|
| | | {
|
| | | AssetCopyFinished = false;
|
| | | }
|
| | | else
|
| | | {
|
| | | AssetCopyFinished = VersionConfig.Get().version == assetsCopyFinishVersion;
|
| | | }
|
| | |
|
| | | #elif UNITY_ANDROID
|
| | |
|
| | | SyncClientPackageID();
|
| | |
|
| | | #endif
|
| | |
|
| | | InitFinished = false;
|
| | | m_Json.Clear();
|
| | | m_Json["code"] = CodeU2A.Init;
|
| | | SendMessageToSDK(m_Json);
|
| | | #endif
|
| | | }
|
| | |
|
| | | private void OnApplicationFocus(bool focus)
|
| | | {
|
| | | #if !UNITY_EDITOR
|
| | | m_Json.Clear();
|
| | | if (focus)
|
| | | {
|
| | | m_Json["code"] = CodeU2A.BatteryListenStart;
|
| | | StopCoroutine("ProcessNetworkStatus");
|
| | | StartCoroutine("ProcessNetworkStatus");
|
| | | }
|
| | | else
|
| | | {
|
| | | m_Json["code"] = CodeU2A.BatteryListenStop;
|
| | | StopCoroutine("ProcessNetworkStatus");
|
| | | }
|
| | | SendMessageToSDK(m_Json);
|
| | | #endif
|
| | | }
|
| | |
|
| | | private IEnumerator ProcessNetworkStatus()
|
| | | {
|
| | | while (true)
|
| | | {
|
| | | if (Application.internetReachability != NetworkType)
|
| | | {
|
| | | NetworkType = Application.internetReachability;
|
| | |
|
| | | if (OnNetworkStatusChanged != null)
|
| | | {
|
| | | OnNetworkStatusChanged(NetworkType);
|
| | | }
|
| | | }
|
| | | yield return WaitingForSecondConst.WaitMS1000;
|
| | | }
|
| | | }
|
| | |
|
| | | #region 业务层定义相关逻辑
|
| | |
|
| | | public void InstallAPK(string path)
|
| | | {
|
| | | m_Json.Clear();
|
| | | m_Json["code"] = CodeU2A.InstallAPK;
|
| | | m_Json["path"] = path;
|
| | | SendMessageToSDK(m_Json);
|
| | | }
|
| | |
|
| | | public void CopyAsset()
|
| | | {
|
| | | if (AssetCopyFinished)
|
| | | {
|
| | | return;
|
| | | }
|
| | | m_Json.Clear();
|
| | | m_Json["code"] = CodeU2A.AssetCopy;
|
| | | SendMessageToSDK(m_Json);
|
| | | }
|
| | |
|
| | | public void CopyContent(string content)
|
| | | {
|
| | | m_Json.Clear();
|
| | | m_Json["code"] = CodeU2A.CopyContent;
|
| | | m_Json["content"] = content;
|
| | | SendMessageToSDK(m_Json);
|
| | | }
|
| | |
|
| | | public void RestartApp()
|
| | | {
|
| | | m_Json.Clear();
|
| | | m_Json["code"] = CodeU2A.RestartApp;
|
| | | SendMessageToSDK(m_Json);
|
| | | }
|
| | |
|
| | | public void OpenUrl(string url)
|
| | | {
|
| | | m_Json.Clear();
|
| | | m_Json["code"] = CodeU2A.OpenWebView;
|
| | | m_Json["url"] = url;
|
| | | SendMessageToSDK(m_Json);
|
| | | }
|
| | |
|
| | | public void MakeKeyAndVisible()
|
| | | {
|
| | | #if !UNITY_EDITOR
|
| | | m_Json.Clear();
|
| | | m_Json["code"] = CodeU2A.MakeKeyAndVisible;
|
| | | SendMessageToSDK(m_Json);
|
| | | #endif
|
| | | }
|
| | |
|
| | | public void SyncClientPackageID()
|
| | | {
|
| | | #if !UNITY_EDITOR
|
| | | #if UNITY_ANDROID
|
| | | m_Json.Clear();
|
| | | m_Json["code"] = CodeU2A.ClientPackage;
|
| | | m_Json["clientPkgID"] = VersionConfig.Get().clientPackageFlag;
|
| | | SendMessageToSDK(m_Json);
|
| | | #endif
|
| | | #endif
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region 处理与SDK交互的底层方法
|
| | |
|
| | | public static AndroidJavaObject GetApplicationContext()
|
| | | {
|
| | | using (AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
|
| | | {
|
| | | using (AndroidJavaObject jo = jc.GetStatic<AndroidJavaObject>("currentActivity"))
|
| | | {
|
| | | return jo.Call<AndroidJavaObject>("getApplicationContext");
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | private void SendMessageToSDK(JsonData json)
|
| | | {
|
| | | #if !UNITY_EDITOR
|
| | | #if UNITY_ANDROID
|
| | | using (AndroidJavaClass H2engineSDK = new AndroidJavaClass("com.secondworld.univeralsdk.H2EngineSDK"))
|
| | | {
|
| | | H2engineSDK.CallStatic("HandleUnityMessage", json.ToJson());
|
| | | }
|
| | | #elif UNITY_IOS
|
| | | IOSMessageHandle(json.ToJson());
|
| | | #endif
|
| | | #endif
|
| | | }
|
| | |
|
| | | public void HandleSdkMessage(string jsonString)
|
| | | {
|
| | | Debug.Log("收到SDK发来的信息: " + jsonString);
|
| | | var _json = JsonMapper.ToObject(jsonString);
|
| | | var _code = (int)_json["code"];
|
| | | switch (_code)
|
| | | {
|
| | | case CodeA2U.DeviceInfo:
|
| | |
|
| | | Device = new DeviceInfo ();
|
| | | Device.uniqueID = _json ["unique_id"].ToString ();
|
| | | Device.androidID = _json ["android_id"].ToString ();// ios平台下为idfa
|
| | | Device.userAgent = _json ["userAgent"].ToString ();
|
| | | #if UNITY_ANDROID
|
| | | Device.macAddress = _json ["mac"].ToString ();
|
| | | Device.imei = _json ["imei"].ToString ();
|
| | | Device.totalMemory = (int)_json ["memoryTotal"];
|
| | | #endif
|
| | | if (OnDeviceInfoChanged != null)
|
| | | {
|
| | | OnDeviceInfoChanged(Device);
|
| | | }
|
| | |
|
| | | break;
|
| | | case CodeA2U.AssetCopyFinished:
|
| | | AssetCopyFinished = true;
|
| | | break;
|
| | | case CodeA2U.BatteryLevel:
|
| | |
|
| | | BatteryLevel = (int)_json["level"];
|
| | | if (OnBatteryLevelChanged != null)
|
| | | {
|
| | | OnBatteryLevelChanged(BatteryLevel);
|
| | | }
|
| | |
|
| | | break;
|
| | | case CodeA2U.BatteryCharging:
|
| | |
|
| | | ChargingType = (E_ChargingType)((int)_json["status"]);
|
| | | if (OnChargingTypeChanged != null)
|
| | | {
|
| | | OnChargingTypeChanged(ChargingType);
|
| | | }
|
| | |
|
| | | break;
|
| | | case CodeA2U.SdkInitComplete:
|
| | | InitFinished = true;
|
| | | break;
|
| | | case CodeA2U.PushClientID:
|
| | | RegistrationID = _json["clientID"].ToString();
|
| | | break;
|
| | | case CodeA2U.ExternalStorage:
|
| | | DeviceRootPath = _json["path"].ToString();
|
| | | break;
|
| | |
|
| | | case CodeA2U.FreePlatformInitOk:
|
| | |
|
| | | if (onFreePlatformInitOk != null)
|
| | | {
|
| | | onFreePlatformInitOk();
|
| | | }
|
| | |
|
| | | break;
|
| | | case CodeA2U.FreePlatformInitFail:
|
| | | if (onFreePlatformInitFail != null)
|
| | | {
|
| | | onFreePlatformInitFail();
|
| | | }
|
| | | break;
|
| | | case CodeA2U.FreePlatformRegisterOk:
|
| | | HandleFreePlatformRegisteOk(_json);
|
| | | break;
|
| | | case CodeA2U.FreePlatformLoginOk:
|
| | | HandleFreePlatformLoginOk(_json["info"]);
|
| | | break;
|
| | | case CodeA2U.FreePlatformLoginFail:
|
| | | if (onFreePlatformLoginFail != null)
|
| | | {
|
| | | onFreePlatformLoginFail();
|
| | | }
|
| | | break;
|
| | | case CodeA2U.FreePlatformLogoutOk:
|
| | | if (onFreePlatformLogoutOk != null)
|
| | | {
|
| | | onFreePlatformLogoutOk();
|
| | | }
|
| | | break;
|
| | | case CodeA2U.FreePlatformLogoutFail:
|
| | | if (onFreePlatformLogoutFail != null)
|
| | | {
|
| | | onFreePlatformLogoutFail();
|
| | | }
|
| | | break;
|
| | | case CodeA2U.FreePlatformPayOk:
|
| | | if (onFreePlatformPayOk != null)
|
| | | {
|
| | | onFreePlatformPayOk();
|
| | | }
|
| | | break;
|
| | | case CodeA2U.FreePlatformPayFail:
|
| | | if (onFreePlatformPayFail != null)
|
| | | {
|
| | | onFreePlatformPayFail();
|
| | | }
|
| | | break;
|
| | | case CodeA2U.FreePlatformPayCancel:
|
| | | if (onFreePlatformPayCancel != null)
|
| | | {
|
| | | onFreePlatformPayCancel();
|
| | | }
|
| | | break;
|
| | | }
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | #region 交互相关约定编号
|
| | |
|
| | | private static class CodeA2U
|
| | | {
|
| | | #region 自由sdk_code
|
| | | public const int FreePlatformInitOk = 10;
|
| | | public const int FreePlatformInitFail = 11;
|
| | | public const int FreePlatformLoginOk = 12;
|
| | | public const int FreePlatformLoginFail = 13;
|
| | | public const int FreePlatformLoginCancel = 14;
|
| | | public const int FreePlatformLogoutOk = 15;
|
| | | public const int FreePlatformLogoutFail = 16;
|
| | | public const int FreePlatformSwitchAccountOk = 17;
|
| | | public const int FreePlatformPayOk = 18;
|
| | | public const int FreePlatformPayFail = 19;
|
| | | public const int FreePlatformPayCancel = 20;
|
| | | public const int FreePlatformRegisterOk = 21;
|
| | | #endregion
|
| | |
|
| | | #region 基础sdk_code
|
| | | /**
|
| | | * 资源拷贝完成
|
| | | */
|
| | | public const int AssetCopyFinished = 0;
|
| | | /**
|
| | | * 电量改变
|
| | | */
|
| | | public const int BatteryLevel = 1;
|
| | | /**
|
| | | * 充电状态改变
|
| | | */
|
| | | public const int BatteryCharging = 2;
|
| | | /**
|
| | | * 回调sdk逻辑完毕
|
| | | * */
|
| | | public const int SdkInitComplete = 90;
|
| | | /**
|
| | | * 回调android设备信息
|
| | | * */
|
| | | public const int DeviceInfo = 3;
|
| | | /**
|
| | | * 回调推送的独立id
|
| | | * */
|
| | | public const int PushClientID = 4;
|
| | | /**
|
| | | * 回调外部存储根目录地址
|
| | | */
|
| | | public const int ExternalStorage = 5;
|
| | | #endregion
|
| | | }
|
| | |
|
| | | private static class CodeU2A
|
| | | {
|
| | | /**
|
| | | * 执行资源拷贝
|
| | | */
|
| | | public const int AssetCopy = 0;
|
| | | /**
|
| | | * 执行开始电量改变,充电状态改变监听
|
| | | */
|
| | | public const int BatteryListenStart = 1;
|
| | | /**
|
| | | * 执行停止电量改变,充电状态改变监听
|
| | | */
|
| | | public const int BatteryListenStop = 2;
|
| | | /**
|
| | | * 获取唯一识别码
|
| | | */
|
| | | public const int UniqueID = 3;
|
| | | /**
|
| | | * 申请在AndroidManifest文件中
|
| | | */
|
| | | public const int RequestManifestPermissions = 4;
|
| | | /**
|
| | | * 单独动态申请某一个权限
|
| | | */
|
| | | public const int RequestPermission = 5;
|
| | | /**
|
| | | * 重启应用
|
| | | */
|
| | | public const int RestartApp = 6;
|
| | | /**
|
| | | * 拷贝文本信息
|
| | | */
|
| | | public const int CopyContent = 7;
|
| | | /**
|
| | | * 打开网址
|
| | | */
|
| | | public const int OpenWebView = 8;
|
| | | /**
|
| | | * SDK初始化, 完全自动初始化的流程, 完成必要逻辑后再回调回去
|
| | | */
|
| | | public const int Init = 9;
|
| | | /**
|
| | | * 安装应用
|
| | | */
|
| | | public const int InstallAPK = 10;
|
| | | /**
|
| | | * 外部存储根目录地址
|
| | | */
|
| | | public const int ExteneralStorage = 11;
|
| | | /**
|
| | | * 自由sdk相关
|
| | | * */
|
| | | public const int FreePlatformInit = 100;
|
| | | public const int FreePlatformLogin = 101;
|
| | | public const int FreePlatformLogout = 102;
|
| | | public const int FreePlatformSwitchAccount = 103;
|
| | | public const int FreePlatformPay = 104;
|
| | | public const int PayFinished = 105;
|
| | | /**
|
| | | * 极光推送
|
| | | * */
|
| | | public const int JPushAddLocalMessage = 200;
|
| | | public const int JPushRemoveLocalMessage = 201;
|
| | | /**
|
| | | * IOS特殊需求
|
| | | */
|
| | | public const int MakeKeyAndVisible = 300;
|
| | | /**
|
| | | * ClientPackage向sdk发送分包id
|
| | | */
|
| | | public const int ClientPackage = 400;
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
|
| | | public class DeviceInfo
|
| | | {
|
| | | public string imei;
|
| | | public string macAddress;
|
| | | public string androidID;
|
| | | public string uniqueID;
|
| | | public string userAgent;
|
| | | public int totalMemory;
|
| | | }
|
| | |
|
| | | #region 自由sdk相关
|
| | |
|
| | | public UnityAction onFreePlatformInitOk;
|
| | | public UnityAction onFreePlatformInitFail;
|
| | | public UnityAction<FP_LoginOk> onFreePlatformLoginOk;
|
| | | public UnityAction onFreePlatformLoginFail;
|
| | | public UnityAction onFreePlatformLogoutOk;
|
| | | public UnityAction onFreePlatformLogoutFail;
|
| | | public UnityAction onFreePlatformPayOk;
|
| | | public UnityAction onFreePlatformPayFail;
|
| | | public UnityAction onFreePlatformPayCancel;
|
| | | public UnityAction onFreePlatformBindOk;
|
| | | public UnityAction onFreePlatformBindFail;
|
| | |
|
| | | public class FP_LoginOk
|
| | | {
|
| | | public string account;
|
| | | public string token;
|
| | | public string tokenExpire;
|
| | | public int phone;
|
| | | public int accountID;
|
| | | }
|
| | |
|
| | | public struct FP_CheckIDAuthentication
|
| | | {
|
| | | public string errorcode;
|
| | | public string errordesc;
|
| | | public string type;
|
| | | public string card_id;
|
| | | }
|
| | |
|
| | | public struct FP_DoIDAuthentication
|
| | | {
|
| | | public string errorcode;
|
| | | public string errordesc;
|
| | | public string card_id;
|
| | | }
|
| | |
|
| | | string authenticationCardId = "";
|
| | | public string channelId = "1000";
|
| | | public string platfromId = "1000";
|
| | | public UnityAction<FP_CheckIDAuthentication> onFreePlatfromCheckIDOK;
|
| | | public UnityAction<FP_DoIDAuthentication> onFreePlatfromDoIDAuthenticationOk;
|
| | |
|
| | |
|
| | | public void FreePlatformInit()
|
| | | {
|
| | | #if !UNITY_EDITOR
|
| | | m_Json.Clear();
|
| | | m_Json["code"] = CodeU2A.FreePlatformInit;
|
| | | SendMessageToSDK(m_Json);
|
| | | #endif
|
| | | }
|
| | |
|
| | | public void FreePlatformBindPhone()
|
| | | {
|
| | | #if UNITY_ANDROID
|
| | | AndroidJavaClass _jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
|
| | | AndroidJavaObject _jo = _jc.GetStatic<AndroidJavaObject>("currentActivity");
|
| | | _jo.Call("BindPhone");
|
| | | #endif
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 自由SDK登陆
|
| | | /// </summary>
|
| | | public void FreePlatformLogin()
|
| | | {
|
| | | #if !UNITY_EDITOR
|
| | | m_Json.Clear();
|
| | | m_Json["code"] = CodeU2A.FreePlatformLogin;
|
| | | SendMessageToSDK(m_Json);
|
| | | #endif
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 自由SDK登出
|
| | | /// </summary>
|
| | | public void FreePlatformLoginout()
|
| | | {
|
| | | #if !UNITY_EDITOR
|
| | | m_Json.Clear();
|
| | | m_Json["code"] = CodeU2A.FreePlatformLogout;
|
| | | SendMessageToSDK(m_Json);
|
| | | #endif
|
| | | }
|
| | |
|
| | | public void FreePlatformSwitchAccount()
|
| | | {
|
| | | #if UNITY_ANDROID
|
| | | AndroidJavaClass _jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
|
| | | AndroidJavaObject _jo = _jc.GetStatic<AndroidJavaObject>("currentActivity");
|
| | | _jo.Call("SwitchAccount");
|
| | | #endif
|
| | | }
|
| | |
|
| | | private Dictionary<string, string> m_PaymentTable = new Dictionary<string, string>();
|
| | | private string m_EncodeKey = "03sujm7gerywdvyd5vkkk772rs4by230";
|
| | |
|
| | | /// <summary>
|
| | | /// 自由SDK支付 fixed sdk 支付逻辑修改
|
| | | /// </summary>
|
| | | public void FreePlatformPay(string title, float money, string cpInfo)
|
| | | {
|
| | | m_PaymentTable["ProductID"] = "snxxz";
|
| | | m_PaymentTable["OperatorID"] = VersionConfig.Get().appId;
|
| | | m_PaymentTable["RegionName"] = "s" + ServerListCenter.Instance.currentServer.region_flag;
|
| | | m_PaymentTable["TimeStamp"] = ((long)(System.DateTime.Now - System.TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1))).TotalSeconds).ToString();
|
| | | m_PaymentTable["Time"] = System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
| | | m_PaymentTable["EventID"] = "12001";
|
| | | m_PaymentTable["IP"] = DeviceUtility.GetIp();
|
| | | m_PaymentTable["AccountID"] = FreePlatformInfo.account;
|
| | | m_PaymentTable["SessionID"] = "11";
|
| | | m_PaymentTable["Level"] = PlayerDatas.Instance.baseData.LV.ToString();
|
| | | m_PaymentTable["VIPLevel"] = PlayerDatas.Instance.baseData.VIPLv.ToString();
|
| | | m_PaymentTable["CurrencyAmount"] = money.ToString();
|
| | | m_PaymentTable["OrderTitle"] = title;
|
| | | m_PaymentTable["OrderInfo"] = cpInfo;
|
| | | m_PaymentTable["AppID"] = VersionConfig.Get().appId;
|
| | |
|
| | | var _stringBuilder = new System.Text.StringBuilder();
|
| | | var _md5Body = _stringBuilder.Append(m_PaymentTable["AppID"]).
|
| | | Append(m_PaymentTable["AccountID"]).
|
| | | Append(m_PaymentTable["TimeStamp"]).
|
| | | Append(m_PaymentTable["CurrencyAmount"]).
|
| | | Append(m_EncodeKey);
|
| | |
|
| | | var _md5Encode = System.Security.Cryptography.MD5.Create();
|
| | | var _encodeResult = _md5Encode.ComputeHash(System.Text.Encoding.UTF8.GetBytes(_md5Body.ToString()));
|
| | |
|
| | | _stringBuilder.Remove(0, _stringBuilder.Length);
|
| | | for (int i = 0; i < _encodeResult.Length; ++i)
|
| | | {
|
| | | _stringBuilder.Append(_encodeResult[i].ToString("x2"));
|
| | | }
|
| | |
|
| | | m_PaymentTable["Sign"] = _stringBuilder.ToString();
|
| | | m_PaymentTable["RoleID"] = PlayerDatas.Instance.baseData.PlayerName;
|
| | |
|
| | | _stringBuilder.Remove(0, _stringBuilder.Length);
|
| | |
|
| | | HttpRequest.Instance.RequestHttpGet(_stringBuilder.Append("http://recharge.game.173on.com:11000/api?").
|
| | | Append(HttpRequest.HashtablaToString(m_PaymentTable)).ToString(),
|
| | | HttpRequest.defaultHttpContentType, 1, (bool result, string message) =>
|
| | | {
|
| | | if (result)
|
| | | {
|
| | | JsonData _json = JsonMapper.ToObject(message);
|
| | |
|
| | | int _callbackResult = (int)_json["result"];
|
| | |
|
| | | if (_callbackResult == 1)
|
| | | {
|
| | | #if !UNITY_EDITOR
|
| | | m_Json.Clear();
|
| | | m_Json["code"] = CodeU2A.FreePlatformPay;
|
| | | m_Json["orderId"] = _json["orderid"].ToString();
|
| | | m_Json["mount"] = money;
|
| | | m_Json["cpInfo"] = cpInfo;
|
| | | m_Json["title"] = title;
|
| | | #if UNITY_IOS
|
| | | m_Json["identifier"] = VersionConfig.Get().bundleIdentifier;
|
| | | #endif
|
| | | SendMessageToSDK(m_Json);
|
| | | #endif
|
| | | }
|
| | | else
|
| | | {
|
| | | Debug.Log(_json["msg"].ToString());
|
| | | if (onFreePlatformPayFail != null)
|
| | | {
|
| | | onFreePlatformPayFail();
|
| | | }
|
| | | }
|
| | | }
|
| | | else
|
| | | {
|
| | | if (onFreePlatformPayFail != null)
|
| | | {
|
| | | onFreePlatformPayFail();
|
| | | }
|
| | | }
|
| | | });
|
| | | }
|
| | |
|
| | | public void FreePlatformDoIDAuthentication(string _account, string _userName, string _idNumber)
|
| | | {
|
| | | authenticationCardId = _idNumber;
|
| | |
|
| | | var tables = new Dictionary<string, string>();
|
| | | tables["app_id"] = VersionConfig.Get().appId;
|
| | | tables["account"] = _account;
|
| | | tables["card_id"] = _idNumber;
|
| | | tables["mac"] = DeviceUtility.GetMac();
|
| | | tables["rolename"] = _userName;
|
| | | tables["channelid"] = channelId;
|
| | |
|
| | | var url = "http://zysdk.xileyougame.com/api.php/Service/anti_mystery?";
|
| | | HttpRequest.Instance.RequestHttpGet(StringUtility.Contact(url, HttpRequest.HashtablaToString(tables)), HttpRequest.defaultHttpContentType, 1, HandleIDAuthenticationResult);
|
| | | }
|
| | |
|
| | | public void FreePlatformCheckIDAuthentication(string _account)
|
| | | {
|
| | | var url = "http://zysdk.xileyougame.com/api.php/Service/check_mystery?";
|
| | | var tables = new Dictionary<string, string>();
|
| | | tables["app_id"] = VersionConfig.Get().appId;
|
| | | tables["channelid"] = channelId;
|
| | | tables["account"] = _account;
|
| | | tables["platfrom_id"] = platfromId;
|
| | |
|
| | | HttpRequest.Instance.RequestHttpGet(StringUtility.Contact(url, HttpRequest.HashtablaToString(tables)), HttpRequest.defaultHttpContentType, 1, HandleCheckIDAuthenticationResult);
|
| | | }
|
| | |
|
| | | private void HandleIDAuthenticationResult(bool _ok, string _result)
|
| | | {
|
| | | if (_ok)
|
| | | {
|
| | | if (onFreePlatfromDoIDAuthenticationOk != null)
|
| | | {
|
| | | var result = JsonMapper.ToObject<FP_DoIDAuthentication>(_result);
|
| | | result.card_id = authenticationCardId;
|
| | | onFreePlatfromDoIDAuthenticationOk(result);
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | private void HandleCheckIDAuthenticationResult(bool _ok, string _result)
|
| | | {
|
| | | if (_ok)
|
| | | {
|
| | | if (onFreePlatfromCheckIDOK != null)
|
| | | {
|
| | | var result = JsonMapper.ToObject<FP_CheckIDAuthentication>(_result);
|
| | | onFreePlatfromCheckIDOK(result);
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | | private void BuildFreePlatformInfo(JsonData json)
|
| | | {
|
| | | if (FreePlatformInfo == null)
|
| | | {
|
| | | FreePlatformInfo = new FP_LoginOk();
|
| | | }
|
| | |
|
| | | IDictionary _iDict = json as IDictionary;
|
| | |
|
| | | if (_iDict.Contains("token"))
|
| | | {
|
| | | FreePlatformInfo.token = json["token"].ToString();
|
| | | }
|
| | | if (_iDict.Contains("token_expire"))
|
| | | {
|
| | | FreePlatformInfo.tokenExpire = json["token_expire"].ToString();
|
| | | }
|
| | | if (_iDict.Contains("account"))
|
| | | {
|
| | | FreePlatformInfo.account = json["account"].ToString();
|
| | | }
|
| | | if (_iDict.Contains("account_id"))
|
| | | {
|
| | | int.TryParse(json["account_id"].ToString(), out FreePlatformInfo.accountID);
|
| | | }
|
| | |
|
| | | FreePlatformInfo.phone = 0;
|
| | | }
|
| | |
|
| | | private void HandleFreePlatformRegisteOk(JsonData json)
|
| | | {
|
| | | BuildFreePlatformInfo(json);
|
| | | }
|
| | |
|
| | | private void HandleFreePlatformLoginOk(JsonData data)
|
| | | {
|
| | | BuildFreePlatformInfo(data);
|
| | |
|
| | | if (onFreePlatformLoginOk != null)
|
| | | {
|
| | | onFreePlatformLoginOk(FreePlatformInfo);
|
| | | }
|
| | | }
|
| | |
|
| | | public void OnServerChargeOk(string orderID, uint coin)
|
| | | {
|
| | | OperationLogCollect.Instance.RecordEvent(9, coin);
|
| | |
|
| | | if (onFreePlatformPayOk != null)
|
| | | {
|
| | | onFreePlatformPayOk();
|
| | | }
|
| | |
|
| | | m_Json.Clear();
|
| | | m_Json["code"] = CodeU2A.PayFinished;
|
| | | m_Json["orderID"] = orderID;
|
| | | m_Json["payType"] = "_default_";
|
| | | m_Json["moneyType"] = "CNY";
|
| | | m_Json["money"] = (float)coin / 100;
|
| | | SendMessageToSDK(m_Json);
|
| | | }
|
| | | #endregion
|
| | |
|
| | | #region 极光推送相关
|
| | | public void GeTui_SendLocalMessage(JsonData jsonData)
|
| | | {
|
| | | DebugEx.Log("GeTui_SendLocalMessage:" + jsonData["id"]);
|
| | | // ------ 举例 ------
|
| | | // JsonData _params = new JsonData ();
|
| | | // _params ["code"] = 2005;
|
| | | // _params ["id"] = 5;// id 重要, 标示每个通知的更新或者移除
|
| | | // _params ["title"] = "the title";// 推送标题
|
| | | // _params ["subtitle"] = "the subtitle";// 副标题
|
| | | // _params ["content"] = "the content";// 具体内容
|
| | | // _params ["badge"] = -1;// 角标
|
| | | //
|
| | | // // 以下为决定应该多久后弹出此通知
|
| | | // System.TimeSpan ts = System.DateTime.UtcNow - new System.DateTime (1970, 1, 1, 0, 0, 0, 0);
|
| | | // long ret = System.Convert.ToInt64 (ts.TotalSeconds) + 3;// 表示3秒后
|
| | | // _params ["fireTime"] = ret;
|
| | | #if !UNITY_EDITOR
|
| | | jsonData["code"] = CodeU2A.JPushAddLocalMessage;
|
| | | #if UNITY_ANDROID
|
| | | jsonData["fireTime"] = (long)jsonData["fireTime"] * 1000;
|
| | | #endif
|
| | | SendMessageToSDK(jsonData);
|
| | | #endif
|
| | | }
|
| | |
|
| | | public void GeTui_RemoveLocalMessage(string id)
|
| | | {
|
| | | DebugEx.Log("GeTui_RemoveLocalMessage:" + id);
|
| | | #if !UNITY_EDITOR
|
| | | m_Json.Clear();
|
| | | m_Json["code"] = CodeU2A.JPushRemoveLocalMessage;
|
| | | m_Json["id"] = id;// id 重要, 标示每个通知的更新或者移除
|
| | |
|
| | | SendMessageToSDK(m_Json);
|
| | | #endif
|
| | | }
|
| | |
|
| | | #endregion
|
| | | }
|