From c137cad44e9604642975d553cac18571331ad6b9 Mon Sep 17 00:00:00 2001 From: "yifeng.yl" Date: Fri, 31 May 2019 17:51:41 +0800 Subject: [PATCH] add token ,feedback --- lib/api/api.dart | 5 ++++- lib/event/event_model.dart | 3 ++- lib/utils/data_utils.dart | 11 +++++++++-- lib/utils/net_utils.dart | 15 +++++++++++++-- lib/views/first_page/drawer_page.dart | 8 +++++++- lib/views/login_page/login_page.dart | 4 ++-- lib/views/web_page/web_view_page.dart | 27 +++++++++++++++++++++------ 7 files changed, 58 insertions(+), 15 deletions(-) diff --git a/lib/api/api.dart b/lib/api/api.dart index 9e42dc97..1ac76d44 100644 --- a/lib/api/api.dart +++ b/lib/api/api.dart @@ -1,5 +1,5 @@ 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 DO_LOGIN = BASE_URL+'doLogin';//登陆 @@ -11,5 +11,8 @@ class Api{ static const String GET_USER_INFO = BASE_URL+'getUserInfo';//获取用户信息 static const String RedirectIp = 'http://100.81.211.172/'; + static const String VERSION = BASE_URL+'getAppVersion';//检查版本 + + static const String FEEDBACK = BASE_URL+'feedback';//建议反馈 } \ No newline at end of file diff --git a/lib/event/event_model.dart b/lib/event/event_model.dart index ffe88bf0..301ad47d 100644 --- a/lib/event/event_model.dart +++ b/lib/event/event_model.dart @@ -8,6 +8,7 @@ class CollectionEvent{ class UserGithubOAuthEvent{ final String loginName; + final String token; final bool isSuccess; - UserGithubOAuthEvent(this.loginName,this.isSuccess); + UserGithubOAuthEvent(this.loginName,this.token,this.isSuccess); } \ No newline at end of file diff --git a/lib/utils/data_utils.dart b/lib/utils/data_utils.dart index 40b23daf..c526d146 100644 --- a/lib/utils/data_utils.dart +++ b/lib/utils/data_utils.dart @@ -45,6 +45,13 @@ class DataUtils { } } + // 一键反馈 + static Future feedback(Map params) async { + var response = await NetUtils.post(Api.FEEDBACK, params); + print(response); + return response; + } + // 退出登陆 static Future logout() async { var response = await NetUtils.get(Api.LOGOUT); @@ -60,8 +67,8 @@ class DataUtils { PackageInfo packageInfo = await PackageInfo.fromPlatform(); var localVersion = packageInfo.version; //相同=0、大于=1、小于=-1 -// localVersion = '0.0.2'; -// currVersion = '1.0.6'; + // localVersion = '0.0.2'; + // currVersion = '1.0.6'; if (currVersion.compareTo(localVersion) == 1) { return true; } else { diff --git a/lib/utils/net_utils.dart b/lib/utils/net_utils.dart index 927fa78e..b1992123 100644 --- a/lib/utils/net_utils.dart +++ b/lib/utils/net_utils.dart @@ -20,7 +20,7 @@ class NetUtils { // (dio.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate = // (HttpClient client) { // 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; 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); @@ -39,6 +38,18 @@ class NetUtils { } static Future post(String url, Map 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); return response.data; } diff --git a/lib/views/first_page/drawer_page.dart b/lib/views/first_page/drawer_page.dart index dfe2332c..94b38746 100644 --- a/lib/views/first_page/drawer_page.dart +++ b/lib/views/first_page/drawer_page.dart @@ -1,6 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_go/model/user_info.dart'; import 'package:share/share.dart'; +import 'package:flutter_go/utils/data_utils.dart'; class DrawerPage extends StatefulWidget { final UserInformation userInfo; @@ -83,7 +84,12 @@ class _DrawerPageState extends State { '反馈/建议', style: textStyle, ), - onTap: () {}, + onTap: () { + DataUtils.feedback({'title':"这是客户端 FeedBack title","body":"这是客户端 FeedBack body"}) + .then((result){ + print(result); + }); + }, ), ListTile( leading: Icon( diff --git a/lib/views/login_page/login_page.dart b/lib/views/login_page/login_page.dart index 61232bc0..1b06191e 100644 --- a/lib/views/login_page/login_page.dart +++ b/lib/views/login_page/login_page.dart @@ -61,13 +61,13 @@ class _LoginPageState extends State { } ApplicationEvent.event.on().listen((event) { + print('loginName:${event.loginName} token:${event.token} 1234567'); if (event.isSuccess == true) { // oAuth 认证成功 setState(() { isLoading = true; }); - DataUtils.getUserInfo({'loginName': event.loginName}).then((result) { - print(result); + DataUtils.getUserInfo({'loginName': event.loginName,'token':event.token}).then((result) { setState(() { isLoading = false; }); diff --git a/lib/views/web_page/web_view_page.dart b/lib/views/web_page/web_view_page.dart index e620987f..fe080ae2 100644 --- a/lib/views/web_page/web_view_page.dart +++ b/lib/views/web_page/web_view_page.dart @@ -34,22 +34,37 @@ class _WebViewPageState extends State { super.initState(); flutterWebviewPlugin.onUrlChanged.listen((String url) { print('url change:$url'); - if (url.indexOf('${Api.RedirectIp}loginSuccess') == 0) { - String loginName = url.substring(url.indexOf('=') + 1); - if (ApplicationEvent.event != null) { - ApplicationEvent.event.fire(UserGithubOAuthEvent(loginName, true)); + if (url.indexOf('loginSuccess') > -1) { + String urlQuery = url.substring(url.indexOf('?') + 1); + String loginName, token; + List 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(); // 验证成功 } else if (url.indexOf('${Api.RedirectIp}loginFail') == 0) { // 验证失败 if (ApplicationEvent.event != null) { - ApplicationEvent.event.fire(UserGithubOAuthEvent('', true)); + ApplicationEvent.event.fire(UserGithubOAuthEvent('', '', true)); } flutterWebviewPlugin.close(); } - // if(url == '${Api.RedirectIp}loginSuccess') }); + _collectionControl .getRouterByName(Uri.encodeComponent(widget.title.trim())) .then((list) {