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. 30
      lib/union/union_select_city.dart

8
lib/address/city_picker_page.dart

@ -57,15 +57,17 @@ class _CityPickerPage extends State<CityPickerPage> {
style: TextStyle( style: TextStyle(
fontSize: 12.sp, fontSize: 12.sp,
color: Colors.black, color: Colors.black,
fontWeight: MyFontWeight.regular), fontWeight: MyFontWeight.regular,
),
), ),
), ),
), ),
Container( Container(
width: 1.w, width: 1.w,
color: Colors.black, color: Colors.black,
margin: margin: EdgeInsets.only(
EdgeInsets.only(top: 2.h, bottom: 2.h, left: 10.w, right: 16.w), top: 2.h, bottom: 2.h, left: 10.w, right: 16.w,
),
), ),
Icon( Icon(
Icons.search, 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 String socketHost = kDebugMode ? '192.168.10.200' : '47.93.216.24';
const int socketPort = 9090; const int socketPort = 9090;
const ipBaseUrl = "http://whois.pconline.com.cn";
/// ///
const localMiniBaseUrl = "http://192.168.10.54:8765/app/"; /// 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(); VipCard();
@JsonKey(includeToJson: false, includeFromJson: false)
Color color = Color(0xFF32A060); Color color = Color(0xFF32A060);
factory VipCard.fromJson(Map<String, dynamic> json) => _$VipCardFromJson(json); factory VipCard.fromJson(Map<String, dynamic> json) => _$VipCardFromJson(json);
Map<String, dynamic> toJson() => _$VipCardToJson(this); Map<String, dynamic> toJson() => _$VipCardToJson(this);
} }

2
lib/main_page.dart

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

2
lib/retrofit/min_api.g.dart

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

19
lib/retrofit/retrofit_api.dart

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

43
lib/retrofit/retrofit_api.g.dart

@ -14,7 +14,7 @@ class _ApiService implements ApiService {
this.baseUrl, this.baseUrl,
this.errorLogger, this.errorLogger,
}) { }) {
baseUrl ??= serviceBaseUrl; baseUrl ??= 'http://192.168.10.54:8766/app/';
} }
final Dio _dio; final Dio _dio;
@ -3744,7 +3744,7 @@ class _ApiService implements ApiService {
} }
@override @override
Future<String?> getIpInfo() async { Future<String> getIpInfo() async {
final _extra = <String, dynamic>{}; final _extra = <String, dynamic>{};
final queryParameters = <String, dynamic>{}; final queryParameters = <String, dynamic>{};
final _headers = <String, dynamic>{}; final _headers = <String, dynamic>{};
@ -3756,7 +3756,7 @@ class _ApiService implements ApiService {
) )
.compose( .compose(
_dio.options, _dio.options,
'/ipJson.jsp', 'http://whois.pconline.com.cn/ipJson.jsp?json=true',
queryParameters: queryParameters, queryParameters: queryParameters,
data: _data, data: _data,
) )
@ -3766,9 +3766,42 @@ class _ApiService implements ApiService {
baseUrl, baseUrl,
))); )));
final _result = await _dio.fetch<String>(_options); final _result = await _dio.fetch<String>(_options);
late String? _value; late String _value;
try { 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) { } on Object catch (e, s) {
errorLogger?.logError(e, s, _options); errorLogger?.logError(e, s, _options);
rethrow; rethrow;

23
lib/union/union_page.dart

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

30
lib/union/union_select_city.dart

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

Loading…
Cancel
Save