import 'dart:convert'; // import 'dart:io'; import 'package:bytedesk_kefu/http/bytedesk_base_api.dart'; import 'package:bytedesk_kefu/util/bytedesk_constants.dart'; import 'package:bytedesk_kefu/util/bytedesk_utils.dart'; import 'package:device_info_plus/device_info_plus.dart'; import 'package:devicelocale/devicelocale.dart'; import 'package:package_info/package_info.dart'; class BytedeskDeviceHttpApi extends BytedeskBaseHttpApi { // static final DeviceInfoPlugin deviceInfoPlugin = DeviceInfoPlugin(); // Future setDeviceInfo() async { // if (BytedeskUtils.isWeb) { // } else if (BytedeskUtils.isAndroid) { updateAndroidDeviceInfo(); } else if (BytedeskUtils.isIOS) { updateIOSDeviceInfo(); } else { // TODO: web/windows/mac } } // APP当前版本 // The package version. `CFBundleShortVersionString` on iOS, `versionName` on Android. Future getAppVersion() async { PackageInfo packageInfo = await PackageInfo.fromPlatform(); return packageInfo.version; } // The build number. `CFBundleVersion` on iOS, `versionCode` on Android. Future getAppBuildNumber() async { PackageInfo packageInfo = await PackageInfo.fromPlatform(); return packageInfo.buildNumber; } // 上传安卓设备信息 Future updateAndroidDeviceInfo() async { // Map deviceData = _readAndroidBuildData(await deviceInfoPlugin.androidInfo); // String? locale = await Devicelocale.currentLocale; PackageInfo packageInfo = await PackageInfo.fromPlatform(); var body = json.encode({ "sdkVersion": deviceData['version.sdkInt'], "osVersion": deviceData['version.release'], "deviceModel": deviceData['model'], "brand": deviceData['brand'], "language": locale, "appVersion": packageInfo.version, "appVersionName": packageInfo.buildNumber, "client": client }); // // final initUrl = '$baseUrl/api/fingerprint2/android/deviceInfo'; final initUrl = Uri.http( BytedeskConstants.host, '/api/fingerprint2/android/deviceInfo'); await this.httpClient.post(initUrl, headers: getHeaders(), body: body); } // 上传苹果设备信息 Future updateIOSDeviceInfo() async { // Map deviceData = _readIosDeviceInfo(await deviceInfoPlugin.iosInfo); // String? locale = await Devicelocale.currentLocale; // Locale locale2 = await Devicelocale.currentAsLocale; PackageInfo packageInfo = await PackageInfo.fromPlatform(); var body = json.encode({ "os": deviceData['systemName'], "osVersion": deviceData['systemVersion'], "deviceName": deviceData['name'], "deviceModel": deviceData['utsname.machine'], "appName": packageInfo.appName, "appVersion": packageInfo.version, "language": locale, "appCountry": deviceData[''], // TODO: 获取国家 "client": client }); // // final initUrl = '$baseUrl/api/fingerprint2/ios/deviceInfo'; final initUrl = Uri.http(BytedeskConstants.host, '/api/fingerprint2/ios/deviceInfo'); await this.httpClient.post(initUrl, headers: getHeaders(), body: body); } // 上传苹果deviceToken Future updateIOSDeviceToken( String appkey, String build, String deviceToken) async { // var body = json.encode({ "appkey": appkey, "build": build, "token": deviceToken, "client": client }); // // final initUrl = '$baseUrl/api/push/update/token'; final initUrl = Uri.http(BytedeskConstants.host, '/api/push/update/token'); await this.httpClient.post(initUrl, headers: getHeaders(), body: body); } // 删除设备信息 Future deleteIOSDeviceToken(String build) async { // var body = json.encode({"build": build, "client": client}); // // final initUrl = '$baseUrl/api/push/delete/token'; final initUrl = Uri.http(BytedeskConstants.host, '/api/push/delete/token'); await this.httpClient.post(initUrl, headers: getHeaders(), body: body); } Map _readAndroidBuildData(AndroidDeviceInfo build) { return { 'version.securityPatch': build.version.securityPatch, 'version.sdkInt': build.version.sdkInt, 'version.release': build.version.release, 'version.previewSdkInt': build.version.previewSdkInt, 'version.incremental': build.version.incremental, 'version.codename': build.version.codename, 'version.baseOS': build.version.baseOS, 'board': build.board, 'bootloader': build.bootloader, 'brand': build.brand, 'device': build.device, 'display': build.display, 'fingerprint': build.fingerprint, 'hardware': build.hardware, 'host': build.host, 'id': build.id, 'manufacturer': build.manufacturer, 'model': build.model, 'product': build.product, 'supported32BitAbis': build.supported32BitAbis, 'supported64BitAbis': build.supported64BitAbis, 'supportedAbis': build.supportedAbis, 'tags': build.tags, 'type': build.type, 'isPhysicalDevice': build.isPhysicalDevice, 'androidId': build.androidId, 'systemFeatures': build.systemFeatures, }; } Map _readIosDeviceInfo(IosDeviceInfo data) { return { 'name': data.name, 'systemName': data.systemName, 'systemVersion': data.systemVersion, 'model': data.model, 'localizedModel': data.localizedModel, 'identifierForVendor': data.identifierForVendor, 'isPhysicalDevice': data.isPhysicalDevice, 'utsname.sysname:': data.utsname.sysname, 'utsname.nodename:': data.utsname.nodename, 'utsname.release:': data.utsname.release, 'utsname.version:': data.utsname.version, 'utsname.machine:': data.utsname.machine, }; } }