当前位置:   article > 正文

flutter——实现支付宝支付tobias_flutter 支付宝支付

flutter 支付宝支付

需求:支付宝支付
使用tobias:https://github.com/OpenFlutter/tobias/blob/master/README_CN.md

1、在yaml里

tobias:
  url_scheme: tobiasexample
  ios:
    ignore_security: true
  • 1
  • 2
  • 3
  • 4

2、info plist里。好像会自动生成

<array>
   <dict>
      <key>CFBundleTypeRole</key>
      <string>Editor</string>
      <key>CFBundleURLName</key>
      <string>alipay</string>
      <key>CFBundleURLSchemes</key>
      <array>
         <string>tobiasexample</string>
      </array>
   </dict>
</array>
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

3、在xcode里的info 的url types

设置好,要和2上面的参数一一对应

4、页面代码:

class PayRequest{
  // 支付宝支付,返回一个对象
  static Future<AliPayEntity> aliPay(String itemName) async{
    final url = "alipay-app-pay/";
    final res = await HttpRequest.request(url,method: "post",
        params: {"item_name":itemName});

    // 解决'_Map<String, dynamic>' is not a subtype of type 'FutureOr<LoginEntity>'的报错
    final Map<String,dynamic> jsonData = res;
    final AliPayEntity aliPayEntity = AliPayEntity.fromJson(jsonData);

    return aliPayEntity;
  }
}


Tobias tobias = Tobias();

// 支付宝支付
Future<void> aliPay() async{
  // 先写死
  String itemName = "600钻石";
  AliPayEntity aliPayEntity = await PayRequest.aliPay(itemName);
  print("支付宝支付,后端返回的${aliPayEntity.orderStr}");
  tobias.pay(aliPayEntity.orderStr);
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Monodyee/article/detail/122880
推荐阅读
相关标签
  

闽ICP备14008679号