| | |
| | | import 'package:locations/model/map/location_model.dart'; |
| | | import 'package:locations/model/map/location_user_model.dart'; |
| | | import 'package:locations/ui/widget/dialog.dart'; |
| | | import 'package:locations/utils/app_util.dart'; |
| | | import 'package:locations/utils/encrypt_util.dart'; |
| | | import 'package:locations/utils/global.dart'; |
| | | import 'package:locations/utils/string_util.dart'; |
| | | import 'package:locations/utils/ui_utils.dart'; |
| | | import 'package:locations/utils/user_util.dart'; |
| | |
| | | return EncryptUtil.MD5(signStr); |
| | | } |
| | | |
| | | static Future<HttpRequestResult> baseRequest(String api, |
| | | Map<String, dynamic> params, OnHttpRequestStart? onStart) async { |
| | | static Future<HttpRequestResult> baseRequest( |
| | | String api, Map<String, dynamic> params, OnHttpRequestStart? onStart, |
| | | {bool notifyError = false}) async { |
| | | // params ??= {}; |
| | | |
| | | if (Platform.isAndroid) { |
| | |
| | | } |
| | | } |
| | | |
| | | print("androidId:${_androidInfo!.androidId}"); |
| | | print("device:${_androidInfo!.device}"); |
| | | print("type:${_androidInfo!.type}"); |
| | | params["version"] = (await AppUtil.getVersionCode()).toString(); |
| | | |
| | | print("androidInfo:${_androidInfo!.version}"); |
| | | |
| | | //添加附加参数 |
| | | params["timestamp"] = DateTime.now().millisecondsSinceEpoch.toString(); |
| | | params["platform"] = Platform.isAndroid ? "android" : "ios"; |
| | | params["packages"] = "com.dw.zzql"; |
| | | if (Platform.isAndroid) { |
| | | params["device"] = _androidInfo!.device; |
| | | if (Global.utdId != null) { |
| | | params["utdId"] = Global.utdId; |
| | | } |
| | | params["osVersion"] = _androidInfo!.version.release; |
| | | } else if (Platform.isIOS) { |
| | | params["device"] = _iosInfo!.identifierForVendor; |
| | |
| | | params["sign"] = _getSign(params); |
| | | |
| | | var httpClient = HttpClient(); |
| | | httpClient.connectionTimeout = const Duration(seconds: 10); |
| | | httpClient.connectionTimeout = const Duration(seconds: 20); |
| | | var uri = Uri( |
| | | scheme: "http", |
| | | host: "193.112.35.168", |
| | | host: "192.168.3.122", |
| | | path: api, |
| | | port: 8082, |
| | | queryParameters: params); |
| | |
| | | if (onStart != null) { |
| | | onStart(); |
| | | } |
| | | HttpRequestResult requestResult; |
| | | |
| | | try { |
| | | HttpClientRequest request = await httpClient.postUrl(uri); |
| | | var response = await request.close(); |
| | | if (response.statusCode == HttpStatus.ok) { |
| | | String result = await response.transform(const Utf8Decoder()).join(); |
| | | return HttpRequestResult(true, jsonDecode(result)); |
| | | requestResult = HttpRequestResult(true, jsonDecode(result)); |
| | | } else { |
| | | return HttpRequestResult(true, null, msg: "网络请求失败"); |
| | | requestResult = HttpRequestResult(false, null, msg: "网络请求失败"); |
| | | } |
| | | } on TimeoutException catch (_) { |
| | | return HttpRequestResult(true, null, msg: "网络请求超时"); |
| | | requestResult = HttpRequestResult(false, null, msg: "网络请求超时"); |
| | | } on SocketException catch (_) { |
| | | Fluttertoast.showToast(msg: "网络请求出错"); |
| | | return HttpRequestResult(true, null, msg: "网络请求出错"); |
| | | requestResult = HttpRequestResult(false, null, msg: "网络请求出错"); |
| | | } |
| | | if (notifyError && !requestResult.success) { |
| | | ToastUtil.toast(requestResult.msg!); |
| | | } |
| | | return requestResult; |
| | | } |
| | | } |
| | | |
| | |
| | | _showLoading(context); |
| | | }); |
| | | _dismissDialog(context); |
| | | if (result.success) { |
| | | return result.data; |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | static Future<Map<String, dynamic>?> uploadPushRegId( |
| | | BuildContext context, String regId) async { |
| | | var uid = await UserUtil.getUid(); |
| | | var params = {"regId": regId}; |
| | | if (uid != null) { |
| | | params["uid"] = uid.toString(); |
| | | } |
| | | |
| | | var result = |
| | | await HttpUtil.baseRequest("/api/v1/user/uploadPushRegId", params, () { |
| | | }); |
| | | if (result.success) { |
| | | return result.data; |
| | | } |
| | |
| | | var result = |
| | | await HttpUtil.baseRequest("/api/v1/user/loginPhone", params, () { |
| | | _showLoading(context); |
| | | }); |
| | | }, notifyError: true); |
| | | _dismissDialog(context); |
| | | if (result.success) { |
| | | return result.data; |
| | |
| | | return null; |
| | | } |
| | | |
| | | |
| | | ///获取求助信息 |
| | | static Future<Map<String, dynamic>?> addSOSRecord( |
| | | BuildContext context, SimpleLocation location) async { |
| | |
| | | params["address"] = location.address.toString(); |
| | | params["addressDetail"] = location.addressDetail.toString(); |
| | | |
| | | |
| | | var result = |
| | | await HttpUtil.baseRequest("/api/v1/sos/addSOSRecord", params, () { |
| | | await HttpUtil.baseRequest("/api/v1/sos/addSOSRecord", params, () { |
| | | _showLoading(context); |
| | | |
| | | }); |
| | | _dismissDialog(context); |
| | | if (result.success) { |
| | |
| | | } |
| | | return null; |
| | | } |
| | | |
| | | |
| | | ///获取求助信息 |
| | | static Future<Map<String, dynamic>?> listSOSRecord( |
| | |
| | | Map<String, dynamic> params = {"page": page.toString()}; |
| | | params["uid"] = uid.toString(); |
| | | |
| | | var result = |
| | | await HttpUtil.baseRequest("/api/v1/sos/getSOSRecordList", params, () {}); |
| | | var result = await HttpUtil.baseRequest( |
| | | "/api/v1/sos/getSOSRecordList", params, () {}); |
| | | if (result.success) { |
| | | return result.data; |
| | | } |
| | |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | class FeedBackApiUtil { |
| | | ///查阅向我求救的SOS |
| | | static Future<Map<String, dynamic>?> advice( |
| | | BuildContext context, String? type, String content) async { |
| | | var uid = await UserUtil.getUid(); |
| | | Map<String, dynamic> params = {}; |
| | | if (uid != null) { |
| | | params["uid"] = uid.toString(); |
| | | } |
| | | |
| | | if (type != null) { |
| | | params["type"] = type; |
| | | } |
| | | |
| | | params["content"] = content; |
| | | var result = |
| | | await HttpUtil.baseRequest("/api/v1/feedback/advice", params, () { |
| | | _showLoading(context); |
| | | }, notifyError: true); |
| | | |
| | | _dismissDialog(context); |
| | | if (result.success) { |
| | | return result.data; |
| | | } |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | class ConfigApiUtil { |
| | | ///查阅向我求救的SOS |
| | | static Future<Map<String, dynamic>?> getConfig() async { |
| | | var result = await HttpUtil.baseRequest( |
| | | "/api/v1/config/getConfig", {}, () {}, |
| | | notifyError: true); |
| | | if (result.success) { |
| | | return result.data; |
| | | } |
| | | return null; |
| | | } |
| | | } |