Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
B
base_data_channel
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PublicSource
base_data_channel
Commits
7e9add2c
Commit
7e9add2c
authored
Apr 06, 2023
by
tongzifang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add dio
parent
047a6a5e
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
245 additions
and
2 deletions
+245
-2
GeneratedPluginRegistrant.swift
example/macos/Flutter/GeneratedPluginRegistrant.swift
+2
-0
pubspec.lock
example/pubspec.lock
+72
-0
base_entity.dart
lib/data/base_entity.dart
+25
-0
basedio.dart
lib/http/basedio.dart
+72
-0
baseurl_interceptor.dart
lib/http/baseurl_interceptor.dart
+10
-0
header_interceptor.dart
lib/http/header_interceptor.dart
+30
-0
qmai_host.dart
lib/http/qmai_host.dart
+30
-0
pubspec.yaml
pubspec.yaml
+4
-2
No files found.
example/macos/Flutter/GeneratedPluginRegistrant.swift
View file @
7e9add2c
...
...
@@ -7,10 +7,12 @@ import Foundation
import
base_data_channel
import
path_provider_foundation
import
shared_preferences_foundation
import
sqflite
func
RegisterGeneratedPlugins
(
registry
:
FlutterPluginRegistry
)
{
BaseDataChannelPlugin
.
register
(
with
:
registry
.
registrar
(
forPlugin
:
"BaseDataChannelPlugin"
))
PathProviderPlugin
.
register
(
with
:
registry
.
registrar
(
forPlugin
:
"PathProviderPlugin"
))
SharedPreferencesPlugin
.
register
(
with
:
registry
.
registrar
(
forPlugin
:
"SharedPreferencesPlugin"
))
SqflitePlugin
.
register
(
with
:
registry
.
registrar
(
forPlugin
:
"SqflitePlugin"
))
}
example/pubspec.lock
View file @
7e9add2c
...
...
@@ -248,6 +248,14 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "4.0.2"
http_proxy:
dependency: transitive
description:
name: http_proxy
sha256: "7d5bc7ad1b0c6d0cfb5da97c5bfe302082f93d32cf5c67d484d1a4085b3ffa58"
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.2.1"
image_picker:
dependency: transitive
description:
...
...
@@ -488,6 +496,62 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.27.7"
shared_preferences:
dependency: transitive
description:
name: shared_preferences
sha256: "858aaa72d8f61637d64e776aca82e1c67e6d9ee07979123c5d17115031c1b13b"
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.1.0"
shared_preferences_android:
dependency: transitive
description:
name: shared_preferences_android
sha256: "8304d8a1f7d21a429f91dee552792249362b68a331ac5c3c1caf370f658873f6"
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.1.0"
shared_preferences_foundation:
dependency: transitive
description:
name: shared_preferences_foundation
sha256: cf2a42fb20148502022861f71698db12d937c7459345a1bdaa88fc91a91b3603
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.2.0"
shared_preferences_linux:
dependency: transitive
description:
name: shared_preferences_linux
sha256: "9d387433ca65717bbf1be88f4d5bb18f10508917a8fa2fb02e0fd0d7479a9afa"
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.2.0"
shared_preferences_platform_interface:
dependency: transitive
description:
name: shared_preferences_platform_interface
sha256: fb5cf25c0235df2d0640ac1b1174f6466bd311f621574997ac59018a6664548d
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.2.0"
shared_preferences_web:
dependency: transitive
description:
name: shared_preferences_web
sha256: "74083203a8eae241e0de4a0d597dbedab3b8fef5563f33cf3c12d7e93c655ca5"
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.1.0"
shared_preferences_windows:
dependency: transitive
description:
name: shared_preferences_windows
sha256: "5e588e2efef56916a3b229c3bfe81e6a525665a454519ca51dbcc4236a274173"
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.2.0"
sky_engine:
dependency: transitive
description: flutter
...
...
@@ -501,6 +565,14 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.9.1"
sp_util:
dependency: transitive
description:
name: sp_util
sha256: "9da43dce5de79c17a787d0626bf01538d63090ca32521200d22a232171c495dc"
url: "https://pub.flutter-io.cn"
source: hosted
version: "2.0.3"
sqflite:
dependency: transitive
description:
...
...
lib/data/base_entity.dart
0 → 100644
View file @
7e9add2c
class
BaseEntity
{
int
?
code
;
dynamic
data
;
String
?
message
;
bool
?
status
;
BaseEntity
({
this
.
code
,
this
.
data
,
this
.
message
,
this
.
status
});
BaseEntity
.
fromJson
(
Map
<
String
,
dynamic
>
json
)
{
code
=
json
[
'code'
];
data
=
json
[
'data'
];
message
=
json
[
'message'
];
status
=
json
[
'status'
];
}
Map
<
String
,
dynamic
>
toJson
()
{
final
Map
<
String
,
dynamic
>
data
=
new
Map
<
String
,
dynamic
>();
data
[
'code'
]
=
this
.
code
;
data
[
'data'
]
=
this
.
data
;
data
[
'message'
]
=
this
.
message
;
data
[
'status'
]
=
this
.
status
;
return
data
;
}
}
\ No newline at end of file
lib/http/basedio.dart
0 → 100644
View file @
7e9add2c
import
'dart:io'
;
import
'package:base_data_channel/http/qmai_host.dart'
;
import
'package:dio/dio.dart'
;
import
'package:dio/io.dart'
;
import
'package:http_proxy/http_proxy.dart'
;
import
'package:pretty_dio_logger/pretty_dio_logger.dart'
;
import
'package:sp_util/sp_util.dart'
;
import
'baseurl_interceptor.dart'
;
class
BaseDio
{
BaseDio
.
_
();
static
BaseDio
?
_instance
;
static
BaseDio
?
getInstance
()
{
_instance
??=
BaseDio
.
_
();
return
_instance
;
}
Dio
getDio
()
{
final
Dio
dio
=
Dio
();
dio
.
options
=
BaseOptions
(
receiveTimeout:
Duration
(
seconds:
5
),
connectTimeout:
Duration
(
seconds:
5
),
sendTimeout:
Duration
(
seconds:
5
),
baseUrl:
QmaiHost
.
getBaseUrl
());
// 设置超时时间等 ...
dio
.
interceptors
.
add
(
HeaderInterceptor
());
// 添加拦截器,如 token之类,需要全局使用的参数
dio
.
interceptors
.
add
(
PrettyDioLogger
(
// 添加日志格式化工具类
requestHeader:
true
,
requestBody:
true
,
responseBody:
true
,
responseHeader:
false
,
compact:
false
,
));
checkForCharlesProxy
(
dio
);
// (dio.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate = (client) {
//
// client.badCertificateCallback =
// (X509Certificate cert, String host, int port) {
// return Platform.isAndroid;
// };
// client.findProxy = (uri) {
// //proxy all request to localhost:8888
// // return "PROXY 192.168.100.179:8888";
// return "PROXY 192.168.20.64:8888";
// // return "PROXY 192.168.10.223:8888";
// };
// // 你也可以自己创建一个新的HttpClient实例返回。
// // return new HttpClient(SecurityContext);
// };
return
dio
;
}
void
checkForCharlesProxy
(
Dio
dio
)
async
{
if
(
SpUtil
.
getString
(
'build_type'
)
!=
'release'
)
{
HttpProxy
httpProxy
=
await
HttpProxy
.
createHttpProxy
();
var
proxyHost
=
httpProxy
.
host
;
var
proxyPort
=
httpProxy
.
port
;
if
(
proxyHost
==
null
)
return
;
(
dio
.
httpClientAdapter
as
IOHttpClientAdapter
).
onHttpClientCreate
=
(
client
)
{
client
.
findProxy
=
(
uri
)
=>
"PROXY
$proxyHost
:
$proxyPort
"
;
client
.
badCertificateCallback
=
(
X509Certificate
cert
,
String
host
,
int
port
)
=>
Platform
.
isAndroid
;
};
}
}
}
lib/http/baseurl_interceptor.dart
0 → 100644
View file @
7e9add2c
import
'package:base_data_channel/http/qmai_host.dart'
;
import
'package:dio/dio.dart'
;
class
HeaderInterceptor
extends
Interceptor
{
@override
void
onRequest
(
RequestOptions
options
,
RequestInterceptorHandler
handler
)
{
options
.
baseUrl
=
QmaiHost
.
getBaseUrl
();
super
.
onRequest
(
options
,
handler
);
}
}
lib/http/header_interceptor.dart
0 → 100644
View file @
7e9add2c
import
'package:base_data_channel/http/qmai_host.dart'
;
import
'package:dio/dio.dart'
;
import
'package:sp_util/sp_util.dart'
;
class
HeaderInterceptor
extends
Interceptor
{
@override
void
onRequest
(
RequestOptions
options
,
RequestInterceptorHandler
handler
)
{
var
userToken
=
SpUtil
.
getString
(
'user_token'
);
var
userTokenNew
=
SpUtil
.
getString
(
'user_token_new'
);
Map
<
String
,
dynamic
>
dictionary
=
{
'Accept'
:
'*/*; v=1.0'
,
'Accept-Language'
:
'zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2'
,
'QM-STORE-AUTH'
:
'undefined2'
,
'X-CSRF-TOKEN'
:
'{{csrf_token()}}'
,
'Connection'
:
'close'
,
'Referer'
:
QmaiHost
.
getBasicUrl
(),
'Cookie'
:
'qm_account_token=
$userToken
'
,
'content-type'
:
'application/json'
,
'User-Agent'
:
'wechatdevtools appservice port/62739'
,
'Qm-From-Type'
:
userToken
,
'Authorization'
:
'Bearer
$userToken
'
,
'Qm-Account-Token'
:
userToken
,
'Qm-seller-Token'
:
userTokenNew
,
'Qm-From'
:
'android'
,
};
options
.
headers
.
addAll
(
dictionary
);
super
.
onRequest
(
options
,
handler
);
}
}
lib/http/qmai_host.dart
0 → 100644
View file @
7e9add2c
import
'package:sp_util/sp_util.dart'
;
class
QmaiHost
{
//base copy原生逻辑
static
String
getBaseUrl
()
{
String
?
buildType
=
SpUtil
.
getString
(
'build_type'
);
String
?
organ
=
SpUtil
.
getString
(
'organ'
);
if
(
buildType
==
'debug'
||
buildType
==
'dev'
)
{
return
'http://inapi.zmcms.cn/
$organ
/'
;
}
else
if
(
buildType
==
'shop'
)
{
return
'http://inapi.qimai.shop/
$organ
/'
;
}
else
if
(
buildType
==
'beta'
)
{
return
'http://inapi.qmai.co/
$organ
/'
;
}
else
return
'https://inapi.qmai.cn/
$organ
/'
;
}
//basic copy原生逻辑
static
String
getBasicUrl
()
{
String
?
buildType
=
SpUtil
.
getString
(
'build_type'
);
if
(
buildType
==
'debug'
||
buildType
==
'dev'
)
{
return
'http://qmapp.dev.zmcms.cn/'
;
}
else
if
(
buildType
==
'shop'
)
{
return
'http://qmapp.qimai.shop/'
;
}
else
if
(
buildType
==
'beta'
)
{
return
'http://qmapp.qmai.co/'
;
}
else
return
'http://sellerapp.qmai.cn/'
;
}
}
pubspec.yaml
View file @
7e9add2c
...
...
@@ -32,13 +32,15 @@ dependencies:
flutter_web_plugins
:
sdk
:
flutter
plugin_platform_interface
:
^2.1.4
dio
:
^5.1.1
retrofit
:
^4.0.1
pretty_dio_logger
:
^1.3.1
pigeon
:
^9.2.3
image_picker
:
^0.8.7+1
dotted_border
:
^2.0.0+3
cached_network_image
:
^3.2.3
http_proxy
:
^1.2.1
sp_util
:
^2.0.3
dio
:
^5.1.1
retrofit
:
^4.0.1
flutter_boost
:
git
:
url
:
'
https://github.com/alibaba/flutter_boost.git'
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment