import 'dart:async';

import 'package:zhiying_comm/zhiying_comm.dart';
import 'package:fluwx/fluwx.dart' as fluwx;

////微信支付简单封装
class WxPayUtil {
  static StreamSubscription subscription;

  ////调用此方法
  static  toPay(Map<String, dynamic> params,Function (bool) callback) async {

    subscription = fluwx.weChatResponseEventHandler.listen((res) {
      if (res is fluwx.WeChatPaymentResponse) {
        subscription.cancel();
        callback(res.isSuccessful);
      }
    });

    print(params);
     await payWithWeChat(
      appId: params['appid'].toString(),
      partnerId: params['partnerid'].toString(),
      prepayId: params['prepayid'].toString(),
      packageValue: params['package'].toString(),
      nonceStr: params['noncestr'].toString(),
      timeStamp: int.tryParse(params['timestamp']),
      sign: params['sign'],
    );

    // var payInfo = SyPayInfo();
    // payInfo.appid = params['appid'];
    // payInfo.noncestr = params['noncestr'];
    // payInfo.package = params['package'];
    // payInfo.partnerid = params['partnerid'];
    // payInfo.sign = params['sign'];
    // payInfo.timestamp = params['timestamp'];
    // payInfo.prepayid = params['prepayid'];
    // print("发起微信支付");
    // SyPayResult result = await SyFlutterWechat.pay(payInfo);
    //
    // if (result == SyPayResult.success) {
    //   return true;
    // } else {
    //   return false;
    // }
  }
}
