Browse Source

IP获取城市修改

dart3_last
fff 3 days ago
parent
commit
4f6ee37163
  1. 8
      lib/address/city_picker_page.dart
  2. 2
      lib/constant.dart
  3. 29
      lib/data/mip_data.dart
  4. 30
      lib/data/mip_data.g.dart
  5. 2
      lib/data/vip_card.dart
  6. 2
      lib/main_page.dart
  7. 2
      lib/retrofit/min_api.g.dart
  8. 19
      lib/retrofit/retrofit_api.dart
  9. 43
      lib/retrofit/retrofit_api.g.dart
  10. 23
      lib/union/union_page.dart
  11. 24
      lib/union/union_select_city.dart

8
lib/address/city_picker_page.dart

@ -57,15 +57,17 @@ class _CityPickerPage extends State<CityPickerPage> {
style: TextStyle(
fontSize: 12.sp,
color: Colors.black,
fontWeight: MyFontWeight.regular),
fontWeight: MyFontWeight.regular,
),
),
),
),
Container(
width: 1.w,
color: Colors.black,
margin:
EdgeInsets.only(top: 2.h, bottom: 2.h, left: 10.w, right: 16.w),
margin: EdgeInsets.only(
top: 2.h, bottom: 2.h, left: 10.w, right: 16.w,
),
),
Icon(
Icons.search,

2
lib/constant.dart

@ -11,8 +11,6 @@ const String chatImageHost = "http://skk8mlm5b.hn-bkt.clouddn.com/";
const String socketHost = kDebugMode ? '192.168.10.200' : '47.93.216.24';
const int socketPort = 9090;
const ipBaseUrl = "http://whois.pconline.com.cn";
///
const localMiniBaseUrl = "http://192.168.10.54:8765/app/"; ///
///线

29
lib/data/mip_data.dart

@ -0,0 +1,29 @@
import 'package:json_annotation/json_annotation.dart';
part 'mip_data.g.dart';
@JsonSerializable(explicitToJson: true)
class MIpData {
String? ret;
Mip? data;
MIpData();
factory MIpData.fromJson(Map<String, dynamic> json) => _$MIpDataFromJson(json);
Map<String, dynamic> toJson() => _$MIpDataToJson(this);
}
@JsonSerializable(explicitToJson: true)
class Mip {
String? ip;
List<String>? location;
Mip({this.ip, this.location});
factory Mip.fromJson(Map<String, dynamic> json) => _$MipFromJson(json);
Map<String, dynamic> toJson() => _$MipToJson(this);
}

30
lib/data/mip_data.g.dart

@ -0,0 +1,30 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'mip_data.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
MIpData _$MIpDataFromJson(Map<String, dynamic> json) => MIpData()
..ret = json['ret'] as String?
..data = json['data'] == null
? null
: Mip.fromJson(json['data'] as Map<String, dynamic>);
Map<String, dynamic> _$MIpDataToJson(MIpData instance) => <String, dynamic>{
'ret': instance.ret,
'data': instance.data?.toJson(),
};
Mip _$MipFromJson(Map<String, dynamic> json) => Mip(
ip: json['ip'] as String?,
location: (json['location'] as List<dynamic>?)
?.map((e) => e as String)
.toList(),
);
Map<String, dynamic> _$MipToJson(Mip instance) => <String, dynamic>{
'ip': instance.ip,
'location': instance.location,
};

2
lib/data/vip_card.dart

@ -68,11 +68,11 @@ class VipCard {
VipCard();
@JsonKey(includeToJson: false, includeFromJson: false)
Color color = Color(0xFF32A060);
factory VipCard.fromJson(Map<String, dynamic> json) => _$VipCardFromJson(json);
Map<String, dynamic> toJson() => _$VipCardToJson(this);
}

2
lib/main_page.dart

@ -90,6 +90,8 @@ class _MainPage extends State<MainPage> with WidgetsBindingObserver {
break;
case AppLifecycleState.detached: // APP结束时调用
break;
case AppLifecycleState.hidden:
break;
}
}

2
lib/retrofit/min_api.g.dart

@ -14,7 +14,7 @@ class _MinApiService implements MinApiService {
this.baseUrl,
this.errorLogger,
}) {
baseUrl ??= serviceMiniBaseUrl;
baseUrl ??= 'http://192.168.10.54:8765/app/';
}
final Dio _dio;

19
lib/retrofit/retrofit_api.dart

@ -81,7 +81,6 @@ abstract class ApiService {
BuildContext? context,
String? token,
bool showLoading = false,
bool isIp = false,
bool pay = true,
ParseErrorLogger? errorLogger,
}) {
@ -91,7 +90,6 @@ abstract class ApiService {
}
print("软件当前运行的模式 kReleaseMode:" + (kReleaseMode ? "发布模式" : "调试模式"));
baseUrl = kReleaseMode ? serviceBaseUrl : localBaseUrl;
if (isIp) baseUrl = ipBaseUrl;
dio.options = BaseOptions(
connectTimeout: 30000.milliseconds,
receiveTimeout: 30000.milliseconds,
@ -188,14 +186,12 @@ abstract class ApiService {
@Part(name: "folderId") int folderId, bool isVideo);
///
@GET(
"https://restapi.amap.com/v3/place/around?key=542b46afa8e4b88fe1eb3c4d0ba0872f&location={lat},{lng}&keywords={keywords}&offset={size}&page={page}&extensions=all")
@GET("https://restapi.amap.com/v3/place/around?key=542b46afa8e4b88fe1eb3c4d0ba0872f&location={lat},{lng}&keywords={keywords}&offset={size}&page={page}&extensions=all")
Future<dynamic> searchPoi(@Path("lat") String lat, @Path("lng") String lng,
@Path("keywords") String keywords, int size, int page);
///
@GET(
"https://restapi.amap.com/v3/geocode/regeo?key=542b46afa8e4b88fe1eb3c4d0ba0872f&location={lat},{lng}&extensions=base")
@GET("https://restapi.amap.com/v3/geocode/regeo?key=542b46afa8e4b88fe1eb3c4d0ba0872f&location={lat},{lng}&extensions=base")
Future<dynamic> geocodeRegeo(
@Path("lat") String lat, @Path("lng") String lng);
@ -612,12 +608,15 @@ abstract class ApiService {
///
@GET("/store/storeListByCreditId/{creditGoodsId}")
Future<BaseListData<Store>> storeListByCreditId(
@Path("creditGoodsId") String creditGoodsId);
Future<BaseListData<Store>> storeListByCreditId(@Path("creditGoodsId") String creditGoodsId);
///APP门店推广渠道
@GET("http://whois.pconline.com.cn/ipJson.jsp?json=true")
Future<String> getIpInfo();
///APP门店推广渠道
@GET("/ipJson.jsp")
Future<String?> getIpInfo();
@GET("https://myip.ipip.net/json")
Future<String> getIpInfo1();
// Future<Uint8List> getUrlFile(String url);

43
lib/retrofit/retrofit_api.g.dart

@ -14,7 +14,7 @@ class _ApiService implements ApiService {
this.baseUrl,
this.errorLogger,
}) {
baseUrl ??= serviceBaseUrl;
baseUrl ??= 'http://192.168.10.54:8766/app/';
}
final Dio _dio;
@ -3744,7 +3744,7 @@ class _ApiService implements ApiService {
}
@override
Future<String?> getIpInfo() async {
Future<String> getIpInfo() async {
final _extra = <String, dynamic>{};
final queryParameters = <String, dynamic>{};
final _headers = <String, dynamic>{};
@ -3756,7 +3756,7 @@ class _ApiService implements ApiService {
)
.compose(
_dio.options,
'/ipJson.jsp',
'http://whois.pconline.com.cn/ipJson.jsp?json=true',
queryParameters: queryParameters,
data: _data,
)
@ -3766,9 +3766,42 @@ class _ApiService implements ApiService {
baseUrl,
)));
final _result = await _dio.fetch<String>(_options);
late String? _value;
late String _value;
try {
_value = _result.data;
_value = _result.data!;
} on Object catch (e, s) {
errorLogger?.logError(e, s, _options);
rethrow;
}
return _value;
}
@override
Future<String> getIpInfo1() async {
final _extra = <String, dynamic>{};
final queryParameters = <String, dynamic>{};
final _headers = <String, dynamic>{};
const Map<String, dynamic>? _data = null;
final _options = _setStreamType<String>(Options(
method: 'GET',
headers: _headers,
extra: _extra,
)
.compose(
_dio.options,
'https://myip.ipip.net/json',
queryParameters: queryParameters,
data: _data,
)
.copyWith(
baseUrl: _combineBaseUrls(
_dio.options.baseUrl,
baseUrl,
)));
final _result = await _dio.fetch<String>(_options);
late String _value;
try {
_value = _result.data!;
} on Object catch (e, s) {
errorLogger?.logError(e, s, _options);
rethrow;

23
lib/union/union_page.dart

@ -1,5 +1,6 @@
import 'dart:convert';
import 'dart:io';
import 'dart:typed_data';
import 'package:device_info_plus/device_info_plus.dart';
import 'package:dio/dio.dart';
@ -10,6 +11,7 @@ import 'package:geolocator/geolocator.dart';
import 'package:get/utils.dart';
import 'package:huixiang/constant.dart';
import 'package:huixiang/data/ip_data.dart';
import 'package:huixiang/data/mip_data.dart';
import 'package:huixiang/generated/l10n.dart';
import 'package:huixiang/main.dart';
import 'package:huixiang/retrofit/retrofit_api.dart';
@ -197,18 +199,14 @@ class UnionPageState extends State<UnionPage>
queryIpInfo() async {
S.current.zhengzaijiazai.loading;
try {
ApiService apiIpService = ApiService(Dio(), context: context, isIp: true);
String? baseData = await apiIpService.getIpInfo().catchError((onError) {
debugPrint("onError: ${onError}");
return Future.value(null);
ApiService apiIpService = ApiService(Dio(), context: context);
String ipResult = await apiIpService.getIpInfo1().catchError((onError) {
return "";
});
if (baseData?.isNotEmpty ?? false) {
debugPrint("baseData: ${baseData}");
String ipDataStr = baseData!
.replaceAll("if(window.IPCallBack) {IPCallBack(", "")
.replaceAll(");}", "");
IpData ipData = IpData.fromJson(jsonDecode(ipDataStr));
areaName = ipData.city?.replaceAll("", "");
if (ipResult.isNotEmpty) {
String string = ipResult.replaceAll("\n", "");
MIpData ipData = MIpData.fromJson(jsonDecode(string));
areaName = ipData.data?.location?[2];
}
} finally {
getLocation(showLoading: false);
@ -218,8 +216,9 @@ class UnionPageState extends State<UnionPage>
loadFinish({bool showLoading = true}) {
SmartDialog.dismiss(status: SmartStatus.loading);
if (showLoading)
if (showLoading) {
S.current.zhengzaijiazai.loading;
}
_allKey = [GlobalKey(), GlobalKey(), GlobalKey(), GlobalKey()];
setState(() {});
}

24
lib/union/union_select_city.dart

@ -3,12 +3,13 @@ import 'dart:convert';
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:huixiang/data/ip_data.dart';
import 'package:huixiang/data/mip_data.dart';
import 'package:huixiang/retrofit/retrofit_api.dart';
import 'package:huixiang/utils/font_weight.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import '../data/ip_data.dart';
import '../retrofit/retrofit_api.dart';
class UnionSelectCity extends StatefulWidget {
final Map<String, dynamic>? arguments;
@ -23,7 +24,6 @@ class UnionSelectCity extends StatefulWidget {
class _UnionSelectCity extends State<UnionSelectCity> {
RefreshController refreshController = RefreshController();
late Map<String, dynamic> areaMap;
ApiService? apiIpService;
String? ipName;
int ipState = 0;
List<String> hotCity = [];
@ -60,19 +60,19 @@ class _UnionSelectCity extends State<UnionSelectCity> {
}
queryIpInfo() async {
apiIpService = ApiService(
ApiService? apiIpService = ApiService(
Dio(),
context: context,
isIp: true
);
String? baseData = await apiIpService?.getIpInfo().catchError((onError) {});
if (baseData?.isNotEmpty ?? false) {
print("baseData: ${baseData}");
String ipDataStr = baseData!.replaceAll("if(window.IPCallBack) {IPCallBack(", "").replaceAll(");}", "");
IpData ipData = IpData.fromJson(jsonDecode(ipDataStr));
ipName = ipData.city?.replaceAll("", "");
String ipResult = await apiIpService.getIpInfo1().catchError((onError) {
return "";
});
if (ipResult.isNotEmpty) {
String string = ipResult.replaceAll("\n", "");
MIpData ipData = MIpData.fromJson(jsonDecode(string));
ipName = ipData.data?.location?[2];
}
if(ipName != widget.arguments?["cityName"] ){
if (ipName != widget.arguments?["cityName"] && (ipName?.isNotEmpty ?? false)) {
ipState = 2;
setState((){});
}

Loading…
Cancel
Save