mirror of
https://github.com/alibaba/flutter-go.git
synced 2025-05-21 23:06:33 +08:00
add token ,feedback
This commit is contained in:
@ -1,5 +1,5 @@
|
|||||||
class Api{
|
class Api{
|
||||||
static const String BASE_URL = 'http://30.10.25.17:6001/';
|
static const String BASE_URL = 'http://30.10.27.34:6001/';
|
||||||
// static const String BASE_URL = 'http://flutter-go.alibaba.net/';
|
// 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';//登陆
|
||||||
@ -11,5 +11,8 @@ class Api{
|
|||||||
static const String GET_USER_INFO = BASE_URL+'getUserInfo';//获取用户信息
|
static const String GET_USER_INFO = BASE_URL+'getUserInfo';//获取用户信息
|
||||||
|
|
||||||
static const String RedirectIp = 'http://100.81.211.172/';
|
static const String RedirectIp = 'http://100.81.211.172/';
|
||||||
|
|
||||||
static const String VERSION = BASE_URL+'getAppVersion';//检查版本
|
static const String VERSION = BASE_URL+'getAppVersion';//检查版本
|
||||||
|
|
||||||
|
static const String FEEDBACK = BASE_URL+'feedback';//建议反馈
|
||||||
}
|
}
|
@ -8,6 +8,7 @@ class CollectionEvent{
|
|||||||
|
|
||||||
class UserGithubOAuthEvent{
|
class UserGithubOAuthEvent{
|
||||||
final String loginName;
|
final String loginName;
|
||||||
|
final String token;
|
||||||
final bool isSuccess;
|
final bool isSuccess;
|
||||||
UserGithubOAuthEvent(this.loginName,this.isSuccess);
|
UserGithubOAuthEvent(this.loginName,this.token,this.isSuccess);
|
||||||
}
|
}
|
@ -45,6 +45,13 @@ class DataUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 一键反馈
|
||||||
|
static Future feedback(Map<String, String> params) async {
|
||||||
|
var response = await NetUtils.post(Api.FEEDBACK, params);
|
||||||
|
print(response);
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
// 退出登陆
|
// 退出登陆
|
||||||
static Future<bool> logout() async {
|
static Future<bool> logout() async {
|
||||||
var response = await NetUtils.get(Api.LOGOUT);
|
var response = await NetUtils.get(Api.LOGOUT);
|
||||||
@ -60,8 +67,8 @@ class DataUtils {
|
|||||||
PackageInfo packageInfo = await PackageInfo.fromPlatform();
|
PackageInfo packageInfo = await PackageInfo.fromPlatform();
|
||||||
var localVersion = packageInfo.version;
|
var localVersion = packageInfo.version;
|
||||||
//相同=0、大于=1、小于=-1
|
//相同=0、大于=1、小于=-1
|
||||||
// localVersion = '0.0.2';
|
// localVersion = '0.0.2';
|
||||||
// currVersion = '1.0.6';
|
// currVersion = '1.0.6';
|
||||||
if (currVersion.compareTo(localVersion) == 1) {
|
if (currVersion.compareTo(localVersion) == 1) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
@ -20,7 +20,7 @@ class NetUtils {
|
|||||||
// (dio.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate =
|
// (dio.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate =
|
||||||
// (HttpClient client) {
|
// (HttpClient client) {
|
||||||
// client.findProxy = (uri) {
|
// client.findProxy = (uri) {
|
||||||
// return "PROXY 30.10.25.17:8888";
|
// return "PROXY 30.10.27.34:8888";
|
||||||
// };
|
// };
|
||||||
// };
|
// };
|
||||||
|
|
||||||
@ -28,7 +28,6 @@ class NetUtils {
|
|||||||
String documentsPath = documentsDir.path;
|
String documentsPath = documentsDir.path;
|
||||||
var dir = new Directory("$documentsPath/cookies");
|
var dir = new Directory("$documentsPath/cookies");
|
||||||
await dir.create();
|
await dir.create();
|
||||||
// print('documentPath:${dir.path}');
|
|
||||||
dio.interceptors.add(CookieManager(PersistCookieJar(dir: dir.path)));
|
dio.interceptors.add(CookieManager(PersistCookieJar(dir: dir.path)));
|
||||||
if (params != null) {
|
if (params != null) {
|
||||||
response = await dio.get(url, queryParameters: params);
|
response = await dio.get(url, queryParameters: params);
|
||||||
@ -39,6 +38,18 @@ class NetUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static Future post(String url, Map<String, dynamic> params) async {
|
static Future post(String url, Map<String, dynamic> params) async {
|
||||||
|
// 设置代理 便于本地 charles 抓包
|
||||||
|
(dio.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate =
|
||||||
|
(HttpClient client) {
|
||||||
|
client.findProxy = (uri) {
|
||||||
|
return "PROXY 30.10.27.34:8888";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
Directory documentsDir = await getApplicationDocumentsDirectory();
|
||||||
|
String documentsPath = documentsDir.path;
|
||||||
|
var dir = new Directory("$documentsPath/cookies");
|
||||||
|
await dir.create();
|
||||||
|
dio.interceptors.add(CookieManager(PersistCookieJar(dir: dir.path)));
|
||||||
var response = await dio.post(url, data: params);
|
var response = await dio.post(url, data: params);
|
||||||
return response.data;
|
return response.data;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_go/model/user_info.dart';
|
import 'package:flutter_go/model/user_info.dart';
|
||||||
import 'package:share/share.dart';
|
import 'package:share/share.dart';
|
||||||
|
import 'package:flutter_go/utils/data_utils.dart';
|
||||||
|
|
||||||
class DrawerPage extends StatefulWidget {
|
class DrawerPage extends StatefulWidget {
|
||||||
final UserInformation userInfo;
|
final UserInformation userInfo;
|
||||||
@ -83,7 +84,12 @@ class _DrawerPageState extends State<DrawerPage> {
|
|||||||
'反馈/建议',
|
'反馈/建议',
|
||||||
style: textStyle,
|
style: textStyle,
|
||||||
),
|
),
|
||||||
onTap: () {},
|
onTap: () {
|
||||||
|
DataUtils.feedback({'title':"这是客户端 FeedBack title","body":"这是客户端 FeedBack body"})
|
||||||
|
.then((result){
|
||||||
|
print(result);
|
||||||
|
});
|
||||||
|
},
|
||||||
),
|
),
|
||||||
ListTile(
|
ListTile(
|
||||||
leading: Icon(
|
leading: Icon(
|
||||||
|
@ -61,13 +61,13 @@ class _LoginPageState extends State<LoginPage> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ApplicationEvent.event.on<UserGithubOAuthEvent>().listen((event) {
|
ApplicationEvent.event.on<UserGithubOAuthEvent>().listen((event) {
|
||||||
|
print('loginName:${event.loginName} token:${event.token} 1234567');
|
||||||
if (event.isSuccess == true) {
|
if (event.isSuccess == true) {
|
||||||
// oAuth 认证成功
|
// oAuth 认证成功
|
||||||
setState(() {
|
setState(() {
|
||||||
isLoading = true;
|
isLoading = true;
|
||||||
});
|
});
|
||||||
DataUtils.getUserInfo({'loginName': event.loginName}).then((result) {
|
DataUtils.getUserInfo({'loginName': event.loginName,'token':event.token}).then((result) {
|
||||||
print(result);
|
|
||||||
setState(() {
|
setState(() {
|
||||||
isLoading = false;
|
isLoading = false;
|
||||||
});
|
});
|
||||||
|
@ -34,22 +34,37 @@ class _WebViewPageState extends State<WebViewPage> {
|
|||||||
super.initState();
|
super.initState();
|
||||||
flutterWebviewPlugin.onUrlChanged.listen((String url) {
|
flutterWebviewPlugin.onUrlChanged.listen((String url) {
|
||||||
print('url change:$url');
|
print('url change:$url');
|
||||||
if (url.indexOf('${Api.RedirectIp}loginSuccess') == 0) {
|
if (url.indexOf('loginSuccess') > -1) {
|
||||||
String loginName = url.substring(url.indexOf('=') + 1);
|
String urlQuery = url.substring(url.indexOf('?') + 1);
|
||||||
if (ApplicationEvent.event != null) {
|
String loginName, token;
|
||||||
ApplicationEvent.event.fire(UserGithubOAuthEvent(loginName, true));
|
List<String> queryList = urlQuery.split('&');
|
||||||
|
for (int i = 0; i < queryList.length; i++) {
|
||||||
|
String queryNote = queryList[i];
|
||||||
|
int eqIndex = queryNote.indexOf('=');
|
||||||
|
if (queryNote.substring(0, eqIndex) == 'loginName') {
|
||||||
|
loginName = queryNote.substring(eqIndex + 1);
|
||||||
|
}
|
||||||
|
if (queryNote.substring(0, eqIndex) == 'accessToken') {
|
||||||
|
token = queryNote.substring(eqIndex + 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if (ApplicationEvent.event != null) {
|
||||||
|
ApplicationEvent.event
|
||||||
|
.fire(UserGithubOAuthEvent(loginName, token, true));
|
||||||
|
}
|
||||||
|
print('ready close');
|
||||||
|
|
||||||
flutterWebviewPlugin.close();
|
flutterWebviewPlugin.close();
|
||||||
// 验证成功
|
// 验证成功
|
||||||
} else if (url.indexOf('${Api.RedirectIp}loginFail') == 0) {
|
} else if (url.indexOf('${Api.RedirectIp}loginFail') == 0) {
|
||||||
// 验证失败
|
// 验证失败
|
||||||
if (ApplicationEvent.event != null) {
|
if (ApplicationEvent.event != null) {
|
||||||
ApplicationEvent.event.fire(UserGithubOAuthEvent('', true));
|
ApplicationEvent.event.fire(UserGithubOAuthEvent('', '', true));
|
||||||
}
|
}
|
||||||
flutterWebviewPlugin.close();
|
flutterWebviewPlugin.close();
|
||||||
}
|
}
|
||||||
// if(url == '${Api.RedirectIp}loginSuccess')
|
|
||||||
});
|
});
|
||||||
|
|
||||||
_collectionControl
|
_collectionControl
|
||||||
.getRouterByName(Uri.encodeComponent(widget.title.trim()))
|
.getRouterByName(Uri.encodeComponent(widget.title.trim()))
|
||||||
.then((list) {
|
.then((list) {
|
||||||
|
Reference in New Issue
Block a user