platform_api.dart 5.78 KB
import 'package:pigeon/pigeon.dart';

class AppleSignInModel {
  final String userId;
  final String? email;
  final String? nickname;
  final String? identityToken;

  AppleSignInModel({
    required this.userId,
    this.email,
    this.nickname,
    this.identityToken,
  });
}

class GoogleSignInModel {
  final String? email;
  final String? clientID;
  final String idToken;
  final String? nickname;
  final String? avatarUrl;

  GoogleSignInModel({
    this.email,
    this.clientID,
    required this.idToken,
    this.nickname,
    this.avatarUrl,
  });
}

class WatchAppOtherInfo {
  final int? userId;
  final String? nickname;
  final String? markName;

  WatchAppOtherInfo({
    this.userId,
    this.nickname,
    this.markName,
  });
}

class AppleProductInfo {
  /// 苹果商品id
  final String productId;

  /// 苹果商品名称
  final String productName;

  /// 原价描述
  final String originPriceDescription;

  /// 真实价格描述
  final String priceDescription;

  /// 原价格
  final double originPrice;

  /// 真实价格, = 0 代表试用商品
  final double price;

  /// price/unit = 单位价格
  final String unitPrice;

  /// 当前货币符号
  final String currencyCode;

  /// 当前用户是否可以试用
  final bool isTrialPeriod;
  AppleProductInfo({
    required this.productId,
    required this.productName,
    required this.originPriceDescription,
    required this.priceDescription,
    required this.originPrice,
    required this.price,
    required this.unitPrice,
    required this.currencyCode,
    required this.isTrialPeriod,
  });
}

class AppleProductPaymentResult {
  final String productId;
  final String? appAccountToken;
  final String? originalTransactionId;
  final String? transactionId;

  /// success 为空时是支付pending状态,不需要处理
  /// 只有 true/false时才是支付结果出来的时候
  final bool? success;

  /// 错误描述, success = false时取用:
  /// 优先取 errorCode: -1: UUID格式错误, -2: productID查询商品失败,-3:用户取消支付, -4:支付校验失败,-5:未知错误(Apple未知错误)
  /// errorCode 为空时,取用 errorMessage
  final String? errorMessage;
  final int? errorCode;

  AppleProductPaymentResult({
    required this.productId,
    this.appAccountToken,
    this.originalTransactionId,
    this.transactionId,
    this.success,
    this.errorMessage,
    this.errorCode,
  });
}

enum HResourceType {
  image,
  video,
}

@ConfigurePigeon(
  PigeonOptions(
    dartOut: 'lib/pigeon/platform_api.g.dart',
    dartPackageName: 'doublefeel_flutter',
    dartOptions: DartOptions(),
    kotlinOut:
        'android/app/src/main/kotlin/com/doublefeel/app/pigeon/PlatformApi.kt',
    kotlinOptions: KotlinOptions(
      package: 'com.doublefeel.app.pigeon.platform',
    ),
    swiftOut: 'ios/Runner/Pigeon/PlatformApi.swift',
    swiftOptions: SwiftOptions(),
    // arkTSOut: 'ohos/entry/src/main/ets/pigeon/PlatformApi.ets',
    copyrightHeader: 'pigeon/copyright.txt',
  ),
)
@HostApi()
abstract class PlatformHostApi {
  /// 返回完整的 User-Agent 字符串,由 native 侧组装:
  /// `{systemWebViewUA} {appName}/{versionCode}({versionName})({manufacturer}##{brand}##{model}; {OS}{osVersion}; {height}x{width})(huawei)`
  String getFullUserAgent();

  /// 是否是中国大陆地区
  @async
  bool isChinaRegion();

  /// 获取是否开启了通知权限
  /// -1: 已拒绝, 0:需要请求权限, 1:已授权
  @async
  int getApnsAuthStatus();

  /// 申请通知权限
  @async
  bool requestNotificationAuth();

  /// 是否是测试环境
  bool isDebugEnvoriment();

  @async
  bool shareText(String text);
  @async
  bool shareFileData(Uint8List databytes);

  /// 更新用户信息, 有登录态后调用
  /// jsonString: UserPreferences的序列化string
  /// baseUrl: 请求地址, https://api.doublefeel.cn
  void updateLoginInfo(String jsonString, String baseUrl);

  /// 退出登录
  void logout();

  /// 刷新会员信息
  void refreshVip();

  /// 刷新watch app 和 表盘的所有数据:
  /// 任何可能导致展示watch内容变化时调用(好友变化、某些设置导致变化等)
  void refreshWatchAppAndWidgets();

  /// 请求评分弹窗
  @async
  bool requestAppReview();

  /// 跳app应用设置:通知、定位等权限
  bool jumpAppSetting();

  /// 原生处理跳转url
  bool nativeHandleUrl(String urlString);

  /// 从原生拿需要处理的url, 主要场景是点击通知跳转
  String? requestUnhandedUrl();

  /// 请求苹果登录
  @async
  AppleSignInModel? requestAppleSignIn();

  /// google登录
  @async
  GoogleSignInModel? requestGoogleSignIn();

  /// 发送邮件
  @async
  bool sendEmail(String mailTo, String title, String content);

  /// 查询指定id的苹果商品
  /// productId: 苹果商品id
  /// baseUnit: 除数基础单位(多少个天、周、月) ->
  @async
  AppleProductInfo? requestAppleProductInfo(String productId, int baseUnit);

  /// 从服务器下单后请求苹果支付
  @async
  AppleProductPaymentResult? performApplePayment(String productId, String uuid);

  /// 恢复购买
  @async
  bool performRestore();

  /// 获取应用 Documents 目录路径。
  // @async
  // String getApplicationDocumentsPath();

  /// 上传文件到云端
  /// 注意catch flutter error
  @async
  String? uploadFile(String filePath, HResourceType resourceType);

  /// 原生切图片,
  /// imageUrl: 图片本地地址
  /// maxKB: 压缩大小
  /// width.height 切图后输出的大小
  @async
  String? performCropImage(
      String imageUrl, int? maxKB, int? width, int? height);

  /// 发起本地推送
  /// dataType: 0: hr ,1: hrv , 2: sleep
  /// dateTime: 数据对应的时间戳
  @async
  bool sendLocalNotification(
      int dataType, int dateTime, String title, String content, String link);
}