Former-commit-id: 1af2271c88a54ec1f35a4dd5d13fe91b21aee363
TangShanKaiPing
wanggang 6 years ago
parent 4a7cad5546
commit ad60931b15

@ -229,9 +229,9 @@ namespace Assets.Scripts
{
var form = new WWWForm();
form.AddBinaryData("face", jpgBytes);
using (var request = UnityWebRequest.Post(WebViewController.Server + "/Account/FaceLogin", form))
using (var request = UnityWebRequest.Post(WebViewController.FaceLoginUrl, form))
{
text.text = WebViewController.Server;
text.text = WebViewController.FaceLoginUrl;
yield return request.SendWebRequest();
if (request.isNetworkError || request.isHttpError)
{
@ -244,10 +244,7 @@ namespace Assets.Scripts
var result = JsonUtility.FromJson<LoginResult>(response);
if (result.Code == 0)
{
text.text = result.NickName;
result.Server = WebViewController.Server;
result.RememberMe = WebViewController.RememberMe;
WebViewController.LoginMessage = JsonUtility.ToJson(result);
WebViewController.Token = result.Token;
SceneManager.LoadScene(0);
}
}

@ -1,11 +1,5 @@
public class LoginResult
{
public int Code;
public string UserName;
public string NickName;
public string Token;
public string Title;
public string IoTServer;
public string Server;
public bool RememberMe;
}

@ -10,9 +10,8 @@ public class WebViewController : MonoBehaviour
private UniWebView webView;
private SerialDevice _sp;
public static string LoginMessage { get; set; }
public static string Server { get; set; }
public static bool RememberMe { get; set; }
public static string Token { get; set; }
public static string FaceLoginUrl { get; set; }
private void Start()
{
@ -26,22 +25,17 @@ public class WebViewController : MonoBehaviour
};
webView.OnMessageReceived += (view, message) =>
{
if (message.Path == "init")
if (message.Path == "getToken")
{
if (string.IsNullOrEmpty(LoginMessage))
if (!string.IsNullOrEmpty(Token))
{
webView.EvaluateJavaScript($"load()");
}
else
{
webView.EvaluateJavaScript($"load2('{LoginMessage}')");
LoginMessage = null;
this.webView.EvaluateJavaScript($"faceLoginCallback('{Token}')");
Token = null;
}
}
else if (message.Path == "facelogin")
{
Server = UnityWebRequest.UnEscapeURL(Regex.Match(message.RawMessage, "Server=(.*)&").Groups[1].Value);
RememberMe = Regex.Match(message.RawMessage, "RememberMe=(.*)").Groups[1].Value == "true";
FaceLoginUrl = "http://" + UnityWebRequest.UnEscapeURL(Regex.Match(message.RawMessage, "host=(.*)").Groups[1].Value) + "/UserCenter/Account/FaceLogin";
this.FaceLogin();
}
};
@ -52,7 +46,7 @@ public class WebViewController : MonoBehaviour
};
//
webView.CleanCache();
webView.Load(UniWebViewHelper.StreamingAssetURLForPath("wwwroot/index.html"));
webView.Load(UniWebViewHelper.StreamingAssetURLForPath("wwwroot/index2.html"));
webView.Show();
}

@ -24,9 +24,9 @@
<template id="page-login">
<f7-page>
<f7-navbar>
<f7-nav-title>登录</f7-nav-title>
<f7-nav-title>登录2</f7-nav-title>
<f7-nav-right>
<f7-link external panel-open="right" icon-f7="add" v-on:click="FaceLogin(vm.Login.Host,vm.Login.RememberMe)"></f7-link>
<f7-link external panel-open="right" icon-f7="add" v-on:click="FaceLogin(vm.Login.Host)"></f7-link>
</f7-nav-right>
</f7-navbar>
<form v-bind:action="'http://'+vm.Login.Host+'/UserCenter/Account/AppLogin'" v-on:submit.prevent="OnSubmit" class="login">
@ -975,8 +975,14 @@
},
mounted() {
localStorage.removeItem('Token');
if ((window.navigator.userAgent.indexOf("app") > -1)) {
window.location.href = "uniwebview://getToken";
}
},
methods: {
FaceLogin: function (host) {
window.location.href = "uniwebview://facelogin?host=" + encodeURIComponent(host);
},
OnSubmit: function (e) {
if (!$(e.target).valid()) {
return;
@ -1052,7 +1058,7 @@
],
},
Login: {
Host: localStorage.getItem('Host') || 'localhost',
Host: localStorage.getItem('Host') || '192.168.253.1',
UserName: localStorage.getItem('UserName')
},
Home: {

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: fd85ad0316efa844b871a737cee211f0
guid: ec8e9d99389141f42b8a6596cf6f1f51
DefaultImporter:
externalObjects: {}
userData:

@ -67,7 +67,6 @@ namespace UserCenter.Services
public string FindFace(System.Drawing.Bitmap bitmap)
{
bitmap.Save(Path.Combine(this._env.WebRootPath, "temp.bmp"));
var userName = "";
var data = this.GetBytes(bitmap);
using (var faceImage = FaceRecognition.LoadImage(data, bitmap.Height, bitmap.Width, 3))

Loading…
Cancel
Save