1、导入依赖包
import ‘package:fluwx/fluwx.dart’ as fluwx;
2、初始化设置监听
@override
void initState() {
super.initState();
getMyHeadPic();
// 微信支付代码
fluwx.responseFromPayment.listen((data) {
_result = "${data.errCode}";
print('_result_result > $_result errStrerrStr ${data.errStr}');
if (_result == '-2') {
payState = false;
Util.showToast('用户取消');
}else if(_result == '0'){
payState = true;
Util.showToast('付款成功');
jump2PayForAskDetail();
}else {
payState = false;
}
if (!mounted) return;
setState(() {});
});
youKnowRecognizer.onTap = () {
Util.jump2PrivacyAsk(context,'11','请教服务协议');
};
}
3、在合理的地方调用微信支付代码(将后台数据请求成功后调用)
fluwx.pay(
appId: wxPayInfo.appid,
partnerId: wxPayInfo.partnerid,
prepayId: wxPayInfo.prepayId,
packageValue: wxPayInfo.package,
nonceStr: wxPayInfo.nonceStr,
timeStamp: wxPayInfo.time,
sign: wxPayInfo.sign,
) .then((data) {
print("---》$data");
}).catchError((e){
print('#### $e');
});