diff --git a/Assets/Scripts/LoginAndPay/LoginView.cs b/Assets/Scripts/LoginAndPay/LoginView.cs index d135898..c40f642 100644 --- a/Assets/Scripts/LoginAndPay/LoginView.cs +++ b/Assets/Scripts/LoginAndPay/LoginView.cs @@ -15,11 +15,12 @@ public class LoginView : MonoBehaviour public Text SendCodeButtonText; public Button LoginButton; - public GameObject PhoneTrans; + public GameObject PhoneTrans; public GameObject loginBthTrans; - public Button PhoneLoginButton; + public Button PhoneLoginButton; public Button WxLoginButton; + public Button WxBindButton; // Start is called before the first frame update @@ -27,18 +28,42 @@ public class LoginView : MonoBehaviour { SendCodeButton.onClick.AddListener(SendVerifyCode); LoginButton.onClick.AddListener(Login); - PhoneLoginButton.onClick.AddListener(ClickPhoneLoginButton); + PhoneLoginButton.onClick.AddListener(ClickPhoneLoginButton); WxLoginButton.onClick.AddListener(ClickWxLoginButton); - // 读取缓存的手机号 - if (PlayerPrefs.HasKey("CachedPhoneNumber")) + WxBindButton.onClick.AddListener(ClickWxBindButton); + string cachedPhoneNumber = PlayerPrefs.GetString("CachedPhoneNumber", ""); + string cachedWxUnionId = PlayerPrefs.GetString("CachedWxUnionId", ""); + + if (!string.IsNullOrEmpty(cachedPhoneNumber) || !string.IsNullOrEmpty(cachedWxUnionId)) { - string cachedPhoneNumber = PlayerPrefs.GetString("CachedPhoneNumber"); - if (!string.IsNullOrEmpty(cachedPhoneNumber)) - { - HttpManager.Instance.phoneNum = cachedPhoneNumber; - SceneManager.LoadScene("LoadingScreen"); - } + HttpManager.Instance.phoneNum = cachedPhoneNumber; + HttpManager.Instance.wxUnionID = cachedWxUnionId; + SceneManager.LoadScene("LoadingScreen"); } + else + { + PlayerPrefs.DeleteKey("CachedPhoneNumber"); + PlayerPrefs.DeleteKey("CachedWxUnionId"); + PlayerPrefs.Save(); + NativeBridgeUtil.Instance.loginCallback = WxloginCallback; + } + } + + public void OnDestroy() + { + NativeBridgeUtil.Instance.loginCallback = null; + } + + + public void WxloginCallback(string wxUnionID) + { + // 缓存手机号 + PlayerPrefs.SetString("CachedWxUnionId", wxUnionID); + PlayerPrefs.Save(); + + HttpManager.Instance.wxUnionID = wxUnionID; + isWeChatAuthorized = true; + CheckAuthorized(); } private void SendVerifyCode() @@ -78,7 +103,6 @@ public class LoginView : MonoBehaviour void Login() { LoginTask().Forget(); - NativeBridgeUtil.Instance.WeChatLogin(1); } async UniTask LoginTask() @@ -94,7 +118,9 @@ public class LoginView : MonoBehaviour //ShowHomeView(phonenum); //SceneManager.LoadSceneAsync("LoadingScreen"); HttpManager.Instance.phoneNum = phonenum; - SceneManager.LoadScene("LoadingScreen"); + isPhoneAuthorized = true; + + CheckAuthorized(); } else { @@ -102,9 +128,43 @@ public class LoginView : MonoBehaviour } } - void ClickPhoneLoginButton() - { - + private void CheckAuthorized() + { + if (isWeChatAuthorized && isPhoneAuthorized) + { + SceneManager.LoadScene("LoadingScreen"); + } + else if (isWeChatAuthorized && !isPhoneAuthorized) + { + WxBindButton.gameObject.SetActive(true); + PhoneTrans.SetActive(false); + loginBthTrans.SetActive(false); + } + else if (isPhoneAuthorized && !isWeChatAuthorized) + { + WxBindButton.gameObject.SetActive(false); + PhoneTrans.SetActive(true); + loginBthTrans.SetActive(false); + } + if (!isPhoneAuthorized && !isWeChatAuthorized) + { + WxBindButton.gameObject.SetActive(false); + PhoneTrans.SetActive(false); + loginBthTrans.SetActive(true); + } + } + + // 是否微信授权 + private bool isWeChatAuthorized = false; + + // 是否手机授权 + private bool isPhoneAuthorized = false; + + void ClickPhoneLoginButton() + { + WxBindButton.gameObject.SetActive(false); + PhoneTrans.SetActive(true); + loginBthTrans.SetActive(false); } void ClickWxLoginButton() @@ -112,4 +172,9 @@ public class LoginView : MonoBehaviour NativeBridgeUtil.Instance.WeChatLogin(1); } + void ClickWxBindButton() + { + NativeBridgeUtil.Instance.WeChatLogin(1); + } + } diff --git a/Assets/Scripts/LoginAndPay/http/HttpManager.cs b/Assets/Scripts/LoginAndPay/http/HttpManager.cs index f16f3fe..55459a9 100644 --- a/Assets/Scripts/LoginAndPay/http/HttpManager.cs +++ b/Assets/Scripts/LoginAndPay/http/HttpManager.cs @@ -13,7 +13,9 @@ public class HttpManager : MonoBehaviour string urlHead = GetUrlHead(isZhengShi); [HideInInspector] - public string phoneNum = "13212713350"; + public string phoneNum = ""; + [HideInInspector] + public string wxUnionID = ""; [HideInInspector] public string LastOrderNo; public CIG3StoreProduct LastProduct;