void toWxPay() async {
await fluwx.registerWxApi(
doOnAndroid: true,
doOnIOS: true,
appId: wx_appid);
var isInstalled = await fluwx.isWeChatInstalled;
if (!isInstalled) {
ToastUtil.show("请先安装微信");
}
// 将下面这些参数替换成后台返回的即可
var payRes = await fluwx.payWithWeChat(
appId: wx_appid,
partnerId: wx_partnerid,
prepayId: wx_prepayid,
packageValue: wx_package,
nonceStr: wx_noncestr,
timeStamp: int.parse(wx_timestamp),
sign: wx_sign,
);
fluwx.weChatResponseEventHandler.listen((res) {
if (res is fluwx.WeChatPaymentResponse) {
if (res.errCode == 0) {
ToastUtil.show("微信支付成功");
Navigator.of(context).pop();
} else {
ToastUtil.show("微信支付失败");
}
}});
// 支付回调
// 一般情况下打开微信支付闪退,errCode为 -1 ,多半是包名、签名和在微信开放平台创建时的配置不一致。
}