Flutter实现微信支付、微信登录

71次阅读
没有评论

// 微信支付
 
// 插件引用
# 微信支付,插件内也包括分享、微信登录等操作,非常推荐
# 插件地址:https://pub.dev/packages/fluwx
fluwx: ^4.5.5
 
 
// 代码部分
Fluwx fluwx = Fluwx();
fluwx.registerApi(appId:"your Appid",universalLink:" your univerallink ");
fluwx.pay(
    which: Payment(
    appId: result['appid'],
    partnerId: result['partnerid'],
    prepayId: result['prepayid'],
    packageValue: result['package'],
    nonceStr: result['noncestr'],
    // 此处为 int 格式,如果后端返回的int格式则不需要进行额外处理
    timestamp: int.parse(result['timestamp']),
    sign: result['sign'],
));
 
 
// 监听支付回调
var cancelable;
cancelable = WeChat.fluwx.addSubscriber((res)=>{
    if(res.errCode == 0){
        // 这里建议去额外让后端处理支付结果回调
 
        // 支付成功则关闭监听 cancel
        cancelable.cancel(),
        EasyLoading.showToast('支付成功')
    }
});

正文完
 0
wujingquan
版权声明:本站原创文章,由 wujingquan 于2025-05-04发表,共计619字。
转载说明:Unless otherwise specified, all articles are published by cc-4.0 protocol. Please indicate the source of reprint.
评论(没有评论)