| | |
| | | import 'dart:convert'; |
| | | import 'dart:io'; |
| | | |
| | | import 'package:cookie_jar/cookie_jar.dart'; |
| | | import 'package:device_info/device_info.dart'; |
| | | import 'package:dio/adapter.dart'; |
| | | import 'package:dio/dio.dart'; |
| | | import 'package:dio_cookie_manager/dio_cookie_manager.dart'; |
| | | import 'package:flutter/cupertino.dart'; |
| | | import 'package:flutter/material.dart'; |
| | | import '../../utils/des/des.dart'; |
| | | import '../../utils/share_preference.dart'; |
| | | |
| | | import '../../utils/share_preference.dart'; |
| | | import '../model/common/http_model.dart'; |
| | | import '../ui/widget/dialog.dart'; |
| | | import '../utils/app_util.dart'; |
| | |
| | | List list = []; |
| | | //签名 |
| | | params.forEach((key, value) { |
| | | list.add("$key=$value"); |
| | | print(value.runtimeType); |
| | | //文件不参与签名 |
| | | if(value.runtimeType.toString() != "_File"&&value.runtimeType.toString() != "MultipartFile") { |
| | | list.add("$key=$value"); |
| | | } |
| | | }); |
| | | //排序 |
| | | list.sort(); |
| | |
| | | list.forEach((element) { |
| | | signStr += element + "&"; |
| | | }); |
| | | print("签名字符串:$signStr"); |
| | | |
| | | if (signStr.endsWith("&")) { |
| | | signStr = signStr.substring(0, signStr.length - 1); |
| | | } |
| | | |
| | | signStr += "8888B&*@-uWan88/',@@^"; |
| | | signStr += "BuWan*@_%MakeMoney!!"; |
| | | |
| | | return EncryptUtil.MD5(signStr); |
| | | } |
| | | |
| | | static String _decode(String content) { |
| | | String key = utf8.decode(base64Decode("VW1nT3R2WVk=")); |
| | | String iv = utf8.decode(base64Decode("WXlIeEhsY0o=")); |
| | | // static String _decode(String content) { |
| | | // String key = utf8.decode(base64Decode("VW1nT3R2WVk=")); |
| | | // String iv = utf8.decode(base64Decode("WXlIeEhsY0o=")); |
| | | // |
| | | // List<int> result = |
| | | // DES().decryptWithCBC(base64Decode(content), key.codeUnits, iv: iv); |
| | | // |
| | | // return utf8.decode(result); |
| | | // } |
| | | |
| | | List<int> result = |
| | | DES().decryptWithCBC(base64Decode(content), key.codeUnits, iv: iv); |
| | | |
| | | return utf8.decode(result); |
| | | } |
| | | |
| | | static Future<Map<String, dynamic>> getBaseParams( |
| | | Map<String, dynamic>? params) async { |
| | | static Future<dynamic> getBaseParams(Map<String, dynamic>? params) async { |
| | | params ??= {}; |
| | | |
| | | //判断params中是否有文件类型 |
| | | List<String> fileKeys = []; |
| | | params.forEach((key, value) async { |
| | | print("$key: ${value.runtimeType}"); |
| | | if (value.runtimeType.toString() == "_File") { |
| | | fileKeys.add(key); |
| | | } |
| | | }); |
| | | |
| | | for (int i = 0; i < fileKeys.length; i++) { |
| | | params[fileKeys[i]] = |
| | | await MultipartFile.fromFile((params[fileKeys[i]] as File).path); |
| | | } |
| | | |
| | | if (Platform.isIOS) { |
| | | String finalParams = |
| | | await dataMethodChannel.invokeMethod("getBaseRequestParams", params); |
| | | await dataMethodChannel.invokeMethod("getBaseRequestParams", params); |
| | | return jsonDecode(finalParams); |
| | | } |
| | | if (Platform.isAndroid) { |
| | |
| | | _androidInfo = await deviceInfo.androidInfo; |
| | | } |
| | | print("androidInfo:${_androidInfo!.version}"); |
| | | params["Version"] = (await AppUtil.getVersionCode()).toString(); |
| | | params["version"] = (await AppUtil.getVersionCode()).toString(); |
| | | } else if (Platform.isIOS) { |
| | | if (_iosInfo == null) { |
| | | DeviceInfoPlugin deviceInfo = DeviceInfoPlugin(); |
| | | _iosInfo = await deviceInfo.iosInfo; |
| | | } |
| | | params["Version"] = "105"; |
| | | params["version"] = "105"; |
| | | } |
| | | |
| | | //添加附加参数 |
| | | params["Timestamp"] = DateTime.now().millisecondsSinceEpoch.toString(); |
| | | params["Platform"] = "Android"; // Platform.isAndroid ? "Android" : "IOS"; |
| | | params["Package"] = "com.hanju.video"; |
| | | params["System"] = "1"; |
| | | params["timestamp"] = DateTime.now().millisecondsSinceEpoch.toString(); |
| | | params["platform"] = "android"; // Platform.isAndroid ? "Android" : "IOS"; |
| | | params["packages"] = "com.yeshi.makemoney.video"; |
| | | Global.utdId = "testtest"; |
| | | Global.channel = "QQ"; |
| | | if (Platform.isAndroid) { |
| | | if (Global.utdId != null) { |
| | | params["UtdId"] = Global.utdId; |
| | | params["Device"] = Global.utdId; |
| | | params["utdId"] = Global.utdId; |
| | | } |
| | | params["osVersion"] = _androidInfo!.version.release; |
| | | } else if (Platform.isIOS) { |
| | | params["Device"] = "test123123"; //_iosInfo!.identifierForVendor; |
| | | params["device"] = "test123123"; //_iosInfo!.identifierForVendor; |
| | | } |
| | | |
| | | if (Global.channel != null) { |
| | | params["Channel"] = Global.channel; |
| | | params["channel"] = Global.channel; |
| | | } |
| | | |
| | | //青少年模式 |
| | | params["YouthMode"] = false; |
| | | params["sign"] = _getSign(params); |
| | | |
| | | params["Sign"] = _getSign(params); |
| | | |
| | | return params; |
| | | return fileKeys.isNotEmpty ? FormData.fromMap(params) : params; |
| | | } |
| | | |
| | | static var cookieJar = CookieJar(); |
| | | |
| | | static Future<HttpRequestResult> baseRequest(BuildContext context, String api, |
| | | Map<String, dynamic> params, OnHttpRequestStart? onStart, |
| | | {bool notifyError = false}) async { |
| | | // params ??= {}; |
| | | params = await getBaseParams(params); |
| | | dynamic paramsNew = await getBaseParams(params); |
| | | |
| | | if (onStart != null) { |
| | | onStart(); |
| | |
| | | try { |
| | | var dio = Dio() |
| | | ..options = BaseOptions( |
| | | baseUrl: "http://api.hanju.goxcw.com:8089/BuWan", |
| | | baseUrl: "http://api.dsp.yeshitv.com", |
| | | connectTimeout: 20000, |
| | | receiveTimeout: 1000 * 60, |
| | | contentType: "application/x-www-form-urlencoded"); |
| | | dio.interceptors.add(CookieManager(cookieJar)); |
| | | //设置代理 |
| | | (dio.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate = |
| | | (HttpClient client) { |
| | | client.findProxy = (uri) { |
| | | return 'PROXY 192.168.3.122:8888'; |
| | | }; |
| | | client.badCertificateCallback = |
| | | (X509Certificate cert, String host, int port) => true; |
| | | }; |
| | | // (dio.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate = |
| | | // (HttpClient client) { |
| | | // client.findProxy = (uri) { |
| | | // return 'PROXY 192.168.3.122:8888'; |
| | | // }; |
| | | // client.badCertificateCallback = |
| | | // (X509Certificate cert, String host, int port) => true; |
| | | // }; |
| | | |
| | | // FormData formData = FormData.fromMap(params); |
| | | var response = await dio.post( |
| | | api, |
| | | data: params, |
| | | data: paramsNew, |
| | | onSendProgress: (int sent, int total) { |
| | | print('$sent $total'); |
| | | }, |
| | | ); |
| | | if (response.statusCode == HttpStatus.ok) { |
| | | String result = response.data.toString(); |
| | | result = _decode(result); |
| | | // result = _decode(result); |
| | | print("网络请求结果:$result"); |
| | | requestResult = HttpRequestResult(true, jsonDecode(result)); |
| | | } else { |