x_jpush_assemble_control.dart 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import 'package:get/get.dart';
  2. import '../models/index.dart';
  3. import '../utils/index.dart';
  4. import '../values/index.dart';
  5. class JpushAssembleControlService extends GetxService {
  6. static JpushAssembleControlService get to => Get.find();
  7. String baseUrl() {
  8. return O2ApiManager.instance.getModuleBaseUrl(
  9. O2DistributeModuleEnum.x_jpush_assemble_control) ?? '';
  10. }
  11. ///
  12. /// 绑定设备号
  13. ///
  14. Future<ValueBoolData?> bindDevice(String deviceName) async {
  15. try {
  16. JPushDeviceData deviceData = JPushDeviceData(deviceName: deviceName, pushType: O2.jPushType, deviceType: GetPlatform.isAndroid ? 'android' : 'ios');
  17. ApiResponse response = await O2HttpClient.instance
  18. .post('${baseUrl()}jaxrs/device/bind', deviceData.toJson());
  19. return ValueBoolData.fromJson(response.data);
  20. } catch (err, stackTrace) {
  21. OLogger.e('绑定设备失败', err, stackTrace);
  22. }
  23. return null;
  24. }
  25. ///
  26. /// 解除绑定
  27. ///
  28. Future<ValueBoolData?> unBindDevice(String deviceName) async {
  29. try {
  30. var deviceType = GetPlatform.isAndroid ? 'android' : 'ios';
  31. ApiResponse response = await O2HttpClient.instance
  32. .get('${baseUrl()}jaxrs/device/unbind/new/$deviceName/$deviceType/${O2.jPushType}');
  33. return ValueBoolData.fromJson(response.data);
  34. } catch (err, stackTrace) {
  35. OLogger.e('解绑设备失败', err, stackTrace);
  36. }
  37. return null;
  38. }
  39. }