mirror of
https://github.com/alibaba/flutter-go.git
synced 2025-05-17 21:05:56 +08:00
cookie 校验
This commit is contained in:
6
android/app/.classpath
Normal file
6
android/app/.classpath
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<classpath>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8/"/>
|
||||||
|
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
|
||||||
|
<classpathentry kind="output" path="bin/default"/>
|
||||||
|
</classpath>
|
23
android/app/.project
Normal file
23
android/app/.project
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>app</name>
|
||||||
|
<comment>Project app created by Buildship.</comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
|
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
|
||||||
|
</natures>
|
||||||
|
</projectDescription>
|
2
android/app/.settings/org.eclipse.buildship.core.prefs
Normal file
2
android/app/.settings/org.eclipse.buildship.core.prefs
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
connection.project.dir=..
|
||||||
|
eclipse.preferences.version=1
|
@ -1,5 +1,6 @@
|
|||||||
class Api{
|
class Api{
|
||||||
static const String BASE_URL = 'http://127.0.0.1:6001/';
|
// static const String BASE_URL = 'http://127.0.0.1:6001/';
|
||||||
|
static const String BASE_URL = 'http://flutter-go.alibaba.net/';
|
||||||
|
|
||||||
static const String DO_LOGIN = BASE_URL+'doLogin';//登陆
|
static const String DO_LOGIN = BASE_URL+'doLogin';//登陆
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ import 'package:fluro/fluro.dart';
|
|||||||
import 'package:flutter/rendering.dart';
|
import 'package:flutter/rendering.dart';
|
||||||
import 'routers/routers.dart';
|
import 'routers/routers.dart';
|
||||||
import 'routers/application.dart';
|
import 'routers/application.dart';
|
||||||
|
import 'package:flutter_spinkit/flutter_spinkit.dart';
|
||||||
import 'package:flutter_go/utils/provider.dart';
|
import 'package:flutter_go/utils/provider.dart';
|
||||||
import 'package:flutter_go/utils/shared_preferences.dart';
|
import 'package:flutter_go/utils/shared_preferences.dart';
|
||||||
import 'package:flutter_go/views/home.dart';
|
import 'package:flutter_go/views/home.dart';
|
||||||
@ -33,6 +33,7 @@ class MyApp extends StatefulWidget {
|
|||||||
|
|
||||||
class _MyAppState extends State<MyApp> {
|
class _MyAppState extends State<MyApp> {
|
||||||
bool _hasLogin = false;
|
bool _hasLogin = false;
|
||||||
|
bool _isLoading = true;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void initState() {
|
void initState() {
|
||||||
@ -40,16 +41,32 @@ class _MyAppState extends State<MyApp> {
|
|||||||
DataUtils.checkLogin().then((hasLogin) {
|
DataUtils.checkLogin().then((hasLogin) {
|
||||||
setState(() {
|
setState(() {
|
||||||
_hasLogin = hasLogin;
|
_hasLogin = hasLogin;
|
||||||
|
_isLoading = false;
|
||||||
});
|
});
|
||||||
|
}).catchError((onError){
|
||||||
|
setState(() {
|
||||||
|
_hasLogin = true;
|
||||||
|
_isLoading = false;
|
||||||
|
});
|
||||||
|
print('身份信息验证失败:$onError');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
showWelcomePage() {
|
showWelcomePage() {
|
||||||
// 暂时关掉欢迎介绍
|
if (_isLoading) {
|
||||||
if (_hasLogin) {
|
return Container(
|
||||||
return AppPage();
|
color: const Color(ThemeColor),
|
||||||
|
child: Center(
|
||||||
|
child: SpinKitPouringHourglass(color: Colors.white),
|
||||||
|
),
|
||||||
|
);
|
||||||
} else {
|
} else {
|
||||||
return LoginPage();
|
// 判断是否已经登录
|
||||||
|
if (_hasLogin) {
|
||||||
|
return AppPage();
|
||||||
|
} else {
|
||||||
|
return LoginPage();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,25 +1,45 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
import 'dart:io';
|
||||||
|
import 'package:cookie_jar/cookie_jar.dart';
|
||||||
import 'package:dio/dio.dart';
|
import 'package:dio/dio.dart';
|
||||||
|
import 'package:path_provider/path_provider.dart';
|
||||||
|
|
||||||
|
Map<String,dynamic> optHeader = {
|
||||||
|
'accept-language':'zh-cn',
|
||||||
|
'content-type':'application/json'
|
||||||
|
};
|
||||||
|
|
||||||
var dio = new Dio();
|
var dio = new Dio(BaseOptions(connectTimeout: 30000,headers: optHeader));
|
||||||
|
|
||||||
class NetUtils {
|
class NetUtils {
|
||||||
|
|
||||||
static Future get(String url,[Map<String,dynamic> params]) async{
|
static Future get(String url, [Map<String, dynamic> params]) async {
|
||||||
var response;
|
var response;
|
||||||
if(params != null){
|
|
||||||
response = await dio.get(url, data: params);
|
// 设置代理 便于本地 charles 抓包
|
||||||
}else{
|
// (dio.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate =
|
||||||
|
// (HttpClient client) {
|
||||||
|
// client.findProxy = (uri) {
|
||||||
|
// return "PROXY 30.10.26.193:8888";
|
||||||
|
// };
|
||||||
|
// };
|
||||||
|
|
||||||
|
Directory documentsDir = await getApplicationDocumentsDirectory();
|
||||||
|
String documentsPath = documentsDir.path;
|
||||||
|
var dir = new Directory("$documentsPath/cookies");
|
||||||
|
await dir.create();
|
||||||
|
// print('documentPath:${dir.path}');
|
||||||
|
dio.interceptors.add(CookieManager(PersistCookieJar(dir: dir.path)));
|
||||||
|
if (params != null) {
|
||||||
|
response = await dio.get(url, queryParameters: params);
|
||||||
|
} else {
|
||||||
response = await dio.get(url);
|
response = await dio.get(url);
|
||||||
}
|
}
|
||||||
|
return response.data;
|
||||||
return response.data;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static Future post(String url,Map<String,dynamic> params) async{
|
static Future post(String url, Map<String, dynamic> params) async {
|
||||||
var response = await dio.post(url, data: params);
|
var response = await dio.post(url, data: params);
|
||||||
return response.data;
|
return response.data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -186,6 +186,7 @@ class _LoginPageState extends State<LoginPage> {
|
|||||||
});
|
});
|
||||||
DataUtils.doLogin({'username': username, 'password': password})
|
DataUtils.doLogin({'username': username, 'password': password})
|
||||||
.then((result) {
|
.then((result) {
|
||||||
|
print(result);
|
||||||
setState(() {
|
setState(() {
|
||||||
isLoading = false;
|
isLoading = false;
|
||||||
});
|
});
|
||||||
|
@ -28,8 +28,10 @@ dependencies:
|
|||||||
# 本地存储、收藏功能
|
# 本地存储、收藏功能
|
||||||
shared_preferences: ^0.4.3
|
shared_preferences: ^0.4.3
|
||||||
flutter_spinkit: "^3.1.0"
|
flutter_spinkit: "^3.1.0"
|
||||||
dio: ^1.0.6
|
path_provider: ^1.0.0
|
||||||
|
dio: ^2.0.15
|
||||||
flutter_webview_plugin: ^0.3.4
|
flutter_webview_plugin: ^0.3.4
|
||||||
|
cookie_jar: ^1.0.0
|
||||||
# 日期格式化
|
# 日期格式化
|
||||||
intl: 0.15.7
|
intl: 0.15.7
|
||||||
city_pickers: ^0.0.1
|
city_pickers: ^0.0.1
|
||||||
|
Reference in New Issue
Block a user