using UnityEngine; using LitJson; using UnityEngine.Events; using System.Collections; using System.Collections.Generic; using System.IO; using System; [XLua.LuaCallCSharp] public class SDKUtility : SingletonMonobehaviour { [System.Runtime.InteropServices.DllImport("__Internal")] private static extern void IOSMessageHandle(string json); public enum E_ChargingType { NoCharging = 1, Charging = 2, ChargingFull = 3, } public enum E_ChannelPlatform { Free = 1,// 自由 Mr = 2,// 猫耳 Sp = 3,// 思璞 Js = 4,// 极速 Yj = 5,// 易接 Yl = 6,// 易乐 Xn = 7,// 小牛 Cjm = 8,// 超级梦 } public E_ChannelPlatform ChannelPlatform { get; set; } public static string Yj_AppID { get; private set; } public static string ThirdPartVersion { get; private set; } public static string Yj_SpID { get; private set; } public static string ThirdPartAppID { get; private set; } public static string Yj_BanHao { get; private set; } /// /// sdk初始化是否完成标识 /// 客户端一般需要等待这个值为true才继续逻辑 /// public bool InitFinished { get; private set; } #region 基础定义与回调 /// /// 当前设备电量值 /// public int BatteryLevel { get; private set; } /// /// 设备电量值改变回调 /// public UnityAction OnBatteryLevelChanged; /// /// 当前充电状态 /// public E_ChargingType ChargingType { get; private set; } /// /// 当前充电状态改变回调 /// public UnityAction OnChargingTypeChanged; /// /// 设备信息 /// public DeviceInfo Device { get; private set; } /// /// 设备信息改变回调 /// public UnityAction OnDeviceInfoChanged; /// /// 当前网络状态 /// public NetworkReachability NetworkType { get; private set; } /// /// 当前网络状态改变回调 /// public UnityAction OnNetworkStatusChanged; public static bool builtinAssetCopyFinished { get; private set; } /// /// 是否已经将StreamingAsset拷贝至目标路径 /// public bool AssetCopyFinished { get; private set; } /// /// 安卓设备根目录 /// 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() { Yj_AppID = string.Empty; Yj_SpID = string.Empty; ThirdPartVersion = string.Empty; RegistrationID = string.Empty; AssetCopyFinished = false; ChannelPlatform = E_ChannelPlatform.Free; NetworkType = NetworkReachability.NotReachable; BatteryLevel = 100; #if !UNITY_EDITOR if (InitFinished) { return; } #if UNITY_ANDROID var builtinAssetsCopyFinishVersion = LocalSave.GetString("BuiltInAssetCopyCompleted_Android"); if (string.IsNullOrEmpty(builtinAssetsCopyFinishVersion)) { builtinAssetCopyFinished = false; } else { builtinAssetCopyFinished = VersionConfig.Get().version == builtinAssetsCopyFinishVersion; } #endif #if UNITY_IOS var builtinAssetsCopyFinishVersion = LocalSave.GetString("BuiltInAssetCopyCompleted_IOS"); if (string.IsNullOrEmpty(builtinAssetsCopyFinishVersion)) { builtinAssetCopyFinished = false; } else { builtinAssetCopyFinished = VersionConfig.Get().version == builtinAssetsCopyFinishVersion; } 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; m_Json["appID"] = VersionConfig.Get().appId; SendMessageToSDK(m_Json); #endif StartCoroutine("ProcessNetworkStatus"); } 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) { if (Application.platform == RuntimePlatform.Android) { var dllPath1 = ResourcesPath.Instance.ExternalStorePath + "Assembly-CSharp-firstpass.dll"; if (File.Exists(dllPath1)) { File.Delete(dllPath1); } var dllPath2 = ResourcesPath.Instance.ExternalStorePath + "Assembly-CSharp.dll"; if (File.Exists(dllPath2)) { File.Delete(dllPath2); } } 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 CopyOneAsset(string relationPath) { m_Json.Clear(); m_Json["code"] = CodeU2A.CopyOneAsset; m_Json["fileName"] = relationPath; 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("currentActivity")) { return jo.Call("getApplicationContext"); } } } public string GetSplicePackageID() { var _result = "default"; switch (Application.platform) { case RuntimePlatform.Android: if (ChannelPlatform == E_ChannelPlatform.Sp) { using (AndroidJavaClass _jc = new AndroidJavaClass("com.sp.sdk.utils.SDKManagerUtils")) { using (AndroidJavaObject _jo = _jc.CallStatic("getAssetPropConfig", GetApplicationContext(), "plugin_config.properties")) { _result = _jo.Call("get", "game_id"); } } } else if (ChannelPlatform == E_ChannelPlatform.Mr) { using (AndroidJavaClass _jc = new AndroidJavaClass("com.secondworld.univeralsdk.UniversalUtil")) { _result = _jc.CallStatic("getMetaString", "Mr_GAME_ID"); } } else if (ChannelPlatform == E_ChannelPlatform.Js) { using (AndroidJavaClass _jc = new AndroidJavaClass("com.secondworld.univeralsdk.UniversalUtil")) { _result = _jc.CallStatic("getMetaString", "LL_APPID"); } } else if (ChannelPlatform == E_ChannelPlatform.Free) { _result = "freeplatform"; } else if (ChannelPlatform == E_ChannelPlatform.Yl) { _result = "yileplatform"; } else if (ChannelPlatform == E_ChannelPlatform.Xn) { using (AndroidJavaClass _jc = new AndroidJavaClass("com.secondworld.univeralsdk.UniversalUtil")) { _result = _jc.CallStatic("getMetaString", "XnAppID"); } } else if (ChannelPlatform == E_ChannelPlatform.Cjm) { using (AndroidJavaClass _jc = new AndroidJavaClass("com.secondworld.univeralsdk.UniversalUtil")) { _result = _jc.CallStatic("getMetaString", "SUPERDREAM_APPID"); } } break; case RuntimePlatform.IPhonePlayer: _result = "ios";//ios平台固定返回ios break; } return _result; } 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(); if (_json["imei"] != null) { Device.imei = _json["imei"].ToString(); } else { Device.imei = Device.uniqueID; } 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; var _dict = _json as IDictionary; if (_dict != null && _dict.Contains("channelPlatform")) { var _channelPlatform = _json["channelPlatform"].ToString(); if (!string.IsNullOrEmpty(_channelPlatform)) { if (_channelPlatform.Equals("mr")) { ChannelPlatform = E_ChannelPlatform.Mr; } else if (_channelPlatform.Equals("sp")) { ChannelPlatform = E_ChannelPlatform.Sp; } else if (_channelPlatform.Equals("js")) { ChannelPlatform = E_ChannelPlatform.Js; } else if (_channelPlatform.Equals("yj")) { ChannelPlatform = E_ChannelPlatform.Yj; } else if (_channelPlatform.Equals("yl")) { ChannelPlatform = E_ChannelPlatform.Yl; } else if (_channelPlatform.Equals("xn")) { ChannelPlatform = E_ChannelPlatform.Xn; } else if (_channelPlatform.Equals("cjm")) { ChannelPlatform = E_ChannelPlatform.Cjm; } } } if (ChannelPlatform == E_ChannelPlatform.Yj) { if (_dict.Contains("yj_appid")) { Yj_AppID = _json["yj_appid"].ToString(); } if (_dict.Contains("yj_spid")) { Yj_SpID = _json["yj_spid"].ToString(); } } else if (ChannelPlatform == E_ChannelPlatform.Xn) { if (_dict.Contains("xnappid")) { ThirdPartAppID = _json["xnappid"].ToString(); } if (_dict.Contains("xnversion")) { ThirdPartVersion = _json["xnversion"].ToString(); } } else if (ChannelPlatform == E_ChannelPlatform.Cjm) { if (_dict.Contains("cjmappid")) { ThirdPartAppID = _json["cjmappid"].ToString(); } } if (_dict.Contains("banhao")) { Yj_BanHao = _json["banhao"].ToString(); } 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); OperationLogCollect.Instance.RecordEvent(5); break; case CodeA2U.FreePlatformLoginOk: HandleFreePlatformLoginOk(_json["info"]); OperationLogCollect.Instance.RecordEvent(6); break; case CodeA2U.FreePlatformLoginFail: if (onFreePlatformLoginFail != null) { onFreePlatformLoginFail(); } break; case CodeA2U.FreePlatformLogoutOk: if (onFreePlatformLogoutOk != null) { onFreePlatformLogoutOk(); } FreePlatformInfo = null; break; case CodeA2U.FreePlatformLogoutFail: if (onFreePlatformLogoutFail != null) { onFreePlatformLogoutFail(); } break; case CodeA2U.FreePlatformPayOk: if (onFreePlatformPayOk != null) { onFreePlatformPayOk(); } SnxxzGame.Instance.StartCoroutine(DelayQueryRecharge()); break; case CodeA2U.FreePlatformPayFail: if (onFreePlatformPayFail != null) { onFreePlatformPayFail(); } break; case CodeA2U.FreePlatformPayCancel: if (onFreePlatformPayCancel != null) { onFreePlatformPayCancel(); } break; case CodeA2U.ExitGame: Snxxz.UI.WindowCenter.Instance.Open(); 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; /** * 触发了退出游戏逻辑, 打开二次确认界面 */ public const int ExitGame = 6; #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; public const int CopyOneAsset = 12; /** * 自由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 CreateRole = 106; public const int RoleLogin = 107; public const int RoleLevelUp = 108; public const int TencentLogin = 109; /** * 极光推送 * */ public const int JPushAddLocalMessage = 200; public const int JPushRemoveLocalMessage = 201; /** * IOS特殊需求 */ public const int MakeKeyAndVisible = 300; /** * ClientPackage向sdk发送分包id */ public const int ClientPackage = 400; /** * 发送事件 */ public static int SendRegistEvent = 500; } #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 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 string timeStamp; public string sessionID; public string yjAppId; public string yjSdkId; } 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 onFreePlatfromCheckIDOK; public UnityAction 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("currentActivity"); _jo.Call("BindPhone"); #endif } /// /// 自由SDK登陆 /// public void FreePlatformLogin() { #if !UNITY_EDITOR m_Json.Clear(); m_Json["code"] = CodeU2A.FreePlatformLogin; SendMessageToSDK(m_Json); #endif } public void TencentLogin(string param) { #if !UNITY_EDITOR m_Json.Clear(); m_Json["code"] = CodeU2A.TencentLogin; if (!string.IsNullOrEmpty(param)) { m_Json["param"] = param; } SendMessageToSDK(m_Json); #endif } /// /// 自由SDK登出 /// public void FreePlatformLoginout() { #if !UNITY_EDITOR m_Json.Clear(); m_Json["code"] = CodeU2A.FreePlatformLogout; SendMessageToSDK(m_Json); if (ChannelPlatform == E_ChannelPlatform.Yl) { FreePlatformLogin(); } #endif } public void FreePlatformSwitchAccount() { #if UNITY_ANDROID AndroidJavaClass _jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); AndroidJavaObject _jo = _jc.GetStatic("currentActivity"); _jo.Call("SwitchAccount"); #endif } private Dictionary m_PaymentTable = new Dictionary(); private string m_EncodeKey = "03sujm7gerywdvyd5vkkk772rs4by230"; private IEnumerator DelayQueryRecharge() { yield return WaitingForSecondConst.WaitMS60000; var _package = new CA806_tagCMQueryRecharge(); GameNetSystem.Instance.SendInfo(_package); } /// /// 自由SDK支付 fixed sdk 支付逻辑修改 /// public void FreePlatformPay(string title, float money, string cpInfo) { m_PaymentTable["ProductID"] = "xbqy"; m_PaymentTable["OperatorID"] = VersionConfig.Get().appId; // 取玩家区服ID 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; if (ChannelPlatform == E_ChannelPlatform.Mr) { m_PaymentTable["RechargeChannel"] = "1"; } else if (ChannelPlatform == E_ChannelPlatform.Sp) { m_PaymentTable["RechargeChannel"] = "2"; } else if (ChannelPlatform == E_ChannelPlatform.Js) { m_PaymentTable["RechargeChannel"] = "3"; } else if (ChannelPlatform == E_ChannelPlatform.Yj) { m_PaymentTable["RechargeChannel"] = "5"; } else if (ChannelPlatform == E_ChannelPlatform.Yl) { m_PaymentTable["RechargeChannel"] = "6"; } else if (ChannelPlatform == E_ChannelPlatform.Xn) { m_PaymentTable["RechargeChannel"] = "7"; m_PaymentTable["serverName"] = ServerListCenter.Instance.currentServer.name; m_PaymentTable["prodCode"] = cpInfo; m_PaymentTable["prodName"] = title; m_PaymentTable["prodNum"] = "1"; m_PaymentTable["prodPrice"] = money.ToString(); m_PaymentTable["extraData"] = ""; } else if (ChannelPlatform == E_ChannelPlatform.Cjm) { m_PaymentTable["RechargeChannel"] = "8"; } 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.2460web.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; m_Json["roleID"] = PlayerDatas.Instance.baseData.PlayerID; m_Json["roleName"] = PlayerDatas.Instance.baseData.PlayerName; m_Json["level"] = PlayerDatas.Instance.baseData.LV.ToString(); m_Json["sid"] = ServerListCenter.Instance.currentServer.region_flag; m_Json["serverName"] = ServerListCenter.Instance.currentServer.name; m_Json["familyName"] = PlayerDatas.Instance.baseData.FamilyName; m_Json["job"] = PlayerDatas.Instance.baseData.Job.ToString(); m_Json["money"] = PlayerDatas.Instance.baseData.copper.ToString(); m_Json["gameName"] = VersionConfig.Get().productName; m_Json["vipLevel"] = PlayerDatas.Instance.baseData.VIPLv.ToString(); if (ChannelPlatform == E_ChannelPlatform.Mr) { m_Json["notifyurl"] = _json["notifyurl"]; }else if(ChannelPlatform == E_ChannelPlatform.Xn) { if((_json as IDictionary).Contains("cpSign")) { m_Json["cpSign"] = _json["cpSign"]; }else { Debug.Log("没有收到cpSign: " + message); } } #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(); 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(); 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(_result); result.card_id = authenticationCardId; onFreePlatfromDoIDAuthenticationOk(result); } } } private void HandleCheckIDAuthenticationResult(bool _ok, string _result) { if (_ok) { if (onFreePlatfromCheckIDOK != null) { var result = JsonMapper.ToObject(_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(); } else { FreePlatformInfo.tokenExpire = ""; } if (_iDict.Contains("account")) { FreePlatformInfo.account = json["account"].ToString(); } if (_iDict.Contains("account_id")) { int.TryParse(json["account_id"].ToString(), out FreePlatformInfo.accountID); } if (_iDict.Contains("session_id")) { FreePlatformInfo.sessionID = (string)json["session_id"]; } if (_iDict.Contains("timeStamp")) { FreePlatformInfo.timeStamp = (string)json["timeStamp"]; } FreePlatformInfo.phone = 0; } private void HandleFreePlatformRegisteOk(JsonData json) { BuildFreePlatformInfo(json); } private void HandleFreePlatformLoginOk(JsonData data) { BuildFreePlatformInfo(data); string _url = StringUtility.Contact("http://pub.game.2460web.com:11000/event_receiver?ProductID=xbqy", "&OperatorID=", VersionConfig.Get().appId, "&RegionName=data&RegionID=0&EventID=1105&Time=", DateTime.Now.ToString(), "&AccountID=", FreePlatformInfo.account); if (DebugUtility.Instance.debugAccount) { Debug.Log("请求注册埋点的地址数据: " + _url); } HttpRequest.Instance.RequestHttpGet(_url, HttpRequest.defaultHttpContentType, 1, SendRegistEvent); 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); } public void SendRegistEvent(bool _ok, string _result) { if (_ok) { if (!_result.Equals("0")) { m_Json.Clear(); m_Json["code"] = CodeU2A.SendRegistEvent; SendMessageToSDK(m_Json); } } } public void CreateRoleOk(string roleID, string roleName, string time) { m_Json.Clear(); m_Json["code"] = CodeU2A.CreateRole; m_Json["roleID"] = roleID; m_Json["roleName"] = roleName; m_Json["sid"] = ServerListCenter.Instance.currentServer.region_flag; m_Json["serverName"] = ServerListCenter.Instance.currentServer.name; m_Json["familyName"] = PlayerDatas.Instance.baseData.FamilyName; m_Json["level"] = "1"; m_Json["job"] = PlayerDatas.Instance.baseData.Job.ToString(); m_Json["money"] = PlayerDatas.Instance.baseData.diamond.ToString(); m_Json["gameName"] = VersionConfig.Get().productName; m_Json["vipLevel"] = PlayerDatas.Instance.baseData.VIPLv.ToString(); m_Json["createTime"] = time; SendMessageToSDK(m_Json); } public void RoleLogin(string roleID, string roleName, string lv, string vipLV) { m_Json.Clear(); m_Json["code"] = CodeU2A.RoleLogin; m_Json["roleID"] = roleID; m_Json["roleName"] = roleName; m_Json["sid"] = ServerListCenter.Instance.currentServer.region_flag; m_Json["serverName"] = ServerListCenter.Instance.currentServer.name; m_Json["familyName"] = PlayerDatas.Instance.baseData.FamilyName; m_Json["level"] = PlayerDatas.Instance.baseData.LV; m_Json["job"] = PlayerDatas.Instance.baseData.Job.ToString(); m_Json["money"] = PlayerDatas.Instance.baseData.diamond.ToString(); m_Json["gameName"] = VersionConfig.Get().productName; m_Json["vipLevel"] = PlayerDatas.Instance.baseData.VIPLv.ToString(); SendMessageToSDK(m_Json); } public void RoleLevelUp() { m_Json.Clear(); m_Json["code"] = CodeU2A.RoleLevelUp; m_Json["roleID"] = PlayerDatas.Instance.PlayerId.ToString(); m_Json["roleName"] = PlayerDatas.Instance.baseData.PlayerName; m_Json["sid"] = ServerListCenter.Instance.currentServer.region_flag; m_Json["serverName"] = ServerListCenter.Instance.currentServer.name; m_Json["familyName"] = PlayerDatas.Instance.baseData.FamilyName; m_Json["level"] = PlayerDatas.Instance.baseData.LV; m_Json["job"] = PlayerDatas.Instance.baseData.Job.ToString(); m_Json["money"] = PlayerDatas.Instance.baseData.diamond.ToString(); m_Json["gameName"] = VersionConfig.Get().productName; m_Json["vipLevel"] = PlayerDatas.Instance.baseData.VIPLv.ToString(); m_Json["levelUpTime"] = TimeUtility.AllSeconds.ToString(); 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 }