Flutter如何接入银联支付
在Flutter项目中如何集成银联支付SDK?需要哪些步骤和配置?有没有现成的插件可以直接使用,还是需要自己写Platform Channel实现?另外,银联支付对Android和iOS端的配置要求有什么区别?希望能提供一个详细的接入流程或示例代码。
2 回复
Flutter可通过flutter_unionpay插件接入银联支付。步骤:
- 在
pubspec.yaml添加依赖; - 调用
startPay方法,传入交易流水号等参数; - 处理支付结果回调。
需提前向银联申请商户号并配置支付参数。
更多关于Flutter如何接入银联支付的实战系列教程也可以访问 https://www.itying.com/category-92-b0.html
在Flutter中接入银联支付,可以通过以下步骤实现:
-
添加依赖 在
pubspec.yaml中添加银联支付插件:dependencies: union_pay: ^3.0.0 # 使用最新版本 -
配置Android
- 在
android/app/src/main/AndroidManifest.xml中添加权限:<uses-permission android:name="android.permission.INTERNET" /> - 添加银联支付Activity:
<activity android:name="com.unionpay.uppay.PayActivity" android:configChanges="orientation|keyboardHidden|navigation" android:excludeFromRecents="true" android:launchMode="singleTop" />
- 在
-
配置iOS
- 在
ios/Runner/Info.plist中添加白名单:<key>LSApplicationQueriesSchemes</key> <array> <string>uppaywallet</string> <string>uppayx1</string> <string>uppayx2</string> <string>uppayx3</string> </array> - 在
ios/Runner/Info.plist中添加URL Types(用于支付回调):<key>CFBundleURLTypes</key> <array> <dict> <key>CFBundleURLName</key> <string>unionpay</string> <key>CFBundleURLSchemes</key> <array> <string>你的App Scheme</string> </array> </dict> </array>
- 在
-
调用支付
import 'package:union_pay/union_pay.dart'; // 检查是否支持银联支付 bool isSupported = await UnionPay.isInstalled; if (isSupported) { // 发起支付(tn为交易流水号,从后台获取) UnionPayResult result = await UnionPay.pay( tn: '你的交易流水号', mode: UnionPayMode.release, // 或 UnionPayMode.debug ); // 处理支付结果 if (result.code == UnionPayResult.success) { // 支付成功 } else if (result.code == UnionPayResult.fail) { // 支付失败 } else if (result.code == UnionPayResult.cancel) { // 用户取消 } } -
注意事项
- 交易流水号(tn)需由后台调用银联接口生成
- 支付结果建议以后台查询为准
- 测试时使用银联提供的测试账号
建议参考银联官方文档和插件文档进行详细配置。

