using Assets.Scripts; using Assets.Scripts.Mobile.Interface; using DG.Tweening; using Facebook.Unity; using Newtonsoft.Json.Linq; using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class LoginControllerMobile : MonoBehaviour, INativeOnMobileWxLoginResp { // Start is called before the first frame update ScrollRect loginScrollView; Transform thirdLoginPage; public WeChatController weChat { get; private set; } void Awake() { loginScrollView = transform.Find("Panel/LoginContainer/LoginScrollView").GetComponent(); thirdLoginPage = loginScrollView.content.Find("FormContainer-Login/Mask/FormContainer-third"); //UIManager.AddEvent(loginScrollView.content.Find("FormContainer-Login/Mask/FormContainer/BtnThirdLogin").gameObject, // UnityEngine.EventSystems.EventTriggerType.PointerClick, // (b)=> ShowThirdLoginPage()); //UIManager.AddEvent(loginScrollView.content.Find("FormContainer-Login/Mask/FormContainer-third/BtnReturn").gameObject, // UnityEngine.EventSystems.EventTriggerType.PointerClick, // (b) => HideThirdLoginPage()); UIManager.AddEvent(loginScrollView.content.Find("FormContainer-Login/Mask/FormContainer/otherContainer/Wechat").gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, (b) => goWxLogin()); } private void Start() { //Utils.showToast(null,"123",duration:10,showSeconds: true); transform.Find("MobileInfo/BatteryText").GetComponent().text = $"{Math.Round(SystemInfo.batteryLevel * 100, 0)}%"; transform.Find("MobileInfo/TimeText").GetComponent().text = DateTime.Now.ToString("HH:mm"); weChat = App.weChatController; weChat.Init(App.WxAppId); transform.Find("Panel/LoginContainer/LoginScrollView/Viewport/Content/FormContainer-Login/Mask/FormContainer/otherContainer/Google") .gameObject.SetActive(Utils.CheckGooglePlayServices()); #if UNITY_IOS transform.Find("Panel/LoginContainer/LoginScrollView/Viewport/Content/FormContainer-Login/Mask/FormContainer/otherContainer/Wechat") .gameObject.SetActive(App.weChatController.IsWeChatAppInstalled()); #endif #if UNITY_IOS UIManager.AddEvent(transform.Find("Panel/LoginContainer/LoginScrollView/Viewport/Content/FormContainer-Login/Mask/FormContainer/otherContainer/Apple").gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, b => { #if UNITY_EDITOR GetComponent() .OnAppleIdLoginCheck("000515.7d1f47f5171b4d66a4bb4a4e7e2c6899.0830", "eyJraWQiOiJZdXlYb1kiLCJhbGciOiJSUzI1NiJ9.eyJpc3MiOiJodHRwczovL2FwcGxlaWQuYXBwbGUuY29tIiwiYXVkIjoiY29tLlpoaVhpbmdQYWkuUG93ZXJGdW4iLCJleHAiOjE2NDAwNDk3NzEsImlhdCI6MTYzOTk2MzM3MSwic3ViIjoiMDAwNTE1LjdkMWY0N2Y1MTcxYjRkNjZhNGJiNGE0ZTdlMmM2ODk5LjA4MzAiLCJjX2hhc2giOiJhekhJdTZNVE1OVGs4Q3RxNndIeHlRIiwiYXV0aF90aW1lIjoxNjM5OTYzMzcxLCJub25jZV9zdXBwb3J0ZWQiOnRydWV9.WM23STabsJqSV1FjPvYRXo3kOB2Cfo7HsPDUuJx8UlqTUthbif1uvhEFpFMF8G5B5_yl3kkmaDtv0nQA25DkDiYowfPVV8gkLx2IMMOm6rVqV5E7kA6xNa64pwgIHDnTSjnn862_DEb4QVkAfi-rXsbkZ1q-EpH5MG-5GLR3Ktq_1n59kQcJrvuvUEpbv8IbSzRLh4VVZLY5rmaoddZ2kg5hw234cwGCmiMxHi55tVHAiGnqgq74IY7HXz3udwRGufaFXpkYbdBuL5-wqAp1SQlQhwpTzhZ5JKr2y4ukejYPFZzLfnkUX0xhLmH8uooKb-TjOa5qaFKGXT0hXh4NHw"); #else App.weChatController.SignWithApple(); #endif }); #else transform.Find("Panel/LoginContainer/LoginScrollView/Viewport/Content/FormContainer-Login/Mask/FormContainer/otherContainer/Apple").gameObject.SetActive(false); #endif UIManager.AddEvent(transform.Find("Panel/LoginContainer/LoginScrollView/Viewport/Content/FormContainer-Login/Mask/FormContainer/otherContainer/Facebook").gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, b => { FB.LogOut(); FB.LogInWithReadPermissions(callback: onFaceBookResp); }); UIManager.AddEvent(transform.Find("Panel/LoginContainer/LoginScrollView/Viewport/Content/FormContainer-Login/Mask/FormContainer/otherContainer/Google").gameObject, UnityEngine.EventSystems.EventTriggerType.PointerClick, b => { #if UNITY_EDITOR OnMobileGoogleLoginResp("true;105370187704207825625|eyJhbGciOiJSUzI1NiIsImtpZCI6ImNhMDA2MjBjNWFhN2JlOGNkMDNhNmYzYzY4NDA2ZTQ1ZTkzYjNjYWIiLCJ0eXAiOiJKV1QifQ.eyJpc3MiOiJodHRwczovL2FjY291bnRzLmdvb2dsZS5jb20iLCJhenAiOiI0OTI0NDAyMDA3NjYtMGZxc2toYjZlYnRhZzFobHFwbzdmbzkzY3VhYXJzbDYuYXBwcy5nb29nbGV1c2VyY29udGVudC5jb20iLCJhdWQiOiI0OTI0NDAyMDA3NjYtZjE0Yjl0OXRtcmF1bGg2N2dxb2JhYTlpc3EzN2cwbmMuYXBwcy5nb29nbGV1c2VyY29udGVudC5jb20iLCJzdWIiOiIxMDUzNzAxODc3MDQyMDc4MjU2MjUiLCJlbWFpbCI6ImNhaXlhbnBlbmcwNjE5QGdtYWlsLmNvbSIsImVtYWlsX3ZlcmlmaWVkIjp0cnVlLCJuYW1lIjoi6JSh5Lil6bmPIiwicGljdHVyZSI6Imh0dHBzOi8vbGgzLmdvb2dsZXVzZXJjb250ZW50LmNvbS9hL0FBVFhBSnhjeWVkS05iZkcwZ3lIbkRhMXpWemVZRGVpdXI3OHUtNWZfbnVWPXM5Ni1jIiwiZ2l2ZW5fbmFtZSI6IuS4pem5jyIsImZhbWlseV9uYW1lIjoi6JShIiwibG9jYWxlIjoiemgtQ04iLCJpYXQiOjE2NDI0ODUxNzEsImV4cCI6MTY0MjQ4ODc3MX0.ZX-9jmB9GaWQEgcv8jbd4Ojy33DiVvl7m_PQZudJEQaLC1S5C6QJOaZRJEHNQ44mWmfSPlHPEhgsEoP-Qn7lKx7r609OuzMYGUE266bdbYer2KzztMtZIUKrI3i0UGLlybQm8YVGJh4vTvtaLZ3Fi2h2aKlDjx4MvFDaQKIwTDsOXzkCmhidYJ4KOhCToZsGIWmR8OhtwhL531p1oV3kOW28nXSbPhl0GalEbu-n970TtpxxQRvJeK61V8R3F29U71pn9PI863xQQ4itWsvQaFNz03pC8RRBGEKN8dvrmTqbKMuoo44fV4pLiY66EqUUoKYST7dOl15zUGfC-ckq5g"); #elif UNITY_IOS App.weChatController.SignWithGoogle(); #else Utils.CallAndroidMethod("signInWithGoogle"); #endif }); //App.weChatController.Init(App.WxAppId); //var s = App.weChatController.isApplicationAvilible("com.gugoumainapp","powerfun").ToString(); //Utils.showToast(null, SystemInfo.batteryLevel.ToString()); CheckUpdate(); } private async void CheckUpdate() { #if UNITY_ANDROID //transform.Find("Panel/LoginContainer/LoginScrollView/Viewport/Content/FormContainer-Login/Mask/FormContainer/BtnThirdLogin") // .gameObject.SetActive(true); #endif var r = await ConfigHelper.userApi.GetVersions(); if (r.result) { #if UNITY_ANDROID || UNITY_IOS #if UNITY_ANDROID var info = r.data.Value("UnityApk"); Debug.Log(info.Value("Version")); if (Utils.isUpdate(App.AppVersion, info.Value("Version"))) { transform.Find("Panel").gameObject.SetActive(false); transform.Find("Version").gameObject.SetActive(false); UIManager.ShowAndroidUpdate(info); } App.WorkoutsUrl = r.data.Value("Apk").Value("Url"); #elif UNITY_IOS //var sw = r.data.Value("ThirdPartSwitch"); //transform.Find("Panel/LoginContainer/LoginScrollView/Viewport/Content/FormContainer-Login/Mask/FormContainer/BtnThirdLogin") // .gameObject.SetActive(sw.Equals("on") && App.weChatController.IsWeChatAppInstalled()); //transform.Find("Panel/LoginContainer/LoginScrollView/Viewport/Content/FormContainer-Login/Mask/FormContainer/BtnThirdLogin") // .gameObject.SetActive(true); var info = r.data.Value("UnityIos"); if (Utils.isUpdate(App.AppVersion, info.Value("Version"))) { Application.OpenURL(info.Value("Url")); Application.Quit(); } App.WorkoutsUrl = r.data.Value("Ios").Value("Url"); #endif #endif } //if (r.result) //{ // //#if !UNITY_EDITOR // var ver = r.data.Value("Version").ToObject(); // if (ver != null && ver.HasUpdate) // { // App.UpdateObject = ver; // Debug.Log(Application.persistentDataPath + "/PowerFun.exe"); // UIManager.ShowDownloadModal(); // } // //#endif // App.notifyContent = r.data.Value("Content"); // if (r.data.Value("Id") != notifyId)//r.data.Value("Id") != notifyId // { // UIManager.ShowNewsModal(); // PlayerPrefs.SetInt("notifyId", r.data.Value("Id")); // } //} } // Update is called once per frame void Update() { } private void ShowThirdLoginPage() { thirdLoginPage.DOLocalMoveY(0, 0.3f); } public void HideThirdLoginPage() { thirdLoginPage.DOLocalMoveY(-301, 0.3f); } private void goWxLogin() { #if !UNITY_EDITOR && (UNITY_ANDROID || UNITY_IOS) if (weChat.IsWeChatAppInstalled()) { weChat.WxLogin("snsapi_userinfo", ""); } #endif } /// /// FaceBook登录返回 /// /// private void onFaceBookResp(ILoginResult res) { Debug.Log(res.ToString()); if (string.IsNullOrEmpty(res.Error)) { if (res.Cancelled) { Utils.showToast(null, App.GetLocalString("User deauthorisation")); } else { GetComponent() .OnFacebookLoginCheck(res.ResultDictionary["user_id"].ToString(), res.ResultDictionary["access_token"].ToString()); Debug.Log("用戶Id" + res.ResultDictionary["user_id"]); } } else { Utils.showToast(null, res.Error); } } /// /// 从ios或者安卓接收code,在c#里不建议调用 /// /// public void OnMobileWxLoginResp(string res) { if (res.Contains("true;")) { GetComponent().goWxLoginWithCode(res.Replace("true;", ""), "mobile"); } else { Utils.showToast(null, res.Replace("false;", "")); } } public void OnMobileGoogleLoginResp(string res) { Debug.Log(res); var sp = res.Replace("true;", "").Split('|'); if (sp.Length == 2) { GetComponent().OnGoogleIdLoginCheck(sp[0], sp[1]); } else { Utils.showToast(null, res.Replace("false;","")); } } public void OnAppleResp(string res) { #if UNITY_IOS var sp = res.Replace("true;", "").Split(','); if (sp.Length == 2) { GetComponent().OnAppleIdLoginCheck(sp[0],sp[1]); } //Utils.showToast(null, "苹果返回"+res); #endif } }