Преглед изворни кода

微信登录注册时增加强制手机绑定

lvjincheng пре 3 година
родитељ
комит
81db27d117

+ 1 - 1
Assets/BowArrow/Scripts/CommonConfig.cs

@@ -58,7 +58,7 @@ public class CommonConfig
                 else if (serverIndex == 1) 
                     return "http://34.238.232.118/SmartBowBusinessServer";
             } 
-            return "http://192.168.137.1:11432/SmartBowBusinessServer";
+            return "http://192.168.101.3:11432/SmartBowBusinessServer";
         }
     }
     //业务服务端WS访问地址

+ 35 - 10
Assets/BowArrow/Scripts/Manager/LoginMgr/LoginView.cs

@@ -4,6 +4,8 @@ using UnityEngine;
 using UnityEngine.UI;
 using UnityEngine.SceneManagement;
 using System.Text.RegularExpressions;
+using Newtonsoft.Json.Linq;
+using JCUnityLib;
 /* 登录界面 */
 public class LoginView : MonoBehaviour
 {
@@ -184,9 +186,7 @@ public class LoginView : MonoBehaviour
                 PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey(res.msg));
                 if (res.code == 0) {
                     string loginToken = (string)res.data;
-                    CommonConfig.businessServerWsURL = loginToken.Split('&')[2];
-                    PlayerPrefs.SetString(LoginMgr.LoginTokenKey, loginToken);
-                    SceneManager.LoadScene("Home", LoadSceneMode.Single);
+                    GoToHome(loginToken);
                 }
             }
         ));
@@ -208,16 +208,36 @@ public class LoginView : MonoBehaviour
         #endif
     }
 
+    private string _loginToken = null;
     public void OnWxLoginResp(string loginCode) {
         if (string.IsNullOrWhiteSpace(loginCode)) return;
         transform.Find("MaskWxLogin").gameObject.SetActive(true);
         StartCoroutine(LoginController.Instance.LoginByWX(loginCode, (res) => {
             Debug.Log($"wxlogin service rescode {res.code}, msg {res.msg}");
             if (res.code == 0) {
-                string loginToken = (string)res.data;
-                CommonConfig.businessServerWsURL = loginToken.Split('&')[2];
-                PlayerPrefs.SetString(LoginMgr.LoginTokenKey, loginToken);
-                SceneManager.LoadScene("Home", LoadSceneMode.Single);
+                JObject data = (JObject)res.data;
+                _loginToken = data.Value<string>("token");
+                bool needBindPhone = data.Value<bool>("needBindPhone");
+                if (needBindPhone)
+                {
+                    transform.Find("MaskWxLogin").gameObject.SetActive(false);
+                    //打开手机绑定界面
+                    RelateValidateView relateValidateView = 
+                            Instantiate(SceneResourceManager.Instance.GetPrefab("RelateValidateView"))
+                                .GetComponent<RelateValidateView>();
+                    CanvasUtils.PlusSortOrder(gameObject.GetComponentInParent<Canvas>().gameObject, relateValidateView.gameObject, 1);
+                    relateValidateView.InitForPhone2();
+                    relateValidateView.onValidateSuccess = (a, b, c) => {
+                        StartCoroutine(UserController.Instance.SavePhone2(_loginToken, a, b, c, (res) => {
+                            if (res.code == 0) {
+                                PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByKey("RelateValidateView-pass1"));
+                                relateValidateView?.CloseView();
+                                DoTweenUtil.CallDelay(0.1f, () => GoToHome(_loginToken));
+                            }
+                        }));
+                    };
+                }
+                else GoToHome(_loginToken);
             } else {
                 transform.Find("MaskWxLogin").gameObject.SetActive(false);
                 PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByKey("wxlogin_fail"));
@@ -225,6 +245,13 @@ public class LoginView : MonoBehaviour
         }));
     }
 
+    private void GoToHome(string loginToken)
+    {
+        CommonConfig.businessServerWsURL = loginToken.Split('&')[2];
+        PlayerPrefs.SetString(LoginMgr.LoginTokenKey, loginToken);
+        SceneManager.LoadScene("Home", LoadSceneMode.Single);
+    }
+
     void LoginByPhone() {
         InputField user = GetInputField(loginInPhone);
         Regex regex = new Regex(@"^(((13[0-9]{1})|(15[0-35-9]{1})|(17[0-9]{1})|(18[0-9]{1}))+\d{8})$");
@@ -238,9 +265,7 @@ public class LoginView : MonoBehaviour
                 PopupMgr.ins.ShowTip(TextAutoLanguage2.GetTextByCNKey(res.msg));
                 if (res.code == 0) {
                     string loginToken = (string)res.data;
-                    CommonConfig.businessServerWsURL = loginToken.Split('&')[2];
-                    PlayerPrefs.SetString(LoginMgr.LoginTokenKey, loginToken);
-                    SceneManager.LoadScene("Home", LoadSceneMode.Single);
+                    GoToHome(loginToken);
                 }
             }
         ));

+ 5 - 1
Assets/BowArrow/Scripts/Network/HttpController/UserController.cs

@@ -8,9 +8,13 @@ using Newtonsoft.Json;
 public class UserController : JCUnityLib.Singleton<UserController>
 {
     public IEnumerator SavePhone(string phone, long timestamp, string sign, Action<RequestResult> callback) {
+        return SavePhone2(PlayerPrefs.GetString(LoginMgr.LoginTokenKey), phone, timestamp, sign, callback);
+    }
+
+    public IEnumerator SavePhone2(string token, string phone, long timestamp, string sign, Action<RequestResult> callback) {
         string url = CommonConfig.gateServerURL + "/gameUser/savePhone";
         WWWForm form = new WWWForm();
-        form.AddField("token", PlayerPrefs.GetString(LoginMgr.LoginTokenKey));
+        form.AddField("token", token);
         form.AddField("phone", phone);
         form.AddField("timestamp", timestamp.ToString());
         form.AddField("sign", sign);