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